From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS57858 46.29.248.0/23 X-Spam-Status: No, score=-1.6 required=3.0 tests=AWL,BAYES_00,RCVD_IN_SBL, RCVD_IN_XBL,RDNS_NONE shortcircuit=no autolearn=no version=3.3.2 X-Original-To: spew@80x24.org Received: from 80x24.org (unknown [46.29.248.238]) by dcvr.yhbt.net (Postfix) with ESMTP id AF0581F4E1 for ; Mon, 9 Nov 2015 21:10:29 +0000 (UTC) From: Eric Wong To: spew@80x24.org Subject: [PATCH] variable.c (rb_autoload_load): allow recursive calls Date: Mon, 9 Nov 2015 21:10:07 +0000 Message-Id: <20151109211007.24278-1-e@80x24.org> List-Id: * variable.c (rb_autoload_load): allow recursive calls [ruby-core:71345] [Bug #11658] * test/ruby/test_autoload.rb (test_autoload_while_autoloading): new test. Test by: Hiroshi Shirosaki --- test/ruby/test_autoload.rb | 19 +++++++++++++++++++ variable.c | 3 +++ 2 files changed, 22 insertions(+) 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); /* -- EW