mirror of
https://github.com/ruby/ruby.git
synced 2026-01-26 20:19:19 +00:00
Method and UnboundMethod can be sharable
with `RUBY_TYPED_FROZEN_SHAREABLE_NO_REC`, if the receiver object is shareable on Method objects.
This commit is contained in:
parent
f2cd772329
commit
4c893e2ff1
Notes:
git
2025-12-04 17:29:01 +00:00
@ -1203,6 +1203,28 @@ assert_equal '[:ok, "Proc\'s self is not shareable:"]', %q{
|
||||
end
|
||||
}
|
||||
|
||||
# Ractor.make_sharable(Method/UnboundMethod)
|
||||
assert_equal 'true', %q{
|
||||
# raise because receiver is unsharable
|
||||
begin
|
||||
_m0 = Ractor.make_shareable(self.method(:__id__))
|
||||
rescue => e
|
||||
raise e unless e.message =~ /can not make shareable object/
|
||||
else
|
||||
raise "no error"
|
||||
end
|
||||
|
||||
# Method with sharable receiver
|
||||
M1 = Ractor.make_shareable(Object.method(:__id__))
|
||||
|
||||
# UnboundMethod
|
||||
M2 = Ractor.make_shareable(Object.instance_method(:__id__))
|
||||
|
||||
Ractor.new do
|
||||
Object.__id__ == M1.call && M1.call == M2.bind_call(Object)
|
||||
end.value
|
||||
}
|
||||
|
||||
# Ractor.shareable?(recursive_objects)
|
||||
assert_equal '[false, false]', %q{
|
||||
y = []
|
||||
|
||||
2
proc.c
2
proc.c
@ -1668,7 +1668,7 @@ static const rb_data_type_t method_data_type = {
|
||||
NULL, // No external memory to report,
|
||||
bm_mark_and_move,
|
||||
},
|
||||
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE
|
||||
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE | RUBY_TYPED_FROZEN_SHAREABLE_NO_REC
|
||||
};
|
||||
|
||||
VALUE
|
||||
|
||||
@ -47,7 +47,7 @@ class TestRactor < Test::Unit::TestCase
|
||||
def x.to_s
|
||||
raise "this should not be called"
|
||||
end
|
||||
assert_unshareable(x, "can not make shareable object for #<Method: String#to_s()>", exception: Ractor::Error)
|
||||
assert_unshareable(x, "can not make shareable object for #<Method: String#to_s()> because it refers unshareable objects", exception: Ractor::Error)
|
||||
end
|
||||
|
||||
def test_default_thread_group
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user