From e3bc7eec5f8ea62586eb1dfe2b3c021a5a9f1f8e Mon Sep 17 00:00:00 2001 From: akr Date: Sat, 8 Jun 2013 16:00:16 +0000 Subject: [PATCH] * 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 --- ChangeLog | 5 +++++ hash.c | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index d7569960e2..b92d2b5160 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun Jun 9 00:59:04 2013 Tanaka Akira + + * hash.c (rb_hash): Use rb_integer_pack to obtain least significant + long integer. + Sat Jun 8 23:56:00 2013 Tanaka Akira * numeric.c (rb_num_to_uint): Use rb_absint_size instead of 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);