[前][次][番号順一覧][スレッド一覧]

ruby-changes:70211

From: Koichi <ko1@a...>
Date: Wed, 15 Dec 2021 02:33:27 +0900 (JST)
Subject: [ruby-changes:70211] 397a509b6d (master): prohibit load by `autoload` on non-main Ractor

https://git.ruby-lang.org/ruby.git/commit/?id=397a509b6d

From 397a509b6d0d1470df8c290d7c4adef78f1532ee Mon Sep 17 00:00:00 2001
From: Koichi Sasada <ko1@a...>
Date: Wed, 15 Dec 2021 01:11:45 +0900
Subject: prohibit load by `autoload` on non-main Ractor

fix [Bug #18120]
---
 bootstraptest/test_ractor.rb | 11 +++++++++++
 variable.c                   |  4 ++++
 2 files changed, 15 insertions(+)

diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb
index e259684974b..5d9edb26d6d 100644
--- a/bootstraptest/test_ractor.rb
+++ b/bootstraptest/test_ractor.rb
@@ -211,6 +211,17 @@ assert_equal '[:a, :b, :c, :d, :e, :f, :g]', %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_ractor.rb#L211
   Ractor.make_shareable(closure).call
 }
 
+# Now autoload in non-main Ractor is not supported
+assert_equal 'ok', %q{
+  autoload :Foo, 'foo.rb'
+  r = Ractor.new do
+    p Foo
+  rescue Ractor::UnsafeError
+    :ok
+  end
+  r.take
+}
+
 ###
 ###
 # Ractor still has several memory corruption so skip huge number of tests
diff --git a/variable.c b/variable.c
index 87d53cdb90f..c2b8146f9a4 100644
--- a/variable.c
+++ b/variable.c
@@ -2553,6 +2553,10 @@ rb_autoload_load(VALUE mod, ID id) https://github.com/ruby/ruby/blob/trunk/variable.c#L2553
     src = rb_sourcefile();
     if (src && loading && strcmp(src, loading) == 0) return Qfalse;
 
+    if (UNLIKELY(!rb_ractor_main_p())) {
+        rb_raise(rb_eRactorUnsafeError, "require by autoload on non-main Ractor is not supported (%s)", rb_id2name(id));
+    }
+
     if ((ce = rb_const_lookup(mod, id))) {
         flag = ce->flag & (CONST_DEPRECATED | CONST_VISIBILITY_MASK);
     }
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]