ruby-changes:4746
From: ko1@a...
Date: Wed, 30 Apr 2008 18:03:26 +0900 (JST)
Subject: [ruby-changes:4746] nobu - Ruby:r16240 (trunk): * load.c (rb_load_path), vm_core.h (rb_vm_t): moved to VM.
nobu 2008-04-30 18:03:03 +0900 (Wed, 30 Apr 2008) New Revision: 16240 Modified files: trunk/ChangeLog trunk/file.c trunk/load.c trunk/ruby.c trunk/vm.c trunk/vm_core.h Log: * 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. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/load.c?r1=16240&r2=16239&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/file.c?r1=16240&r2=16239&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ruby.c?r1=16240&r2=16239&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=16240&r2=16239&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/vm_core.h?r1=16240&r2=16239&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/vm.c?r1=16240&r2=16239&diff_format=u Index: ChangeLog =================================================================== --- ChangeLog (revision 16239) +++ ChangeLog (revision 16240) @@ -1,3 +1,16 @@ +Wed Apr 30 18:03:01 2008 Nobuyoshi Nakada <nobu@r...> + + * 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 <nobu@r...> * re.c (rb_reg_search): use local variable. a patch from wanabe Index: vm_core.h =================================================================== --- vm_core.h (revision 16239) +++ vm_core.h (revision 16240) @@ -303,6 +303,7 @@ /* load */ VALUE top_self; + VALUE load_path; VALUE loaded_features; struct st_table *loading_table; Index: load.c =================================================================== --- load.c (revision 16239) +++ load.c (revision 16240) @@ -23,11 +23,10 @@ 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; @@ -38,6 +37,12 @@ } static VALUE +load_path_getter(ID id, rb_vm_t *vm) +{ + return vm->load_path; +} + +static VALUE get_loaded_features(void) { return GET_VM()->loaded_features; @@ -126,7 +131,7 @@ 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 @@ 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 @@ 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); Index: vm.c =================================================================== --- vm.c (revision 16239) +++ vm.c (revision 16240) @@ -1490,6 +1490,7 @@ 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); Index: ruby.c =================================================================== --- ruby.c (revision 16239) +++ ruby.c (revision 16240) @@ -150,7 +150,7 @@ 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 @@ { 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 @@ 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 @@ void ruby_init_loadpath(void) { + VALUE load_path; #if defined LOAD_RELATIVE char libpath[MAXPATHLEN + 1]; char *p; @@ -375,7 +377,8 @@ #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 @@ 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 @@ 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) { Index: file.c =================================================================== --- file.c (revision 16239) +++ file.c (revision 16240) @@ -4292,14 +4292,14 @@ 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 @@ 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<RARRAY_LEN(rb_load_path);i++) { - VALUE str = RARRAY_PTR(rb_load_path)[i]; + for (i = 0; i < RARRAY_LEN(load_path); i++) { + VALUE str = RARRAY_PTR(load_path)[i]; FilePathValue(str); if (RSTRING_LEN(str) == 0) continue; @@ -4351,7 +4351,7 @@ VALUE rb_find_file(VALUE path) { - VALUE tmp; + VALUE tmp, load_path; char *f = StringValueCStr(path); char *lpath; @@ -4384,13 +4384,13 @@ rb_raise(rb_eSecurityError, "loading from non-absolute path %s", f); } - if (rb_load_path) { + load_path = rb_get_load_path(); + if (load_path) { long i; - Check_Type(rb_load_path, T_ARRAY); tmp = rb_ary_new(); - for (i=0;i<RARRAY_LEN(rb_load_path);i++) { - VALUE str = RARRAY_PTR(rb_load_path)[i]; + for (i = 0; i < RARRAY_LEN(load_path); i++) { + VALUE str = RARRAY_PTR(load_path)[i]; FilePathValue(str); if (RSTRING_LEN(str) > 0) { rb_ary_push(tmp, str); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/