From 01b773a0931901948a5099a6f5e95dc10d0a1c03 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 30 Apr 2008 09:03:03 +0000 Subject: [PATCH] * load.c (rb_load_path), vm_core.h (rb_vm_t): moved to VM. * load.c (rb_get_load_path): returns absolute load path. * load.c (load_path_getter): $LOAD_PATH getter. * file.c (rb_find_file_ext, rb_find_file), ruby.c (push_include, ruby_init_loadpath): use the accessor. * vm.c (rb_vm_mark): mark load_path. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16240 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 13 +++++++++++++ file.c | 22 +++++++++++----------- load.c | 31 ++++++++++++++++++++----------- ruby.c | 13 ++++++++----- vm.c | 1 + vm_core.h | 1 + 6 files changed, 54 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2f662fe943..5d671d4677 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +Wed Apr 30 18:03:01 2008 Nobuyoshi Nakada + + * load.c (rb_load_path), vm_core.h (rb_vm_t): moved to VM. + + * load.c (rb_get_load_path): returns absolute load path. + + * load.c (load_path_getter): $LOAD_PATH getter. + + * file.c (rb_find_file_ext, rb_find_file), ruby.c (push_include, + ruby_init_loadpath): use the accessor. + + * vm.c (rb_vm_mark): mark load_path. + Wed Apr 30 17:47:21 2008 Nobuyoshi Nakada * re.c (rb_reg_search): use local variable. a patch from wanabe diff --git a/file.c b/file.c index 88893e7d9d..4c51c171e8 100644 --- a/file.c +++ b/file.c @@ -4292,14 +4292,14 @@ file_load_ok(const char *path) return eaccess(path, R_OK) == 0; } -extern VALUE rb_load_path; +VALUE rb_get_load_path(void); int rb_find_file_ext(VALUE *filep, const char *const *ext) { char *path, *found; char *f = RSTRING_PTR(*filep); - VALUE fname; + VALUE fname, load_path; long i, j; if (f[0] == '~') { @@ -4325,15 +4325,15 @@ rb_find_file_ext(VALUE *filep, const char *const *ext) return 0; } - if (!rb_load_path) return 0; + load_path = rb_get_load_path(); + if (!load_path) return 0; - Check_Type(rb_load_path, T_ARRAY); for (j=0; ext[j]; j++) { fname = rb_str_dup(*filep); rb_str_cat2(fname, ext[j]); OBJ_FREEZE(fname); - for (i=0;i 0) { rb_ary_push(tmp, str); diff --git a/load.c b/load.c index 0072ed75ac..154572d80a 100644 --- a/load.c +++ b/load.c @@ -23,11 +23,10 @@ static const char *const loadable_ext[] = { 0 }; -VALUE rb_load_path; /* to be moved to VM */ -static VALUE -get_load_path(void) +VALUE +rb_get_load_path(void) { - VALUE load_path = rb_load_path; + VALUE load_path = GET_VM()->load_path; VALUE ary = rb_ary_new2(RARRAY_LEN(load_path)); long i; @@ -37,6 +36,12 @@ get_load_path(void) return ary; } +static VALUE +load_path_getter(ID id, rb_vm_t *vm) +{ + return vm->load_path; +} + static VALUE get_loaded_features(void) { @@ -126,7 +131,7 @@ rb_feature_p(const char *feature, const char *ext, int rb, int expanded, const c if ((n = RSTRING_LEN(v)) < len) continue; if (strncmp(f, feature, len) != 0) { if (expanded) continue; - if (!load_path) load_path = get_load_path(); + if (!load_path) load_path = rb_get_load_path(); if (!(p = loaded_feature_path(f, n, feature, len, type, load_path))) continue; f += RSTRING_LEN(p) + 1; @@ -151,7 +156,7 @@ rb_feature_p(const char *feature, const char *ext, int rb, int expanded, const c fs.name = feature; fs.len = len; fs.type = type; - fs.load_path = load_path ? load_path : get_load_path(); + fs.load_path = load_path ? load_path : rb_get_load_path(); fs.result = 0; st_foreach(loading_tbl, loaded_feature_path_i, (st_data_t)&fs); if ((f = fs.result) != 0) { @@ -670,14 +675,18 @@ rb_f_autoload_p(VALUE obj, VALUE sym) void Init_load() { - rb_define_readonly_variable("$:", &rb_load_path); - rb_define_readonly_variable("$-I", &rb_load_path); - rb_define_readonly_variable("$LOAD_PATH", &rb_load_path); - rb_load_path = rb_ary_new(); + rb_vm_t *vm = GET_VM(); + const char *var_load_path = "$:"; + ID id_load_path = rb_intern(var_load_path); + + rb_define_hooked_variable(var_load_path, (VALUE*)GET_VM(), load_path_getter, 0); + rb_alias_variable((rb_intern)("$-I"), id_load_path); + rb_alias_variable((rb_intern)("$LOAD_PATH"), id_load_path); + vm->load_path = rb_ary_new(); rb_define_virtual_variable("$\"", get_loaded_features, 0); rb_define_virtual_variable("$LOADED_FEATURES", get_loaded_features, 0); - GET_VM()->loaded_features = rb_ary_new(); + vm->loaded_features = rb_ary_new(); rb_define_global_function("load", rb_f_load, -1); rb_define_global_function("require", rb_f_require, 1); diff --git a/ruby.c b/ruby.c index 7301f1ef50..f0c1c27804 100644 --- a/ruby.c +++ b/ruby.c @@ -150,7 +150,7 @@ usage(const char *name) printf(" %s\n", *p++); } -extern VALUE rb_load_path; +VALUE rb_get_load_path(void); #ifndef CharNext /* defined as CharNext[AW] on Windows. */ #define CharNext(p) ((p) + mblen(p, RUBY_MBCHAR_MAXSIZE)) @@ -224,6 +224,7 @@ push_include(const char *path, VALUE (*filter)(VALUE)) { const char sep = PATH_SEP_CHAR; const char *p, *s; + VALUE load_path = GET_VM()->load_path; p = path; while (*p) { @@ -231,7 +232,7 @@ push_include(const char *path, VALUE (*filter)(VALUE)) p++; if (!*p) break; for (s = p; *s && *s != sep; s = CharNext(s)); - rb_ary_push(rb_load_path, (*filter)(rubylib_mangled_path(p, s - p))); + rb_ary_push(load_path, (*filter)(rubylib_mangled_path(p, s - p))); p = s; } } @@ -329,6 +330,7 @@ DllMain(HINSTANCE dll, DWORD reason, LPVOID reserved) void ruby_init_loadpath(void) { + VALUE load_path; #if defined LOAD_RELATIVE char libpath[MAXPATHLEN + 1]; char *p; @@ -375,7 +377,8 @@ ruby_init_loadpath(void) #else #define RUBY_RELATIVE(path) (path) #endif -#define incpush(path) rb_ary_push(rb_load_path, rubylib_mangled_path2(path)) +#define incpush(path) rb_ary_push(load_path, rubylib_mangled_path2(path)) + load_path = GET_VM()->load_path; if (rb_safe_level() == 0) { ruby_incpush(getenv("RUBYLIB")); @@ -1011,7 +1014,7 @@ process_options(VALUE arg) if (rb_safe_level() >= 4) { OBJ_TAINT(rb_argv); - OBJ_TAINT(rb_load_path); + OBJ_TAINT(GET_VM()->load_path); } if (!opt->e_script) { @@ -1100,7 +1103,7 @@ process_options(VALUE arg) if (rb_safe_level() >= 4) { FL_UNSET(rb_argv, FL_TAINT); - FL_UNSET(rb_load_path, FL_TAINT); + FL_UNSET(GET_VM()->load_path, FL_TAINT); } if (opt->do_check) { diff --git a/vm.c b/vm.c index 211ae8bb62..addfd068a0 100644 --- a/vm.c +++ b/vm.c @@ -1490,6 +1490,7 @@ rb_vm_mark(void *ptr) RUBY_MARK_UNLESS_NULL(vm->thgroup_default); RUBY_MARK_UNLESS_NULL(vm->mark_object_ary); RUBY_MARK_UNLESS_NULL(vm->last_status); + RUBY_MARK_UNLESS_NULL(vm->load_path); RUBY_MARK_UNLESS_NULL(vm->loaded_features); RUBY_MARK_UNLESS_NULL(vm->top_self); diff --git a/vm_core.h b/vm_core.h index 40eb9b3b01..19a52eeeff 100644 --- a/vm_core.h +++ b/vm_core.h @@ -303,6 +303,7 @@ typedef struct rb_vm_struct { /* load */ VALUE top_self; + VALUE load_path; VALUE loaded_features; struct st_table *loading_table;