mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
Add missing lock to rb_gc_impl_copy_finalizer
This commit is contained in:
parent
d9248856d2
commit
a294427017
Notes:
git
2025-05-16 18:17:07 +00:00
3 changed files with 25 additions and 0 deletions
|
@ -2803,6 +2803,7 @@ rb_gc_impl_copy_finalizer(void *objspace_ptr, VALUE dest, VALUE obj)
|
|||
|
||||
if (!FL_TEST(obj, FL_FINALIZE)) return;
|
||||
|
||||
int lev = rb_gc_vm_lock();
|
||||
if (RB_LIKELY(st_lookup(finalizer_table, obj, &data))) {
|
||||
table = (VALUE)data;
|
||||
st_insert(finalizer_table, dest, table);
|
||||
|
@ -2811,6 +2812,7 @@ rb_gc_impl_copy_finalizer(void *objspace_ptr, VALUE dest, VALUE obj)
|
|||
else {
|
||||
rb_bug("rb_gc_copy_finalizer: FL_FINALIZE set but not found in finalizer_table: %s", rb_obj_info(obj));
|
||||
}
|
||||
rb_gc_vm_unlock(lev);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
|
|
@ -983,6 +983,7 @@ rb_gc_impl_copy_finalizer(void *objspace_ptr, VALUE dest, VALUE obj)
|
|||
|
||||
if (!FL_TEST(obj, FL_FINALIZE)) return;
|
||||
|
||||
int lev = rb_gc_vm_lock();
|
||||
if (RB_LIKELY(st_lookup(objspace->finalizer_table, obj, &data))) {
|
||||
table = (VALUE)data;
|
||||
st_insert(objspace->finalizer_table, dest, table);
|
||||
|
@ -991,6 +992,7 @@ rb_gc_impl_copy_finalizer(void *objspace_ptr, VALUE dest, VALUE obj)
|
|||
else {
|
||||
rb_bug("rb_gc_copy_finalizer: FL_FINALIZE set but not found in finalizer_table: %s", rb_obj_info(obj));
|
||||
}
|
||||
rb_gc_vm_unlock(lev);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
|
@ -33,4 +33,25 @@ class TestObjSpaceRactor < Test::Unit::TestCase
|
|||
ractors.each(&:take)
|
||||
RUBY
|
||||
end
|
||||
|
||||
def test_copy_finalizer
|
||||
assert_ractor(<<~'RUBY', require: 'objspace')
|
||||
def fin
|
||||
->(id) { }
|
||||
end
|
||||
OBJ = Object.new
|
||||
ObjectSpace.define_finalizer(OBJ, fin)
|
||||
OBJ.freeze
|
||||
|
||||
ractors = 5.times.map do
|
||||
Ractor.new do
|
||||
10_000.times do
|
||||
OBJ.clone
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
ractors.each(&:take)
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue