diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-11-06 07:37:49 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-11-06 07:37:49 +0000 |
commit | 974cd1b3800519d356298b0f7526dd90938c31ed (patch) | |
tree | 77483c16e7ef3d23e728183a316472f54ce4ae49 | |
parent | bb1f1c57823758d2450d184ce7c85beb0d538bf0 (diff) | |
download | ruby-974cd1b3800519d356298b0f7526dd90938c31ed.tar.gz |
* eval_load.c (loaded_feature_path): need to expand relative paths.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13827 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | eval_load.c | 29 |
2 files changed, 26 insertions, 7 deletions
@@ -1,4 +1,6 @@ -Tue Nov 6 15:52:01 2007 Nobuyoshi Nakada <nobu@ruby-lang.org> +Tue Nov 6 16:37:47 2007 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * eval_load.c (loaded_feature_path): need to expand relative paths. * eval_load.c (rb_feature_p): check if the feature is loading with load path. [ruby-dev:31932] diff --git a/eval_load.c b/eval_load.c index c0deda9540..7855429fde 100644 --- a/eval_load.c +++ b/eval_load.c @@ -23,6 +23,18 @@ static const char *const loadable_ext[] = { }; VALUE rb_load_path; /* to be moved to VM */ +static VALUE +get_load_path(void) +{ + VALUE load_path = rb_load_path; + VALUE ary = rb_ary_new2(RARRAY_LEN(load_path)); + long i; + + for (i = 0; i < RARRAY_LEN(load_path); ++i) { + rb_ary_push(ary, rb_file_expand_path(RARRAY_PTR(load_path)[i], Qnil)); + } + return ary; +} static VALUE get_loaded_features(void) @@ -37,12 +49,13 @@ get_loading_table(void) } static VALUE -loaded_feature_path(const char *name, long vlen, const char *feature, long len) +loaded_feature_path(const char *name, long vlen, const char *feature, long len, + VALUE load_path) { long i; - for (i = 0; i < RARRAY_LEN(rb_load_path); ++i) { - VALUE p = RARRAY_PTR(rb_load_path)[i]; + for (i = 0; i < RARRAY_LEN(load_path); ++i) { + VALUE p = RARRAY_PTR(load_path)[i]; const char *s = StringValuePtr(p); long n = RSTRING_LEN(p); @@ -58,6 +71,7 @@ loaded_feature_path(const char *name, long vlen, const char *feature, long len) struct loaded_feature_searching { const char *name; long len; + VALUE load_path; const char *result; }; @@ -66,7 +80,7 @@ loaded_feature_path_i(st_data_t v, st_data_t b, st_data_t f) { const char *s = (const char *)v; struct loaded_feature_searching *fp = (struct loaded_feature_searching *)f; - VALUE p = loaded_feature_path(s, strlen(s), fp->name, fp->len); + VALUE p = loaded_feature_path(s, strlen(s), fp->name, fp->len, fp->load_path); if (!p) return ST_CONTINUE; fp->result = s; return ST_STOP; @@ -75,7 +89,7 @@ loaded_feature_path_i(st_data_t v, st_data_t b, st_data_t f) static int rb_feature_p(const char *feature, const char *ext, int rb, int expanded) { - VALUE v, features, p; + VALUE v, features, p, load_path = 0; const char *f, *e; long i, len, elen, n; st_table *loading_tbl; @@ -94,7 +108,9 @@ rb_feature_p(const char *feature, const char *ext, int rb, int expanded) f = StringValuePtr(v); if ((n = RSTRING_LEN(v)) < len) continue; if (strncmp(f, feature, len) != 0) { - if (expanded || !(p = loaded_feature_path(f, n, feature, len))) + if (expanded) continue; + if (!load_path) load_path = get_load_path(); + if (!(p = loaded_feature_path(f, n, feature, len, load_path))) continue; f += RSTRING_LEN(p) + 1; } @@ -116,6 +132,7 @@ rb_feature_p(const char *feature, const char *ext, int rb, int expanded) struct loaded_feature_searching fs; fs.name = feature; fs.len = len; + fs.load_path = load_path ? load_path : get_load_path(); fs.result = 0; st_foreach(loading_tbl, loaded_feature_path_i, (st_data_t)&fs); if (fs.result) goto loading; |