summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2025-12-05 02:48:05 +0900
committerKoichi Sasada <ko1@atdot.net>2025-12-05 10:45:03 +0900
commit02cddcc2be3150fad1da37ebdeb6e2d9ec29306c (patch)
tree6d8923c3219d9e9a1b4ad97d25400310c1b4741e
parentd105709f2b989c03261371306b08f8fc5ccaa680 (diff)
Ractor.shareable_proc(&pr) should copy pr
`pr` should not change on this method.
-rw-r--r--bootstraptest/test_ractor.rb10
-rw-r--r--ractor.c2
2 files changed, 11 insertions, 1 deletions
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);
}
}