diff options
author | nagachika <nagachika@ruby-lang.org> | 2023-03-25 15:03:14 +0900 |
---|---|---|
committer | nagachika <nagachika@ruby-lang.org> | 2023-03-25 15:03:14 +0900 |
commit | cd4a997e53a02e5a8b24e38a10ba5525c176980e (patch) | |
tree | fca7c7566744314f4c254f08b1bc550435bf3e4f /test | |
parent | bdbe6053853c11ffe9b8737eb4da50ed84c9dbd6 (diff) |
merge revision(s) 548086b34e3dd125edabf5dc1e46b891fad3ea9c,3dc8cde70078ccb38f5f4b0818ad5eecded01bd5,e0cf80d666d4b5df3229f030a16d10d21323508e: [Backport #19529]
ObjectSpace::WeakMap: fix compaction support
[Bug #19529]
`rb_gc_update_tbl_refs` can't be used on `w->obj2wmap` because it's
not a `VALUE -> VALUE` table, but a `VALUE -> VALUE *` table, so
we need some dedicated iterator.
---
test/ruby/test_weakmap.rb | 8 ++++++++
weakmap.c | 37 ++++++++++++++++++++++++++++++++++++-
2 files changed, 44 insertions(+), 1 deletion(-)
Fix crash during compaction
[Bug #19529]
The fix for [Bug #19529] in commit 548086b contained a bug that crashes
on the following script:
```
wm = ObjectSpace::WeakMap.new
obj = Object.new
100.times do
wm[Object.new] = obj
GC.start
end
GC.compact
```
---
test/ruby/test_weakmap.rb | 10 ++++++++++
weakmap.c | 2 +-
2 files changed, 11 insertions(+), 1 deletion(-)
Fix incorrect size of WeakMap buffer
In wmap_final_func, j is the number of elements + 1 (since j also
includes the length at the 0th index), so we should resize the buffer
to size j and the new length is j - 1.
---
weakmap.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_weakmap.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/test/ruby/test_weakmap.rb b/test/ruby/test_weakmap.rb index c482f697c3..5ca6b0fbdd 100644 --- a/test/ruby/test_weakmap.rb +++ b/test/ruby/test_weakmap.rb @@ -176,4 +176,22 @@ class TestWeakMap < Test::Unit::TestCase end end; end + + def test_compaction_bug_19529 + obj = Object.new + 100.times do |i| + GC.compact + @wm[i] = obj + end + + assert_separately(%w(--disable-gems), <<-'end;') + wm = ObjectSpace::WeakMap.new + obj = Object.new + 100.times do + wm[Object.new] = obj + GC.start + end + GC.compact + end; + end end |