ruby-changes:68034
From: Jeremy <ko1@a...>
Date: Sun, 19 Sep 2021 09:39:40 +0900 (JST)
Subject: [ruby-changes:68034] 162ad65fdd (master): Revert "Do not load file with same realpath twice when requiring"
https://git.ruby-lang.org/ruby.git/commit/?id=162ad65fdd From 162ad65fdd5e3f826eff4e0208c58a21151e993a Mon Sep 17 00:00:00 2001 From: Jeremy Evans <code@j...> Date: Sat, 18 Sep 2021 17:37:35 -0700 Subject: Revert "Do not load file with same realpath twice when requiring" This reverts commit ddb85c5d2bdf75a83eb163856508691a7436b446. This commit causes unexpected warnings in TestTranscode#test_loading_race occasionally in CI. --- load.c | 33 +-------------------------------- test/ruby/test_require.rb | 30 ++---------------------------- vm.c | 2 -- vm_core.h | 1 - 4 files changed, 3 insertions(+), 63 deletions(-) diff --git a/load.c b/load.c index 4fb1301..28c17e8 100644 --- a/load.c +++ b/load.c @@ -153,12 +153,6 @@ get_loaded_features(void) https://github.com/ruby/ruby/blob/trunk/load.c#L153 } static VALUE -get_loaded_features_realpaths(void) -{ - return GET_VM()->loaded_features_realpaths; -} - -static VALUE get_LOADED_FEATURES(ID _x, VALUE *_y) { return get_loaded_features(); @@ -323,9 +317,6 @@ get_loaded_features_index(void) https://github.com/ruby/ruby/blob/trunk/load.c#L317 /* The sharing was broken; something (other than us in rb_provide_feature()) modified loaded_features. Rebuild the index. */ st_foreach(vm->loaded_features_index, loaded_features_index_clear_i, 0); - - VALUE realpaths = vm->loaded_features_realpaths; - rb_hash_clear(realpaths); features = vm->loaded_features; for (i = 0; i < RARRAY_LEN(features); i++) { VALUE entry, as_str; @@ -337,15 +328,6 @@ get_loaded_features_index(void) https://github.com/ruby/ruby/blob/trunk/load.c#L328 features_index_add(as_str, INT2FIX(i)); } reset_loaded_features_snapshot(); - - features = rb_ary_dup(vm->loaded_features_snapshot); - long j = RARRAY_LEN(features); - for (i = 0; i < j; i++) { - VALUE as_str = rb_ary_entry(features, i); - VALUE realpath = rb_check_realpath(Qnil, as_str, NULL); - if (NIL_P(realpath)) realpath = as_str; - rb_hash_aset(realpaths, rb_fstring(realpath), Qtrue); - } } return vm->loaded_features_index; } @@ -1081,8 +1063,6 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception) https://github.com/ruby/ruby/blob/trunk/load.c#L1063 char *volatile ftptr = 0; VALUE path; volatile VALUE saved_path; - VALUE realpath = 0; - VALUE realpaths = get_loaded_features_realpaths(); volatile bool reset_ext_config = false; struct rb_ext_config prev_ext_config; @@ -1110,10 +1090,6 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception) https://github.com/ruby/ruby/blob/trunk/load.c#L1090 else if (!*ftptr) { result = TAG_RETURN; } - else if (RTEST(rb_hash_aref(realpaths, - realpath = rb_realpath_internal(Qnil, path, 1)))) { - result = 0; - } else { switch (found) { case 'r': @@ -1165,12 +1141,7 @@ require_internal(rb_execution_context_t *ec, VALUE fname, int exception) https://github.com/ruby/ruby/blob/trunk/load.c#L1141 rb_exc_raise(ec->errinfo); } - if (result == TAG_RETURN) { - rb_provide_feature(path); - if (realpath) { - rb_hash_aset(realpaths, rb_fstring(realpath), Qtrue); - } - } + if (result == TAG_RETURN) rb_provide_feature(path); ec->errinfo = saved.errinfo; RUBY_DTRACE_HOOK(REQUIRE_RETURN, RSTRING_PTR(fname)); @@ -1370,8 +1341,6 @@ Init_load(void) https://github.com/ruby/ruby/blob/trunk/load.c#L1341 vm->loaded_features = rb_ary_new(); vm->loaded_features_snapshot = rb_ary_tmp_new(0); vm->loaded_features_index = st_init_numtable(); - vm->loaded_features_realpaths = rb_hash_new(); - rb_obj_hide(vm->loaded_features_realpaths); rb_define_global_function("load", rb_f_load, -1); rb_define_global_function("require", rb_f_require, 1); diff --git a/test/ruby/test_require.rb b/test/ruby/test_require.rb index e996c6d..401b274 100644 --- a/test/ruby/test_require.rb +++ b/test/ruby/test_require.rb @@ -434,32 +434,6 @@ class TestRequire < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_require.rb#L434 } end - def test_relative_symlink_realpath - Dir.mktmpdir {|tmp| - Dir.chdir(tmp) { - Dir.mkdir "a" - File.open("a/a.rb", "w") {|f| f.puts 'require_relative "b"' } - File.open("a/b.rb", "w") {|f| f.puts '$t += 1' } - Dir.mkdir "b" - File.binwrite("c.rb", <<~RUBY) - $t = 0 - $:.unshift(File.expand_path('../b', __FILE__)) - require "b" - require "a" - print $t - RUBY - begin - File.symlink("../a/a.rb", "b/a.rb") - File.symlink("../a/b.rb", "b/b.rb") - result = IO.popen([EnvUtil.rubybin, "c.rb"], &:read) - assert_equal("1", result, "bug17885 [ruby-core:104010]") - rescue NotImplementedError, Errno::EACCES - skip "File.symlink is not implemented" - end - } - } - end - def test_frozen_loaded_features bug3756 = '[ruby-core:31913]' assert_in_out_err(['-e', '$LOADED_FEATURES.freeze; require "ostruct"'], "", @@ -737,8 +711,8 @@ class TestRequire < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_require.rb#L711 assert_in_out_err([{"RUBYOPT" => nil}, "-", script.path], "#{<<~"begin;"}\n#{<<~"end;"}", %w(:ok), [], bug7530, timeout: 60) begin; PATH = ARGV.shift - THREADS = 30 - ITERATIONS_PER_THREAD = 300 + THREADS = 4 + ITERATIONS_PER_THREAD = 1000 THREADS.times.map { Thread.new do diff --git a/vm.c b/vm.c index f6b0f94..1a21638 100644 --- a/vm.c +++ b/vm.c @@ -2486,7 +2486,6 @@ rb_vm_update_references(void *ptr) https://github.com/ruby/ruby/blob/trunk/vm.c#L2486 vm->expanded_load_path = rb_gc_location(vm->expanded_load_path); vm->loaded_features = rb_gc_location(vm->loaded_features); vm->loaded_features_snapshot = rb_gc_location(vm->loaded_features_snapshot); - vm->loaded_features_realpaths = rb_gc_location(vm->loaded_features_realpaths); vm->top_self = rb_gc_location(vm->top_self); vm->orig_progname = rb_gc_location(vm->orig_progname); @@ -2574,7 +2573,6 @@ rb_vm_mark(void *ptr) https://github.com/ruby/ruby/blob/trunk/vm.c#L2573 rb_gc_mark_movable(vm->expanded_load_path); rb_gc_mark_movable(vm->loaded_features); rb_gc_mark_movable(vm->loaded_features_snapshot); - rb_gc_mark_movable(vm->loaded_features_realpaths); rb_gc_mark_movable(vm->top_self); rb_gc_mark_movable(vm->orig_progname); RUBY_MARK_MOVABLE_UNLESS_NULL(vm->coverages); diff --git a/vm_core.h b/vm_core.h index 6b627f4..58243b1 100644 --- a/vm_core.h +++ b/vm_core.h @@ -631,7 +631,6 @@ typedef struct rb_vm_struct { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L631 VALUE expanded_load_path; VALUE loaded_features; VALUE loaded_features_snapshot; - VALUE loaded_features_realpaths; struct st_table *loaded_features_index; struct st_table *loading_table; -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/