Skip to content

Commit be54504

Browse files
peterzhu2118byroot
authored andcommitted
Fix reference updating for id2ref table
The id2ref table could contain dead entries which should not be passed into rb_gc_location. Also, we already update references in gc_update_references using rb_gc_vm_weak_table_foreach so we do not need to update it again.
1 parent 061d364 commit be54504

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

gc.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,19 +1848,6 @@ id2ref_tbl_memsize(const void *data)
18481848
return rb_st_memsize(data);
18491849
}
18501850

1851-
static void
1852-
id2ref_tbl_compact(void *data)
1853-
{
1854-
st_table *table = (st_table *)data;
1855-
if (LIKELY(RB_POSFIXABLE(LAST_OBJECT_ID()))) {
1856-
// We know keys are all FIXNUM, so no need to update them.
1857-
gc_ref_update_table_values_only(table);
1858-
}
1859-
else {
1860-
gc_update_table_refs(table);
1861-
}
1862-
}
1863-
18641851
static void
18651852
id2ref_tbl_free(void *data)
18661853
{
@@ -1875,7 +1862,8 @@ static const rb_data_type_t id2ref_tbl_type = {
18751862
.dmark = id2ref_tbl_mark,
18761863
.dfree = id2ref_tbl_free,
18771864
.dsize = id2ref_tbl_memsize,
1878-
.dcompact = id2ref_tbl_compact,
1865+
// dcompact function not required because the table is reference updated
1866+
// in rb_gc_vm_weak_table_foreach
18791867
},
18801868
.flags = RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_FREE_IMMEDIATELY
18811869
};

0 commit comments

Comments
 (0)