diff options
author | Koichi Sasada <ko1@atdot.net> | 2021-12-15 01:11:45 +0900 |
---|---|---|
committer | Koichi Sasada <ko1@atdot.net> | 2021-12-15 02:33:17 +0900 |
commit | 397a509b6d0d1470df8c290d7c4adef78f1532ee (patch) | |
tree | 35e1775cae465eb1d5a7d793ce8b7b48b6cd0123 | |
parent | 2e6e2fd9da18b74aa9555d09a871b24895e42773 (diff) |
prohibit load by `autoload` on non-main Ractor
fix [Bug #18120]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5267
-rw-r--r-- | bootstraptest/test_ractor.rb | 11 | ||||
-rw-r--r-- | variable.c | 4 |
2 files changed, 15 insertions, 0 deletions
diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb index e259684974..5d9edb26d6 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{ 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 87d53cdb90..c2b8146f9a 100644 --- a/variable.c +++ b/variable.c @@ -2553,6 +2553,10 @@ rb_autoload_load(VALUE mod, ID id) 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); } |