13 #define IS_RBEXT(e) (strcmp((e), ".rb") == 0) 14 #define IS_SOEXT(e) (strcmp((e), ".so") == 0 || strcmp((e), ".o") == 0) 16 #define IS_DLEXT(e) (strcmp((e), DLEXT) == 0 || strcmp((e), DLEXT2) == 0) 18 #define IS_DLEXT(e) (strcmp((e), DLEXT) == 0) 60 VALUE path, as_str, expanded_path;
61 int is_string, non_cache;
65 non_cache = !is_string ? 1 : 0;
73 (!as_cstr[0] || as_cstr[0] !=
'~')) ||
82 if (!*has_non_cache && non_cache)
114 int has_relative = 0, has_non_cache = 0;
119 else if (has_non_cache) {
128 int has_relative = 1, has_non_cache = 1;
131 &has_relative, &has_non_cache);
134 int has_relative = 1, has_non_cache = 1;
141 &has_relative, &has_non_cache);
146 &has_relative, &has_non_cache);
161 return GET_VM()->loaded_features;
174 return GET_VM()->loaded_features_index;
180 return GET_VM()->loading_table;
188 char *short_feature_cstr;
197 if (
NIL_P(this_feature_index)) {
201 VALUE feature_indexes[2];
202 feature_indexes[0] = this_feature_index;
203 feature_indexes[1] = offset;
227 const char *feature_str, *feature_end, *ext, *p;
232 for (ext = feature_end; ext > feature_str; ext--)
233 if (*ext ==
'.' || *ext ==
'/')
240 p = ext ? ext : feature_end;
245 while (p >= feature_str && *p !=
'/')
250 beg = p + 1 - feature_str;
251 short_feature =
rb_str_subseq(feature, beg, feature_end - p - 1);
260 short_feature =
rb_str_subseq(feature, 0, ext - feature_str);
322 if (vlen < len+1)
return 0;
323 if (
strchr(feature,
'.') && !strncmp(name+(vlen-len), feature, len)) {
327 for (e = name + vlen; name != e && *e !=
'.' && *e !=
'/'; --e);
330 strncmp(e-len, feature, len))
332 plen = e - name -
len;
334 if (plen > 0 && name[plen-1] !=
'/') {
337 if (type ==
's' ? !
IS_DLEXT(&name[plen+len]) :
338 type ==
'r' ? !
IS_RBEXT(&name[plen+len]) :
345 if (plen > 0) --plen;
351 if (n != plen)
continue;
352 if (n && strncmp(name, s, n))
continue;
369 const char *s = (
const char *)v;
379 rb_feature_p(
const char *feature,
const char *ext,
int rb,
int expanded,
const char **fn)
383 long i,
len, elen, n;
384 st_table *loading_tbl, *features_index;
391 len =
strlen(feature) - elen;
392 type = rb ?
'r' :
's';
429 if (!
NIL_P(this_feature_index)) {
434 if (i >=
RARRAY_LEN(this_feature_index))
break;
439 entry = this_feature_index;
446 if (strncmp(f, feature, len) != 0) {
447 if (expanded)
continue;
454 if (!*(e = f + len)) {
458 if (*e !=
'.')
continue;
462 if ((rb || !ext) && (
IS_RBEXT(e))) {
478 if ((f = fs.result) != 0) {
484 if (fn) *fn = (
const char*)data;
486 if (!ext)
return 'u';
492 static const char so_ext[][4] = {
496 if (ext && *ext)
return 0;
499 MEMCPY(buf, feature,
char, len);
504 if (fn) *fn = (
const char*)data;
505 return i ?
's' :
'r';
508 for (i = 0; i <
numberof(so_ext); i++) {
512 if (fn) *fn = (
const char*)data;
530 const char *ext =
strrchr(feature,
'.');
533 if (*feature ==
'.' &&
534 (feature[1] ==
'/' || strncmp(feature+1,
"./", 2) == 0)) {
538 if (ext && !
strchr(ext,
'/')) {
562 "$LOADED_FEATURES is frozen; cannot append feature");
586 #if !defined __GNUC__ 621 #if !defined __GNUC__ 630 if (
NIL_P(exc))
return state;
671 volatile VALUE path = 0;
700 VALUE fname, wrap, path, orig_fname;
732 return (
char *)ftptr;
736 void (*init)(void) = (
void (*)(void))memo->
u3.
func;
743 rb_warning(
"loading in progress, circular require considered harmful - %s", ftptr);
751 return (
char *)ftptr;
855 if (ext && !
strchr(ext,
'/')) {
916 goto statically_linked;
932 return type ?
's' :
'r';
965 char *
volatile ftptr = 0;
1036 return result ==
TAG_RETURN ? 1 : result ? -1 : 0;
1066 const char *
name = (
char *)*key;
1069 rb_warn(
"%s is already registered", name);
1182 #define rb_intern(str) rb_intern2((str), strlen(str)) 1184 static const char var_load_path[] =
"$:";
1185 ID id_load_path =
rb_intern2(var_load_path,
sizeof(var_load_path)-1);
1193 vm->load_path_check_cache = 0;
static VALUE ruby_dln_librefs
void rb_backtrace_print_to(VALUE output)
VALUE rb_get_path_check_convert(VALUE obj, VALUE tmp, int level)
static void features_index_add(VALUE feature, VALUE offset)
ID rb_check_id(volatile VALUE *)
Returns ID for the given name if it is interned already, or 0.
VALUE rb_get_path(VALUE obj)
static int rb_load_internal0(rb_thread_t *th, VALUE fname, int wrap)
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 *)
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))
static void rb_construct_expanded_load_path(enum expand_type type, int *has_relative, int *has_non_cache)
ID rb_intern2(const char *, long)
int rb_is_absolute_path(const char *path)
NORETURN(static void load_failed(VALUE))
VALUE rb_setup_fake_str(struct RString *fake_str, const char *name, long len, rb_encoding *enc)
#define rb_usascii_str_new2
static const struct st_features features[]
static void rb_load_internal(VALUE fname, int wrap)
VALUE rb_current_realfilepath(void)
struct st_table * loaded_features_index
static void rb_provide_feature(VALUE feature)
int rb_provided(const char *feature)
VALUE rb_vm_call_cfunc(VALUE recv, VALUE(*func)(VALUE), VALUE arg, VALUE block_handler, VALUE filename)
VALUE rb_get_path_check_to_string(VALUE obj, int level)
int ruby_require_internal(const char *fname, unsigned int len)
#define TH_JUMP_TAG(th, st)
static VALUE load_ext(VALUE path)
VALUE rb_ary_push(VALUE ary, VALUE item)
#define VM_BLOCK_HANDLER_NONE
VALUE rb_ary_tmp_new(long capa)
static VALUE file_to_load(VALUE fname)
VALUE rb_ary_shared_with_p(VALUE ary1, VALUE ary2)
int st_get_key(st_table *, st_data_t, st_data_t *)
int rb_require_internal(VALUE fname, int safe)
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rb_f_require_relative(VALUE obj, VALUE fname)
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.
#define RUBY_DTRACE_HOOK(name, arg)
#define MEMO_NEW(a, b, c)
void rb_load_fail(VALUE path, const char *err)
VALUE rb_str_tmp_new(long)
VALUE rb_ary_cat(VALUE ary, const VALUE *argv, long len)
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)
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)
const rb_iseq_t * rb_iseq_load_iseq(VALUE fname)
VALUE rb_f_require(VALUE obj, VALUE fname)
static const char *const loadable_ext[]
RUBY_SYMBOL_EXPORT_BEGIN typedef unsigned long st_data_t
static char * load_lock(const char *ftptr)
void rb_exc_raise(VALUE mesg)
static struct st_table * get_loaded_features_index_raw(void)
#define RB_TYPE_P(obj, type)
void * rb_parser_load_file(VALUE parser, VALUE name)
void rb_ary_free(VALUE ary)
VALUE rb_find_file(VALUE path)
VALUE rb_str_encode_ospath(VALUE path)
char * ruby_strdup(const char *)
VALUE rb_require(const char *fname)
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)
VALUE rb_parser_set_context(VALUE vparser, const struct rb_block *base, int main)
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_str_subseq(VALUE, long, long)
void rb_alias_variable(ID, ID)
static VALUE load_path_getcwd(void)
void rb_gvar_readonly_setter(VALUE v, ID id, void *d, struct rb_global_variable *g)
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_vm_top_self(void)
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)
void rb_define_hooked_variable(const char *, VALUE *, VALUE(*)(ANYARGS), void(*)(ANYARGS))
VALUE rb_class_real(VALUE cl)
register unsigned int len
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)
RUBY_EXTERN VALUE rb_stderr
VALUE rb_thread_shield_new(void)
static VALUE rb_mod_autoload(VALUE mod, VALUE sym, VALUE file)
VALUE rb_module_new(void)
#define RARRAY_AREF(a, i)
void rb_set_errinfo(VALUE err)
VALUE rb_iseq_eval(const rb_iseq_t *iseq)
void rb_scope_visibility_set(rb_method_visibility_t)
const struct st_hash_type * type
VALUE loaded_features_snapshot
VALUE rb_filesystem_str_new_cstr(const char *)
VALUE rb_parser_new(void)
VALUE rb_thread_shield_wait(VALUE self)
VALUE rb_realpath_internal(VALUE basedir, VALUE path, int strict)
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)
void rb_autoload_str(VALUE mod, ID id, VALUE file)
#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,...)
rb_iseq_t * rb_iseq_new_top(NODE *node, VALUE name, VALUE path, VALUE absolute_path, const rb_iseq_t *parent)
static VALUE rb_f_autoload_p(VALUE obj, VALUE sym)
VALUE rb_obj_freeze(VALUE)
#define SPECIAL_CONST_P(x)
VALUE rb_vm_make_jump_tag_but_local_jump(int state, VALUE val)
static void load_unlock(const char *ftptr, int done)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
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)