[前][次][番号順一覧][スレッド一覧]

ruby-changes:29443

From: akr <ko1@a...>
Date: Thu, 20 Jun 2013 22:24:51 +0900 (JST)
Subject: [ruby-changes:29443] akr:r41495 (trunk): * bignum.c (big2ulong): Change the return type to unsigned long.

akr	2013-06-20 22:23:33 +0900 (Thu, 20 Jun 2013)

  New Revision: 41495

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41495

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41494)
+++ ChangeLog	(revision 41495)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Jun 20 22:22:46 2013  Tanaka Akira  <akr@f...>
+
+	* 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@f...>
 
 	* bignum.c (bary_unpack_internal): Return -2 when negative overflow.
Index: bignum.c
===================================================================
--- bignum.c	(revision 41494)
+++ bignum.c	(revision 41495)
@@ -2275,7 +2275,7 @@ rb_big_to_s(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/bignum.c#L2275
     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 https://github.com/ruby/ruby/blob/trunk/bignum.c#L2293
 	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) https://github.com/ruby/ruby/blob/trunk/bignum.c#L2309
 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) https://github.com/ruby/ruby/blob/trunk/bignum.c#L2326
 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) https://github.com/ruby/ruby/blob/trunk/bignum.c#L4729
 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) https://github.com/ruby/ruby/blob/trunk/bignum.c#L4804
 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) https://github.com/ruby/ruby/blob/trunk/bignum.c#L4914
 {
     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) https://github.com/ruby/ruby/blob/trunk/bignum.c#L4930
     else {
 	i = NUM2LONG(y);
 	if (i < 0) return INT2FIX(0);
-	shift = (VALUE)i;
+	shift = i;
     }
     s1 = shift/BITSPERDIG;
     s2 = shift%BITSPERDIG;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]