dumping ground for random patches and texts
 help / color / mirror / Atom feed
* [PATCH] variable.c (rb_autoload_load): allow recursive calls
@ 2015-11-09 21:10 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-11-09 21:10 UTC (permalink / raw)
  To: spew

* 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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-11-09 21:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-09 21:10 [PATCH] variable.c (rb_autoload_load): allow recursive calls Eric Wong

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).