コード例 #1
0
void connection_close(connection_t *c)
{
  ev_io_stop(c->loop, &c->read_watcher);
  ev_io_stop(c->loop, &c->write_watcher);
  ev_timer_stop(c->loop, &c->timeout_watcher);

  close(c->fd);
  shutdown(c->fd, SHUT_RDWR);
  
  buffer_reset(&c->read_buffer);
  buffer_reset(&c->write_buffer);
  
  /* tell Ruby GC vars are not used anymore */
  rb_gc_unregister_address(&c->env);
  rb_gc_unregister_address(&c->input);
  
  /* kill the thread if still running */
  if (c->thread.active) {
    c->backend->thread_count--;
    rb_thread_kill(c->thread.obj);
  }
  
  /* put back in the queue of unused connections */
  queue_push(&c->backend->connections, c);
}
コード例 #2
0
ファイル: world.c プロジェクト: danorine/shoes
void
shoes_world_free(shoes_world_t *world)
{
#ifdef SHOES_QUARTZ
  CFRelease(world->os.clip);
  TECDisposeConverter(world->os.converter);
#endif
  rb_gc_unregister_address(&world->apps);
  rb_gc_unregister_address(&world->msgs);
  if (world != NULL)
    SHOE_FREE(world);
}
コード例 #3
0
VALUE db_sqlite3_statement_execute(int argc, VALUE *argv, VALUE self) {
    int expect, n;
    VALUE bind, result;

    Statement *s = db_sqlite3_statement_handle_safe(self);

    sqlite3_reset(s->s);
    sqlite3_clear_bindings(s->s);

    rb_scan_args(argc, argv, "00*", &bind);
    expect = sqlite3_bind_parameter_count(s->s);
    if (expect != RARRAY_LEN(bind))
        rb_raise(eSwiftArgumentError, "expected %d bind values got %d", expect, (int)RARRAY_LEN(bind));

    rb_gc_register_address(&bind);
    for (n = 0; n < expect; n++) {
        VALUE value = rb_ary_entry(bind, n);
        if (NIL_P(value))
            sqlite3_bind_null(s->s, n + 1);
        else {
            VALUE text = typecast_to_string(value);
            sqlite3_bind_text(s->s, n + 1, RSTRING_PTR(text), RSTRING_LEN(text), 0);
        }
    }

    result = db_sqlite3_result_allocate(cDSR);
    db_sqlite3_result_initialize(result, self);
    db_sqlite3_result_consume(result);
    rb_gc_unregister_address(&bind);
    return result;
}
コード例 #4
0
ファイル: ruby_xml.c プロジェクト: xml4r/libxml-ruby
/*
 * call-seq:
 *    XML.features -> ["feature", ..., "feature"]
 *
 * Obtains an array of strings representing features supported
 * (and enabled) by the installed libxml.
 */
