[前][次][番号順一覧][スレッド一覧]

ruby-changes:63225

From: Marc-Andre <ko1@a...>
Date: Thu, 1 Oct 2020 07:11:43 +0900 (JST)
Subject: [ruby-changes:63225] 0977040133 (master): [ruby/ostruct] Add test that frozen OpenStructs are Ractor-shareable

https://git.ruby-lang.org/ruby.git/commit/?id=0977040133

From 0977040133c53be92713e9054b491a0b3649e148 Mon Sep 17 00:00:00 2001
From: Marc-Andre Lafortune <github@m...>
Date: Fri, 25 Sep 2020 21:17:06 -0400
Subject: [ruby/ostruct] Add test that frozen OpenStructs are Ractor-shareable


diff --git a/lib/ostruct.rb b/lib/ostruct.rb
index 8cfccb0..d2e93b1 100644
--- a/lib/ostruct.rb
+++ b/lib/ostruct.rb
@@ -62,6 +62,8 @@ https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L62
 #   first_pet                 # => #<OpenStruct name="Rowdy">
 #   first_pet == second_pet   # => true
 #
+# Ractor compatibility: A frozen OpenStruct with shareable values is itself shareable.
+#
 # == Caveats
 #
 # An OpenStruct utilizes Ruby's method lookup structure to find and define the
diff --git a/test/ostruct/test_ostruct.rb b/test/ostruct/test_ostruct.rb
index 6105f37..5de6f27 100644
--- a/test/ostruct/test_ostruct.rb
+++ b/test/ostruct/test_ostruct.rb
@@ -298,4 +298,15 @@ class TC_OpenStruct < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ostruct/test_ostruct.rb#L298
     o.foo = 42
     assert_equal 42, o.foo
   end
+
+  def test_ractor
+    obj1 = OpenStruct.new(a: 42, b: 42)
+    obj1.c = 42
+    obj1.freeze
+
+    obj2 = Ractor.new obj1 do |obj|
+      obj
+    end.take
+    assert obj1.object_id == obj2.object_id
+  end if defined?(Ractor)
 end
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]