diff options
| author | nagachika <nagachika@ruby-lang.org> | 2023-07-22 11:44:54 +0900 |
|---|---|---|
| committer | nagachika <nagachika@ruby-lang.org> | 2023-07-22 11:44:54 +0900 |
| commit | 46b62f44ce30bf234a76114c8249081e47ce3da4 (patch) | |
| tree | 33db10d6af02dc6d59cb1c53df6a446e5a6892d1 /test | |
| parent | 3f6187a94797d3c4a7db00563a885e4e613b51cf (diff) | |
merge revision(s) 3592b24cdc07ed89eecb39161f21fe721a89a5de: [Backport #19531]
ObjectSpace::WeakMap: clean inverse reference when an entry is
re-assigned
[Bug #19531]
```ruby
wmap[1] = "A"
wmap[1] = "B"
```
In the example above, we need to remove the `"A" => 1` inverse reference
so that when `"A"` is GCed the `1` key isn't deleted.
---
test/ruby/test_weakmap.rb | 17 +++++++++
weakmap.c | 91 ++++++++++++++++++++++++++++++++++++++---------
2 files changed, 91 insertions(+), 17 deletions(-)
Diffstat (limited to 'test')
| -rw-r--r-- | test/ruby/test_weakmap.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/test/ruby/test_weakmap.rb b/test/ruby/test_weakmap.rb index 6455034743..7fc956dfae 100644 --- a/test/ruby/test_weakmap.rb +++ b/test/ruby/test_weakmap.rb @@ -196,4 +196,21 @@ class TestWeakMap < Test::Unit::TestCase GC.compact end; end + + def test_replaced_values_bug_19531 + a = "A".dup + b = "B".dup + + @wm[1] = a + @wm[1] = a + @wm[1] = a + + @wm[1] = b + assert_equal b, @wm[1] + + a = nil + GC.start + + assert_equal b, @wm[1] + end end |
