summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Gruber <luke.gru@gmail.com>2024-02-16 14:08:39 -0500
committerKoichi Sasada <ko1@atdot.net>2024-12-24 11:38:44 +0900
commit38af38edcbceb9d17aaf84420008fe839f77e42f (patch)
tree07899ad0a45f0e06a68d6e3f87472007183a3d8f
parent1eb5c03fda7e9616a1461f48f4bd8b8739de122d (diff)
Fix ractor move of unshareable frozen objects
These objects didn't retain their frozen status after the move Bug [#19408]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/9996
-rw-r--r--bootstraptest/test_ractor.rb11
-rw-r--r--ractor.c4
2 files changed, 15 insertions, 0 deletions
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);