Skip to content

Commit 02cddcc

Browse files
committed
Ractor.shareable_proc(&pr) should copy pr
`pr` should not change on this method.
1 parent d105709 commit 02cddcc

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

bootstraptest/test_ractor.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@
157157
Ractor.shareable_proc(&closure).call
158158
}
159159

160+
# Ractor.make_shareable makes a copy of given Proc
161+
assert_equal '[true, true]', %q{
162+
pr1 = Proc.new do
163+
self
164+
end
165+
pr2 = Ractor.shareable_proc(&pr1)
166+
167+
[pr1.call == self, pr2.call == nil]
168+
}
169+
160170
# Ractor::IsolationError cases
161171
assert_equal '3', %q{
162172
ok = 0

ractor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2376,7 +2376,7 @@ ractor_shareable_proc(rb_execution_context_t *ec, VALUE replace_self, bool is_la
23762376
}
23772377
else {
23782378
VALUE proc = is_lambda ? rb_block_lambda() : rb_block_proc();
2379-
return rb_proc_ractor_make_shareable(proc, replace_self);
2379+
return rb_proc_ractor_make_shareable(rb_proc_dup(proc), replace_self);
23802380
}
23812381
}
23822382

0 commit comments

Comments
 (0)