diff options
| author | Peter Zhu <peter@peterzhu.ca> | 2023-12-08 15:17:51 -0500 |
|---|---|---|
| committer | Peter Zhu <peter@peterzhu.ca> | 2023-12-12 09:01:21 -0500 |
| commit | 33cf8f640bab35c463186ef0856689c22559fbeb (patch) | |
| tree | 0ce361ab7d02f27526b494f941b1759b3514e1b3 | |
| parent | d313c82f797852037012138284d4e49fdaf284c4 (diff) | |
Make WeakMap safe for compaction during allocation
During allocation, the table may not have been allocated yet which would
crash in the st_foreach.
| -rw-r--r-- | test/ruby/test_weakmap.rb | 4 | ||||
| -rw-r--r-- | weakmap.c | 4 |
2 files changed, 7 insertions, 1 deletions
diff --git a/test/ruby/test_weakmap.rb b/test/ruby/test_weakmap.rb index a30004bce3..0371afa77a 100644 --- a/test/ruby/test_weakmap.rb +++ b/test/ruby/test_weakmap.rb @@ -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 @@ -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 = { |
