summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorAaron Patterson <tenderlove@ruby-lang.org>2019-04-23 12:10:52 -0700
committerAaron Patterson <tenderlove@ruby-lang.org>2019-04-23 14:21:15 -0700
commit75061f46ae646e821e9228caa5e3b7f23fa609f0 (patch)
tree9ea4054d0594295bfcf347c4a820fe4b3508ec24 /hash.c
parentcf930985da1ae15b66577ec8286e54ad04ccda78 (diff)
Fix complex hash keys to work with compaction
For example when an array containing objects is a hash key, the contents of the array may move which can cause the hash value for the array to change. This commit makes the default `hash` value based off the object id, so the hash value will remain stable. Fixes test/shell/test_command_processor.rb
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/hash.c b/hash.c
index 000c39e178..b4b0415c84 100644
--- a/hash.c
+++ b/hash.c
@@ -272,7 +272,11 @@ rb_objid_hash(st_index_t index)
static st_index_t
objid_hash(VALUE obj)
{
- return (st_index_t)st_index_hash((st_index_t)obj);
+#if SIZEOF_LONG == SIZEOF_VOIDP
+ return (st_index_t)st_index_hash((st_index_t)NUM2LONG(rb_obj_id(obj)));
+#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
+ return (st_index_t)st_index_hash((st_index_t)NUM2LL(rb_obj_id(obj)));
+#endif
}
VALUE