diff options
author | Koichi Sasada <ko1@atdot.net> | 2020-09-25 03:19:27 +0900 |
---|---|---|
committer | Koichi Sasada <ko1@atdot.net> | 2020-09-25 12:52:53 +0900 |
commit | 52865263467b48c0f5af6d9548972dd1f9e5bee1 (patch) | |
tree | e3f9292d6cdba7c2746f8eef9c69adb001d465b9 /bootstraptest | |
parent | fde136152eacca454bfb978347abfa67bd73ac4d (diff) |
frozen T_OBJECT can be shareable.
If an T_OBJECT object is frozen and all ivars are shareable,
the object should be shareable.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3575
Diffstat (limited to 'bootstraptest')
-rw-r--r-- | bootstraptest/test_ractor.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb index b6f00de515..c693a9c496 100644 --- a/bootstraptest/test_ractor.rb +++ b/bootstraptest/test_ractor.rb @@ -424,6 +424,33 @@ assert_equal "[[[1, true], [:sym, true], [:xyzzy, true], [\"frozen\", true], " \ [sr, ur].inspect } +# frozen Objects are shareable +assert_equal [false, true, false].inspect, %q{ + class C + def initialize freeze + @a = 1 + @b = :sym + @c = 'frozen_str' + @c.freeze if freeze + @d = true + end + end + + def check obj1 + obj2 = Ractor.new obj1 do |obj| + obj + end.take + + obj1.object_id == obj2.object_id + end + + results = [] + results << check(C.new(true)) # false + results << check(C.new(true).freeze) # true + results << check(C.new(false).freeze) # false +} + + # move example2: String # touching moved object causes an error assert_equal 'hello world', %q{ |