Actions
Bug #20868
closedMethod#hash changes after compaction
Description
Fix: https://github.com/ruby/ruby/pull/12004
The hash value of a Method may change after a compaction but must remain constant because otherwise it may not work as the key in a hash table.
For example:
def a; end
# Need this method here because otherwise the iseq may be on the C stack
# which would get pinned and not move during compaction
def get_hash
method(:a).hash
end
puts get_hash # => 2993401401091578131
GC.verify_compaction_references(expand_heap: true, toward: :empty)
puts get_hash # => -2162775864511574135
Updated by peterzhu2118 (Peter Zhu) 13 days ago
- Backport changed from 3.1: UNKNOWN, 3.2: REQUIRED, 3.3: REQUIRED to 3.1: WONTFIX, 3.2: REQUIRED, 3.3: REQUIRED
Updated by peterzhu2118 (Peter Zhu) 12 days ago
- Status changed from Open to Closed
Applied in changeset git|56ecc243e230e8e99761ec0ffc5116601f094bb0.
[Bug #20868] Fix Method#hash to not change after compaction
The hash value of a Method must remain constant after a compaction, otherwise
it may not work as the key in a hash table.
For example:
def a; end
# Need this method here because otherwise the iseq may be on the C stack
# which would get pinned and not move during compaction
def get_hash
method(:a).hash
end
puts get_hash # => 2993401401091578131
GC.verify_compaction_references(expand_heap: true, toward: :empty)
puts get_hash # => -2162775864511574135
Updated by nagachika (Tomoyuki Chikanaga) 9 days ago
- Backport changed from 3.1: WONTFIX, 3.2: REQUIRED, 3.3: REQUIRED to 3.1: WONTFIX, 3.2: DONE, 3.3: REQUIRED
ruby_3_2 ee3428aa0e3a11ed1574b7d99222f6f08737f818 merged revision(s) 56ecc243e230e8e99761ec0ffc5116601f094bb0.
Actions
Like0
Like0Like0Like0