From 38af38edcbceb9d17aaf84420008fe839f77e42f Mon Sep 17 00:00:00 2001 From: Luke Gruber Date: Fri, 16 Feb 2024 14:08:39 -0500 Subject: [PATCH] Fix ractor move of unshareable frozen objects These objects didn't retain their frozen status after the move Bug [#19408] --- bootstraptest/test_ractor.rb | 11 +++++++++++ ractor.c | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb index 08f269dda9..b3ab7f607c 100644 --- a/bootstraptest/test_ractor.rb +++ b/bootstraptest/test_ractor.rb @@ -752,6 +752,17 @@ assert_equal '[0, 1]', %q{ end } +# unshareable frozen objects should still be frozen in new ractor after move +assert_equal 'true', %q{ +r = Ractor.new do + obj = receive + { frozen: obj.frozen? } +end +obj = [Object.new].freeze +r.send(obj, move: true) +r.take[:frozen] +} + # move with yield assert_equal 'hello', %q{ r = Ractor.new do diff --git a/ractor.c b/ractor.c index 0240d1f216..2dfd56d068 100644 --- a/ractor.c +++ b/ractor.c @@ -3581,6 +3581,10 @@ move_leave(VALUE obj, struct obj_traverse_replace_data *data) rb_replace_generic_ivar(v, obj); } + if (OBJ_FROZEN(obj)) { + OBJ_FREEZE(v); + } + // TODO: generic_ivar ractor_moved_bang(obj);