diff options
author | Koichi Sasada <ko1@atdot.net> | 2021-12-24 12:26:21 +0900 |
---|---|---|
committer | Koichi Sasada <ko1@atdot.net> | 2021-12-24 13:52:02 +0900 |
commit | 6050e3e2a6ce2269c56fa74bc5b75a94d064b61f (patch) | |
tree | 2547646ab7a59516ddc0f40a6bded331904dfcd7 | |
parent | e029560b22fef5dd665495a2af01c11ffcd33e12 (diff) |
@@cv is not accessible from non-main ractors
Class variables (@@cv) is not accessible from non-main ractors.
But without this patch cached @@cv can be read.
fix [Bug #18128]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5335
-rw-r--r-- | bootstraptest/test_ractor.rb | 22 | ||||
-rw-r--r-- | vm_insnhelper.c | 4 |
2 files changed, 25 insertions, 1 deletions
diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb index 5d9edb26d6..b29db7ab0e 100644 --- a/bootstraptest/test_ractor.rb +++ b/bootstraptest/test_ractor.rb @@ -1101,6 +1101,28 @@ assert_equal 'can not access class variables from non-main Ractors', %q{ end } +# also cached cvar in shareable-objects are not allowed to access from non-main Ractor +assert_equal 'can not access class variables from non-main Ractors', %q{ + class C + @@cv = 'str' + def self.cv + @@cv + end + end + + C.cv # cache + + r = Ractor.new do + C.cv + end + + begin + r.take + rescue Ractor::RemoteError => e + e.cause.message + end +} + # Getting non-shareable objects via constants by other Ractors is not allowed assert_equal 'can not access non-shareable objects in constant C::CONST by non-main Ractor.', %q{ class C diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 37229b5dc0..e01d39de77 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -1320,7 +1320,9 @@ vm_getclassvariable(const rb_iseq_t *iseq, const rb_control_frame_t *reg_cfp, ID VALUE v = Qundef; RB_DEBUG_COUNTER_INC(cvar_read_inline_hit); - if (st_lookup(RCLASS_IV_TBL(ic->entry->class_value), (st_data_t)id, &v)) { + if (st_lookup(RCLASS_IV_TBL(ic->entry->class_value), (st_data_t)id, &v) && + LIKELY(rb_ractor_main_p())) { + return v; } } |