void Init_eval_method(void) { #undef rb_intern #define rb_intern(str) rb_intern_const(str) rb_define_method(rb_mKernel, "respond_to?", obj_respond_to, -1); rb_define_private_method(rb_cModule, "remove_method", rb_mod_remove_method, -1); rb_define_private_method(rb_cModule, "undef_method", rb_mod_undef_method, -1); rb_define_private_method(rb_cModule, "alias_method", rb_mod_alias_method, 2); rb_define_private_method(rb_cModule, "public", rb_mod_public, -1); rb_define_private_method(rb_cModule, "protected", rb_mod_protected, -1); rb_define_private_method(rb_cModule, "private", rb_mod_private, -1); rb_define_private_method(rb_cModule, "module_function", rb_mod_modfunc, -1); rb_define_method(rb_cModule, "method_defined?", rb_mod_method_defined, 1); rb_define_method(rb_cModule, "public_method_defined?", rb_mod_public_method_defined, 1); rb_define_method(rb_cModule, "private_method_defined?", rb_mod_private_method_defined, 1); rb_define_method(rb_cModule, "protected_method_defined?", rb_mod_protected_method_defined, 1); rb_define_method(rb_cModule, "public_class_method", rb_mod_public_method, -1); rb_define_method(rb_cModule, "private_class_method", rb_mod_private_method, -1); rb_define_singleton_method(rb_vm_top_self(), "public", top_public, -1); rb_define_singleton_method(rb_vm_top_self(), "private", top_private, -1); object_id = rb_intern("object_id"); added = rb_intern("method_added"); singleton_added = rb_intern("singleton_method_added"); removed = rb_intern("method_removed"); singleton_removed = rb_intern("singleton_method_removed"); undefined = rb_intern("method_undefined"); singleton_undefined = rb_intern("singleton_method_undefined"); }
VALUE rb_require_safe(VALUE fname, int safe) { volatile VALUE result = Qnil; rb_thread_t *th = GET_THREAD(); volatile VALUE errinfo = th->errinfo; int state; struct { int safe; } volatile saved; char *volatile ftptr = 0; PUSH_TAG(); saved.safe = rb_safe_level(); if ((state = EXEC_TAG()) == 0) { VALUE path; long handle; int found; rb_set_safe_level_force(safe); FilePathValue(fname); rb_set_safe_level_force(0); found = search_required(fname, &path, safe); if (found) { if (!path || !(ftptr = load_lock(RSTRING_PTR(path)))) { result = Qfalse; } else { switch (found) { case 'r': rb_load_internal(path, 0); break; case 's': handle = (long)rb_vm_call_cfunc(rb_vm_top_self(), load_ext, path, 0, path); rb_ary_push(ruby_dln_librefs, LONG2NUM(handle)); break; } rb_provide_feature(path); result = Qtrue; } } } POP_TAG(); load_unlock(ftptr, !state); rb_set_safe_level_force(saved.safe); if (state) { JUMP_TAG(state); } if (NIL_P(result)) { load_failed(fname); } th->errinfo = errinfo; return result; }
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; }
static void require_libraries(VALUE *req_list) { VALUE list = *req_list; VALUE self = rb_vm_top_self(); ID require; rb_thread_t *th = GET_THREAD(); rb_block_t *prev_base_block = th->base_block; rb_encoding *extenc = rb_default_external_encoding(); int prev_parse_in_eval = th->parse_in_eval; th->base_block = 0; th->parse_in_eval = 0; Init_ext(); /* should be called here for some reason :-( */ CONST_ID(require, "require"); while (list && RARRAY_LEN(list) > 0) { VALUE feature = rb_ary_shift(list); rb_enc_associate(feature, extenc); RBASIC(feature)->klass = rb_cString; OBJ_FREEZE(feature); rb_funcall2(self, require, 1, &feature); } *req_list = 0; th->parse_in_eval = prev_parse_in_eval; th->base_block = prev_base_block; }
RUBY_FUNC_EXPORTED void ruby_init_ext(const char *name, void (*init)(void)) { if (load_lock(name)) { rb_vm_call_cfunc(rb_vm_top_self(), init_ext_call, (VALUE)init, 0, rb_str_new2(name)); rb_provide(name); load_unlock(name, 1); } }
void Init_eval_method(void) { #undef rb_intern rb_define_method(rb_mKernel, "respond_to?", obj_respond_to, -1); basic_respond_to = rb_method_node(rb_cObject, idRespond_to); rb_register_mark_object((VALUE)basic_respond_to); rb_define_private_method(rb_cModule, "remove_method", rb_mod_remove_method, -1); rb_define_private_method(rb_cModule, "undef_method", rb_mod_undef_method, -1); rb_define_private_method(rb_cModule, "alias_method", rb_mod_alias_method, 2); rb_define_private_method(rb_cModule, "public", rb_mod_public, -1); rb_define_private_method(rb_cModule, "protected", rb_mod_protected, -1); rb_define_private_method(rb_cModule, "private", rb_mod_private, -1); rb_define_private_method(rb_cModule, "module_function", rb_mod_modfunc, -1); rb_define_method(rb_cModule, "method_defined?", rb_mod_method_defined, 1); rb_define_method(rb_cModule, "public_method_defined?", rb_mod_public_method_defined, 1); rb_define_method(rb_cModule, "private_method_defined?", rb_mod_private_method_defined, 1); rb_define_method(rb_cModule, "protected_method_defined?", rb_mod_protected_method_defined, 1); rb_define_method(rb_cModule, "public_class_method", rb_mod_public_method, -1); rb_define_method(rb_cModule, "private_class_method", rb_mod_private_method, -1); rb_define_singleton_method(rb_vm_top_self(), "public", top_public, -1); rb_define_singleton_method(rb_vm_top_self(), "private", top_private, -1); object_id = rb_intern("object_id"); __send__ = rb_intern("__send__"); eqq = rb_intern("==="); each = rb_intern("each"); aref = rb_intern("[]"); aset = rb_intern("[]="); match = rb_intern("=~"); missing = rb_intern("method_missing"); added = rb_intern("method_added"); singleton_added = rb_intern("singleton_method_added"); removed = rb_intern("method_removed"); singleton_removed = rb_intern("singleton_method_removed"); undefined = rb_intern("method_undefined"); singleton_undefined = rb_intern("singleton_method_undefined"); }
void Init_eval_method(void) { #undef rb_intern #define rb_intern(str) rb_intern_const(str) rb_define_method(rb_mKernel, "respond_to?", obj_respond_to, -1); rb_define_method(rb_mKernel, "respond_to_missing?", obj_respond_to_missing, 2); rb_define_private_method(rb_cModule, "remove_method", rb_mod_remove_method, -1); rb_define_private_method(rb_cModule, "undef_method", rb_mod_undef_method, -1); rb_define_private_method(rb_cModule, "alias_method", rb_mod_alias_method, 2); rb_define_private_method(rb_cModule, "public", rb_mod_public, -1); rb_define_private_method(rb_cModule, "protected", rb_mod_protected, -1); rb_define_private_method(rb_cModule, "private", rb_mod_private, -1); rb_define_private_method(rb_cModule, "module_function", rb_mod_modfunc, -1); rb_define_method(rb_cModule, "method_defined?", rb_mod_method_defined, 1); rb_define_method(rb_cModule, "public_method_defined?", rb_mod_public_method_defined, 1); rb_define_method(rb_cModule, "private_method_defined?", rb_mod_private_method_defined, 1); rb_define_method(rb_cModule, "protected_method_defined?", rb_mod_protected_method_defined, 1); rb_define_method(rb_cModule, "public_class_method", rb_mod_public_method, -1); rb_define_method(rb_cModule, "private_class_method", rb_mod_private_method, -1); rb_define_private_method(rb_singleton_class(rb_vm_top_self()), "public", top_public, -1); rb_define_private_method(rb_singleton_class(rb_vm_top_self()), "private", top_private, -1); { #define REPLICATE_METHOD(klass, id, noex) \ rb_method_entry_set((klass), (id), \ rb_method_entry((klass), (id), 0), \ (rb_method_flag_t)(noex | NOEX_BASIC | NOEX_NOREDEF)) REPLICATE_METHOD(rb_eException, idMethodMissing, NOEX_PRIVATE); REPLICATE_METHOD(rb_eException, idRespond_to, NOEX_PUBLIC); REPLICATE_METHOD(rb_eException, idRespond_to_missing, NOEX_PUBLIC); } }
void* dln_load(const char *file, bool call_init) { if (ruby_is_miniruby) { rb_raise(rb_eLoadError, "miniruby can't load C extension bundles due to technical problems"); } const char *error = 0; #define DLN_ERROR() (error = dln_strerror(), strcpy(ALLOCA_N(char, strlen(error) + 1), error)) char *buf; /* Load the file as an object one */ init_funcname(&buf, file); { void *handle; /* Load file */ __mrep__ = NULL; if ((handle = (void*)dlopen(file, RTLD_LAZY|RTLD_GLOBAL)) == NULL) { error = dln_strerror(); goto failed; } if (call_init) { void (*init_fct)(); init_fct = (void(*)())dlsym(handle, buf); if (init_fct == NULL) { error = DLN_ERROR(); dlclose(handle); goto failed; } /* Call the init code */ (*init_fct)(); } else { if (__mrep__ == NULL) { rb_raise(rb_eLoadError, "Can't load %s: entry point function not located (this can happen when you load twice the same .rbo file with a different case on a case-insensitive filesystem)", file); } ((IMP)__mrep__)((id)rb_vm_top_self(), 0); } return handle; } failed: rb_loaderror("%s - %s", error, file); return 0; /* dummy return */ }
static VALUE ruby_thread_init(VALUE self) { rb_thread_t *th; rb_vm_t *vm = GET_THREAD()->vm; GetThreadPtr(self, th); th_init(th, self); th->vm = vm; th->top_wrapper = 0; th->top_self = rb_vm_top_self(); return self; }
void Init_eval(void) { rb_define_virtual_variable("$@", errat_getter, errat_setter); rb_define_virtual_variable("$!", errinfo_getter, 0); rb_objc_define_module_function(rb_mKernel, "eval", rb_f_eval, -1); rb_objc_define_module_function(rb_mKernel, "iterator?", rb_f_block_given_p, 0); rb_objc_define_module_function(rb_mKernel, "block_given?", rb_f_block_given_p, 0); rb_objc_define_module_function(rb_mKernel, "fail", rb_f_raise, -1); rb_objc_define_module_function(rb_mKernel, "raise", rb_f_raise, -1); rb_objc_define_module_function(rb_mKernel, "global_variables", rb_f_global_variables, 0); /* in variable.c */ rb_objc_define_module_function(rb_mKernel, "local_variables", rb_f_local_variables, 0); rb_objc_define_method(rb_mKernel, "__method__", rb_f_method_name, 0); rb_objc_define_method(rb_mKernel, "__callee__", rb_f_method_name, 0); rb_objc_define_private_method(rb_cModule, "append_features", rb_mod_append_features, 1); rb_objc_define_private_method(rb_cModule, "extend_object", rb_mod_extend_object, 1); rb_objc_define_private_method(rb_cModule, "include", rb_mod_include, -1); rb_objc_define_method(rb_cModule, "module_eval", rb_mod_module_eval, -1); rb_objc_define_method(rb_cModule, "class_eval", rb_mod_module_eval, -1); rb_undef_method(rb_cClass, "module_function"); Init_vm_eval(); Init_eval_method(); rb_objc_define_method(*(VALUE *)rb_cModule, "nesting", rb_mod_nesting, -3); rb_objc_define_method(*(VALUE *)rb_cModule, "constants", rb_mod_s_constants, -1); VALUE cTopLevel = *(VALUE *)rb_vm_top_self(); rb_objc_define_method(cTopLevel, "include", top_include, -1); rb_objc_define_method(rb_mKernel, "extend", rb_obj_extend, -1); rb_objc_define_module_function(rb_mKernel, "trace_var", rb_f_trace_var, -1); /* in variable.c */ rb_objc_define_module_function(rb_mKernel, "untrace_var", rb_f_untrace_var, -1); /* in variable.c */ rb_define_virtual_variable("$SAFE", safe_getter, safe_setter); exception_error = rb_exc_new2(rb_eFatal, "exception reentered"); //rb_ivar_set(exception_error, idThrowState, INT2FIX(TAG_FATAL)); GC_RETAIN(exception_error); }
void Init_eval_method(void) { rb_objc_define_method(rb_mKernel, "respond_to?", obj_respond_to, -1); rb_objc_define_method(rb_mKernel, "respond_to_missing?", obj_respond_to_missing, 2); selRespondToDefault = sel_registerName("respond_to_missing?:"); basic_respond_to_imp = class_getMethodImplementation((Class)rb_mKernel, selRespondTo); rb_objc_define_private_method(rb_cModule, "remove_method", rb_mod_remove_method, -1); rb_objc_define_private_method(rb_cModule, "undef_method", rb_mod_undef_method, -1); rb_objc_define_private_method(rb_cModule, "alias_method", rb_mod_alias_method, 2); rb_objc_define_private_method(rb_cModule, "public", rb_mod_public, -1); rb_objc_define_private_method(rb_cModule, "protected", rb_mod_protected, -1); rb_objc_define_private_method(rb_cModule, "private", rb_mod_private, -1); rb_objc_define_private_method(rb_cModule, "module_function", rb_mod_modfunc, -1); rb_objc_define_method(rb_cModule, "method_defined?", rb_mod_method_defined, 1); rb_objc_define_method(rb_cModule, "public_method_defined?", rb_mod_public_method_defined, 1); rb_objc_define_method(rb_cModule, "private_method_defined?", rb_mod_private_method_defined, 1); rb_objc_define_method(rb_cModule, "protected_method_defined?", rb_mod_protected_method_defined, 1); rb_objc_define_method(rb_cModule, "public_class_method", rb_mod_public_method, -1); rb_objc_define_method(rb_cModule, "private_class_method", rb_mod_private_method, -1); VALUE cTopLevel = *(VALUE *)rb_vm_top_self(); rb_objc_define_method(cTopLevel, "public", top_public, -1); rb_objc_define_method(cTopLevel, "private", top_private, -1); object_id = rb_intern("object_id"); __send__ = rb_intern("__send__"); eqq = rb_intern("==="); each = rb_intern("each"); aref = rb_intern("[]"); aset = rb_intern("[]="); match = rb_intern("=~"); missing = rb_intern("method_missing"); added = rb_intern("method_added"); singleton_added = rb_intern("singleton_method_added"); removed = rb_intern("method_removed"); singleton_removed = rb_intern("singleton_method_removed"); undefined = rb_intern("method_undefined"); singleton_undefined = rb_intern("singleton_method_undefined"); }
void Init_Binding(void) { rb_cBinding = rb_define_class("Binding", rb_cObject); rb_undef_alloc_func(rb_cBinding); rb_undef_method(CLASS_OF(rb_cBinding), "new"); rb_objc_define_method(rb_cBinding, "clone", binding_clone, 0); rb_objc_define_method(rb_cBinding, "dup", binding_dup, 0); rb_objc_define_method(rb_cBinding, "eval", bind_eval, -1); rb_objc_define_module_function(rb_mKernel, "binding", rb_f_binding, 0); rb_vm_binding_t *binding = (rb_vm_binding_t *)xmalloc( sizeof(rb_vm_binding_t)); GC_WB(&binding->self, rb_vm_top_self()); binding->outer_stack = NULL; rb_define_global_const("TOPLEVEL_BINDING", rb_binding_new_from_binding(binding)); }
static void require_libraries(struct cmdline_options *opt) { VALUE list = opt->req_list; ID require; rb_thread_t *th = GET_THREAD(); rb_block_t *prev_base_block = th->base_block; int prev_parse_in_eval = th->parse_in_eval; th->base_block = 0; th->parse_in_eval = 0; Init_ext(); /* should be called here for some reason :-( */ CONST_ID(require, "require"); while (list && RARRAY_LEN(list) > 0) { VALUE feature = rb_ary_shift(list); rb_funcall2(rb_vm_top_self(), require, 1, &feature); } opt->req_list = 0; th->parse_in_eval = prev_parse_in_eval; th->base_block = prev_base_block; }
VALUE rb_eval_cmd(VALUE cmd, VALUE arg, int level) { VALUE val = Qnil; /* OK */ volatile int safe = rb_safe_level(); if (OBJ_TAINTED(cmd)) { level = 4; } if (TYPE(cmd) != T_STRING) { rb_set_safe_level_force(level); val = rb_funcall2(cmd, rb_intern("call"), RARRAY_LENINT(arg), RARRAY_PTR(arg)); rb_set_safe_level_force(safe); return val; } val = eval_string(0, rb_vm_top_self(), cmd, Qnil, "(eval)", 1); rb_set_safe_level_force(safe); return val; }
VALUE rb_eval_cmd(VALUE cmd, VALUE arg, int level) { int state; VALUE val = Qnil; /* OK */ volatile int safe = rb_safe_level(); if (OBJ_TAINTED(cmd)) { level = 4; } if (TYPE(cmd) != T_STRING) { PUSH_TAG(); rb_set_safe_level_force(level); if ((state = EXEC_TAG()) == 0) { val = rb_funcall2(cmd, rb_intern("call"), RARRAY_LEN(arg), RARRAY_PTR(arg)); } POP_TAG(); rb_set_safe_level_force(safe); if (state) JUMP_TAG(state); return val; } PUSH_TAG(); if ((state = EXEC_TAG()) == 0) { val = eval_string(rb_vm_top_self(), cmd, Qnil, 0, 0); } POP_TAG(); rb_set_safe_level_force(safe); if (state) rb_vm_jump_tag_but_local_jump(state, val); return val; }
/* * returns * 0: if already loaded (false) * 1: successfully loaded (true) * <0: not found (LoadError) * >1: exception */ int rb_require_internal(VALUE fname, int safe) { volatile int result = -1; rb_thread_t *th = GET_THREAD(); volatile VALUE errinfo = th->errinfo; int state; struct { int safe; } volatile saved; char *volatile ftptr = 0; if (RUBY_DTRACE_REQUIRE_ENTRY_ENABLED()) { RUBY_DTRACE_REQUIRE_ENTRY(StringValuePtr(fname), rb_sourcefile(), rb_sourceline()); } TH_PUSH_TAG(th); saved.safe = rb_safe_level(); if ((state = EXEC_TAG()) == 0) { VALUE path; long handle; int found; rb_set_safe_level_force(safe); FilePathValue(fname); rb_set_safe_level_force(0); if (RUBY_DTRACE_FIND_REQUIRE_ENTRY_ENABLED()) { RUBY_DTRACE_FIND_REQUIRE_ENTRY(StringValuePtr(fname), rb_sourcefile(), rb_sourceline()); } path = rb_str_encode_ospath(fname); found = search_required(path, &path, safe); if (RUBY_DTRACE_FIND_REQUIRE_RETURN_ENABLED()) { RUBY_DTRACE_FIND_REQUIRE_RETURN(StringValuePtr(fname), rb_sourcefile(), rb_sourceline()); } if (found) { if (!path || !(ftptr = load_lock(RSTRING_PTR(path)))) { result = 0; } else if (!*ftptr) { rb_provide_feature(path); result = TAG_RETURN; } else { switch (found) { case 'r': rb_load_internal(path, 0); break; case 's': handle = (long)rb_vm_call_cfunc(rb_vm_top_self(), load_ext, path, 0, path); rb_ary_push(ruby_dln_librefs, LONG2NUM(handle)); break; } rb_provide_feature(path); result = TAG_RETURN; } } } TH_POP_TAG(); load_unlock(ftptr, !state); rb_set_safe_level_force(saved.safe); if (state) { /* never TAG_RETURN */ return state; } th->errinfo = errinfo; if (RUBY_DTRACE_REQUIRE_RETURN_ENABLED()) { RUBY_DTRACE_REQUIRE_RETURN(StringValuePtr(fname), rb_sourcefile(), rb_sourceline()); } return result; }
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 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); } }
VALUE rb_eval_string(const char *str) { return eval_string(rb_vm_top_self(), rb_str_new2(str), Qnil, "(eval)", 1); }
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; }
/* * returns * 0: if already loaded (false) * 1: successfully loaded (true) * <0: not found (LoadError) * >1: exception */ int rb_require_internal(VALUE fname, int safe) { volatile int result = -1; rb_execution_context_t *ec = GET_EC(); volatile VALUE errinfo = ec->errinfo; enum ruby_tag_type state; struct { int safe; } volatile saved; char *volatile ftptr = 0; VALUE path; fname = rb_get_path_check(fname, safe); path = rb_str_encode_ospath(fname); RUBY_DTRACE_HOOK(REQUIRE_ENTRY, RSTRING_PTR(fname)); EC_PUSH_TAG(ec); saved.safe = rb_safe_level(); if ((state = EC_EXEC_TAG()) == TAG_NONE) { long handle; int found; rb_set_safe_level_force(0); RUBY_DTRACE_HOOK(FIND_REQUIRE_ENTRY, RSTRING_PTR(fname)); found = search_required(path, &path, safe, rb_feature_p); RUBY_DTRACE_HOOK(FIND_REQUIRE_RETURN, RSTRING_PTR(fname)); if (found) { if (!path || !(ftptr = load_lock(RSTRING_PTR(path)))) { result = 0; } else if (!*ftptr) { rb_provide_feature(path); result = TAG_RETURN; } else { switch (found) { case 'r': state = rb_load_internal0(ec, path, 0); break; case 's': handle = (long)rb_vm_call_cfunc(rb_vm_top_self(), load_ext, path, VM_BLOCK_HANDLER_NONE, path); rb_ary_push(ruby_dln_librefs, LONG2NUM(handle)); break; } if (!state) { rb_provide_feature(path); result = TAG_RETURN; } } } } EC_POP_TAG(); load_unlock(ftptr, !state); rb_set_safe_level_force(saved.safe); if (state) { RB_GC_GUARD(fname); /* never TAG_RETURN */ return state; } ec->errinfo = errinfo; RUBY_DTRACE_HOOK(REQUIRE_RETURN, RSTRING_PTR(fname)); return result; }