summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-04-30 09:03:03 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-04-30 09:03:03 +0000
commit01b773a0931901948a5099a6f5e95dc10d0a1c03 (patch)
tree2a4b651b8a8772f75832a36733606b1a337b7585
parentcc88283badde1cac04463a990659aa33fb33ca79 (diff)
* 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
-rw-r--r--ChangeLog13
-rw-r--r--file.c22
-rw-r--r--load.c31
-rw-r--r--ruby.c13
-rw-r--r--vm.c1
-rw-r--r--vm_core.h1
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 <nobu@ruby-lang.org>
+
+ * 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@ruby-lang.org>
* 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<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 @@ rb_find_file_ext(VALUE *filep, const char *const *ext)
VALUE
rb_find_file(VALUE path)
{
- VALUE tmp;
+ VALUE tmp, load_path;
char *f = StringValueCStr(path);
char *lpath;
@@ -4384,13 +4384,13 @@ rb_find_file(VALUE path)
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);
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;
@@ -38,6 +37,12 @@ get_load_path(void)
}
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 @@ 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;