14 #define numberof(array) (int)(sizeof(array) / sizeof((array)[0]))
16 #define IS_RBEXT(e) (strcmp((e), ".rb") == 0)
17 #define IS_SOEXT(e) (strcmp((e), ".so") == 0 || strcmp((e), ".o") == 0)
19 #define IS_DLEXT(e) (strcmp((e), DLEXT) == 0 || strcmp((e), DLEXT2) == 0)
21 #define IS_DLEXT(e) (strcmp((e), DLEXT) == 0)
63 VALUE path, as_str, expanded_path;
64 int is_string, non_cache;
68 non_cache = !is_string ? 1 : 0;
76 (!as_cstr[0] || as_cstr[0] !=
'~')) ||
85 if (!*has_non_cache && non_cache)
117 int has_relative = 0, has_non_cache = 0;
122 else if (has_non_cache) {
131 int has_relative = 1, has_non_cache = 1;
134 &has_relative, &has_non_cache);
137 int has_relative = 1, has_non_cache = 1;
144 &has_relative, &has_non_cache);
149 &has_relative, &has_non_cache);
164 return GET_VM()->loaded_features;
177 return GET_VM()->loaded_features_index;
183 return GET_VM()->loading_table;
191 char *short_feature_cstr;
200 if (
NIL_P(this_feature_index)) {
204 VALUE feature_indexes[2];
205 feature_indexes[0] = this_feature_index;
206 feature_indexes[1] = offset;
229 const char *feature_str, *feature_end, *ext, *
p;
234 for (ext = feature_end; ext > feature_str; ext--)
235 if (*ext ==
'.' || *ext ==
'/')
242 p = ext ? ext : feature_end;
245 while (p >= feature_str && *p !=
'/')
250 short_feature =
rb_str_subseq(feature, p + 1 - feature_str, feature_end - p - 1);
253 short_feature =
rb_str_subseq(feature, p + 1 - feature_str, ext - p - 1);
259 short_feature =
rb_str_subseq(feature, 0, ext - feature_str);
316 if (vlen < len+1)
return 0;
317 if (!strncmp(name+(vlen-len), feature, len)) {
318 plen = vlen - len - 1;
321 for (e = name + vlen; name != e && *e !=
'.' && *e !=
'/'; --e);
324 strncmp(e-len, feature, len))
326 plen = e - name - len - 1;
328 if (type ==
's' && !
IS_DLEXT(&name[plen+len+1])
329 || type ==
'r' && !
IS_RBEXT(&name[plen+len+1])
330 || name[plen] !=
'/') {
341 if (n != plen)
continue;
342 if (n && strncmp(name, s, n))
continue;
359 const char *s = (
const char *)v;
369 rb_feature_p(
const char *feature,
const char *ext,
int rb,
int expanded,
const char **fn)
373 long i,
len, elen, n;
374 st_table *loading_tbl, *features_index;
381 len =
strlen(feature) - elen;
382 type = rb ?
'r' :
's';
419 for (i = 0; !
NIL_P(this_feature_index); i++) {
423 if (i >=
RARRAY_LEN(this_feature_index))
break;
428 entry = this_feature_index;
435 if (strncmp(f, feature, len) != 0) {
436 if (expanded)
continue;
443 if (!*(e = f + len)) {
447 if (*e !=
'.')
continue;
451 if ((rb || !ext) && (
IS_RBEXT(e))) {
467 if ((f = fs.result) != 0) {
473 if (fn) *fn = (
const char*)data;
475 if (!ext)
return 'u';
482 if (ext && *ext)
return 0;
485 MEMCPY(buf, feature,
char, len);
490 if (fn) *fn = (
const char*)data;
491 return i ?
's' :
'r';
509 const char *ext =
strrchr(feature,
'.');
510 volatile VALUE fullpath = 0;
512 if (*feature ==
'.' &&
513 (feature[1] ==
'/' || strncmp(feature+1,
"./", 2) == 0)) {
517 if (ext && !
strchr(ext,
'/')) {
540 "$LOADED_FEATURES is frozen; cannot append feature");
564 volatile int loaded =
FALSE;
565 volatile int mild_compile_error;
660 VALUE fname, wrap, path;
702 return (
char *)ftptr;
705 rb_warning(
"loading in progress, circular require considered harmful - %s", ftptr);
717 return (
char *)ftptr;
816 if (ext && !
strchr(ext,
'/')) {
890 return type ?
's' :
'r';
916 char *
volatile ftptr = 0;
1004 (*(void (*)(void))
arg)();
1114 #define rb_intern(str) rb_intern2((str), strlen(str))
1116 static const char var_load_path[] =
"$:";
1117 ID id_load_path =
rb_intern2(var_load_path,
sizeof(var_load_path)-1);