summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-08 16:00:16 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-08 16:00:16 +0000
commite3bc7eec5f8ea62586eb1dfe2b3c021a5a9f1f8e (patch)
tree0577c8a73f981e003817f2ce66a0d026405a8ae7 /hash.c
parent893a8bb65386fb56d0c445bd87c8bd0e96c611c3 (diff)
* hash.c (rb_hash): Use rb_integer_pack to obtain least significant
long integer. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41186 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/hash.c b/hash.c
index a8fcaf90db..cc50a64f52 100644
--- a/hash.c
+++ b/hash.c
@@ -89,7 +89,16 @@ rb_hash(VALUE obj)
return hval;
case T_BIGNUM:
- return LONG2FIX(((long*)(RBIGNUM_DIGITS(hval)))[0]);
+ {
+ int sign;
+ unsigned long ul;
+ rb_integer_pack(hval, &sign, NULL, &ul, 1, sizeof(ul), 0,
+ INTEGER_PACK_LSWORD_FIRST|INTEGER_PACK_NATIVE_BYTE_ORDER);
+ ul &= (1UL << (sizeof(long)*CHAR_BIT-1)) - 1;
+ if (sign < 0)
+ return LONG2FIX(-(long)ul);
+ return LONG2FIX((long)ul);
+ }
default:
hval = rb_to_int(hval);