summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-11-05 12:22:24 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-11-05 12:22:24 +0000
commitee3e66e7a61c2deba096756aadc390c82fd2d17b (patch)
tree462f4ce61b5c2a6ee594ff09894f09e5a3f26100 /hash.c
parent60a40ecaf65435c93ad24a4cbb5cd1779aeb2bda (diff)
Merged r22308. [ruby-dev:39637]
* hash.c (rb_hash): always return a fixnum value because a return value of rb_hash may be used as a hash value itself and bignums have no unique VALUE. * test/ruby/test_hash.rb: add a test for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@25661 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/hash.c b/hash.c
index fc44b8e01d..0b962c8ae7 100644
--- a/hash.c
+++ b/hash.c
@@ -83,7 +83,19 @@ VALUE
rb_hash(obj)
VALUE obj;
{
- return rb_funcall(obj, id_hash, 0);
+ VALUE hval = rb_funcall(obj, id_hash, 0);
+ retry:
+ switch (TYPE(hval)) {
+ case T_FIXNUM:
+ return hval;
+
+ case T_BIGNUM:
+ return LONG2FIX(((long*)(RBIGNUM_DIGITS(hval)))[0]);
+
+ default:
+ hval = rb_to_int(hval);
+ goto retry;
+ }
}
static int
@@ -104,10 +116,7 @@ rb_any_hash(a)
break;
default:
- hval = rb_funcall(a, id_hash, 0);
- if (!FIXNUM_P(hval)) {
- hval = rb_funcall(hval, '%', 1, INT2FIX(536870923));
- }
+ hval = rb_hash(a);
hnum = (int)FIX2LONG(hval);
}
hnum <<= 1;