Skip to content

Commit

Permalink
compile.c: use putspecialobject for RubyVM::FrozenCore
Browse files Browse the repository at this point in the history
[Bug #20569]

`putobject RubyVM::FrozenCore`, is not serializable, we
have to use `putspecialobject VM_SPECIAL_OBJECT_VMCORE`.
  • Loading branch information
byroot authored and nagachika committed Jun 15, 2024
1 parent ab7dfa7 commit e0e1a0f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -9750,7 +9750,12 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const no
case NODE_LIT:{
debugp_param("lit", node->nd_lit);
if (!popped) {
ADD_INSN1(ret, node, putobject, node->nd_lit);
if (UNLIKELY(node->nd_lit == rb_mRubyVMFrozenCore)) {
ADD_INSN1(ret, node, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE)); // [Bug #20569]
}
else {
ADD_INSN1(ret, node, putobject, node->nd_lit);
}
RB_OBJ_WRITTEN(iseq, Qundef, node->nd_lit);
}
break;
Expand Down
8 changes: 8 additions & 0 deletions test/ruby/test_iseq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ def obj.foo(*) nil.instance_eval{ ->{super} } end
end
end

def test_ractor_shareable_value_frozen_core
iseq = RubyVM::InstructionSequence.compile(<<~'RUBY')
# shareable_constant_value: literal
REGEX = /#{}/ # [Bug #20569]
RUBY
assert_includes iseq.to_binary, "REGEX".b
end

def test_disasm_encoding
src = "\u{3042} = 1; \u{3042}; \u{3043}"
asm = compile(src).disasm
Expand Down

0 comments on commit e0e1a0f

Please sign in to comment.