diff options
author | shirosaki <shirosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-11-05 15:27:08 +0000 |
---|---|---|
committer | shirosaki <shirosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-11-05 15:27:08 +0000 |
commit | d33b9a8a724f5c46308b1a76062ac5722269905b (patch) | |
tree | feab65ac1008f1ff64fea87eff57b72972e39f9c /file.c | |
parent | 9823c46189d7447692ea6c33e07b4cae5fed74f2 (diff) | |
download | ruby-d33b9a8a724f5c46308b1a76062ac5722269905b.tar.gz |
Fix compatibility of cached expanded load path
* file.c (rb_get_path_check_to_string): extract from
rb_get_path_check(). We change the spec not to call to_path of
String object.
* file.c (rb_get_path_check_convert): extract from rb_get_path_check().
* file.c (rb_get_path_check): follow the above change.
* file.c (rb_file_expand_path_fast): remove check_expand_path_args().
Instead we call it in load.c.
* file.c (rb_find_file_ext_safe): use rb_get_expanded_load_path() to
reduce expand cost.
* file.c (rb_find_file_safe): ditto.
* internal.h (rb_get_expanded_load_path): add a declaration.
* internal.h (rb_get_path_check_to_string, rb_get_path_check_convert):
add declarations.
* load.c (rb_construct_expanded_load_path): fix for compatibility.
Same checks in rb_get_path_check() are added. We don't replace
$LOAD_PATH and ensure that String object of $LOAD_PATH are frozen.
We don't freeze non String object and expand it every times. We add
arguments for expanding load path partially and checking if load path
have relative paths or non String objects.
* load.c (load_path_getcwd): get current working directory for checking
if it's changed when getting load path.
* load.c (rb_get_expanded_load_path): fix for rebuilding cache properly.
We check if current working directory is changed and rebuild expanded
load path cache. We expand paths which start with ~ (User HOME) and
non String objects every times for compatibility. We make this
accessible from other source files.
* load.c (rb_feature_provided): call rb_get_path() since we changed
rb_file_expand_path_fast() not to call it.
* load.c (Init_load): initialize vm->load_path_check_cache.
* vm.c (rb_vm_mark): mark vm->load_path_check_cache for GC.
* vm_core.h (rb_vm_struct): add vm->load_path_check_cache to store data
to check load path cache validity.
* test/ruby/test_require.rb (TestRequire): add tests for require
compatibility related to cached expanded load path.
[ruby-core:47970] [Bug #7158]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37482 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'file.c')
-rw-r--r-- | file.c | 24 |
1 files changed, 19 insertions, 5 deletions
@@ -167,8 +167,8 @@ check_path_encoding(VALUE str) return enc; } -static VALUE -rb_get_path_check(VALUE obj, int level) +VALUE +rb_get_path_check_to_string(VALUE obj, int level) { VALUE tmp; ID to_path; @@ -177,13 +177,21 @@ rb_get_path_check(VALUE obj, int level) rb_insecure_operation(); } + if (RB_TYPE_P(obj, T_STRING)) { + return obj; + } CONST_ID(to_path, "to_path"); tmp = rb_check_funcall(obj, to_path, 0, 0); if (tmp == Qundef) { tmp = obj; } StringValue(tmp); + return tmp; +} +VALUE +rb_get_path_check_convert(VALUE obj, VALUE tmp, int level) +{ tmp = file_path_convert(tmp); if (obj != tmp && insecure_obj_p(tmp, level)) { rb_insecure_operation(); @@ -195,6 +203,13 @@ rb_get_path_check(VALUE obj, int level) return rb_str_new4(tmp); } +static VALUE +rb_get_path_check(VALUE obj, int level) +{ + VALUE tmp = rb_get_path_check_to_string(obj, level); + return rb_get_path_check_convert(obj, tmp, level); +} + VALUE rb_get_path_no_checksafe(VALUE obj) { @@ -3255,7 +3270,6 @@ rb_file_expand_path(VALUE fname, VALUE dname) VALUE rb_file_expand_path_fast(VALUE fname, VALUE dname) { - check_expand_path_args(fname, dname); return rb_file_expand_path_internal(fname, dname, 0, 0, EXPAND_PATH_BUFFER()); } @@ -5258,7 +5272,7 @@ rb_find_file_ext_safe(VALUE *filep, const char *const *ext, int safe_level) rb_raise(rb_eSecurityError, "loading from non-absolute path %s", f); } - RB_GC_GUARD(load_path) = rb_get_load_path(); + RB_GC_GUARD(load_path) = rb_get_expanded_load_path(); if (!load_path) return 0; fname = rb_str_dup(*filep); @@ -5323,7 +5337,7 @@ rb_find_file_safe(VALUE path, int safe_level) rb_raise(rb_eSecurityError, "loading from non-absolute path %s", f); } - RB_GC_GUARD(load_path) = rb_get_load_path(); + RB_GC_GUARD(load_path) = rb_get_expanded_load_path(); if (load_path) { long i; |