[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-core
Subject: [ruby-core:105062] [Ruby master Bug#17722] define_method with shareable results in "defined in a dif
From: "tagomoris (Satoshi TAGOMORI)" <noreply () ruby-lang ! org>
Date: 2021-08-24 12:03:56
Message-ID: redmine.journal-93470.20210824120355.10442 () ruby-lang ! org
[Download RAW message or body]
Issue #17722 has been updated by tagomoris (Satoshi TAGOMORI).
The reason of the unexpected error is, the block parameter of `define_method` is \
un-shareable. I created a patch to explain it: https://github.com/ruby/ruby/pull/4771
----------------------------------------
Bug #17722: define_method with shareable results in "defined in a different Ractor"
https://bugs.ruby-lang.org/issues/17722#change-93470
* Author: chucke (Tiago Cardoso)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.1.0dev (2021-03-13 master c7e6914b39) [x86_64-linux]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
Testing against latest master, and expectinng \
[this](https://bugs.ruby-lang.org/issues/17159?tab=history) to already be handled, I \
nonetheless found a weird case, for which I managed to build a short reproduction.
```ruby
class A
define_method :"a=" do |val|
instance_variable_set(:"@#{v}", val)
end
attr_reader :a
def initialize(opts)
opts.each do |k, v|
puts "#{k} = #{v}"
__send__(:"#{k}=", v)
end
end
end
ractors = []
DEFAULTS = { a: 1 }
Ractor.make_shareable(DEFAULTS)
1.times do
ractors << Ractor.new do
a = A.new(DEFAULTS)
end
end
ractors.map(&:take)
```
This script fails with "defined in a different Ractor (RuntimeError)".
The error comes from the execution of "define_method". I was under the expectation \
that it would work, given that the passed value is shareable, so it shouldn't make a \
difference if it was defined in a different ractor.
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic