From 64c08dafe2e592fe3d4f18c5b90ca392453c8221 Mon Sep 17 00:00:00 2001 From: normal Date: Mon, 9 Nov 2015 21:18:42 +0000 Subject: variable.c (rb_autoload_load): allow recursive calls * variable.c (rb_autoload_load): allow recursive calls [ruby-core:71345] [Bug #11658] * test/ruby/test_autoload.rb (test_autoload_while_autoloading): new test by: Hiroshi Shirosaki [ruby-core:71390] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52511 b2dd03c8-39d4-4d8f-98ff-823fe69b080e diff --git a/ChangeLog b/ChangeLog index 20c5a6c..c4bc28f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Tue Nov 10 06:17:17 2015 Eric Wong + + * variable.c (rb_autoload_load): allow recursive calls + [ruby-core:71345] [Bug #11658] + * test/ruby/test_autoload.rb (test_autoload_while_autoloading): + new test by: Hiroshi Shirosaki + [ruby-core:71390] + Tue Nov 10 00:36:46 2015 Tanaka Akira * lib/resolv.rb (Resolv::DNS::Message::MessageEncoder#put_labels): diff --git a/test/ruby/test_autoload.rb b/test/ruby/test_autoload.rb index 719502d..a672e0b 100644 --- a/test/ruby/test_autoload.rb +++ b/test/ruby/test_autoload.rb @@ -215,6 +215,25 @@ p Foo::Bar end end + def test_autoload_while_autoloading + ruby_impl_require do |called_with| + Tempfile.create(%w(a .rb)) do |a| + Tempfile.create(%w(b .rb)) do |b| + a.puts "require '#{b.path}'; class AutoloadTest; end" + b.puts "class AutoloadTest; module B; end; end" + [a, b].each(&:flush) + add_autoload(a.path) + begin + assert(Object::AutoloadTest) + ensure + remove_autoload_constant + end + assert_equal [a.path, b.path], called_with + end + end + end + end + def add_autoload(path) (@autoload_paths ||= []) << path ::Object.class_eval {autoload(:AutoloadTest, path)} diff --git a/variable.c b/variable.c index ec6924a..c8264b1 100644 --- a/variable.c +++ b/variable.c @@ -2179,6 +2179,9 @@ rb_autoload_load(VALUE mod, ID id) */ list_head_init(&state.waitq.head); } + else if (state.thread == ele->state->thread) { + return Qfalse; + } else { list_add_tail(&ele->state->waitq.head, &state.waitq.node); /* -- cgit v0.10.2