Example #1
0
File: unpack.c Project: bcg/msgpack
static VALUE template_execute_rescue_enc(VALUE data)
{
	rb_gc_enable();
	VALUE* resc = (VALUE*)data;
	rb_enc_set_index(resc[0], (int)resc[1]);
	RERAISE;
}
Example #2
0
void  rho_ruby_enable_gc(VALUE val)
{
    if ( val == Qtrue )
        rb_gc_enable();
    else
        rb_gc_disable();
}
Example #3
0
static VALUE
newobj_tramp()
{
  VALUE ret = rb_newobj();
  struct obj_track *tracker = NULL;

  if (track_objs && objs) {
    tracker = malloc(sizeof(*tracker));

    if (tracker) {
      if (ruby_current_node && ruby_current_node->nd_file &&
          *ruby_current_node->nd_file) {
        tracker->source = ruby_current_node->nd_file;
        tracker->line = nd_line(ruby_current_node);
      } else if (ruby_sourcefile) {
        tracker->source = ruby_sourcefile;
        tracker->line = ruby_sourceline;
      } else {
        tracker->source = NULL;
        tracker->line = 0;
      }

      tracker->obj = ret;
      rb_gc_disable();
      st_insert(objs, (st_data_t)ret, (st_data_t)tracker);
      rb_gc_enable();
    } else {
      fprintf(stderr, "Warning, unable to allocate a tracker. "
              "You are running dangerously low on RAM!\n");
    }
  }

  return ret;
}
Example #4
0
static void
ca_check_mem_count()
{
  VALUE is_gc_disabled = rb_gc_enable();
  if ( is_gc_disabled ) {
    rb_gc_disable();
    return;
  }
  else if ( ca_mem_count > (ca_gc_interval * MB) ) {
    rb_gc();
    ca_mem_count = 0;
  }
}
Example #5
0
VALUE require_compiled(VALUE fname, VALUE* result)
{
    VALUE path;
    char* szName1 = 0;

    rb_funcall(fname, rb_intern("sub!"), 2, rb_str_new2(".rb"), rb_str_new2("") );

    szName1 = RSTRING_PTR(fname);
    if ( strcmp("strscan",szName1)==0 || strcmp("enumerator",szName1)==0 ||
        strcmp("stringio",szName1)==0 || strcmp("socket",szName1)==0 ||
        strcmp("digest.so",szName1)==0 || strcmp("openssl.so",szName1)==0 ||
        strcmp("fcntl",szName1)==0 || strcmp("digest/md5",szName1)==0 ||
        strcmp("digest/sha1",szName1)==0 )
        return Qtrue;

    if ( isAlreadyLoaded(fname) == Qtrue )
        return Qtrue;

    //RAWLOG_INFO1("find_file: %s", RSTRING_PTR(fname));
    path = find_file(fname);

    if ( path != 0 )
    {
        VALUE seq;

//        if ( isAlreadyLoaded(path) == Qtrue )
//            return Qtrue;

        RAWLOG_INFO1("require_compiled: %s", szName1);

        //optimize require
        //rb_ary_push(GET_VM()->loaded_features, path);
        rb_ary_push(GET_VM()->loaded_features, fname);

        rb_gc_disable();
        seq = loadISeqFromFile(path);
        rb_gc_enable();

        //*result = rb_funcall(seq, rb_intern("eval"), 0 );
        *result = rb_iseq_eval(seq);

        return Qtrue;
    }

    RAWLOG_ERROR1("require_compiled: error: can not find %s", RSTRING_PTR(fname));
    return Qnil;
}
Example #6
0
/* get information from texture */
void
get_texture_info(VALUE image, texture_info * tex)
{
    VALUE info, gc_state_off;
    int toppos, leftpos;
    float top, left;
    cache_entry * entry;

    /* hack to prevent segfault */
    gc_state_off = rb_gc_disable();

    tex->width = FIX2INT(rb_funcall(image, rb_intern("width"), 0));
    tex->height = FIX2INT(rb_funcall(image, rb_intern("height"), 0));

    /* ensure gl_tex_info returns non nil */
    info = check_for_texture_info(image);

    top = NUM2DBL(rb_funcall(info, rb_intern("top"), 0));
    left = NUM2DBL(rb_funcall(info, rb_intern("left"), 0));
    tex->tname = FIX2INT(rb_funcall(info ,rb_intern("tex_name"),0));

    /* search for texture in cache (& create if not extant) */
    entry = find_or_create_cache_entry(tex->tname);

    tex->td_array = entry->tdata;
    tex->yincr = entry->sidelength;

    /* scratch variables */
    toppos = ROUND(top * entry->sidelength * entry->sidelength);
    leftpos = ROUND(left * entry->sidelength);

    /* find the first pixel for the image */
    tex->firstpixel = (int)(toppos + leftpos);

    tex->x_offset = ROUND(left * tex->yincr);
    tex->y_offset = ROUND(top * tex->yincr);

    /* save the associated Gosu::Image */
    tex->image = image;

    /* only enable gc if was enabled on function entry */
    if(!gc_state_off) rb_gc_enable();
}
Example #7
0
static int template_execute_wrap_each(msgpack_unpack_t* mp,
		const char* ptr, size_t dlen, size_t* from)
{
	VALUE args[4] = {
		(VALUE)mp,
		(VALUE)ptr,
		(VALUE)dlen,
		(VALUE)from,
	};

	// FIXME execute実行中はmp->topが更新されないのでGC markが機能しない
	rb_gc_disable();

	mp->user.source = Qnil;

	int ret = (int)rb_rescue(template_execute_do, (VALUE)args,
			template_execute_rescue, Qnil);

	rb_gc_enable();

	return ret;
}
Example #8
0
static int template_execute_wrap(msgpack_unpack_t* mp,
		VALUE str, size_t dlen, size_t* from)
{
	VALUE args[4] = {
		(VALUE)mp,
		(VALUE)RSTRING_PTR(str),
		(VALUE)dlen,
		(VALUE)from,
	};

	// FIXME execute実行中はmp->topが更新されないのでGC markが機能しない
	rb_gc_disable();

	mp->user.source = str;

	int ret = (int)rb_rescue(template_execute_do, (VALUE)args,
			template_execute_rescue, Qnil);

	rb_gc_enable();

	return ret;
}
Example #9
0
File: unpack.c Project: bcg/msgpack
static int template_execute_wrap(msgpack_unpack_t* mp,
		VALUE str, size_t dlen, size_t* from)
{
	VALUE args[4] = {
		(VALUE)mp,
		(VALUE)RSTRING_PTR(str),
		(VALUE)dlen,
		(VALUE)from,
	};

#ifdef HAVE_RUBY_ENCODING_H
	int enc_orig = rb_enc_get_index(str);
	rb_enc_set_index(str, s_ascii_8bit);
#endif

	// FIXME execute実行中はmp->topが更新されないのでGC markが機能しない
	rb_gc_disable();

	mp->user.source = str;

#ifdef HAVE_RUBY_ENCODING_H
	VALUE resc[2] = {str, enc_orig};
	int ret = (int)rb_rescue(template_execute_do, (VALUE)args,
			template_execute_rescue_enc, (VALUE)resc);
#else
	int ret = (int)rb_rescue(template_execute_do, (VALUE)args,
			template_execute_rescue, Qnil);
#endif

	rb_gc_enable();

#ifdef HAVE_RUBY_ENCODING_H
	rb_enc_set_index(str, enc_orig);
#endif

	return ret;
}
Example #10
0
static VALUE
oobgc(VALUE self, int dry_run)
{
  size_t curr = rb_gc_stat(sym_total_allocated_object);
  size_t prev_allocated_object = _oobgc.prev_allocated_object;
  size_t threshold_mean = _oobgc.threshold.mean;
  size_t threshold_max = _oobgc.threshold.max;

  if (!_oobgc.installed) install();

  if (!prev_allocated_object) {
    prev_allocated_object = curr;
  } else {
    size_t diff = curr - prev_allocated_object;
    prev_allocated_object = curr;

    if (threshold_mean)
      threshold_mean = (diff / 4) + (threshold_mean * 3 / 4);
    else
      threshold_mean = diff;

    if (diff > threshold_max)
      threshold_max = diff;
    if (threshold_max > 200000)
      threshold_max = 200000;
  }

  if (!dry_run) {
    _oobgc.prev_allocated_object = prev_allocated_object;
    _oobgc.threshold.mean = threshold_mean;
    _oobgc.threshold.max = threshold_max;
  }

  if (_oobgc.sweep_needed) {
    /* lazy sweep started sometime recently.
     * disable/enable the GC to force gc_rest_sweep() OOB
     */
    if (!dry_run) {
      if (rb_gc_disable() == Qfalse) rb_gc_enable();
      _oobgc.stat.sweep++;
    }
    return Qtrue;

  } else if (_oobgc.allocation_limit) {
    /* GC will be required when total_allocated_object gets
     * close to allocation_limit
     */
    if ((rb_gc_stat(sym_old_object) >= rb_gc_stat(sym_old_object_limit)*0.97 ||
        rb_gc_stat(sym_remembered_shady_object) >= rb_gc_stat(sym_remembered_shady_object_limit)*0.97) &&
        curr >= _oobgc.allocation_limit - threshold_max*0.98) {
      /*fprintf(stderr, "oobgc MAJOR: %zu >= %zu - %zu\n", curr, _oobgc.allocation_limit, threshold_max);*/
      if (!dry_run) {
        gc_start_major();
      }
      return Qtrue;

    } else if (curr >= _oobgc.allocation_limit - threshold_mean) {
      /*fprintf(stderr, "oobgc minor: %zu >= %zu - %zu\n", curr, _oobgc.allocation_limit, threshold_mean);*/
      if (!dry_run) {
        gc_start_minor();
      }
      return Qtrue;
    }
  }

  return Qfalse;
}
Example #11
0
static VALUE template_execute_rescue(VALUE nouse)
{
	rb_gc_enable();
	COMPAT_RERAISE;
}