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

ruby-changes:21697

From: kosaki <ko1@a...>
Date: Mon, 14 Nov 2011 14:56:20 +0900 (JST)
Subject: [ruby-changes:21697] kosaki:r33746 (trunk): * bignum.c (rb_big2ull): fix 32bit platform breakage. we must

kosaki	2011-11-14 14:56:09 +0900 (Mon, 14 Nov 2011)

  New Revision: 33746

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

  Log:
    * bignum.c (rb_big2ull): fix 32bit platform breakage. we must
      not assume sizeof(VALUE) == sizeof(LONG_LONG).
    * test/-ext-/num2int/test_num2int.rb (class TestNum2int):
      fix false assumption on 32bit platform.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c
    trunk/test/-ext-/num2int/test_num2int.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 33745)
+++ ChangeLog	(revision 33746)
@@ -1,3 +1,10 @@
+Mon Nov 14 14:54:17 2011  KOSAKI Motohiro  <kosaki.motohiro@g...>
+
+	* bignum.c (rb_big2ull): fix 32bit platform breakage. we must
+	  not assume sizeof(VALUE) == sizeof(LONG_LONG).
+	* test/-ext-/num2int/test_num2int.rb (class TestNum2int):
+	  fix false assumption on 32bit platform.
+
 Mon Nov 14 14:52:54 2011  KOSAKI Motohiro  <kosaki.motohiro@g...>
 
 	* numeric.c (rb_fix2ushort): fix typo. use num rb_num2ushort()
Index: bignum.c
===================================================================
--- bignum.c	(revision 33745)
+++ bignum.c	(revision 33746)
@@ -1258,10 +1258,10 @@
     unsigned LONG_LONG num = big2ull(x, "unsigned long long");
 
     if (!RBIGNUM_SIGN(x)) {
-	VALUE v = (VALUE)(-(SIGNED_VALUE)num);
+	LONG_LONG v = -num;
 
 	/* FIXNUM_MIN-1 .. LLONG_MIN mapped into 0xbfffffffffffffff .. LONG_MAX+1 */
-	if (v <= LLONG_MAX)
+	if ((unsigned LONG_LONG)v <= LLONG_MAX)
 	    rb_raise(rb_eRangeError, "bignum out of range of unsigned long long");
 	return v;
     }
Index: test/-ext-/num2int/test_num2int.rb
===================================================================
--- test/-ext-/num2int/test_num2int.rb	(revision 33745)
+++ test/-ext-/num2int/test_num2int.rb	(revision 33746)
@@ -23,12 +23,10 @@
     LONG_MIN = -9223372036854775808
     ULONG_MAX = 18446744073709551615
   end
-  ULONG_HALF = ULONG_MAX - LONG_MAX
 
   LLONG_MAX = 9223372036854775807
   LLONG_MIN = -9223372036854775808
   ULLONG_MAX = 18446744073709551615
-  ULLONG_HALF = ULLONG_MAX - LLONG_MAX # 0x8000000000000000
 
   FIXNUM_MAX = LONG_MAX/2
   FIXNUM_MIN = LONG_MIN/2
@@ -151,10 +149,10 @@
     assert_raise(RangeError) do
       Num2int.print_num2ulong(ULONG_MAX+1)
     end
-    assert_output((ULONG_HALF+FIXNUM_MAX+1).to_s) do
+    assert_output((ULONG_MAX-FIXNUM_MAX).to_s) do
       Num2int.print_num2ulong(FIXNUM_MIN)
     end
-    assert_output((ULONG_HALF+FIXNUM_MAX).to_s) do
+    assert_output((ULONG_MAX-FIXNUM_MAX-1).to_s) do
       Num2int.print_num2ulong(FIXNUM_MIN-1)
     end
     assert_output(FIXNUM_MAX.to_s) do
@@ -211,10 +209,10 @@
     assert_raise(RangeError) do
       Num2int.print_num2ull(ULLONG_MAX+1)
     end
-    assert_output((ULLONG_HALF+FIXNUM_MAX+1).to_s) do
+    assert_output((ULLONG_MAX-FIXNUM_MAX).to_s) do
       Num2int.print_num2ull(FIXNUM_MIN)
     end
-    assert_output((ULLONG_HALF+FIXNUM_MAX).to_s) do
+    assert_output((ULLONG_MAX-FIXNUM_MAX-1).to_s) do
       Num2int.print_num2ull(FIXNUM_MIN-1)
     end
     assert_output(FIXNUM_MAX.to_s) do

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

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