diff options
-rw-r--r-- | eval.c | 155 | ||||
-rw-r--r-- | file.c | 106 | ||||
-rw-r--r-- | intern.h | 3 | ||||
-rw-r--r-- | regex.c | 2 |
4 files changed, 133 insertions, 133 deletions
@@ -5142,8 +5142,8 @@ rb_load(fname, wrap) VALUE fname; int wrap; { + VALUE tmp; int state; - char *file; volatile ID last_func; volatile VALUE wrapper = 0; volatile VALUE self = ruby_top_self; @@ -5156,10 +5156,11 @@ rb_load(fname, wrap) else { Check_SafeStr(fname); } - file = rb_find_file(RSTRING(fname)->ptr); - if (!file) { + tmp = rb_find_file(fname); + if (!tmp) { rb_raise(rb_eLoadError, "No such file to load -- %s", RSTRING(fname)->ptr); } + fname = tmp; ruby_errinfo = Qnil; /* ensure */ PUSH_VARS(); @@ -5184,19 +5185,8 @@ rb_load(fname, wrap) ruby_frame->self = self; ruby_frame->cbase = (VALUE)rb_node_newnode(NODE_CREF,ruby_class,0,0); PUSH_SCOPE(); - if (ruby_class == rb_cObject && top_scope->local_tbl) { - int len = top_scope->local_tbl[0]+1; - ID *tbl = ALLOC_N(ID, len); - VALUE *vars = TMP_ALLOC(len); - *vars++ = 0; - MEMCPY(tbl, top_scope->local_tbl, ID, len); - MEMCPY(vars, top_scope->local_vars, VALUE, len-1); - ruby_scope->local_tbl = tbl; /* copy toplevel scope */ - ruby_scope->local_vars = vars; /* will not alter toplevel variables */ - } /* default visibility is private at loading toplevel */ SCOPE_SET(SCOPE_PRIVATE); - PUSH_TAG(PROT_NONE); state = EXEC_TAG(); last_func = ruby_frame->last_func; @@ -5205,7 +5195,7 @@ rb_load(fname, wrap) DEFER_INTS; ruby_in_eval++; - rb_load_file(file); + rb_load_file(RSTRING(fname)->ptr); ruby_in_eval--; node = ruby_eval_tree; ALLOW_INTS; @@ -5271,18 +5261,16 @@ rb_feature_p(feature, wait) const char *feature; int wait; { - VALUE *p, *pend; + VALUE v; char *f; - int len; + int i, len = strlen(feature); - p = RARRAY(rb_features)->ptr; - pend = p + RARRAY(rb_features)->len; - while (p < pend) { - f = STR2CSTR(*p); + for (i = 0; i < RARRAY(rb_features)->len; ++i) { + v = RARRAY(rb_features)->ptr[i]; + f = STR2CSTR(v); if (strcmp(f, feature) == 0) { goto load_wait; } - len = strlen(feature); if (strncmp(f, feature, len) == 0) { if (strcmp(f+len, ".so") == 0) { return Qtrue; @@ -5292,7 +5280,6 @@ rb_feature_p(feature, wait) return Qtrue; } } - p++; } return Qfalse; @@ -5321,33 +5308,39 @@ rb_provided(feature) return rb_feature_p(feature, Qfalse); } -void -rb_provide(feature) - const char *feature; +static void +rb_provide_feature(feature) + VALUE feature; { - char *buf, *ext; + char *ext; + char *f = RSTRING(feature)->ptr; - ext = strrchr(feature, '.'); + ext = strrchr(f, '.'); if (ext && (strcmp(DLEXT, ext) == 0 #ifdef DLEXT2 || strcmp(DLEXT2, ext) == 0 #endif )) { - buf = ALLOCA_N(char, strlen(feature)+4); - strcpy(buf, feature); - ext = strrchr(buf, '.'); - strcpy(ext, ".so"); - feature = buf; + feature = rb_str_new(RSTRING(feature)->ptr, ext-RSTRING(feature)->ptr); + rb_str_cat2(feature, ".so"); } - if (rb_feature_p(feature, Qtrue)) return; - rb_ary_push(rb_features, rb_str_new2(feature)); + if (rb_feature_p(RSTRING(feature)->ptr, Qtrue)) return; + rb_ary_push(rb_features, feature); +} + +void +rb_provide(feature) + const char *feature; +{ + rb_provide_feature(rb_str_new2(feature)); } VALUE rb_f_require(obj, fname) VALUE obj, fname; { - char *ext, *file, *feature, *buf; /* OK */ + VALUE feature, tmp; + char *ext, *ftptr; /* OK */ volatile VALUE load; int state; volatile int safe = ruby_safe_level; @@ -5357,83 +5350,79 @@ rb_f_require(obj, fname) return Qfalse; ext = strrchr(RSTRING(fname)->ptr, '.'); if (ext) { - feature = file = RSTRING(fname)->ptr; if (strcmp(".rb", ext) == 0) { - file = rb_find_file(file); - if (file) goto load_rb; + feature = rb_str_dup(fname); + tmp = rb_find_file(fname); + if (tmp) { + fname = tmp; + goto load_rb; + } } else if (strcmp(".so", ext) == 0 || strcmp(".o", ext) == 0) { - if (strcmp(ext, DLEXT) != 0) { - buf = ALLOCA_N(char, strlen(file)+sizeof(DLEXT)+4); - strcpy(buf, feature); - ext = strrchr(buf, '.'); - strcpy(ext, DLEXT); - file = feature = buf; + fname = rb_str_new(RSTRING(fname)->ptr, ext-RSTRING(fname)->ptr); + tmp = rb_str_dup(fname); + rb_str_cat2(tmp, DLEXT); + tmp = rb_find_file(tmp); + if (tmp) { + feature = fname = tmp; + goto load_dyna; } - file = rb_find_file(file); - if (file) goto load_dyna; #ifdef DLEXT2 - file = feature = RSTRING(fname)->ptr; - if (strcmp(ext, DLEXT2) != 0) { - buf = ALLOCA_N(char, strlen(file)+sizeof(DLEXT2)+4); - strcpy(buf, feature); - ext = strrchr(buf, '.'); - strcpy(ext, DLEXT2); - file = feature = buf; + tmp = rb_str_dup(fname); + rb_str_cat2(tmp, DLEXT); + tmp = rb_find_file(tmp); + if (tmp) { + feature = fname = tmp; + goto load_dyna; } - file = rb_find_file(file); - if (file) goto load_dyna; #endif } else if (strcmp(DLEXT, ext) == 0) { - feature = RSTRING(fname)->ptr; - file = rb_find_file(feature); - if (file) goto load_dyna; + tmp = rb_find_file(fname); + if (tmp) { + feature = fname = tmp; + goto load_dyna; + } } #ifdef DLEXT2 else if (strcmp(DLEXT2, ext) == 0) { - feature = RSTRING(fname)->ptr; - file = rb_find_file(feature); - if (file) goto load_dyna; + tmp = rb_find_file(fname); + if (tmp) { + feature = fname = tmp; + goto load_dyna; + } } #endif } - obj = fname; - if (RSTRING(fname)->ptr[0] == '~') { - obj = rb_file_s_expand_path(1, &fname); - } - buf = ALLOCA_N(char, strlen(RSTRING(obj)->ptr) + 5); - strcpy(buf, RSTRING(fname)->ptr); - switch (rb_find_file_noext(buf)) { + tmp = fname; + switch (rb_find_file_noext(&tmp)) { case 0: break; case 1: - fname = rb_str_new2(buf); - file = feature = buf; + feature = fname; + fname = tmp; goto load_rb; default: - feature = buf; - file = rb_find_file(buf); + feature = fname; + fname = rb_find_file(tmp); goto load_dyna; } rb_raise(rb_eLoadError, "No such file to load -- %s", RSTRING(fname)->ptr); load_dyna: - rb_provide(feature); + rb_provide_feature(feature); { - int old_vmode = scope_vmode; + int volatile old_vmode = scope_vmode; PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { void *handle; SCOPE_SET(SCOPE_PUBLIC); - load = rb_str_new2(file); - file = RSTRING(load)->ptr; - handle = dln_load(file); + handle = dln_load(RSTRING(fname)->ptr); rb_ary_push(ruby_dln_librefs, INT2NUM((long)handle)); } POP_TAG(); @@ -5445,21 +5434,22 @@ rb_f_require(obj, fname) load_rb: ruby_safe_level = 0; - rb_provide(feature); + rb_provide_feature(feature); /* loading ruby library should be serialized. */ if (!loading_tbl) { loading_tbl = st_init_strtable(); } /* partial state */ - st_insert(loading_tbl, strdup(feature), curr_thread); + ftptr = ruby_strdup(RSTRING(feature)->ptr); + st_insert(loading_tbl, ftptr, curr_thread); PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { rb_load(fname, 0); } POP_TAG(); - st_delete(loading_tbl, &feature, 0); /* loading done */ - free(feature); + st_delete(loading_tbl, &ftptr, 0); /* loading done */ + free(ftptr); ruby_safe_level = safe; if (state) JUMP_TAG(state); @@ -5643,6 +5633,7 @@ rb_mod_include(argc, argv, module) for (i=0; i<argc; i++) { Check_Type(argv[i], T_MODULE); rb_funcall(argv[i], rb_intern("append_features"), 1, module); + rb_funcall(argv[i], rb_intern("included"), 1, module); } return module; } @@ -2139,26 +2139,27 @@ is_macos_native_path(path) } #endif -static char* +static int file_load_ok(file) char *file; { FILE *f; + if (!file) return 0; f = fopen(file, "r"); if (f == NULL) return 0; fclose(f); - return file; + return 1; } extern VALUE rb_load_path; int -rb_find_file_noext(file) - char *file; +rb_find_file_noext(filep) + VALUE *filep; { char *path, *e, *found; - char *fend = file + strlen(file); + char *f = RSTRING(*filep)->ptr; VALUE fname; int i, j; @@ -2170,10 +2171,22 @@ rb_find_file_noext(file) 0 }; - if (is_absolute_path(file)) { + if (f[0] == '~') { + fname = *filep; + fname = rb_file_s_expand_path(1, &fname); + if (rb_safe_level() >= 2 && OBJ_TAINTED(fname)) { + rb_raise(rb_eSecurityError, "loading from unsafe file %s", f); + } + } + + if (is_absolute_path(f)) { for (i=0; ext[i]; i++) { - strcpy(fend, ext[i]); - if (file_load_ok(file)) return i+1; + fname = rb_str_dup(*filep); + rb_str_cat2(fname, ext[i]); + if (file_load_ok(RSTRING(fname)->ptr)) { + *filep = fname; + return i+1; + } } return 0; } @@ -2187,81 +2200,76 @@ rb_find_file_noext(file) Check_SafeStr(str); path = RSTRING(str)->ptr; for (j=0; ext[j]; j++) { - strcpy(fend, ext[j]); - found = dln_find_file(file, path); - if (found && file_load_ok(found)) return j+1; + fname = rb_str_dup(*filep); + rb_str_cat2(fname, ext[j]); + found = dln_find_file(RSTRING(fname)->ptr, path); + if (found && file_load_ok(found)) { + *filep = fname; + return j+1; + } } } return 0; } -char* -rb_find_file(file) - char *file; +VALUE +rb_find_file(path) + VALUE path; { - volatile VALUE vpath; - VALUE fname; - char *path; + VALUE tmp, fname; + char *f = RSTRING(path)->ptr; + char *lpath; struct stat st; - if (file[0] == '~') { - fname = rb_str_new2(file); - fname = rb_file_s_expand_path(1, &fname); - if (rb_safe_level() >= 2 && OBJ_TAINTED(fname)) { - rb_raise(rb_eSecurityError, "loading from unsafe file %s", file); + if (f[0] == '~') { + tmp = rb_file_s_expand_path(1, &path); + if (rb_safe_level() >= 2 && OBJ_TAINTED(tmp)) { + rb_raise(rb_eSecurityError, "loading from unsafe file %s", f); } - file = STR2CSTR(fname); } #if defined(__MACOS__) || defined(riscos) - if (is_macos_native_path(file)) { - if (rb_safe_level() >= 2 && !rb_path_check(file)) { - rb_raise(rb_eSecurityError, "loading from unsafe file %s", file); + if (is_macos_native_path(f)) { + if (rb_safe_level() >= 2 && !rb_path_check(f)) { + rb_raise(rb_eSecurityError, "loading from unsafe file %s", f); } - return file_load_ok(file); + if (file_load_ok(f)) return path; } #endif - if (is_absolute_path(file)) { - if (rb_safe_level() >= 2 && !rb_path_check(file)) { - rb_raise(rb_eSecurityError, "loading from unsafe file %s", file); + if (is_absolute_path(f)) { + if (rb_safe_level() >= 2 && !rb_path_check(f)) { + rb_raise(rb_eSecurityError, "loading from unsafe file %s", f); } - return file_load_ok(file); - } - - if (file[0] == '~') { - fname = rb_str_new2(file); - fname = rb_file_s_expand_path(1, &fname); - if (rb_safe_level() >= 2 && OBJ_TAINTED(fname)) { - rb_raise(rb_eSecurityError, "loading from unsafe file %s", file); - } - file = STR2CSTR(fname); + if (file_load_ok(f)) return path; } if (rb_load_path) { int i; Check_Type(rb_load_path, T_ARRAY); - vpath = rb_ary_new(); + tmp = rb_ary_new(); for (i=0;i<RARRAY(rb_load_path)->len;i++) { VALUE str = RARRAY(rb_load_path)->ptr[i]; Check_SafeStr(str); if (RSTRING(str)->len > 0) { - rb_ary_push(vpath, str); + rb_ary_push(tmp, str); } } - vpath = rb_ary_join(vpath, rb_str_new2(PATH_SEP)); - path = STR2CSTR(vpath); - if (rb_safe_level() >= 2 && !rb_path_check(path)) { - rb_raise(rb_eSecurityError, "loading from unsafe path %s", path); + tmp = rb_ary_join(tmp, rb_str_new2(PATH_SEP)); + lpath = STR2CSTR(tmp); + if (rb_safe_level() >= 2 && !rb_path_check(lpath)) { + rb_raise(rb_eSecurityError, "loading from unsafe path %s", lpath); } } else { - path = 0; + lpath = 0; } - path = dln_find_file(file, path); - return file_load_ok(path); + f = dln_find_file(f, lpath); + if (file_load_ok(f)) { + return rb_str_new2(f); + } } static void @@ -179,7 +179,8 @@ void rb_thread_atfork _((void)); int eaccess _((const char*, int)); VALUE rb_file_s_expand_path _((int, VALUE *)); void rb_file_const _((const char*, VALUE)); -char *rb_find_file _((char*)); +int rb_find_file_noext _((VALUE*)); +VALUE rb_find_file _((VALUE)); /* gc.c */ void rb_gc_mark_locations _((VALUE*, VALUE*)); void rb_mark_tbl _((struct st_table*)); @@ -3373,7 +3373,7 @@ re_search(bufp, string, size, startpos, range, regs) #define MAX_NUM_FAILURE_ITEMS (num_regs * NUM_REG_ITEMS + NUM_NONREG_ITEMS) /* We push this many things on the stack whenever we fail. */ -#define NUM_FAILURE_ITEMS (last_used_reg * NUM_REG_ITEMS + NUM_NOREG_ITEMS + 1) +#define NUM_FAILURE_ITEMS (last_used_reg * NUM_REG_ITEMS + NUM_NONREG_ITEMS + 1) /* This pushes counter information for succeed_n and jump_n */ #define PUSH_FAILURE_COUNT(ptr) \ |