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

ruby-changes:70112

From: Koichi <ko1@a...>
Date: Thu, 9 Dec 2021 04:49:12 +0900 (JST)
Subject: [ruby-changes:70112] 9c26931635 (master): [ruby/ostruct] `Proc`'s self should be shareable.

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

From 9c269316357a1a5b6ef27794f3c9412b2e33a6cd Mon Sep 17 00:00:00 2001
From: Koichi Sasada <ko1@a...>
Date: Thu, 9 Dec 2021 04:06:53 +0900
Subject: [ruby/ostruct] `Proc`'s self should be shareable.

To fix the issue https://bugs.ruby-lang.org/issues/18243
we need to make sure the Proc's self is shareable.
These procs are used by `define_method` and it doesn't use
Proc's self, so `nil` is enough.
---
 lib/ostruct.rb | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lib/ostruct.rb b/lib/ostruct.rb
index 4f0a4a7dbed..ec44a525d9f 100644
--- a/lib/ostruct.rb
+++ b/lib/ostruct.rb
@@ -221,11 +221,14 @@ class OpenStruct https://github.com/ruby/ruby/blob/trunk/lib/ostruct.rb#L221
   #
   def new_ostruct_member!(name) # :nodoc:
     unless @table.key?(name) || is_method_protected!(name)
-      getter_proc = Proc.new { @table[name] }
-      setter_proc = Proc.new {|x| @table[name] = x}
       if defined?(::Ractor)
+        getter_proc = nil.instance_eval{ Proc.new { @table[name] } }
+        setter_proc = nil.instance_eval{ Proc.new {|x| @table[name] = x} }
         ::Ractor.make_shareable(getter_proc)
         ::Ractor.make_shareable(setter_proc)
+      else
+        getter_proc = Proc.new { @table[name] }
+        setter_proc = Proc.new {|x| @table[name] = x}
       end
       define_singleton_method!(name, &getter_proc)
       define_singleton_method!("#{name}=", &setter_proc)
-- 
cgit v1.2.1


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

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