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

ruby-changes:29563

From: akr <ko1@a...>
Date: Tue, 25 Jun 2013 12:31:31 +0900 (JST)
Subject: [ruby-changes:29563] akr:r41615 (trunk): * bignum.c (big2ulong): Add code specialized for SIZEOF_LONG <=

akr	2013-06-25 12:31:20 +0900 (Tue, 25 Jun 2013)

  New Revision: 41615

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

  Log:
    * bignum.c (big2ulong): Add code specialized for SIZEOF_LONG <=
      SIZEOF_BDIGITS.
      This prevents shift witdth warning from "num <<= BITSPERDIG".

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41614)
+++ ChangeLog	(revision 41615)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Jun 25 12:28:57 2013  Tanaka Akira  <akr@f...>
+
+	* 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@a...>
 
 	* gc.c: fix oldgen/remembered_shady counting algorithm.
Index: bignum.c
===================================================================
--- bignum.c	(revision 41614)
+++ bignum.c	(revision 41615)
@@ -2413,17 +2413,24 @@ big2ulong(VALUE x, const char *type, int https://github.com/ruby/ruby/blob/trunk/bignum.c#L2413
     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;
 }
 

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

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