dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] variable.c (rb_autoload_load): allow recursive calls
Date: Mon,  9 Nov 2015 21:10:07 +0000	[thread overview]
Message-ID: <20151109211007.24278-1-e@80x24.org> (raw)

* 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 <h.shirosaki@gmail.com>
---
 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


                 reply	other threads:[~2015-11-09 21:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151109211007.24278-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=spew@80x24.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).