static VALUE rxml_features(VALUE klass)
{
  VALUE arr, str;
  int i, len = MAX_LIBXML_FEATURES_LEN;
  char **list = NULL;

  list = ALLOC_N(char *,MAX_LIBXML_FEATURES_LEN);
  MEMZERO(list, char *, MAX_LIBXML_FEATURES_LEN);

  arr = rb_ary_new();
  if (xmlGetFeaturesList(&len, (const char **) list) == -1)
    return Qnil;

  for (i = 0; i < len; i++)
  {
    str = rb_str_new2((const char *) list[i]);
    rb_gc_unregister_address(&str);
    rb_ary_push(arr, str);
  }

  if (len == MAX_LIBXML_FEATURES_LEN)
    rb_warn(
        "Please contact [email protected] and ask to have the \"MAX_LIBXML_FEATURES_LEN increased\" because you could possibly be seeing an incomplete list");

  ruby_xfree(list);
  return (arr);
}
コード例 #5
0
ファイル: weechat-ruby.c プロジェクト: munkee/weechat
void
weechat_ruby_unload (struct t_plugin_script *script)
{
    int *rc;
    void *interpreter;

    if ((weechat_ruby_plugin->debug >= 1) || !ruby_quiet)
    {
        weechat_printf (NULL,
                        weechat_gettext ("%s: unloading script \"%s\""),
                        RUBY_PLUGIN_NAME, script->name);
    }

    if (script->shutdown_func && script->shutdown_func[0])
    {
        rc = (int *)weechat_ruby_exec (script,
                                       WEECHAT_SCRIPT_EXEC_INT,
                                       script->shutdown_func,
                                       0, NULL);
        if (rc)
            free (rc);
    }

    interpreter = script->interpreter;

    if (ruby_current_script == script)
        ruby_current_script = (ruby_current_script->prev_script) ?
            ruby_current_script->prev_script : ruby_current_script->next_script;

    script_remove (weechat_ruby_plugin, &ruby_scripts, &last_ruby_script,
                   script);

    if (interpreter)
        rb_gc_unregister_address (interpreter);
}
コード例 #6
0
ファイル: world.c プロジェクト: Klokka/Lumi
void
lumi_world_free(lumi_world_t *world)
{
#ifdef VLC_0_9
  if (world->vlc != NULL) libvlc_release(world->vlc);
#endif
  lumi_native_cleanup(world);
  st_foreach(world->image_cache, CASTFOREACH(lumi_world_free_image_cache), 0);
  st_free_table(world->image_cache);
  SHOE_FREE(world->blank_cache);
  cairo_surface_destroy(world->blank_image);
  pango_font_description_free(world->default_font);
  rb_gc_unregister_address(&world->apps);
  rb_gc_unregister_address(&world->msgs);
  if (world != NULL)
    SHOE_FREE(world);
}
コード例 #7
0
ファイル: plugin-ruby.c プロジェクト: thorgul/proxenet
static char* proxenet_ruby_execute_function(interpreter_t* interpreter, ID rFunc, request_t* request)
{
	char *buf, *data;
	int buflen, i;
	VALUE rRet;
	char *uri;

        struct proxenet_ruby_args args;

	uri = request->http_infos.uri;
	if (!uri)
		return NULL;

	/* build args */
	args.rVM = (VALUE)interpreter->vm;

        args.rFunc = rFunc;

	args.rArgs[0] = INT2NUM(request->id);
	args.rArgs[1] = rb_str_new(request->data, request->size);
	args.rArgs[2] = rb_str_new2(uri);

        for(i=0; i<3; i++) {
                rb_gc_register_address(&args.rArgs[i]);
	}

	/* safe function call */
        rRet = (VALUE)_safe_call_func(&args);
	if (!rRet) {
		xlog(LOG_ERROR, "%s\n", "[ruby] funcall2() failed");
		data = NULL;
		goto call_end;
	}

	rb_check_type(rRet, T_STRING);

        for(i=0; i<3; i++) {
                rb_gc_unregister_address(&args.rArgs[i]);
	}


	/* copy result to exploitable buffer */
	buf = RSTRING_PTR(rRet);
	buflen = RSTRING_LEN(rRet);

	data = proxenet_xmalloc(buflen + 1);
	data = memcpy(data, buf, buflen);

	request->data = data;
	request->size = buflen;

call_end:

	return data;
}
コード例 #8
0
ファイル: riconv.c プロジェクト: TheMadKhajit/rjb
static void reinit()
{
    charcode = get_charcode_name();
    if (charcode)
    {
        VALUE rb_iconv_klass = rb_const_get(rb_cObject, rb_intern("Iconv"));
        if (RTEST(rb_iconv_klass)) {
            ID sym_new = rb_intern("new");
	    rb_gc_unregister_address(&objIconvR2J);
            objIconvR2J = rb_funcall(rb_iconv_klass, sym_new, 2, rb_str_new2(CS_UTF8), rb_str_new2(charcode));
	    rb_gc_register_address(&objIconvR2J);
	    rb_gc_unregister_address(&objIconvJ2R);
            objIconvJ2R = rb_funcall(rb_iconv_klass, sym_new, 2, rb_str_new2(charcode), rb_str_new2(CS_UTF8));
	    rb_gc_register_address(&objIconvJ2R);
        }
    }
    else
    {
        objIconvR2J = objIconvJ2R = Qnil;
    }
}
コード例 #9
0
VALUE db_postgres_adapter_execute(int argc, VALUE *argv, VALUE self) {
    char **bind_args_data = 0;
    int n, *bind_args_size = 0, *bind_args_fmt = 0;
    PGresult *result;
    VALUE sql, bind, data;
    Adapter *a = db_postgres_adapter_handle_safe(self);

    rb_scan_args(argc, argv, "10*", &sql, &bind);
    if (!a->native)
        sql = db_postgres_normalized_sql(sql);

    if (RARRAY_LEN(bind) > 0) {
        bind_args_size = (int   *) malloc(sizeof(int)    * RARRAY_LEN(bind));
        bind_args_fmt  = (int   *) malloc(sizeof(int)    * RARRAY_LEN(bind));
        bind_args_data = (char **) malloc(sizeof(char *) * RARRAY_LEN(bind));

        rb_gc_register_address(&bind);
        for (n = 0; n < RARRAY_LEN(bind); n++) {
            data = rb_ary_entry(bind, n);
            if (NIL_P(data)) {
                bind_args_size[n] = 0;
                bind_args_data[n] = 0;
                bind_args_fmt[n]  = 0;
            }
            else {
                if (rb_obj_is_kind_of(data, rb_cIO) || rb_obj_is_kind_of(data, cStringIO))
                    bind_args_fmt[n] = 1;
                else
                    bind_args_fmt[n] = 0;

                data = typecast_to_string(data);
                bind_args_size[n] = RSTRING_LEN(data);
                bind_args_data[n] = RSTRING_PTR(data);
            }
        }

        Query q = {
            .connection = a->connection,
            .command    = CSTRING(sql),
            .n_args     = RARRAY_LEN(bind),
            .data       = bind_args_data,
            .size       = bind_args_size,
            .format     = bind_args_fmt
        };

        result = (PGresult *)rb_thread_blocking_region(nogvl_pq_exec_params, &q, RUBY_UBF_IO, 0);
        rb_gc_unregister_address(&bind);
        free(bind_args_size);
        free(bind_args_data);
        free(bind_args_fmt);
    }
    else {
コード例 #10
0
ファイル: fiber.c プロジェクト: AGoodId/uwsgi
static void fiber_schedule_to_req() {

	int id = uwsgi.wsgi_req->async_id;

	int error = 0;
	rb_protect(rb_fiber_schedule_to_req, 0, &error);
	if (error) {
                uwsgi_ruby_exception();
		rb_gc_unregister_address(&ufiber.fib[id]);
		uwsgi.wsgi_req->async_status = UWSGI_OK;
	}

}
コード例 #11
0
ファイル: ruby.c プロジェクト: Shoes3/shoes3
void shoes_ele_remove_all(VALUE contents) {
    if (!NIL_P(contents)) {
        long i;
        VALUE ary;
        ary = rb_ary_dup(contents);
        rb_gc_register_address(&ary);
        for (i = 0; i < RARRAY_LEN(ary); i++)
            if (!NIL_P(rb_ary_entry(ary, i)))
                rb_funcall(rb_ary_entry(ary, i), s_remove, 0);
        rb_gc_unregister_address(&ary);
        rb_ary_clear(contents);
    }
}
コード例 #12
0
ファイル: ruby.c プロジェクト: Shoes3/shoes3
VALUE shoes_safe_block(VALUE self, VALUE block, VALUE args) {
    safe_block sb;
    VALUE v;

    sb.canvas = shoes_find_canvas(self);
    sb.block = block;
    sb.args = args;
    rb_gc_register_address(&args);

    v = rb_rescue2(CASTHOOK(shoes_safe_block_call), (VALUE)&sb,
                   CASTHOOK(shoes_safe_block_exception), (VALUE)&sb, rb_cObject, 0);
    rb_gc_unregister_address(&args);
    return v;
}
コード例 #13
0
ファイル: purple_ruby.c プロジェクト: strelok1111/purple_ruby
static void main_loop_run2()
{
  main_loop = g_main_loop_new(NULL, FALSE);
  g_main_loop_run(main_loop);
  purple_core_quit();
  
#ifdef DEBUG_MEM_LEAK
  printf("QUIT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
  if (im_handler == Qnil) rb_gc_unregister_address(&im_handler);
  if (signed_on_handler == Qnil) rb_gc_unregister_address(&signed_on_handler);
  if (signed_off_handler == Qnil) rb_gc_unregister_address(&signed_off_handler);
  if (connection_error_handler == Qnil) rb_gc_unregister_address(&connection_error_handler);
  if (notify_message_handler == Qnil) rb_gc_unregister_address(&notify_message_handler);
  if (request_handler == Qnil) rb_gc_unregister_address(&request_handler);
  if (ipc_handler == Qnil) rb_gc_unregister_address(&ipc_handler);
  if (timer_timeout != 0) g_source_remove(timer_timeout);
  if (timer_handler == Qnil) rb_gc_unregister_address(&timer_handler);
  if (new_buddy_handler == Qnil) rb_gc_unregister_address(&new_buddy_handler);
  rb_gc_start();
#endif
}
コード例 #14
0
ファイル: callback.c プロジェクト: gchudnov/async-ruby-vips
/* Callback executed by Ruby Thread */
static VALUE av_handle_proc(void *d)
{
    transform_data_t* tdata = (transform_data_t*)d;

    // Invoke callback with task argument
    VALUE proc = (VALUE)tdata->proc;
    VALUE img = rb_class_new_instance(0, NULL, cImage);

    av_image_init(img, tdata);
    rb_funcall2(proc, rb_intern("call"), 1, &img);
    rb_gc_unregister_address(&tdata->proc);

    av_free_transform_data(tdata);

    return Qnil;
}
コード例 #15
0
ファイル: weechat-ruby.c プロジェクト: AlexTalker/weechat
void
weechat_ruby_unload (struct t_plugin_script *script)
{
    int *rc;
    void *interpreter;
    char *filename;

    if ((weechat_ruby_plugin->debug >= 2) || !ruby_quiet)
    {
        weechat_printf (NULL,
                        weechat_gettext ("%s: unloading script \"%s\""),
                        RUBY_PLUGIN_NAME, script->name);
    }

    if (script->shutdown_func && script->shutdown_func[0])
    {
        rc = (int *)weechat_ruby_exec (script,
                                       WEECHAT_SCRIPT_EXEC_INT,
                                       script->shutdown_func,
                                       0, NULL);
        if (rc)
            free (rc);
    }

    filename = strdup (script->filename);
    interpreter = script->interpreter;

    if (ruby_current_script == script)
        ruby_current_script = (ruby_current_script->prev_script) ?
            ruby_current_script->prev_script : ruby_current_script->next_script;

    plugin_script_remove (weechat_ruby_plugin, &ruby_scripts, &last_ruby_script,
                          script);

    if (interpreter)
        rb_gc_unregister_address (interpreter);

    (void) weechat_hook_signal_send ("ruby_script_unloaded",
                                     WEECHAT_HOOK_SIGNAL_STRING, filename);
    if (filename)
        free (filename);
}
コード例 #16
0
ファイル: ruby.c プロジェクト: filp/slash
static void
free_ruby_object(void* vobj)
{
    sl_ruby_object_t* obj = vobj;
    rb_gc_unregister_address(&obj->obj);
}
コード例 #17
0
ファイル: sax.c プロジェクト: gouravtiwari/ox
void
ox_sax_drive_cleanup(SaxDrive dr) {
    rb_gc_unregister_address(&dr->value_obj);
    buf_cleanup(&dr->buf);
    stack_cleanup(&dr->stack);
}
コード例 #18
0
static void ruby_funcall(xmlXPathParserContextPtr ctx, int nargs)
{
  VALUE xpath_handler = Qnil;
  VALUE result;
  VALUE *argv;
  VALUE doc;
  VALUE node_set = Qnil;
  xmlNodeSetPtr xml_node_set = NULL;
  xmlXPathObjectPtr obj;
  int i;
  nokogiriNodeSetTuple *node_set_tuple;

  assert(ctx);
  assert(ctx->context);
  assert(ctx->context->userData);
  assert(ctx->context->doc);
  assert(DOC_RUBY_OBJECT_TEST(ctx->context->doc));

  xpath_handler = (VALUE)(ctx->context->userData);

  argv = (VALUE *)calloc((size_t)nargs, sizeof(VALUE));
  for (i = 0 ; i < nargs ; ++i) {
    rb_gc_register_address(&argv[i]);
  }

  doc = DOC_RUBY_OBJECT(ctx->context->doc);

  if (nargs > 0) {
    i = nargs - 1;
    do {
      obj = valuePop(ctx);
      switch(obj->type) {
        case XPATH_STRING:
          argv[i] = NOKOGIRI_STR_NEW2(obj->stringval);
          break;
        case XPATH_BOOLEAN:
          argv[i] = obj->boolval == 1 ? Qtrue : Qfalse;
          break;
        case XPATH_NUMBER:
          argv[i] = rb_float_new(obj->floatval);
          break;
        case XPATH_NODESET:
          argv[i] = Nokogiri_wrap_xml_node_set(obj->nodesetval, doc);
          break;
        default:
          argv[i] = NOKOGIRI_STR_NEW2(xmlXPathCastToString(obj));
      }
      xmlXPathFreeNodeSetList(obj);
    } while(i-- > 0);
  }

  result = rb_funcall2(
      xpath_handler,
      rb_intern((const char *)ctx->context->function),
      nargs,
      argv
  );

  for (i = 0 ; i < nargs ; ++i) {
    rb_gc_unregister_address(&argv[i]);
  }
  free(argv);

  switch(TYPE(result)) {
    case T_FLOAT:
    case T_BIGNUM:
    case T_FIXNUM:
      xmlXPathReturnNumber(ctx, NUM2DBL(result));
      break;
    case T_STRING:
      xmlXPathReturnString(
          ctx,
          (xmlChar *)xmlXPathWrapCString(StringValuePtr(result))
      );
      break;
    case T_TRUE:
      xmlXPathReturnTrue(ctx);
      break;
    case T_FALSE:
      xmlXPathReturnFalse(ctx);
      break;
    case T_NIL:
      break;
    case T_ARRAY:
      {
        VALUE args[2];
	args[0] = doc;
	args[1] = result;
        node_set = rb_class_new_instance(2, args, cNokogiriXmlNodeSet);
        Data_Get_Struct(node_set, nokogiriNodeSetTuple, node_set_tuple);
	xml_node_set = node_set_tuple->node_set;
        xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
      }
      break;
    case T_DATA:
      if(rb_obj_is_kind_of(result, cNokogiriXmlNodeSet)) {
        Data_Get_Struct(result, nokogiriNodeSetTuple, node_set_tuple);
	xml_node_set = node_set_tuple->node_set;
        /* Copy the node set, otherwise it will get GC'd. */
        xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetMerge(NULL, xml_node_set));
        break;
      }
    default:
      rb_raise(rb_eRuntimeError, "Invalid return type");
  }
}
コード例 #19
0
ファイル: k_ruby_list.cpp プロジェクト: Adimpression/TideSDK
 KRubyList::~KRubyList()
 {
     rb_gc_unregister_address(&list);
 }
コード例 #20
0
ファイル: k_ruby_object.cpp プロジェクト: jonnymind/kroll
	KRubyObject::~KRubyObject()
	{
		rb_gc_unregister_address(&object);
	}
コード例 #21
0
void
rbclt_callback_func_destroy (RBCLTCallbackFunc *func)
{
  rb_gc_unregister_address (&func->proc);
  g_slice_free (RBCLTCallbackFunc, func);
}
コード例 #22
0
	KRubyHash::~KRubyHash()
	{
		rb_gc_unregister_address(&hash);
	}
コード例 #23
0
ファイル: ruby.cpp プロジェクト: bdheeman/mod_ruby
Objects::~Objects()
{
    rb_gc_unregister_address(&objects);
}
コード例 #24
0
ファイル: k_ruby_method.cpp プロジェクト: jonnymind/kroll
	KRubyMethod::~KRubyMethod() {
		rb_gc_unregister_address(&method);
	}