From 02cddcc2be3150fad1da37ebdeb6e2d9ec29306c Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Fri, 5 Dec 2025 02:48:05 +0900 Subject: Ractor.shareable_proc(&pr) should copy pr `pr` should not change on this method. --- bootstraptest/test_ractor.rb | 10 ++++++++++ ractor.c | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb index 7d09ac5283..bec742da4b 100644 --- a/bootstraptest/test_ractor.rb +++ b/bootstraptest/test_ractor.rb @@ -157,6 +157,16 @@ assert_equal '[:a, :b, :c, :d, :e]', %q{ Ractor.shareable_proc(&closure).call } +# Ractor.make_shareable makes a copy of given Proc +assert_equal '[true, true]', %q{ + pr1 = Proc.new do + self + end + pr2 = Ractor.shareable_proc(&pr1) + + [pr1.call == self, pr2.call == nil] +} + # Ractor::IsolationError cases assert_equal '3', %q{ ok = 0 diff --git a/ractor.c b/ractor.c index b7c7d94679..9fec70a1df 100644 --- a/ractor.c +++ b/ractor.c @@ -2376,7 +2376,7 @@ ractor_shareable_proc(rb_execution_context_t *ec, VALUE replace_self, bool is_la } else { VALUE proc = is_lambda ? rb_block_lambda() : rb_block_proc(); - return rb_proc_ractor_make_shareable(proc, replace_self); + return rb_proc_ractor_make_shareable(rb_proc_dup(proc), replace_self); } } -- cgit v1.2.3