Make WeakMap safe for compaction during allocation

During allocation, the table may not have been allocated yet which would
crash in the st_foreach.
This commit is contained in:
Peter Zhu 2023-12-08 15:17:51 -05:00
parent d313c82f79
commit 33cf8f640b
2 changed files with 7 additions and 1 deletions

View File

@ -237,6 +237,10 @@ class TestWeakMap < Test::Unit::TestCase
end;
end
def test_gc_compact_stress
EnvUtil.under_gc_compact_stress { ObjectSpace::WeakMap.new }
end
def test_replaced_values_bug_19531
a = "A".dup
b = "B".dup

View File

@ -144,7 +144,9 @@ wmap_compact(void *ptr)
{
struct weakmap *w = ptr;
st_foreach(w->table, wmap_compact_table_i, (st_data_t)w->table);
if (w->table) {
st_foreach(w->table, wmap_compact_table_i, (st_data_t)w->table);
}
}
static const rb_data_type_t weakmap_type = {