VALUE rb_eval_string_wrap(const char *str, int *state) { int status; rb_thread_t *th = GET_THREAD(); VALUE self = th->top_self; VALUE wrapper = th->top_wrapper; VALUE val; th->top_wrapper = rb_module_new(); th->top_self = rb_obj_clone(rb_vm_top_self()); rb_extend_object(th->top_self, th->top_wrapper); val = rb_eval_string_protect(str, &status); th->top_self = self; th->top_wrapper = wrapper; if (state) { *state = status; } else if (status) { JUMP_TAG(status); } return val; }
VALUE rb_define_module_id(ID id) { VALUE mdl; mdl = rb_module_new(); rb_name_class(mdl, id); return mdl; }
static gboolean load_plugin_module (RBPluginInfo *info) { gchar *path; gchar *dirname; g_return_val_if_fail (info != NULL, FALSE); g_return_val_if_fail (info->file != NULL, FALSE); g_return_val_if_fail (info->location != NULL, FALSE); g_return_val_if_fail (info->plugin == NULL, FALSE); switch (info->lang) { case RB_PLUGIN_LOADER_C: dirname = g_path_get_dirname (info->file); g_return_val_if_fail (dirname != NULL, FALSE); path = g_module_build_path (dirname, info->location); #ifdef USE_UNINSTALLED_DIRS if (!g_file_test (path, G_FILE_TEST_EXISTS)) { char *temp; g_free (path); temp = g_build_filename (dirname, ".libs", NULL); path = g_module_build_path (temp, info->location); g_free (temp); } #endif g_free (dirname); g_return_val_if_fail (path != NULL, FALSE); info->module = G_TYPE_MODULE (rb_module_new (path, info->location)); g_free (path); break; case RB_PLUGIN_LOADER_PY: #ifdef ENABLE_PYTHON info->module = G_TYPE_MODULE (rb_python_module_new (info->file, info->location)); #else rb_debug ("cannot load plugin %s, python plugin support is disabled", info->location); #endif break; } if (g_type_module_use (info->module) == FALSE) { g_warning ("Could not load plugin %s\n", info->location); g_object_unref (G_OBJECT (info->module)); info->module = NULL; return FALSE; } switch (info->lang) { case RB_PLUGIN_LOADER_C: info->plugin = RB_PLUGIN (rb_module_new_object (RB_MODULE (info->module))); break; case RB_PLUGIN_LOADER_PY: #ifdef ENABLE_PYTHON info->plugin = RB_PLUGIN (rb_python_module_new_object (RB_PYTHON_MODULE (info->module))); #endif break; } return TRUE; }
static int rb_load_internal0(rb_thread_t *th, VALUE fname, int wrap) { int state; volatile VALUE wrapper = th->top_wrapper; volatile VALUE self = th->top_self; volatile int loaded = FALSE; volatile int mild_compile_error; #if !defined __GNUC__ rb_thread_t *volatile th0 = th; #endif th->errinfo = Qnil; /* ensure */ if (!wrap) { th->top_wrapper = 0; } else { /* load in anonymous module as toplevel */ th->top_self = rb_obj_clone(rb_vm_top_self()); th->top_wrapper = rb_module_new(); rb_extend_object(th->top_self, th->top_wrapper); } mild_compile_error = th->mild_compile_error; TH_PUSH_TAG(th); state = EXEC_TAG(); if (state == 0) { NODE *node; rb_iseq_t *iseq; th->mild_compile_error++; node = (NODE *)rb_load_file_str(fname); loaded = TRUE; iseq = rb_iseq_new_top(node, rb_str_new2("<top (required)>"), fname, rb_realpath_internal(Qnil, fname, 1), NULL); th->mild_compile_error--; rb_iseq_eval(iseq); } TH_POP_TAG(); #if !defined __GNUC__ th = th0; fname = RB_GC_GUARD(fname); #endif th->mild_compile_error = mild_compile_error; th->top_self = self; th->top_wrapper = wrapper; if (!loaded && !FIXNUM_P(th->errinfo)) { /* an error on loading don't include INT2FIX(TAG_FATAL) see r35625 */ return TAG_RAISE; } if (state) { VALUE exc = rb_vm_make_jump_tag_but_local_jump(state, Qundef); if (NIL_P(exc)) return state; th->errinfo = exc; return TAG_RAISE; } if (!NIL_P(th->errinfo)) { /* exception during load */ return TAG_RAISE; } return state; }
static const RGObjClassInfo * rbgobj_lookup_class_by_gtype_without_lock(GType gtype, VALUE parent, gboolean create_class) { GType fundamental_type; RGObjClassInfo* cinfo; RGObjClassInfoDynamic* cinfod; void* gclass = NULL; VALUE c; if (gtype == G_TYPE_INVALID) return NULL; cinfo = g_hash_table_lookup(gtype_to_cinfo, GUINT_TO_POINTER(gtype)); if (cinfo) return cinfo; if (!create_class) return NULL; c = Data_Make_Struct(rb_cData, RGObjClassInfo, cinfo_mark, NULL, cinfo); cinfo->gtype = gtype; cinfo->mark = NULL; cinfo->free = NULL; cinfo->flags = 0; fundamental_type = G_TYPE_FUNDAMENTAL(gtype); switch (fundamental_type) { case G_TYPE_POINTER: case G_TYPE_BOXED: case G_TYPE_PARAM: case G_TYPE_OBJECT: case G_TYPE_ENUM: case G_TYPE_FLAGS: if (NIL_P(parent)) parent = get_superclass(gtype); cinfo->klass = rb_funcall(rb_cClass, id_new, 1, parent); break; case G_TYPE_INTERFACE: cinfo->klass = rb_module_new(); break; default: if (NIL_P(parent)) parent = get_superclass(gtype); if (NIL_P(parent)) { fprintf(stderr, "%s: %s's fundamental type %s isn't supported\n", "rbgobj_lookup_class_by_gtype", g_type_name(gtype), g_type_name(fundamental_type)); return NULL; } cinfo->klass = rb_funcall(rb_cClass, id_new, 1, parent); } cinfod = (RGObjClassInfoDynamic *)g_hash_table_lookup(dynamic_gtype_list, g_type_name(gtype)); if (cinfod) { cinfo->mark = cinfod->mark; cinfo->free = cinfod->free; rb_define_const(cinfod->module, cinfod->name, cinfo->klass); } rb_hash_aset(klass_to_cinfo, cinfo->klass, c); g_hash_table_insert(gtype_to_cinfo, GUINT_TO_POINTER(gtype), cinfo); if (G_TYPE_IS_CLASSED(gtype)) gclass = g_type_class_ref(gtype); if (G_TYPE_IS_INSTANTIATABLE(gtype) || G_TYPE_IS_INTERFACE(gtype)) rbgobj_define_action_methods(cinfo->klass); if (G_TYPE_IS_INSTANTIATABLE(gtype)) { GType* interfaces = NULL; guint n_interfaces = 0; guint i; interfaces = g_type_interfaces(gtype, &n_interfaces); for (i = 0; i < n_interfaces; i++) { const RGObjClassInfo *iface_cinfo; iface_cinfo = rbgobj_lookup_class_by_gtype_without_lock(interfaces[i], Qnil, TRUE); rb_include_module(cinfo->klass, iface_cinfo->klass); } g_free(interfaces); } if (!rbgobj_convert_type_init_hook(gtype, cinfo->klass)) { switch (fundamental_type) { case G_TYPE_OBJECT: rbgobj_init_object_class(cinfo->klass); break; case G_TYPE_ENUM: rbgobj_init_enum_class(cinfo->klass); break; case G_TYPE_FLAGS: rbgobj_init_flags_class(cinfo->klass); break; case G_TYPE_INTERFACE: rbgobj_init_interface(cinfo->klass); break; default: rbgobj_convert_type_init_hook(fundamental_type, cinfo->klass); break; } } if (gclass) g_type_class_unref(gclass); return cinfo; }
static int rb_load_internal0(rb_execution_context_t *ec, VALUE fname, int wrap) { enum ruby_tag_type state; rb_thread_t *th = rb_ec_thread_ptr(ec); volatile VALUE wrapper = th->top_wrapper; volatile VALUE self = th->top_self; #if !defined __GNUC__ rb_thread_t *volatile th0 = th; #endif th->ec->errinfo = Qnil; /* ensure */ if (!wrap) { th->top_wrapper = 0; } else { /* load in anonymous module as toplevel */ th->top_self = rb_obj_clone(rb_vm_top_self()); th->top_wrapper = rb_module_new(); rb_extend_object(th->top_self, th->top_wrapper); } EC_PUSH_TAG(th->ec); state = EC_EXEC_TAG(); if (state == TAG_NONE) { rb_ast_t *ast; const rb_iseq_t *iseq; if ((iseq = rb_iseq_load_iseq(fname)) != NULL) { /* OK */ } else { VALUE parser = rb_parser_new(); rb_parser_set_context(parser, NULL, FALSE); ast = (rb_ast_t *)rb_parser_load_file(parser, fname); iseq = rb_iseq_new_top(&ast->body, rb_fstring_lit("<top (required)>"), fname, rb_realpath_internal(Qnil, fname, 1), NULL); rb_ast_dispose(ast); } rb_exec_event_hook_script_compiled(ec, iseq, Qnil); rb_iseq_eval(iseq); } EC_POP_TAG(); #if !defined __GNUC__ th = th0; fname = RB_GC_GUARD(fname); #endif th->top_self = self; th->top_wrapper = wrapper; if (state) { /* usually state == TAG_RAISE only, except for * rb_iseq_load_iseq case */ VALUE exc = rb_vm_make_jump_tag_but_local_jump(state, Qundef); if (NIL_P(exc)) return state; th->ec->errinfo = exc; return TAG_RAISE; } if (!NIL_P(th->ec->errinfo)) { /* exception during load */ return TAG_RAISE; } return state; }
/* * call-seq: * Module.load(String) => Module * * Load a module from a string. */ static VALUE module_load(VALUE klass, VALUE str) { VALUE arr, class_name, metaclass_str, metaclass, superclass_name, included_modules, class_variables_str, class_variables, instance_methods_str, instance_methods, flags, module; if( rb_safe_level() >= 4 || (rb_safe_level() >= 1 && OBJ_TAINTED(str))) { /* no playing with knives in the sandbox */ rb_raise(rb_eSecurityError, "Insecure: can't load module"); } arr = marshal_load(str); class_name = rb_ary_pop(arr); metaclass_str = rb_ary_pop(arr); superclass_name = rb_ary_pop(arr); included_modules = rb_ary_pop(arr); class_variables_str = rb_ary_pop(arr); instance_methods_str = rb_ary_pop(arr); flags = rb_ary_pop(arr); if(RTEST(superclass_name)) { VALUE superclass; rb_check_type(superclass_name, T_STRING); superclass = rb_funcall( lookup_module_proc, rb_intern("call"), 1, superclass_name); #if RUBY_VERSION_CODE >= 180 /* Can't make subclass of Class on 1.8.x */ module = rb_class_boot(superclass); rb_define_alloc_func(module, module_instance_allocate); #else module = rb_class_new(superclass); #endif } else { module = rb_module_new(); } if(!NIL_P(class_name)) { VALUE outer_module = rb_funcall(outer_module_proc, rb_intern("call"), 1, class_name); VALUE module_name = rb_funcall(module_name_proc, rb_intern("call"), 1, class_name); rb_const_set(outer_module, SYM2ID(module_name), module); } RBASIC(module)->flags = NUM2INT(flags); include_modules(module, included_modules); class_variables = marshal_load(class_variables_str); add_class_variables(module, class_variables); instance_methods = marshal_load(instance_methods_str); add_methods(module, instance_methods); metaclass = marshal_load(metaclass_str); if(RTEST(metaclass)) { rb_singleton_class_attached(metaclass, module); RBASIC(module)->klass = metaclass; } return module; }
static void rb_load_internal(VALUE fname, int wrap) { int state; rb_thread_t *th = GET_THREAD(); volatile VALUE wrapper = th->top_wrapper; volatile VALUE self = th->top_self; volatile int loaded = FALSE; volatile int mild_compile_error; #ifndef __GNUC__ rb_thread_t *volatile th0 = th; #endif th->errinfo = Qnil; /* ensure */ if (!wrap) { rb_secure(4); /* should alter global state */ th->top_wrapper = 0; } else { /* load in anonymous module as toplevel */ th->top_self = rb_obj_clone(rb_vm_top_self()); th->top_wrapper = rb_module_new(); rb_extend_object(th->top_self, th->top_wrapper); } mild_compile_error = th->mild_compile_error; PUSH_TAG(); state = EXEC_TAG(); if (state == 0) { NODE *node; VALUE iseq; th->mild_compile_error++; node = (NODE *)rb_load_file(RSTRING_PTR(fname)); loaded = TRUE; iseq = rb_iseq_new_top(node, rb_str_new2("<top (required)>"), fname, rb_realpath_internal(Qnil, fname, 1), Qfalse); th->mild_compile_error--; rb_iseq_eval(iseq); } POP_TAG(); #ifndef __GNUC__ th = th0; fname = RB_GC_GUARD(fname); #endif th->mild_compile_error = mild_compile_error; th->top_self = self; th->top_wrapper = wrapper; if (!loaded) { rb_exc_raise(GET_THREAD()->errinfo); } if (state) { rb_vm_jump_tag_but_local_jump(state, Qundef); } if (!NIL_P(GET_THREAD()->errinfo)) { /* exception during load */ rb_exc_raise(th->errinfo); } }