summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-14 18:53:40 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-14 18:53:40 +0000
commita48f90b05b654cc98727a91c5fd9952c5a86221c (patch)
tree1f1c3bfccf90207a542fce694d9040315457bfe1 /hash.c
parent766df600db46f3cc8a2bd0c0af2dfceeec2d8fb3 (diff)
* 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/trunk@22308 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 bfd3fe7f61..5d6b20cea9 100644
--- a/hash.c
+++ b/hash.c
@@ -57,7 +57,19 @@ rb_any_cmp(VALUE a, VALUE b)
VALUE
rb_hash(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
@@ -80,10 +92,7 @@ rb_any_hash(VALUE 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;