Skip to content

Commit

Permalink
Set Ractor moved object's shape to original object's shape
Browse files Browse the repository at this point in the history
Fixes [Bug #19409]
  • Loading branch information
luke-gru authored and ko1 committed Jan 1, 2024
1 parent e12d4c6 commit 32c4b01
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
21 changes: 21 additions & 0 deletions bootstraptest/test_ractor.rb
Expand Up @@ -1087,6 +1087,27 @@ def self.fstr = @fstr
a + b + c + d + e + f
}

# moved objects have their shape properly set to original object's shape
assert_equal '1234', %q{
class Obj
attr_accessor :a, :b, :c, :d
def initialize
@a = 1
@b = 2
@c = 3
end
end
r = Ractor.new do
obj = receive
obj.d = 4
[obj.a, obj.b, obj.c, obj.d]
end
obj = Obj.new
r.send(obj, move: true)
values = r.take
values.join
}

# cvar in shareable-objects are not allowed to access from non-main Ractor
assert_equal 'can not access class variables from non-main Ractors', %q{
class C
Expand Down
4 changes: 3 additions & 1 deletion ractor.c
Expand Up @@ -3504,7 +3504,9 @@ move_enter(VALUE obj, struct obj_traverse_replace_data *data)
return traverse_skip;
}
else {
data->replacement = rb_obj_alloc(RBASIC_CLASS(obj));
VALUE moved = rb_obj_alloc(RBASIC_CLASS(obj));
rb_shape_set_shape(moved, rb_shape_get_shape(obj));
data->replacement = moved;
return traverse_cont;
}
}
Expand Down

0 comments on commit 32c4b01

Please sign in to comment.