Skip to content

Commit a294427

Browse files
committed
Add missing lock to rb_gc_impl_copy_finalizer
1 parent d924885 commit a294427

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

gc/default/default.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2803,6 +2803,7 @@ rb_gc_impl_copy_finalizer(void *objspace_ptr, VALUE dest, VALUE obj)
28032803

28042804
if (!FL_TEST(obj, FL_FINALIZE)) return;
28052805

2806+
int lev = rb_gc_vm_lock();
28062807
if (RB_LIKELY(st_lookup(finalizer_table, obj, &data))) {
28072808
table = (VALUE)data;
28082809
st_insert(finalizer_table, dest, table);
@@ -2811,6 +2812,7 @@ rb_gc_impl_copy_finalizer(void *objspace_ptr, VALUE dest, VALUE obj)
28112812
else {
28122813
rb_bug("rb_gc_copy_finalizer: FL_FINALIZE set but not found in finalizer_table: %s", rb_obj_info(obj));
28132814
}
2815+
rb_gc_vm_unlock(lev);
28142816
}
28152817

28162818
static VALUE

gc/mmtk/mmtk.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,7 @@ rb_gc_impl_copy_finalizer(void *objspace_ptr, VALUE dest, VALUE obj)
983983

984984
if (!FL_TEST(obj, FL_FINALIZE)) return;
985985

986+
int lev = rb_gc_vm_lock();
986987
if (RB_LIKELY(st_lookup(objspace->finalizer_table, obj, &data))) {
987988
table = (VALUE)data;
988989
st_insert(objspace->finalizer_table, dest, table);
@@ -991,6 +992,7 @@ rb_gc_impl_copy_finalizer(void *objspace_ptr, VALUE dest, VALUE obj)
991992
else {
992993
rb_bug("rb_gc_copy_finalizer: FL_FINALIZE set but not found in finalizer_table: %s", rb_obj_info(obj));
993994
}
995+
rb_gc_vm_unlock(lev);
994996
}
995997

996998
static int

test/objspace/test_ractor.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,25 @@ def fin
3333
ractors.each(&:take)
3434
RUBY
3535
end
36+
37+
def test_copy_finalizer
38+
assert_ractor(<<~'RUBY', require: 'objspace')
39+
def fin
40+
->(id) { }
41+
end
42+
OBJ = Object.new
43+
ObjectSpace.define_finalizer(OBJ, fin)
44+
OBJ.freeze
45+
46+
ractors = 5.times.map do
47+
Ractor.new do
48+
10_000.times do
49+
OBJ.clone
50+
end
51+
end
52+
end
53+
54+
ractors.each(&:take)
55+
RUBY
56+
end
3657
end

0 commit comments

Comments
 (0)