From d741c77b5fd976300815c1ea987e76e92b71122f Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Fri, 11 Dec 2020 16:37:20 +0900 Subject: fix ivar with shareable objects issue Instance variables of sharable objects are accessible only from main ractor, so we need to check it correctly. --- bootstraptest/test_ractor.rb | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'bootstraptest') diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb index 2bbf823f37..81bea95e01 100644 --- a/bootstraptest/test_ractor.rb +++ b/bootstraptest/test_ractor.rb @@ -809,6 +809,53 @@ assert_equal 'can not access instance variables of shareable objects from non-ma end } +# ivar in shareable-objects are not allowed to access from non-main Ractor, by @iv (get) +assert_equal 'can not access instance variables of shareable objects from non-main Ractors', %q{ + class Ractor + def setup + @foo = '' + end + + def foo + @foo + end + end + + shared = Ractor.new{} + shared.setup + + r = Ractor.new shared do |shared| + p shared.foo + end + + begin + r.take + rescue Ractor::RemoteError => e + e.cause.message + end +} + +# ivar in shareable-objects are not allowed to access from non-main Ractor, by @iv (set) +assert_equal 'can not access instance variables of shareable objects from non-main Ractors', %q{ + class Ractor + def setup + @foo = '' + end + end + + shared = Ractor.new{} + + r = Ractor.new shared do |shared| + p shared.setup + end + + begin + r.take + rescue Ractor::RemoteError => e + e.cause.message + end +} + # But a shareable object is frozen, it is allowed to access ivars from non-main Ractor assert_equal '11', %q{ [Object.new, [], ].map{|obj| -- cgit v1.2.3