From acb23454e57e1bbe828e7f3114430cab2d5db44c Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Fri, 22 Oct 2021 17:24:34 +0900 Subject: allow to access ivars of classes/modules if an ivar of a class/module refer to a shareable object, this ivar can be read from non-main Ractors. --- bootstraptest/test_ractor.rb | 49 +++++++++++++++++++++++++++++++++++++++++++- bootstraptest/test_yjit.rb | 4 ++-- 2 files changed, 50 insertions(+), 3 deletions(-) (limited to 'bootstraptest') diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb index 4da348df67..ee3f13cad9 100644 --- a/bootstraptest/test_ractor.rb +++ b/bootstraptest/test_ractor.rb @@ -928,7 +928,7 @@ assert_equal 'ArgumentError', %q{ } # ivar in shareable-objects are not allowed to access from non-main Ractor -assert_equal 'can not access instance variables of classes/modules from non-main Ractors', %q{ +assert_equal "can not get unshareable values from instance variables of classes/modules from non-main Ractors", %q{ class C @iv = 'str' end @@ -1022,6 +1022,53 @@ assert_equal '11', %q{ }.join } +# and instance variables of classes/modules are accessible if they refer shareable objects +assert_equal '333', %q{ + class C + @int = 1 + @str = '-1000'.dup + @fstr = '100'.freeze + + def self.int = @int + def self.str = @str + def self.fstr = @fstr + end + + module M + @int = 2 + @str = '-2000'.dup + @fstr = '200'.freeze + + def self.int = @int + def self.str = @str + def self.fstr = @fstr + end + + a = Ractor.new{ C.int }.take + b = Ractor.new do + C.str.to_i + rescue Ractor::IsolationError + 10 + end.take + c = Ractor.new do + C.fstr.to_i + end.take + + d = Ractor.new{ M.int }.take + e = Ractor.new do + M.str.to_i + rescue Ractor::IsolationError + 20 + end.take + f = Ractor.new do + M.fstr.to_i + end.take + + + # 1 + 10 + 100 + 2 + 20 + 200 + a + b + c + d + e + f +} + # 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 diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb index 20db784a39..183b19c3eb 100644 --- a/bootstraptest/test_yjit.rb +++ b/bootstraptest/test_yjit.rb @@ -2023,14 +2023,14 @@ assert_normal_exit %q{ foo([1]) rescue nil } -# test ractor exception on when getting ivar +# test ractor exception on when setting ivar assert_equal '42', %q{ class A def self.foo _foo = 1 _bar = 2 begin - @bar + @bar = _foo + _bar rescue Ractor::IsolationError 42 end -- cgit v1.2.3