load.c: cwd encoding

* load.c (rb_get_expanded_load_path): save cwd cache in OS path
  encoding, to get rid of unnecessary conversion and infinite
  loading when it needs encoding conversion.
  [ruby-dev:50221] [Bug #13863]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60743 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-11-12 04:45:51 +00:00
parent 74597b0b4b
commit 7a693278c2
2 changed files with 14 additions and 11 deletions

13
load.c
View File

@ -94,15 +94,6 @@ rb_construct_expanded_load_path(enum expand_type type, int *has_relative, int *h
rb_ary_replace(vm->load_path_snapshot, vm->load_path); rb_ary_replace(vm->load_path_snapshot, vm->load_path);
} }
static VALUE
load_path_getcwd(void)
{
char *cwd = my_getcwd();
VALUE cwd_str = rb_filesystem_str_new_cstr(cwd);
xfree(cwd);
return cwd_str;
}
VALUE VALUE
rb_get_expanded_load_path(void) rb_get_expanded_load_path(void)
{ {
@ -114,7 +105,7 @@ rb_get_expanded_load_path(void)
int has_relative = 0, has_non_cache = 0; int has_relative = 0, has_non_cache = 0;
rb_construct_expanded_load_path(EXPAND_ALL, &has_relative, &has_non_cache); rb_construct_expanded_load_path(EXPAND_ALL, &has_relative, &has_non_cache);
if (has_relative) { if (has_relative) {
vm->load_path_check_cache = load_path_getcwd(); vm->load_path_check_cache = rb_dir_getwd_ospath();
} }
else if (has_non_cache) { else if (has_non_cache) {
/* Non string object. */ /* Non string object. */
@ -132,7 +123,7 @@ rb_get_expanded_load_path(void)
} }
else if (vm->load_path_check_cache) { else if (vm->load_path_check_cache) {
int has_relative = 1, has_non_cache = 1; int has_relative = 1, has_non_cache = 1;
VALUE cwd = load_path_getcwd(); VALUE cwd = rb_dir_getwd_ospath();
if (!rb_str_equal(vm->load_path_check_cache, cwd)) { if (!rb_str_equal(vm->load_path_check_cache, cwd)) {
/* Current working directory or filesystem encoding was changed. /* Current working directory or filesystem encoding was changed.
Expand relative load path and non-cacheable objects again. */ Expand relative load path and non-cacheable objects again. */

View File

@ -966,4 +966,16 @@ class TestRubyOptions < Test::Unit::TestCase
end end
end end
end end
def test_cwd_encoding
with_tmpchdir do
testdir = "\u30c6\u30b9\u30c8"
Dir.mkdir(testdir)
Dir.chdir(testdir) do
File.write("a.rb", "require './b'")
File.write("b.rb", "puts 'ok'")
assert_ruby_status([{"RUBYLIB"=>"."}, *%w[-E cp932:utf-8 a.rb]])
end
end
end
end end