15 #define numberof(array) (int)(sizeof(array) / sizeof((array)[0]))
17 #define IS_RBEXT(e) (strcmp((e), ".rb") == 0)
18 #define IS_SOEXT(e) (strcmp((e), ".so") == 0 || strcmp((e), ".o") == 0)
20 #define IS_DLEXT(e) (strcmp((e), DLEXT) == 0 || strcmp((e), DLEXT2) == 0)
22 #define IS_DLEXT(e) (strcmp((e), DLEXT) == 0)
64 VALUE path, as_str, expanded_path;
65 int is_string, non_cache;
69 non_cache = !is_string ? 1 : 0;
77 (!as_cstr[0] || as_cstr[0] !=
'~')) ||
86 if (!*has_non_cache && non_cache)
118 int has_relative = 0, has_non_cache = 0;
123 else if (has_non_cache) {
132 int has_relative = 1, has_non_cache = 1;
135 &has_relative, &has_non_cache);
138 int has_relative = 1, has_non_cache = 1;
145 &has_relative, &has_non_cache);
150 &has_relative, &has_non_cache);
165 return GET_VM()->loaded_features;
178 return GET_VM()->loaded_features_index;
184 return GET_VM()->loading_table;
192 char *short_feature_cstr;
201 if (
NIL_P(this_feature_index)) {
205 VALUE feature_indexes[2];
206 feature_indexes[0] = this_feature_index;
207 feature_indexes[1] = offset;
230 const char *feature_str, *feature_end, *ext, *
p;
235 for (ext = feature_end; ext > feature_str; ext--)
236 if (*ext ==
'.' || *ext ==
'/')
243 p = ext ? ext : feature_end;
246 while (p >= feature_str && *p !=
'/')
251 short_feature =
rb_str_subseq(feature, p + 1 - feature_str, feature_end - p - 1);
254 short_feature =
rb_str_subseq(feature, p + 1 - feature_str, ext - p - 1);
260 short_feature =
rb_str_subseq(feature, 0, ext - feature_str);
317 if (vlen < len+1)
return 0;
318 if (!strncmp(name+(vlen-len), feature, len)) {
322 for (e = name + vlen; name != e && *e !=
'.' && *e !=
'/'; --e);
325 strncmp(e-len, feature, len))
327 plen = e - name - len;
329 if (plen > 0 && name[plen-1] !=
'/') {
332 if (type ==
's' ? !
IS_DLEXT(&name[plen+len]) :
333 type ==
'r' ? !
IS_RBEXT(&name[plen+len]) :
340 if (plen > 0) --plen;
346 if (n != plen)
continue;
347 if (n && strncmp(name, s, n))
continue;
364 const char *s = (
const char *)v;
374 rb_feature_p(
const char *feature,
const char *ext,
int rb,
int expanded,
const char **fn)
378 long i,
len, elen, n;
379 st_table *loading_tbl, *features_index;
386 len =
strlen(feature) - elen;
387 type = rb ?
'r' :
's';
424 for (i = 0; !
NIL_P(this_feature_index); i++) {
428 if (i >=
RARRAY_LEN(this_feature_index))
break;
433 entry = this_feature_index;
440 if (strncmp(f, feature, len) != 0) {
441 if (expanded)
continue;
448 if (!*(e = f + len)) {
452 if (*e !=
'.')
continue;
456 if ((rb || !ext) && (
IS_RBEXT(e))) {
472 if ((f = fs.result) != 0) {
478 if (fn) *fn = (
const char*)data;
480 if (!ext)
return 'u';
486 static const char so_ext[][4] = {
490 if (ext && *ext)
return 0;
493 MEMCPY(buf, feature,
char, len);
498 if (fn) *fn = (
const char*)data;
499 return i ?
's' :
'r';
502 for (i = 0; i <
numberof(so_ext); i++) {
506 if (fn) *fn = (
const char*)data;
525 const char *ext =
strrchr(feature,
'.');
526 volatile VALUE fullpath = 0;
528 if (*feature ==
'.' &&
529 (feature[1] ==
'/' || strncmp(feature+1,
"./", 2) == 0)) {
533 if (ext && !
strchr(ext,
'/')) {
556 "$LOADED_FEATURES is frozen; cannot append feature");
580 volatile int loaded =
FALSE;
581 volatile int mild_compile_error;
676 VALUE fname, wrap, path;
718 return (
char *)ftptr;
722 void (*init)(void) = (
void (*)(void))memo->nd_cfnc;
729 rb_warning(
"loading in progress, circular require considered harmful - %s", ftptr);
741 return (
char *)ftptr;
840 if (ext && !
strchr(ext,
'/')) {
901 goto statically_linked;
917 return type ?
's' :
'r';
943 char *
volatile ftptr = 0;
1008 if (
NIL_P(result)) {
1034 const char *
name = (
char *)*key;
1037 rb_warn(
"%s is already registered", name);
1151 #define rb_intern(str) rb_intern2((str), strlen(str))
1153 static const char var_load_path[] =
"$:";
1154 ID id_load_path =
rb_intern2(var_load_path,
sizeof(var_load_path)-1);
VALUE rb_get_path_check_convert(VALUE obj, VALUE tmp, int level)
static void features_index_add(VALUE feature, VALUE offset)
VALUE rb_get_path(VALUE obj)
static VALUE get_loaded_features(void)
VALUE rb_ary_entry(VALUE ary, long offset)
VALUE rb_str_equal(VALUE str1, VALUE str2)
void rb_load_protect(VALUE fname, int wrap, int *state)
size_t strlen(const char *)
#define RUBY_DTRACE_REQUIRE_ENTRY_ENABLED()
static int register_init_ext(st_data_t *key, st_data_t *value, st_data_t init, int existing)
void rb_define_virtual_variable(const char *, VALUE(*)(ANYARGS), void(*)(ANYARGS))
int rb_is_absolute_path(const char *path)
NORETURN(static void load_failed(VALUE))
#define RUBY_DTRACE_FIND_REQUIRE_ENTRY(arg0, arg1, arg2)
static void rb_load_internal(VALUE fname, int wrap)
int st_insert(st_table *, st_data_t, st_data_t)
VALUE rb_current_realfilepath(void)
#define RUBY_DTRACE_LOAD_RETURN_ENABLED()
struct st_table * loaded_features_index
static void rb_provide_feature(VALUE feature)
#define RUBY_DTRACE_FIND_REQUIRE_RETURN_ENABLED()
int rb_provided(const char *feature)
#define RUBY_DTRACE_FIND_REQUIRE_ENTRY_ENABLED()
VALUE rb_get_path_check_to_string(VALUE obj, int level)
void rb_autoload(VALUE, ID, const char *)
static VALUE load_ext(VALUE path)
VALUE rb_ary_push(VALUE ary, VALUE item)
VALUE rb_ary_tmp_new(long capa)
VALUE rb_ary_shared_with_p(VALUE ary1, VALUE ary2)
int st_get_key(st_table *, st_data_t, st_data_t *)
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rb_f_require_relative(VALUE obj, VALUE fname)
st_table * st_init_strtable(void)
RUBY_FUNC_EXPORTED void ruby_init_ext(const char *name, void(*init)(void))
VALUE rb_get_load_path(void)
int st_update(st_table *table, st_data_t key, st_update_callback_func *func, st_data_t arg)
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
ID rb_check_id(volatile VALUE *namep)
Returns ID for the given name if it is interned already, or 0.
void rb_load_fail(VALUE path, const char *err)
VALUE rb_str_tmp_new(long)
void rb_loaderror(const char *fmt,...)
static int loaded_features_index_clear_i(st_data_t key, st_data_t val, st_data_t arg)
#define RUBY_DTRACE_REQUIRE_ENTRY(arg0, arg1, arg2)
static void reset_loaded_features_snapshot(void)
static int rb_feature_p(const char *feature, const char *ext, int rb, int expanded, const char **fn)
#define RUBY_DTRACE_LOAD_ENTRY_ENABLED()
#define RUBY_DTRACE_LOAD_ENTRY(arg0, arg1, arg2)
VALUE rb_f_require(VALUE obj, VALUE fname)
static const char *const loadable_ext[]
static char * load_lock(const char *ftptr)
void * rb_load_file(const char *)
void rb_exc_raise(VALUE mesg)
static struct st_table * get_loaded_features_index_raw(void)
#define RB_TYPE_P(obj, type)
int st_lookup(st_table *, st_data_t, st_data_t *)
VALUE rb_find_file(VALUE path)
VALUE rb_iseq_new_top(NODE *node, VALUE name, VALUE path, VALUE absolute_path, VALUE parent)
#define RUBY_DTRACE_REQUIRE_RETURN_ENABLED()
VALUE rb_ary_cat(VALUE ary, const VALUE *ptr, long len)
#define RUBY_DTRACE_LOAD_RETURN(arg0, arg1, arg2)
char * ruby_strdup(const char *)
VALUE rb_require(const char *fname)
VALUE rb_class_real(VALUE)
VALUE rb_ary_replace(VALUE copy, VALUE orig)
VALUE rb_str_cat2(VALUE, const char *)
static VALUE load_path_getter(ID id, rb_vm_t *vm)
VALUE rb_thread_shield_release(VALUE self)
static VALUE loaded_feature_path(const char *name, long vlen, const char *feature, long len, int type, VALUE load_path)
VALUE load_path_check_cache
static int release_thread_shield(st_data_t *key, st_data_t *value, st_data_t done, int existing)
void rb_ary_store(VALUE ary, long idx, VALUE val)
static VALUE rb_f_autoload(VALUE obj, VALUE sym, VALUE file)
RUBY_EXTERN VALUE rb_cModule
void rb_gc_register_mark_object(VALUE obj)
#define RUBY_FUNC_EXPORTED
#define MEMCPY(p1, p2, type, n)
void rb_provide(const char *feature)
VALUE rb_find_file_safe(VALUE path, int safe_level)
static st_table * get_loading_table(void)
VALUE rb_file_absolute_path(VALUE fname, VALUE dname)
VALUE rb_str_resize(VALUE, long)
VALUE rb_vm_call_cfunc(VALUE recv, VALUE(*func)(VALUE), VALUE arg, const rb_block_t *blockptr, VALUE filename)
VALUE rb_str_subseq(VALUE, long, long)
void rb_alias_variable(ID, ID)
static VALUE load_path_getcwd(void)
VALUE rb_file_dirname(VALUE fname)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
VALUE rb_thread_shield_destroy(VALUE self)
unsigned char buf[MIME_BUF_SIZE]
void rb_load(VALUE fname, int wrap)
static int loaded_feature_path_i(st_data_t v, st_data_t b, st_data_t f)
static VALUE rb_mod_autoload_p(VALUE mod, VALUE sym)
VALUE rb_iseq_eval(VALUE iseqval)
char * strchr(char *, char)
void rb_extend_object(VALUE obj, VALUE module)
static VALUE rb_f_load(int argc, VALUE *argv)
static st_table * get_loaded_features_index(void)
RUBY_EXTERN size_t strlcpy(char *, const char *, size_t)
void * dln_load(const char *file)
#define RUBY_DTRACE_FIND_REQUIRE_RETURN(arg0, arg1, arg2)
void rb_define_hooked_variable(const char *, VALUE *, VALUE(*)(ANYARGS), void(*)(ANYARGS))
VALUE rb_str_freeze(VALUE)
#define StringValueCStr(v)
void rb_set_safe_level_force(int)
static void features_index_add_single(VALUE short_feature, VALUE offset)
#define NEW_MEMO(a, b, c)
VALUE rb_usascii_str_new2(const char *)
VALUE rb_thread_shield_new(void)
static VALUE rb_mod_autoload(VALUE mod, VALUE sym, VALUE file)
VALUE rb_module_new(void)
int mild_compile_error
Thread-local state of compiling context.
void rb_gvar_readonly_setter(VALUE val, ID id, void *data, struct rb_global_variable *gvar)
static void rb_construct_expanded_load_path(int type, int *has_relative, int *has_non_cache)
VALUE loaded_features_snapshot
VALUE rb_filesystem_str_new_cstr(const char *)
VALUE rb_thread_shield_wait(VALUE self)
VALUE rb_realpath_internal(VALUE basedir, VALUE path, int strict)
#define RUBY_DTRACE_REQUIRE_RETURN(arg0, arg1, arg2)
int rb_feature_provided(const char *feature, const char **loading)
int rb_find_file_ext_safe(VALUE *filep, const char *const *ext, int safe_level)
int rb_file_load_ok(const char *path)
#define StringValuePtr(v)
static int search_required(VALUE fname, volatile VALUE *path, int safe_level)
VALUE rb_get_expanded_load_path(void)
static void load_failed(VALUE fname)
void rb_warning(const char *fmt,...)
static VALUE rb_f_autoload_p(VALUE obj, VALUE sym)
VALUE rb_obj_freeze(VALUE)
ID rb_intern2(const char *name, long len)
static void load_unlock(const char *ftptr, int done)
void rb_vm_jump_tag_but_local_jump(int state)
static rb_thread_t * GET_THREAD(void)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
int st_foreach(st_table *, int(*)(ANYARGS), st_data_t)
VALUE rb_str_new2(const char *)
void rb_warn(const char *fmt,...)
VALUE rb_obj_clone(VALUE)
VALUE rb_require_safe(VALUE fname, int safe)
char * strrchr(const char *, const char)
VALUE rb_file_expand_path_fast(VALUE fname, VALUE dname)
VALUE rb_autoload_p(VALUE, ID)