diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-08 16:00:16 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-08 16:00:16 +0000 |
commit | e3bc7eec5f8ea62586eb1dfe2b3c021a5a9f1f8e (patch) | |
tree | 0577c8a73f981e003817f2ce66a0d026405a8ae7 /hash.c | |
parent | 893a8bb65386fb56d0c445bd87c8bd0e96c611c3 (diff) | |
download | ruby-e3bc7eec5f8ea62586eb1dfe2b3c021a5a9f1f8e.tar.gz |
* 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.c | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -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); |