From 42f043c1893b320b9d2a38ec3b1065dee71ce863 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Tue, 14 Jan 2025 17:40:39 -0800 Subject: merge revision(s) 56ecc243e230e8e99761ec0ffc5116601f094bb0: [Backport #20868] [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 --- vm_method.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'vm_method.c') diff --git a/vm_method.c b/vm_method.c index 232ba03e61..7b57b56cd6 100644 --- a/vm_method.c +++ b/vm_method.c @@ -2237,7 +2237,7 @@ rb_hash_method_definition(st_index_t hash, const rb_method_definition_t *def) switch (def->type) { case VM_METHOD_TYPE_ISEQ: - return rb_hash_uint(hash, (st_index_t)def->body.iseq.iseqptr); + return rb_hash_uint(hash, (st_index_t)def->body.iseq.iseqptr->body); case VM_METHOD_TYPE_CFUNC: hash = rb_hash_uint(hash, (st_index_t)def->body.cfunc.func); return rb_hash_uint(hash, def->body.cfunc.argc); -- cgit v1.2.3