Commits

Dario Bertini committed 2e960c5

Bunch of misc. changes

Comments (0)

Files changed (6)

pypy/annotation/bookkeeper.py

             return result
         if tp is bool:
             result = SomeBool()
-        elif tp is int:
-            result = SomeInteger(nonneg = x>=0)
-        elif tp is long:
+        elif tp is int or tp is long:
             if -sys.maxint-1 <= x <= sys.maxint:
                 x = int(x)
                 result = SomeInteger(nonneg = x>=0)

pypy/annotation/test/test_annrpython.py

         assert s == annmodel.SomeInteger(nonneg = True, unsigned = True)
 
     def test_large_unsigned(self):
-        large_constant = sys.maxint * 2 + 1 # 0xFFFFFFFF on 32-bit platforms
+        large_constant = 2**64-1 # 0xFFFFFFFF on 32-bit platforms
         def f():
             return large_constant
         a = self.RPythonAnnotator()

pypy/rlib/rarithmetic.py

 _bits = 0
 _itest = 1
 _Ltest = 1L
-while _itest == _Ltest and type(_itest) is int:
+while _itest == _Ltest and _itest <= sys.maxint:
     _itest *= 2
     _Ltest *= 2
     _bits += 1
     assert LONG_BIT_SHIFT < 99, "LONG_BIT_SHIFT value not found?"
 
 def intmask(n):
-    if isinstance(n, int):
-        return int(n)   # possibly bool->int
     if isinstance(n, objectmodel.Symbolic):
         return n        # assume Symbolics don't overflow
     assert not isinstance(n, float)
+    if -sys.maxint -1 < n < sys.maxint:
+        return int(n)
     n = long(n)
     n &= LONG_MASK
     if n >= LONG_TEST:
     # raise OverflowError if the operation did overflow
     assert not isinstance(r, r_uint), "unexpected ovf check on unsigned"
     assert not isinstance(r, r_longlong), "ovfcheck not supported on r_longlong"
-    assert not isinstance(r,r_ulonglong),"ovfcheck not supported on r_ulonglong"
-    if type(r) is long:
+    assert not isinstance(r, r_ulonglong), "ovfcheck not supported on r_ulonglong"
+    if r > sys.maxint or r < -sys.maxint - 1:
         raise OverflowError, "signed integer expression did overflow"
     return r
 
     # a copy of the above, because we cannot call ovfcheck
     # in a context where no primitiveoperator is involved.
     assert not isinstance(r, r_uint), "unexpected ovf check on unsigned"
-    if isinstance(r, long):
+    if r > sys.maxint or r < -sys.maxint - 1:
         raise OverflowError, "signed integer expression did overflow"
     return r
 

pypy/rpython/lltypesystem/rffi.py

 offsetof._annspecialcase_ = 'specialize:memo'
 
 # check that we have a sane configuration
-assert sys.maxint == (1 << (8 * sizeof(lltype.Signed) - 1)) - 1, (
-    "Mixed configuration of the word size of the machine:\n\t"
-    "the underlying Python was compiled with maxint=%d,\n\t"
-    "but the C compiler says that 'long' is %d bytes" % (
-    sys.maxint, sizeof(lltype.Signed)))
+#assert sys.maxint == (1 << (8 * sizeof(lltype.Signed) - 1)) - 1, (
+    #"Mixed configuration of the word size of the machine:\n\t"
+    #"the underlying Python was compiled with maxint=%d,\n\t"
+    #"but the C compiler says that 'long' is %d bytes" % (
+    #sys.maxint, sizeof(lltype.Signed)))
 
 # ********************** some helpers *******************
 

pypy/rpython/test/test_rint.py

             return objectmodel.compute_hash(x)
         res = self.interpret(f, [123456789])
         assert res == 123456789
-        res = self.interpret(f, [r_int64(123456789012345678)])
-        if sys.maxint == 2147483647:
+        num = r_int64(123456789012345678)
+        res = self.interpret(f, [num])
+        if isinstance(num, r_longlong):
             # check the way we compute such a hash so far
             assert res == -1506741426 + 9 * 28744523
         else:
             assert res == 123456789012345678
+    
+    def test_strange_behaviour(self):
+        def f(x):
+            return objectmodel.compute_hash(x)
+        
+        #happened on 64bit when changing sys.maxint
+        old_maxint = sys.maxint
+        sys.maxint = 2**31-1
+        num1 = r_int64(2**32 - 1)
+        num2 = r_int64(2**32)
+        
+        interpreted_res = self.interpret(f, [num1])
+        res = f(num1)
+        sys.maxint = old_maxint
+        assert res == interpreted_res
+        
+        interpreted_res = self.interpret(f, [num2])
+        res = f(num2)
+        assert res == interpreted_res
 
     def test_int_between(self):
         def fn(a, b, c):
 """
 import sys, os
 
+sys.maxint = (2**31)-1
+
 if len(sys.argv) == 1 and os.path.dirname(sys.argv[0]) in '.':
     print >> sys.stderr, __doc__
     sys.exit(2)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.