Set Ractor moved object's shape to original object's shape

Fixes [Bug #19409]
This commit is contained in:
Luke Gruber 2023-12-29 13:06:58 -05:00 коммит произвёл Koichi Sasada
Родитель e12d4c654e
Коммит 32c4b0125f
2 изменённых файлов: 24 добавлений и 1 удалений

Просмотреть файл

@ -1087,6 +1087,27 @@ assert_equal '333', %q{
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

Просмотреть файл

@ -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;
}
}