1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
nobu 2008-04-30 09:03:03 +00:00
parent cc88283bad
commit 01b773a093
6 changed files with 54 additions and 27 deletions

View file

@ -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

22
file.c
View file

@ -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);

31
load.c
View file

@ -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);

13
ruby.c
View file

@ -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) {

1
vm.c
View file

@ -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);

View file

@ -303,6 +303,7 @@ typedef struct rb_vm_struct {
/* load */
VALUE top_self;
VALUE load_path;
VALUE loaded_features;
struct st_table *loading_table;