6#include "eval_intern.h"
8#include "internal/dir.h"
9#include "internal/error.h"
10#include "internal/file.h"
11#include "internal/load.h"
12#include "internal/parse.h"
13#include "internal/thread.h"
14#include "internal/variable.h"
21static VALUE ruby_dln_librefs;
23#define IS_RBEXT(e) (strcmp((e), ".rb") == 0)
24#define IS_SOEXT(e) (strcmp((e), ".so") == 0 || strcmp((e), ".o") == 0)
25#define IS_DLEXT(e) (strcmp((e), DLEXT) == 0)
27static const char *
const loadable_ext[] = {
32static const char *
const ruby_ext[] = {
50rb_construct_expanded_load_path(
rb_vm_t *vm,
enum expand_type
type,
int *has_relative,
int *has_non_cache)
52 VALUE load_path = vm->load_path;
53 VALUE expanded_load_path = vm->expanded_load_path;
57 ary = rb_ary_hidden_new(
RARRAY_LEN(load_path));
59 VALUE path, as_str, expanded_path;
60 int is_string, non_cache;
64 non_cache = !is_string ? 1 : 0;
65 as_str = rb_get_path_check_to_string(path);
69 if ((
type == EXPAND_RELATIVE &&
70 rb_is_absolute_path(as_cstr)) ||
71 (
type == EXPAND_HOME &&
72 (!as_cstr[0] || as_cstr[0] !=
'~')) ||
73 (
type == EXPAND_NON_CACHE)) {
75 rb_ary_push(ary,
RARRAY_AREF(expanded_load_path, i));
79 if (!*has_relative && !rb_is_absolute_path(as_cstr))
81 if (!*has_non_cache && non_cache)
86 as_str = rb_get_path_check_convert(as_str);
87 expanded_path = rb_check_realpath(
Qnil, as_str, NULL);
88 if (
NIL_P(expanded_path)) expanded_path = as_str;
89 rb_ary_push(ary, rb_fstring(expanded_path));
92 vm->expanded_load_path = ary;
93 rb_ary_replace(vm->load_path_snapshot, vm->load_path);
97get_expanded_load_path(
rb_vm_t *vm)
101 if (!rb_ary_shared_with_p(vm->load_path_snapshot, vm->load_path)) {
103 int has_relative = 0, has_non_cache = 0;
104 rb_construct_expanded_load_path(vm, EXPAND_ALL, &has_relative, &has_non_cache);
106 vm->load_path_check_cache = rb_dir_getwd_ospath();
108 else if (has_non_cache) {
110 vm->load_path_check_cache = non_cache;
113 vm->load_path_check_cache = 0;
116 else if (vm->load_path_check_cache == non_cache) {
117 int has_relative = 1, has_non_cache = 1;
119 rb_construct_expanded_load_path(vm, EXPAND_NON_CACHE,
120 &has_relative, &has_non_cache);
122 else if (vm->load_path_check_cache) {
123 int has_relative = 1, has_non_cache = 1;
124 VALUE cwd = rb_dir_getwd_ospath();
128 vm->load_path_check_cache = cwd;
129 rb_construct_expanded_load_path(vm, EXPAND_RELATIVE,
130 &has_relative, &has_non_cache);
134 rb_construct_expanded_load_path(vm, EXPAND_HOME,
135 &has_relative, &has_non_cache);
138 return vm->expanded_load_path;
142rb_get_expanded_load_path(
void)
144 return get_expanded_load_path(GET_VM());
148load_path_getter(
ID id,
VALUE * p)
151 return vm->load_path;
155get_loaded_features(
rb_vm_t *vm)
157 return vm->loaded_features;
161get_loaded_features_realpaths(
rb_vm_t *vm)
163 return vm->loaded_features_realpaths;
167get_loaded_features_realpath_map(
rb_vm_t *vm)
169 return vm->loaded_features_realpath_map;
173get_LOADED_FEATURES(
ID _x,
VALUE *_y)
175 return get_loaded_features(GET_VM());
179reset_loaded_features_snapshot(
rb_vm_t *vm)
181 rb_ary_replace(vm->loaded_features_snapshot, vm->loaded_features);
185get_loaded_features_index_raw(
rb_vm_t *vm)
187 return vm->loaded_features_index;
193 return vm->loading_table;
197feature_key(
const char *str,
size_t len)
199 return st_hash(str, len, 0xfea7009e);
203is_rbext_path(
VALUE feature_path)
207 if (len <= rbext_len)
return false;
208 return IS_RBEXT(
RSTRING_PTR(feature_path) + len - rbext_len);
211typedef rb_darray(
long) feature_indexes_t;
213struct features_index_add_single_args {
220features_index_add_single_callback(st_data_t *key, st_data_t *value, st_data_t raw_args,
int existing)
222 struct features_index_add_single_args *args = (
struct features_index_add_single_args *)raw_args;
224 VALUE offset = args->offset;
228 VALUE this_feature_index = *value;
231 VALUE loaded_features = get_loaded_features(vm);
234 feature_indexes_t feature_indexes;
235 rb_darray_make(&feature_indexes, 2);
236 int top = (rb && !is_rbext_path(this_feature_path)) ? 1 : 0;
237 rb_darray_set(feature_indexes, top^0,
FIX2LONG(this_feature_index));
238 rb_darray_set(feature_indexes, top^1,
FIX2LONG(offset));
240 assert(rb_darray_size(feature_indexes) == 2);
244 *value = (st_data_t)feature_indexes;
247 feature_indexes_t feature_indexes = (feature_indexes_t)this_feature_index;
251 VALUE loaded_features = get_loaded_features(vm);
252 for (
size_t i = 0; i < rb_darray_size(feature_indexes); ++i) {
253 long idx = rb_darray_get(feature_indexes, i);
256 if (!is_rbext_path(this_feature_path)) {
263 rb_darray_append(&feature_indexes,
FIX2LONG(offset));
265 *value = (st_data_t)feature_indexes;
268 long *ptr = rb_darray_data_ptr(feature_indexes);
269 long len = rb_darray_size(feature_indexes);
270 MEMMOVE(ptr + pos, ptr + pos + 1,
long, len - pos - 1);
283features_index_add_single(
rb_vm_t *vm,
const char* str,
size_t len,
VALUE offset,
bool rb)
286 st_data_t short_feature_key;
289 short_feature_key = feature_key(str, len);
291 features_index = get_loaded_features_index_raw(vm);
293 struct features_index_add_single_args args = {
299 st_update(features_index, short_feature_key, features_index_add_single_callback, (st_data_t)&args);
313 const char *feature_str, *feature_end, *ext, *p;
319 for (ext = feature_end; ext > feature_str; ext--)
320 if (*ext ==
'.' || *ext ==
'/')
329 p = ext ? ext : feature_end;
332 while (p >= feature_str && *p !=
'/')
337 features_index_add_single(vm, p + 1, feature_end - p - 1, offset,
false);
339 features_index_add_single(vm, p + 1, ext - p - 1, offset, rb);
342 features_index_add_single(vm, feature_str, feature_end - feature_str, offset,
false);
344 features_index_add_single(vm, feature_str, ext - feature_str, offset, rb);
349loaded_features_index_clear_i(st_data_t key, st_data_t val, st_data_t arg)
353 rb_darray_free((
void *)obj);
359get_loaded_features_index(
rb_vm_t *vm)
364 if (!rb_ary_shared_with_p(vm->loaded_features_snapshot, vm->loaded_features)) {
367 st_foreach(vm->loaded_features_index, loaded_features_index_clear_i, 0);
369 VALUE realpaths = vm->loaded_features_realpaths;
370 VALUE realpath_map = vm->loaded_features_realpath_map;
371 VALUE previous_realpath_map = rb_hash_dup(realpath_map);
372 rb_hash_clear(realpaths);
373 rb_hash_clear(realpath_map);
374 features = vm->loaded_features;
377 as_str = entry = rb_ary_entry(features, i);
381 rb_ary_store(features, i, as_str);
382 features_index_add(vm, as_str,
INT2FIX(i));
384 reset_loaded_features_snapshot(vm);
386 features = rb_ary_dup(vm->loaded_features_snapshot);
388 for (i = 0; i < j; i++) {
389 VALUE as_str = rb_ary_entry(features, i);
390 VALUE realpath = rb_hash_aref(previous_realpath_map, as_str);
391 if (
NIL_P(realpath)) {
392 realpath = rb_check_realpath(
Qnil, as_str, NULL);
393 if (
NIL_P(realpath)) realpath = as_str;
394 realpath = rb_fstring(realpath);
396 rb_hash_aset(realpaths, realpath,
Qtrue);
397 rb_hash_aset(realpath_map, as_str, realpath);
400 return vm->loaded_features_index;
415loaded_feature_path(
const char *name,
long vlen,
const char *feature,
long len,
422 if (vlen < len+1)
return 0;
423 if (strchr(feature,
'.') && !strncmp(name+(vlen-len), feature, len)) {
427 for (e = name + vlen; name != e && *e !=
'.' && *e !=
'/'; --e);
430 strncmp(e-len, feature, len))
432 plen = e - name - len;
434 if (plen > 0 && name[plen-1] !=
'/') {
437 if (
type ==
's' ? !IS_DLEXT(&name[plen+len]) :
438 type ==
'r' ? !IS_RBEXT(&name[plen+len]) :
445 if (plen > 0) --plen;
451 if (n != plen)
continue;
452 if (n && strncmp(name, s, n))
continue;
467loaded_feature_path_i(st_data_t v, st_data_t b, st_data_t f)
469 const char *s = (
const char *)v;
471 VALUE p = loaded_feature_path(s, strlen(s), fp->name, fp->len,
472 fp->type, fp->load_path);
473 if (!p)
return ST_CONTINUE;
479rb_feature_p(
rb_vm_t *vm,
const char *feature,
const char *ext,
int rb,
int expanded,
const char **fn)
481 VALUE features, this_feature_index =
Qnil, v, p, load_path = 0;
483 long i, len, elen, n;
484 st_table *loading_tbl, *features_index;
492 len = strlen(feature) - elen;
493 type = rb ?
'r' :
's';
496 len = strlen(feature);
500 features = get_loaded_features(vm);
501 features_index = get_loaded_features_index(vm);
503 key = feature_key(feature, strlen(feature));
530 if (st_lookup(features_index, key, &data) && !
NIL_P(this_feature_index = (
VALUE)data)) {
531 for (
size_t i = 0; ; i++) {
535 index =
FIX2LONG(this_feature_index);
538 feature_indexes_t feature_indexes = (feature_indexes_t)this_feature_index;
539 if (i >= rb_darray_size(feature_indexes))
break;
540 index = rb_darray_get(feature_indexes, i);
546 if (strncmp(f, feature, len) != 0) {
547 if (expanded)
continue;
548 if (!load_path) load_path = get_expanded_load_path(vm);
549 if (!(p = loaded_feature_path(f, n, feature, len,
type, load_path)))
554 if (!*(e = f + len)) {
558 if (*e !=
'.')
continue;
559 if ((!rb || !ext) && (IS_SOEXT(e) || IS_DLEXT(e))) {
562 if ((rb || !ext) && (IS_RBEXT(e))) {
568 loading_tbl = get_loading_table(vm);
575 fs.load_path = load_path ? load_path : get_expanded_load_path(vm);
577 st_foreach(loading_tbl, loaded_feature_path_i, (st_data_t)&fs);
578 if ((f = fs.result) != 0) {
583 if (st_get_key(loading_tbl, (st_data_t)feature, &data)) {
584 if (fn) *fn = (
const char*)data;
590 static const char so_ext[][4] = {
594 if (ext && *ext)
return 0;
597 MEMCPY(buf, feature,
char, len);
598 for (i = 0; (e = loadable_ext[i]) != 0; i++) {
599 strlcpy(buf + len, e, DLEXT_MAXLEN + 1);
600 if (st_get_key(loading_tbl, (st_data_t)buf, &data)) {
602 if (fn) *fn = (
const char*)data;
603 return i ?
's' :
'r';
606 for (i = 0; i < numberof(so_ext); i++) {
607 strlcpy(buf + len, so_ext[i], DLEXT_MAXLEN + 1);
608 if (st_get_key(loading_tbl, (st_data_t)buf, &data)) {
610 if (fn) *fn = (
const char*)data;
619 if (!ext)
return 'u';
620 return !IS_RBEXT(ext) ?
's' :
'r';
630feature_provided(
rb_vm_t *vm,
const char *feature,
const char **loading)
632 const char *ext = strrchr(feature,
'.');
635 if (*feature ==
'.' &&
636 (feature[1] ==
'/' || strncmp(feature+1,
"./", 2) == 0)) {
637 fullpath = rb_file_expand_path_fast(rb_get_path(
rb_str_new2(feature)),
Qnil);
640 if (ext && !strchr(ext,
'/')) {
642 if (rb_feature_p(vm, feature, ext, TRUE, FALSE, loading))
return TRUE;
645 else if (IS_SOEXT(ext) || IS_DLEXT(ext)) {
646 if (rb_feature_p(vm, feature, ext, FALSE, FALSE, loading))
return TRUE;
650 if (rb_feature_p(vm, feature, 0, TRUE, FALSE, loading))
659 return feature_provided(GET_VM(), feature, loading);
667 features = get_loaded_features(vm);
670 "$LOADED_FEATURES is frozen; cannot append feature");
674 get_loaded_features_index(vm);
678 rb_ary_clear(vm->loaded_features_snapshot);
679 rb_ary_push(features, rb_fstring(feature));
681 reset_loaded_features_snapshot(vm);
687 rb_provide_feature(GET_VM(), rb_fstring_cstr(feature));
690NORETURN(
static void load_failed(
VALUE));
695 const rb_iseq_t *iseq = rb_iseq_load_iseq(fname);
699 VALUE v = rb_vm_push_frame_fname(ec, fname);
701 VALUE parser = rb_parser_new();
702 rb_parser_set_context(parser, NULL, FALSE);
703 ast = (
rb_ast_t *)rb_parser_load_file(parser, fname);
704 iseq = rb_iseq_new_top(&ast->body, rb_fstring_lit(
"<top (required)>"),
705 fname, rb_realpath_internal(
Qnil, fname, 1), NULL);
710 rb_exec_event_hook_script_compiled(ec, iseq,
Qnil);
714static inline enum ruby_tag_type
717 enum ruby_tag_type state;
719 volatile VALUE wrapper = th->top_wrapper;
720 volatile VALUE self = th->top_self;
729 th->top_wrapper = load_wrapper;
733 state = EC_EXEC_TAG();
734 if (state == TAG_NONE) {
735 load_iseq_eval(ec, fname);
744 th->top_wrapper = wrapper;
752 rb_vm_jump_tag_but_local_jump(state);
755 if (!
NIL_P(ec->errinfo)) {
764 enum ruby_tag_type state = TAG_NONE;
769 state = load_wrapping(ec, fname, wrap);
772 load_iseq_eval(ec, fname);
774 raise_load_if_failed(ec, state);
781 if (!tmp) load_failed(fname);
782 rb_load_internal(tmp, RBOOL(wrap));
788 enum ruby_tag_type state;
790 EC_PUSH_TAG(GET_EC());
791 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
796 if (state != TAG_NONE) *pstate = state;
833 VALUE fname, wrap, path, orig_fname;
837 orig_fname = rb_get_path_check_to_string(fname);
838 fname = rb_str_encode_ospath(orig_fname);
839 RUBY_DTRACE_HOOK(LOAD_ENTRY,
RSTRING_PTR(orig_fname));
841 path = rb_find_file(fname);
844 load_failed(orig_fname);
847 rb_load_internal(path, wrap);
849 RUBY_DTRACE_HOOK(LOAD_RETURN,
RSTRING_PTR(orig_fname));
855load_lock(
rb_vm_t *vm,
const char *ftptr,
bool warn)
858 st_table *loading_tbl = get_loading_table(vm);
860 if (!st_lookup(loading_tbl, (st_data_t)ftptr, &data)) {
863 data = (st_data_t)rb_thread_shield_new();
864 st_insert(loading_tbl, (st_data_t)ftptr, data);
865 return (
char *)ftptr;
868 if (warn && rb_thread_shield_owned((
VALUE)data)) {
869 VALUE warning = rb_warning_string(
"loading in progress, circular require considered harmful - %s", ftptr);
873 switch (rb_thread_shield_wait((
VALUE)data)) {
878 return (
char *)ftptr;
882release_thread_shield(st_data_t *key, st_data_t *value, st_data_t done,
int existing)
885 if (!existing)
return ST_STOP;
887 rb_thread_shield_destroy(thread_shield);
891 else if (rb_thread_shield_release(thread_shield)) {
900load_unlock(
rb_vm_t *vm,
const char *ftptr,
int done)
903 st_data_t key = (st_data_t)ftptr;
904 st_table *loading_tbl = get_loading_table(vm);
906 st_update(loading_tbl, key, release_thread_shield, done);
910static VALUE rb_require_string_internal(
VALUE fname);
968 VALUE base = rb_current_realfilepath();
972 base = rb_file_dirname(base);
973 return rb_require_string_internal(rb_file_absolute_path(fname, base));
976typedef int (*feature_func)(
rb_vm_t *vm,
const char *feature,
const char *ext,
int rb,
int expanded,
const char **fn);
979search_required(
rb_vm_t *vm,
VALUE fname,
volatile VALUE *path, feature_func rb_feature_p)
988 if (ext && !strchr(ext,
'/')) {
990 if (rb_feature_p(vm, ftptr, ext, TRUE, FALSE, &loading)) {
994 if ((tmp = rb_find_file(fname)) != 0) {
996 if (!rb_feature_p(vm, ftptr, ext, TRUE, TRUE, &loading) || loading)
1002 else if (IS_SOEXT(ext)) {
1003 if (rb_feature_p(vm, ftptr, ext, FALSE, FALSE, &loading)) {
1010 if ((tmp = rb_find_file(tmp)) != 0) {
1012 if (!rb_feature_p(vm, ftptr, ext, FALSE, TRUE, &loading) || loading)
1017 else if (IS_DLEXT(ext)) {
1018 if (rb_feature_p(vm, ftptr, ext, FALSE, FALSE, &loading)) {
1022 if ((tmp = rb_find_file(fname)) != 0) {
1024 if (!rb_feature_p(vm, ftptr, ext, FALSE, TRUE, &loading) || loading)
1030 else if ((ft = rb_feature_p(vm, ftptr, 0, FALSE, FALSE, &loading)) ==
'r') {
1035 type = rb_find_file_ext(&tmp, ft ==
's' ? ruby_ext : loadable_ext);
1037 if (!ft &&
type != 1) {
1038 VALUE lookup_name = tmp;
1047 if (st_lookup(vm->static_ext_inits, (st_data_t)ftptr, NULL)) {
1056 goto feature_present;
1058 return rb_feature_p(vm, ftptr, 0, FALSE, TRUE, 0);
1062 goto feature_present;
1067 if (rb_feature_p(vm, ftptr, ext, !--
type, TRUE, &loading) && !loading)
1071 return type ?
's' :
'r';
1079load_failed(
VALUE fname)
1081 rb_load_fail(fname,
"cannot load such file");
1087 rb_scope_visibility_set(METHOD_VISI_PUBLIC);
1093run_static_ext_init(
rb_vm_t *vm,
const char *feature)
1095 st_data_t key = (st_data_t)feature;
1096 st_data_t init_func;
1097 if (st_delete(vm->static_ext_inits, &key, &init_func)) {
1098 ((void (*)(void))init_func)();
1106no_feature_p(
rb_vm_t *vm,
const char *feature,
const char *ext,
int rb,
int expanded,
const char **fn)
1113rb_resolve_feature_path(
VALUE klass,
VALUE fname)
1119 fname = rb_get_path(fname);
1120 path = rb_str_encode_ospath(fname);
1121 found = search_required(GET_VM(), path, &path, no_feature_p);
1134 return rb_ary_new_from_args(2, sym, path);
1140 *prev = th->ext_config;
1147 th->ext_config = *prev;
1153 GET_THREAD()->ext_config.ractor_safe = flag;
1166 volatile int result = -1;
1168 volatile const struct {
1169 VALUE wrapper, self, errinfo;
1171 th->top_wrapper, th->top_self, ec->errinfo,
1173 enum ruby_tag_type state;
1174 char *
volatile ftptr = 0;
1176 volatile VALUE saved_path;
1177 volatile VALUE realpath = 0;
1178 VALUE realpaths = get_loaded_features_realpaths(th->vm);
1179 VALUE realpath_map = get_loaded_features_realpath_map(th->vm);
1180 volatile bool reset_ext_config =
false;
1183 path = rb_str_encode_ospath(fname);
1184 RUBY_DTRACE_HOOK(REQUIRE_ENTRY,
RSTRING_PTR(fname));
1189 th->top_wrapper = 0;
1190 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
1194 RUBY_DTRACE_HOOK(FIND_REQUIRE_ENTRY,
RSTRING_PTR(fname));
1195 found = search_required(th->vm, path, &saved_path, rb_feature_p);
1196 RUBY_DTRACE_HOOK(FIND_REQUIRE_RETURN,
RSTRING_PTR(fname));
1200 if (!path || !(ftptr = load_lock(th->vm,
RSTRING_PTR(path), warn))) {
1204 result = TAG_RETURN;
1207 else if (found ==
's' && run_static_ext_init(th->vm,
RSTRING_PTR(path))) {
1208 result = TAG_RETURN;
1211 else if (
RTEST(rb_hash_aref(realpaths,
1212 realpath = rb_realpath_internal(
Qnil, path, 1)))) {
1218 load_iseq_eval(ec, path);
1222 reset_ext_config =
true;
1223 ext_config_push(th, &prev_ext_config);
1224 handle = (long)rb_vm_call_cfunc(rb_vm_top_self(), load_ext,
1225 path, VM_BLOCK_HANDLER_NONE, path);
1226 rb_ary_push(ruby_dln_librefs,
LONG2NUM(handle));
1229 result = TAG_RETURN;
1236 th2->top_self = saved.self;
1237 th2->top_wrapper = saved.wrapper;
1238 if (reset_ext_config) ext_config_pop(th2, &prev_ext_config);
1241 if (ftptr) load_unlock(th2->vm,
RSTRING_PTR(path), !state);
1244 if (state == TAG_FATAL || state == TAG_THROW) {
1245 EC_JUMP_TAG(ec, state);
1247 else if (exception) {
1250 VALUE exc = rb_vm_make_jump_tag_but_local_jump(state,
Qundef);
1251 if (!
NIL_P(exc)) ec->errinfo = exc;
1254 else if (state == TAG_RETURN) {
1261 if (!
NIL_P(ec->errinfo)) {
1262 if (!exception)
return TAG_RAISE;
1266 if (result == TAG_RETURN) {
1267 rb_provide_feature(th2->vm, path);
1268 VALUE real = realpath;
1270 real = rb_fstring(real);
1271 rb_hash_aset(realpaths, real,
Qtrue);
1272 rb_hash_aset(realpath_map, path, real);
1275 ec->errinfo = saved.errinfo;
1277 RUBY_DTRACE_HOOK(REQUIRE_RETURN,
RSTRING_PTR(fname));
1283rb_require_internal_silent(
VALUE fname)
1286 return require_internal(ec, fname, 1,
false);
1290rb_require_internal(
VALUE fname)
1297ruby_require_internal(
const char *fname,
unsigned int len)
1300 VALUE str = rb_setup_fake_str(&fake, fname,
len, 0);
1304 return result == TAG_RETURN ? 1 : result ? -1 : 0;
1314rb_require_string_internal(
VALUE fname)
1319 if (result > TAG_RETURN) {
1320 EC_JUMP_TAG(ec, result);
1326 return RBOOL(result);
1333 VALUE str = rb_setup_fake_str(&fake, fname, strlen(fname), 0);
1334 return rb_require_string_internal(str);
1339register_init_ext(st_data_t *key, st_data_t *value, st_data_t init,
int existing)
1341 const char *name = (
char *)*key;
1344 rb_warn(
"%s is already registered", name);
1347 *value = (st_data_t)init;
1353ruby_init_ext(
const char *name,
void (*init)(
void))
1356 st_table *inits_table = vm->static_ext_inits;
1358 if (feature_provided(vm, name, 0))
1360 st_update(inits_table, (st_data_t)name, register_init_ext, (st_data_t)init);
1388 rb_autoload_str(mod,
id, file);
1419rb_mod_autoload_p(
int argc,
VALUE *argv,
VALUE mod)
1422 VALUE sym = argv[0];
1428 return rb_autoload_at_p(mod,
id, recur);
1453 return rb_mod_autoload(klass, sym, file);
1468rb_f_autoload_p(
int argc,
VALUE *argv,
VALUE obj)
1471 VALUE klass = rb_vm_cbase();
1475 return rb_mod_autoload_p(argc, argv, klass);
1482 static const char var_load_path[] =
"$:";
1483 ID id_load_path =
rb_intern2(var_load_path,
sizeof(var_load_path)-1);
1488 vm->load_path = rb_ary_new();
1489 vm->expanded_load_path = rb_ary_hidden_new(0);
1490 vm->load_path_snapshot = rb_ary_hidden_new(0);
1491 vm->load_path_check_cache = 0;
1496 vm->loaded_features = rb_ary_new();
1497 vm->loaded_features_snapshot = rb_ary_hidden_new(0);
1498 vm->loaded_features_index = st_init_numtable();
1499 vm->loaded_features_realpaths = rb_hash_new();
1501 vm->loaded_features_realpath_map = rb_hash_new();
1512 ruby_dln_librefs = rb_ary_hidden_new(0);
1513 rb_gc_register_mark_object(ruby_dln_librefs);
#define rb_define_method(klass, mid, func, arity)
Defines klass#mid.
#define rb_define_singleton_method(klass, mid, func, arity)
Defines klass.mid.
#define rb_define_global_function(mid, func, arity)
Defines rb_mKernel #mid.
void rb_extend_object(VALUE obj, VALUE module)
Extend the object with the module.
VALUE rb_module_new(void)
Creates a new, anonymous module.
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Retrieves argument from argc and argv to given VALUE references according to the format string.
#define rb_str_new2
Old name of rb_str_new_cstr.
#define T_STRING
Old name of RUBY_T_STRING.
#define xfree
Old name of ruby_xfree.
#define Qundef
Old name of RUBY_Qundef.
#define INT2FIX
Old name of RB_INT2FIX.
#define OBJ_FROZEN
Old name of RB_OBJ_FROZEN.
#define rb_str_cat2
Old name of rb_str_cat_cstr.
#define ID2SYM
Old name of RB_ID2SYM.
#define SPECIAL_CONST_P
Old name of RB_SPECIAL_CONST_P.
#define OBJ_FREEZE
Old name of RB_OBJ_FREEZE.
#define T_FIXNUM
Old name of RUBY_T_FIXNUM.
#define T_MODULE
Old name of RUBY_T_MODULE.
#define LONG2NUM
Old name of RB_LONG2NUM.
#define Qtrue
Old name of RUBY_Qtrue.
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define FIX2LONG
Old name of RB_FIX2LONG.
#define NIL_P
Old name of RB_NIL_P.
#define FIXNUM_P
Old name of RB_FIXNUM_P.
void rb_raise(VALUE exc, const char *fmt,...)
Exception entry point.
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
void rb_set_errinfo(VALUE err)
Sets the current exception ($!) to the given value.
#define ruby_verbose
This variable controls whether the interpreter is in debug mode.
VALUE rb_eTypeError
TypeError exception.
VALUE rb_eRuntimeError
RuntimeError exception.
void rb_warn(const char *fmt,...)
Identical to rb_warning(), except it reports always regardless of runtime -W flag.
void rb_loaderror(const char *fmt,...)
Raises an instance of rb_eLoadError.
void rb_warning(const char *fmt,...)
Issues a warning.
VALUE rb_obj_hide(VALUE obj)
Make the object invisible from Ruby code.
VALUE rb_cModule
Module class.
VALUE rb_class_real(VALUE klass)
Finds a "real" class.
VALUE rb_obj_clone(VALUE obj)
Produces a shallow copy of the given object.
VALUE rb_obj_freeze(VALUE obj)
Just calls rb_obj_freeze_inline() inside.
static int rb_check_arity(int argc, int min, int max)
Ensures that the passed integer is in the passed range.
void rb_provide(const char *feature)
Declares that the given feature is already provided by someone else.
VALUE rb_f_require(VALUE self, VALUE feature)
Identical to rb_require_string(), except it ignores the first argument for no reason.
void rb_ext_ractor_safe(bool flag)
Asserts that the extension library that calls this function is aware of Ractor.
VALUE rb_require_string(VALUE feature)
Finds and loads the given feature, if absent.
int rb_feature_provided(const char *feature, const char **loading)
Identical to rb_provided(), except it additionally returns the "canonical" name of the loaded feature...
void rb_load_protect(VALUE path, int wrap, int *state)
Identical to rb_load(), except it avoids potential global escapes.
int rb_provided(const char *feature)
Queries if the given feature has already been loaded into the execution context.
void rb_load(VALUE path, int wrap)
Loads and executes the Ruby program in the given file.
VALUE rb_str_append(VALUE dst, VALUE src)
Identical to rb_str_buf_append(), except it converts the right hand side before concatenating.
VALUE rb_str_tmp_new(long len)
Allocates a "temporary" string.
VALUE rb_str_subseq(VALUE str, long beg, long len)
Identical to rb_str_substr(), except the numbers are interpreted as byte offsets instead of character...
VALUE rb_str_dup(VALUE str)
Duplicates a string.
VALUE rb_filesystem_str_new_cstr(const char *ptr)
Identical to rb_filesystem_str_new(), except it assumes the passed pointer is a pointer to a C string...
VALUE rb_str_equal(VALUE str1, VALUE str2)
Equality of two strings.
#define rb_strlen_lit(str)
Length of a string literal.
VALUE rb_str_freeze(VALUE str)
This is the implementation of String#freeze.
#define rb_str_cat_cstr(buf, str)
Identical to rb_str_cat(), except it assumes the passed pointer is a pointer to a C string.
VALUE rb_str_resize(VALUE str, long len)
Overwrites the length of the string.
void rb_alias_variable(ID dst, ID src)
Aliases a global variable.
ID rb_intern2(const char *name, long len)
Identical to rb_intern(), except it additionally takes the length of the string.
static ID rb_intern_const(const char *str)
This is a "tiny optimisation" over rb_intern().
ID rb_check_id(volatile VALUE *namep)
Detects if the given name is already interned or not.
ID rb_intern(const char *name)
Finds or creates a symbol of the given name.
ID rb_to_id(VALUE str)
Identical to rb_intern(), except it takes an instance of rb_cString.
rb_gvar_setter_t rb_gvar_readonly_setter
This function just raises rb_eNameError.
char * ruby_strdup(const char *str)
This is our own version of strdup(3) that uses ruby_xmalloc() instead of system malloc (benefits our ...
#define MEMCPY(p1, p2, type, n)
Handy macro to call memcpy.
#define RB_GC_GUARD(v)
Prevents premature destruction of local objects.
#define MEMMOVE(p1, p2, type, n)
Handy macro to call memmove.
void rb_define_hooked_variable(const char *q, VALUE *w, type *e, void_type *r)
Define a function-backended global variable.
VALUE type(ANYARGS)
ANYARGS-ed function type.
void rb_define_virtual_variable(const char *q, type *w, void_type *e)
Define a function-backended global variable.
#define RARRAY_LEN
Just another name of rb_array_len.
#define RARRAY_AREF(a, i)
#define StringValue(v)
Ensures that the parameter object is a String.
#define StringValuePtr(v)
Identical to StringValue, except it returns a char*.
static long RSTRING_LEN(VALUE str)
Queries the length of the string.
static char * RSTRING_PTR(VALUE str)
Queries the contents pointer of the string.
VALUE rb_require(const char *feature)
Identical to rb_require_string(), except it takes C's string instead of Ruby's.
#define FilePathValue(v)
Ensures that the parameter object is a path.
#define RTEST
This is an old name of RB_TEST.
#define _(args)
This was a transition path from K&R to ANSI.
long len
Length of the string, not including terminating NUL character.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
uintptr_t VALUE
Type that represents a Ruby object.
static void Check_Type(VALUE v, enum ruby_value_type t)
Identical to RB_TYPE_P(), except it raises exceptions on predication failure.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.