void Init_load(void) { #undef rb_intern #define rb_intern(str) rb_intern2((str), strlen(str)) rb_vm_t *vm = GET_VM(); static const char var_load_path[] = "$:"; ID id_load_path = rb_intern2(var_load_path, sizeof(var_load_path)-1); rb_define_hooked_variable(var_load_path, (VALUE*)vm, load_path_getter, rb_gvar_readonly_setter); rb_alias_variable(rb_intern("$-I"), id_load_path); rb_alias_variable(rb_intern("$LOAD_PATH"), id_load_path); vm->load_path = rb_ary_new(); vm->expanded_load_path = rb_ary_tmp_new(0); vm->load_path_snapshot = rb_ary_tmp_new(0); vm->load_path_check_cache = 0; rb_define_virtual_variable("$\"", get_loaded_features, 0); rb_define_virtual_variable("$LOADED_FEATURES", get_loaded_features, 0); vm->loaded_features = rb_ary_new(); vm->loaded_features_snapshot = rb_ary_tmp_new(0); vm->loaded_features_index = st_init_strtable(); rb_define_global_function("load", rb_f_load, -1); rb_define_global_function("require", rb_f_require, 1); rb_define_global_function("require_relative", rb_f_require_relative, 1); rb_define_method(rb_cModule, "autoload", rb_mod_autoload, 2); rb_define_method(rb_cModule, "autoload?", rb_mod_autoload_p, 1); rb_define_global_function("autoload", rb_f_autoload, 2); rb_define_global_function("autoload?", rb_f_autoload_p, 1); ruby_dln_librefs = rb_ary_tmp_new(0); rb_gc_register_mark_object(ruby_dln_librefs); }
VALUE rb_path2class(const char *path) { const char *pbeg, *p; ID id; VALUE c = rb_cObject; if (path[0] == '#') { rb_raise(rb_eArgError, "can't retrieve anonymous class %s", path); } pbeg = p = path; while (*p) { while (*p && *p != ':') p++; id = rb_intern2(pbeg, p-pbeg); if (p[0] == ':') { if (p[1] != ':') goto undefined_class; p += 2; pbeg = p; } if (!rb_const_defined(c, id)) { undefined_class: rb_raise(rb_eArgError, "undefined class/module %.*s", (int)(p-path), path); } c = rb_const_get_at(c, id); switch (TYPE(c)) { case T_MODULE: case T_CLASS: break; default: rb_raise(rb_eTypeError, "%s does not refer class/module", path); } } return c; }
static ABSTRACT_USERFUNC* is_expr_userfnc (ABSTRACT_FUNCMAP* FuncHash, PSTRING name) { VALUE key = ID2SYM(rb_intern2(name.begin, name.endnext - name.begin)); VALUE val = rb_hash_aref((VALUE)FuncHash, key); if (NIL_P(val)) return NULL; return (ABSTRACT_USERFUNC *)val; }
static ABSTRACT_VALUE* get_ABSTRACT_VALUE_impl (ABSTRACT_DATASTATE *none, ABSTRACT_MAP* hashPtr, PSTRING name) { VALUE key = ID2SYM(rb_intern2(name.begin, name.endnext - name.begin)); VALUE val = rb_hash_aref((VALUE)hashPtr, key); if (NIL_P(val)) { key = rb_str_new(name.begin, name.endnext - name.begin); val = rb_hash_aref((VALUE)hashPtr, key); } return NIL_P(val) ? NULL : (ABSTRACT_VALUE*)val; }
VALUE symbol_spec_rb_intern2_c_compare(VALUE self, VALUE string, VALUE len, VALUE sym) { ID symbol = rb_intern2(RSTRING_PTR(string), FIX2LONG(len)); return (SYM2ID(sym) == symbol) ? Qtrue : Qfalse; }
VALUE symbol_spec_rb_intern2(VALUE self, VALUE string, VALUE len) { return ID2SYM(rb_intern2(RSTRING_PTR(string), FIX2LONG(len))); }
ID rb_intern(const char *name) { return rb_intern2(name, strlen(name)); }