From f0001a4fa7260d0c39e9ddba162f51c549cba2f8 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Mon, 10 Jun 2024 15:12:54 +0200 Subject: [PATCH] compile.c: use putspecialobject for RubyVM::FrozenCore [Bug #20569] `putobject RubyVM::FrozenCore`, is not serializable, we have to use `putspecialobject VM_SPECIAL_OBJECT_VMCORE`. --- compile.c | 4 ++-- test/ruby/test_iseq.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/compile.c b/compile.c index a0bbcab54b..24b90826cd 100644 --- a/compile.c +++ b/compile.c @@ -9882,7 +9882,7 @@ compile_attrasgn(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node static int compile_make_shareable_node(rb_iseq_t *iseq, LINK_ANCHOR *ret, LINK_ANCHOR *sub, const NODE *value, bool copy) { - ADD_INSN1(ret, value, putobject, rb_mRubyVMFrozenCore); + ADD_INSN1(ret, value, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE)); ADD_SEQ(ret, sub); if (copy) { @@ -9971,7 +9971,7 @@ compile_ensure_shareable_node(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE *dest, con *. RubyVM::FrozenCore.ensure_shareable(value, const_decl_path(dest)) */ VALUE path = const_decl_path(dest); - ADD_INSN1(ret, value, putobject, rb_mRubyVMFrozenCore); + ADD_INSN1(ret, value, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE)); CHECK(COMPILE(ret, "compile_ensure_shareable_node", value)); ADD_INSN1(ret, value, putobject, path); RB_OBJ_WRITTEN(iseq, Qundef, path); diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb index a47419253b..1c7de5bb2b 100644 --- a/test/ruby/test_iseq.rb +++ b/test/ruby/test_iseq.rb @@ -167,6 +167,14 @@ class TestISeq < Test::Unit::TestCase 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