🌐 AI搜索 & 代理 主页
Skip to content

Commit 731a1e3

Browse files
committed
Prevent ifunc procs from being made shareable
[Bug #21775]
1 parent f939cf4 commit 731a1e3

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

test/ruby/test_ractor.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,18 @@ def test_max_cpu_1
201201
RUBY
202202
end
203203

204+
def test_symbol_proc_is_shareable
205+
pr = :symbol.to_proc
206+
assert_make_shareable(pr)
207+
end
208+
209+
# [Bug #21775]
210+
def test_ifunc_proc_not_shareable
211+
h = Hash.new { self }
212+
pr = h.to_proc
213+
assert_unshareable(pr, /not supported yet/, exception: RuntimeError)
214+
end
215+
204216
def assert_make_shareable(obj)
205217
refute Ractor.shareable?(obj), "object was already shareable"
206218
Ractor.make_shareable(obj)

vm.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1594,7 +1594,10 @@ rb_proc_ractor_make_shareable(VALUE self, VALUE replace_self)
15941594
proc->is_isolated = TRUE;
15951595
}
15961596
else {
1597-
VALUE proc_self = vm_block_self(vm_proc_block(self));
1597+
const struct rb_block *block = vm_proc_block(self);
1598+
if (block->type != block_type_symbol) rb_raise(rb_eRuntimeError, "not supported yet");
1599+
1600+
VALUE proc_self = vm_block_self(block);
15981601
if (!rb_ractor_shareable_p(proc_self)) {
15991602
rb_raise(rb_eRactorIsolationError,
16001603
"Proc's self is not shareable: %" PRIsVALUE,

0 commit comments

Comments
 (0)