mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
Don't try to move objects with finalizer attached
This commit is contained in:
parent
326c120aa7
commit
fe803d4dee
2 changed files with 24 additions and 0 deletions
5
ractor.c
5
ractor.c
|
@ -3645,6 +3645,10 @@ move_enter(VALUE obj, struct obj_traverse_replace_data *data)
|
|||
return traverse_skip;
|
||||
}
|
||||
else {
|
||||
if (FL_TEST_RAW(obj, FL_FINALIZE)) {
|
||||
rb_raise(rb_eRactorError, "can not move an object with finalizer");
|
||||
}
|
||||
|
||||
VALUE type = RB_BUILTIN_TYPE(obj);
|
||||
type |= wb_protected_types[type] ? FL_WB_PROTECTED : 0;
|
||||
NEWOBJ_OF(moved, struct RBasic, 0, type, rb_gc_obj_slot_size(obj), 0);
|
||||
|
@ -3680,6 +3684,7 @@ move_leave(VALUE obj, struct obj_traverse_replace_data *data)
|
|||
MEMZERO((char *)obj, char, sizeof(struct RBasic));
|
||||
RBASIC(obj)->flags = flags;
|
||||
RBASIC_SET_CLASS_RAW(obj, rb_cRactorMovedObject);
|
||||
|
||||
return traverse_cont;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,4 +54,23 @@ class TestObjSpaceRactor < Test::Unit::TestCase
|
|||
ractors.each(&:take)
|
||||
RUBY
|
||||
end
|
||||
|
||||
def test_move_finalizer
|
||||
assert_ractor(<<~'RUBY', require: 'objspace')
|
||||
r = Ractor.new do
|
||||
Ractor.receive
|
||||
end
|
||||
|
||||
1_000.times do
|
||||
o = Object.new
|
||||
ObjectSpace.define_finalizer(o, proc { })
|
||||
begin
|
||||
r.send(o, move: true)
|
||||
rescue Ractor::Error => e
|
||||
raise unless e.message.include?("finalizer")
|
||||
break
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue