[pypy-svn] pypy jit-longlong: Test and fix: this call to r_ulonglong() used to raise OverflowError.

arigo commits-noreply at bitbucket.org
Sat Jan 8 16:35:38 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: jit-longlong
Changeset: r40494:c4cb8add2f34
Date: 2011-01-08 16:27 +0100
http://bitbucket.org/pypy/pypy/changeset/c4cb8add2f34/

Log:	Test and fix: this call to r_ulonglong() used to raise
	OverflowError.

diff --git a/pypy/rlib/rarithmetic.py b/pypy/rlib/rarithmetic.py
--- a/pypy/rlib/rarithmetic.py
+++ b/pypy/rlib/rarithmetic.py
@@ -342,7 +342,7 @@
 class unsigned_int(base_int):
     SIGNED = False
     def __new__(klass, val=0):
-        if type(val) is float:
+        if isinstance(val, (float, long)):
             val = long(val)
         return super(unsigned_int, klass).__new__(klass, val & klass.MASK)
     typemap = {}

diff --git a/pypy/rlib/test/test_rarithmetic.py b/pypy/rlib/test/test_rarithmetic.py
--- a/pypy/rlib/test/test_rarithmetic.py
+++ b/pypy/rlib/test/test_rarithmetic.py
@@ -401,3 +401,8 @@
     llmin = -(2**(r_longlong.BITS-1))
     assert most_neg_value_of_same_type(r_longlong(123)) == llmin
     assert most_neg_value_of_same_type(r_ulonglong(123)) == 0
+
+def test_r_ulonglong():
+    x = r_longlong(-1)
+    y = r_ulonglong(x)
+    assert long(y) == 2**r_ulonglong.BITS - 1


More information about the Pypy-commit mailing list