* bignum.c (big2ulong): Change the return type to unsigned long.

(rb_big2ulong_pack): Follow the above change.
  (rb_big2long): Ditto.
  (rb_big_lshift): Ditto.
  (rb_big_rshift): Ditto.
  (rb_big_aref): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41495 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2013-06-20 13:23:33 +00:00
Родитель 6ea1aee76e
Коммит a9c71d1139
2 изменённых файлов: 30 добавлений и 15 удалений

Просмотреть файл

@ -1,3 +1,12 @@
Thu Jun 20 22:22:46 2013 Tanaka Akira <akr@fsij.org>
* bignum.c (big2ulong): Change the return type to unsigned long.
(rb_big2ulong_pack): Follow the above change.
(rb_big2long): Ditto.
(rb_big_lshift): Ditto.
(rb_big_rshift): Ditto.
(rb_big_aref): Ditto.
Thu Jun 20 22:02:46 2013 Tanaka Akira <akr@fsij.org>
* bignum.c (bary_unpack_internal): Return -2 when negative overflow.

Просмотреть файл

@ -2275,7 +2275,7 @@ rb_big_to_s(int argc, VALUE *argv, VALUE x)
return rb_big2str(x, base);
}
static VALUE
static unsigned long
big2ulong(VALUE x, const char *type, int check)
{
long len = RBIGNUM_LEN(x);
@ -2293,13 +2293,13 @@ big2ulong(VALUE x, const char *type, int check)
num = BIGUP(num);
num += ds[len];
}
return (VALUE)(unsigned long)num;
return (unsigned long)num;
}
VALUE
rb_big2ulong_pack(VALUE x)
{
VALUE num = big2ulong(x, "unsigned long", FALSE);
unsigned long num = big2ulong(x, "unsigned long", FALSE);
if (!RBIGNUM_SIGN(x)) {
return (VALUE)(-(SIGNED_VALUE)num);
}
@ -2309,7 +2309,7 @@ rb_big2ulong_pack(VALUE x)
VALUE
rb_big2ulong(VALUE x)
{
VALUE num = big2ulong(x, "unsigned long", TRUE);
unsigned long num = big2ulong(x, "unsigned long", TRUE);
if (RBIGNUM_POSITIVE_P(x)) {
return num;
@ -2326,7 +2326,7 @@ rb_big2ulong(VALUE x)
SIGNED_VALUE
rb_big2long(VALUE x)
{
VALUE num = big2ulong(x, "long", TRUE);
unsigned long num = big2ulong(x, "long", TRUE);
if (RBIGNUM_POSITIVE_P(x)) {
if (num <= LONG_MAX)
@ -4729,15 +4729,18 @@ check_shiftdown(VALUE y, VALUE x)
VALUE
rb_big_lshift(VALUE x, VALUE y)
{
long shift;
unsigned long shift;
int neg = 0;
for (;;) {
if (FIXNUM_P(y)) {
shift = FIX2LONG(y);
if (shift < 0) {
long l = FIX2LONG(y);
if (0 <= l) {
shift = l;
}
else {
neg = 1;
shift = -shift;
shift = 1+(unsigned long)(-(l+1));
}
break;
}
@ -4801,15 +4804,18 @@ big_lshift(VALUE x, unsigned long shift)
VALUE
rb_big_rshift(VALUE x, VALUE y)
{
long shift;
unsigned long shift;
int neg = 0;
for (;;) {
if (FIXNUM_P(y)) {
shift = FIX2LONG(y);
if (shift < 0) {
long l = FIX2LONG(y);
if (0 <= l) {
shift = l;
}
else {
neg = 1;
shift = -shift;
shift = 1+(unsigned long)(-(l+1));
}
break;
}
@ -4908,7 +4914,7 @@ rb_big_aref(VALUE x, VALUE y)
{
BDIGIT *xds;
BDIGIT_DBL num;
VALUE shift;
unsigned long shift;
long i, s1, s2;
if (RB_TYPE_P(y, T_BIGNUM)) {
@ -4924,7 +4930,7 @@ rb_big_aref(VALUE x, VALUE y)
else {
i = NUM2LONG(y);
if (i < 0) return INT2FIX(0);
shift = (VALUE)i;
shift = i;
}
s1 = shift/BITSPERDIG;
s2 = shift%BITSPERDIG;