mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* bignum.c (big2ulong): Add code specialized for SIZEOF_LONG <=
SIZEOF_BDIGITS. This prevents shift witdth warning from "num <<= BITSPERDIG". git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41615 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ab0a003183
commit
26dd237449
2 changed files with 14 additions and 1 deletions
|
@ -1,3 +1,9 @@
|
|||
Tue Jun 25 12:28:57 2013 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* bignum.c (big2ulong): Add code specialized for SIZEOF_LONG <=
|
||||
SIZEOF_BDIGITS.
|
||||
This prevents shift witdth warning from "num <<= BITSPERDIG".
|
||||
|
||||
Tue Jun 25 12:23:30 2013 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* gc.c: fix oldgen/remembered_shady counting algorithm.
|
||||
|
|
9
bignum.c
9
bignum.c
|
@ -2413,17 +2413,24 @@ big2ulong(VALUE x, const char *type, int check)
|
|||
unsigned long num;
|
||||
BDIGIT *ds;
|
||||
|
||||
if (len == 0)
|
||||
return 0;
|
||||
if (BIGSIZE(x) > sizeof(long)) {
|
||||
if (check)
|
||||
rb_raise(rb_eRangeError, "bignum too big to convert into `%s'", type);
|
||||
len = bdigit_roomof(sizeof(long));
|
||||
if (bdigit_roomof(sizeof(long)) < len)
|
||||
len = bdigit_roomof(sizeof(long));
|
||||
}
|
||||
ds = BDIGITS(x);
|
||||
#if SIZEOF_LONG <= SIZEOF_BDIGITS
|
||||
num = ds[0];
|
||||
#else
|
||||
num = 0;
|
||||
while (len--) {
|
||||
num <<= BITSPERDIG;
|
||||
num += (unsigned long)ds[len]; /* overflow is already checked */
|
||||
}
|
||||
#endif
|
||||
return num;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue