diff options
-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; } } |