summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hash.c6
-rw-r--r--test/ruby/test_gc_compact.rb7
2 files changed, 12 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
diff --git a/test/ruby/test_gc_compact.rb b/test/ruby/test_gc_compact.rb
index a1e037b70b..b705f601da 100644
--- a/test/ruby/test_gc_compact.rb
+++ b/test/ruby/test_gc_compact.rb
@@ -121,4 +121,11 @@ class TestGCCompact < Test::Unit::TestCase
skip "couldn't get objects to collide" if collisions == 0
assert_operator collisions, :>, 0
end
+
+ def test_complex_hash_keys
+ list_of_objects = big_list
+ hash = list_of_objects.hash
+ GC.verify_compaction_references
+ assert_equal hash, list_of_objects.hash
+ end
end