Justin Peel avatar Justin Peel committed 51221f3 Merge

merge in default

Comments (0)

Files changed (6)


 We therefore can no longer use the int type as it is, but need
 to use long everywhere.
+# XXX returning int(n) should not be necessary and should be simply n.
+# XXX TODO: replace all int(n) by long(n) and fix everything that breaks.
+# XXX       Then relax it and replace int(n) by n.
 def intmask(n):
     if isinstance(n, objectmodel.Symbolic):
         return n        # assume Symbolics don't overflow


 from pypy.objspace.flow.model import FunctionGraph, Constant, Variable, c_last_exception
 from pypy.rlib.rarithmetic import intmask, r_uint, ovfcheck, r_longlong
-from pypy.rlib.rarithmetic import r_ulonglong
+from pypy.rlib.rarithmetic import r_ulonglong, is_valid_int
 from pypy.rpython.lltypesystem import lltype, llmemory, lloperation, llheap
 from pypy.rpython.lltypesystem import rclass
 from pypy.rpython.ootypesystem import ootype
     # Overflow-detecting variants
     def op_int_neg_ovf(self, x):
-        assert type(x) is int
+        assert is_valid_int(x)
             return ovfcheck(-x)
         except OverflowError:
     def op_int_abs_ovf(self, x):
-        assert type(x) is int
+        assert is_valid_int(x)
             return ovfcheck(abs(x))
         except OverflowError:
     def op_int_lshift_ovf(self, x, y):
-        assert isinstance(x, int)
-        assert isinstance(y, int)
+        assert is_valid_int(x)
+        assert is_valid_int(y)
             return ovfcheck(x << y)
         except OverflowError:
                 return r
         elif operator == '%':
-            code = '''r = %(checkfn)s(x %% y)
+            ## overflow check on % does not work with emulated int
+            code = '''%(checkfn)s(x // y)
+                r = x %% y
                 if x^y < 0 and x%%y != 0:
                     r -= y
                 return r
         """ % locals()).compile() in globals(), d
-    _makefunc2('op_int_add_ovf', '+', '(int, llmemory.AddressOffset)')
-    _makefunc2('op_int_mul_ovf', '*', '(int, llmemory.AddressOffset)', 'int')
-    _makefunc2('op_int_sub_ovf',          '-',  'int')
-    _makefunc2('op_int_floordiv_ovf',     '//', 'int')  # XXX negative args
-    _makefunc2('op_int_floordiv_zer',     '//', 'int')  # can get off-by-one
-    _makefunc2('op_int_floordiv_ovf_zer', '//', 'int')  # (see op_int_floordiv)
-    _makefunc2('op_int_mod_ovf',          '%',  'int')
-    _makefunc2('op_int_mod_zer',          '%',  'int')
-    _makefunc2('op_int_mod_ovf_zer',      '%',  'int')
+    _makefunc2('op_int_add_ovf', '+', '(int, long, llmemory.AddressOffset)')
+    _makefunc2('op_int_mul_ovf', '*', '(int, long, llmemory.AddressOffset)', '(int, long)')
+    _makefunc2('op_int_sub_ovf',          '-',  '(int, long)')
+    _makefunc2('op_int_floordiv_ovf',     '//', '(int, long)')  # XXX negative args
+    _makefunc2('op_int_floordiv_zer',     '//', '(int, long)')  # can get off-by-one
+    _makefunc2('op_int_floordiv_ovf_zer', '//', '(int, long)')  # (see op_int_floordiv)
+    _makefunc2('op_int_mod_ovf',          '%',  '(int, long)')
+    _makefunc2('op_int_mod_zer',          '%',  '(int, long)')
+    _makefunc2('op_int_mod_ovf_zer',      '%',  '(int, long)')
     _makefunc2('op_uint_floordiv_zer',    '//', 'r_uint')
     _makefunc2('op_uint_mod_zer',         '%',  'r_uint')
             x = x.default
         # if type(x) is a subclass of Symbolic, bool(x) will usually raise
         # a TypeError -- unless __nonzero__ has been explicitly overridden.
-        assert isinstance(x, (int, Symbolic))
+        assert is_valid_int(x) or isinstance(x, Symbolic)
         return bool(x)
     # hack for jit.codegen.llgraph
     def op_oonewarray(self, ARRAY, length):
         assert isinstance(ARRAY, ootype.Array)
-        assert isinstance(length, int)
+        assert is_valid_int(length)
         return ootype.oonewarray(ARRAY, length)
     def op_runtimenew(self, class_):


 from pypy.rlib.objectmodel import Symbolic
 from pypy.rpython.lltypesystem import lltype
 from pypy.tool.uid import uid
+from pypy.rlib.rarithmetic import is_valid_int
 class AddressOffset(Symbolic):
     def __ge__(self, other):
         if self is other:
             return True
-        elif (isinstance(other, (int, long)) and other == 0 and
+        elif (is_valid_int(other) and other == 0 and
             return True
         return "<ItemOffset %r %r>" % (self.TYPE, self.repeat)
     def __mul__(self, other):
-        if not isinstance(other, int):
+        if not is_valid_int(other):
             return NotImplemented
         return ItemOffset(self.TYPE, self.repeat * other)


 import py
 from pypy.rpython.lltypesystem import lltype, llmemory
 from pypy.rpython.memory.gctypelayout import TypeLayoutBuilder
-from pypy.rlib.rarithmetic import LONG_BIT
+from pypy.rlib.rarithmetic import LONG_BIT, is_valid_int
         p = self.malloc(S)
         hash = self.gc.identityhash(p)
         print hash
-        assert isinstance(hash, (int, long))
+        assert is_valid_int(hash)
         assert hash == self.gc.identityhash(p)
         for i in range(6):
         hash = self.gc.identityhash(self.stackroots[-1])
         print hash
-        assert isinstance(hash, (int, long))
+        assert is_valid_int(hash)
         for i in range(6):
             assert hash == self.gc.identityhash(self.stackroots[-1])
         hash = self.gc.identityhash(self.stackroots[-1])
         print hash
-        assert isinstance(hash, (int, long))
+        assert is_valid_int(hash)
         for i in range(2):
             assert hash == self.gc.identityhash(self.stackroots[-1])
         # (4) p is a prebuilt object
         hash = self.gc.identityhash(p_const)
         print hash
-        assert isinstance(hash, (int, long))
+        assert is_valid_int(hash)
         assert hash == self.gc.identityhash(p_const)
         # (5) p is actually moving (for the markcompact gc)
         p0 = self.malloc(S)


 from pypy.rlib.debug import llinterpcall
 from pypy.rpython.lltypesystem import lltype
 from pypy.tool import udir
-from pypy.rlib.rarithmetic import intmask
+from pypy.rlib.rarithmetic import intmask, is_valid_int
 from pypy.rlib.rarithmetic import r_int, r_uint, r_longlong, r_ulonglong
 from pypy.annotation.builtin import *
 from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin, OORtypeMixin
         if r_longlong is not r_int:
             assert isinstance(res, r_longlong)
-            assert isinstance(res, int)
+            assert is_valid_int(res)
         def llfn(v):
             return rffi.cast(rffi.ULONGLONG, v)


             p_a1 = rffi.cast(rffi.VOIDPP, ll_args[0])[0]
             p_a2 = rffi.cast(rffi.VOIDPP, ll_args[1])[0]
-            a1 = rffi.cast(rffi.LONGP, p_a1)[0]
-            a2 = rffi.cast(rffi.LONGP, p_a2)[0]
+            a1 = rffi.cast(rffi.SIGNEDP, p_a1)[0]
+            a2 = rffi.cast(rffi.SIGNEDP, p_a2)[0]
             res = rffi.cast(rffi.INTP, ll_res)
             if a1 > a2:
                 res[0] = rffi.cast(rffi.INT, 1)
             ptr = CallbackFuncPtr([ffi_type_pointer, ffi_type_pointer],
                                   ffi_type_sint, callback)
-            TP = rffi.CArray(rffi.LONG)
+            TP = rffi.CArray(lltype.Signed)
             to_sort = lltype.malloc(TP, 4, flavor='raw')
             to_sort[0] = 4
             to_sort[1] = 3
             to_sort[3] = 2
             qsort.push_arg(rffi.cast(rffi.VOIDP, to_sort))
             qsort.push_arg(rffi.cast(rffi.SIZE_T, 4))
-            qsort.push_arg(rffi.cast(rffi.SIZE_T, rffi.sizeof(rffi.LONG)))
+            qsort.push_arg(rffi.cast(rffi.SIZE_T, rffi.sizeof(lltype.Signed)))
             qsort.push_arg(rffi.cast(rffi.VOIDP, ptr.ll_closure))
             result = [to_sort[i] for i in range(4)] == [1,2,3,4]
         def f():
             from pypy.rpython.lltypesystem import lltype, rffi
             alist = [A() for i in range(50000)]
-            idarray = lltype.malloc(rffi.LONGP.TO, len(alist), flavor='raw')
+            idarray = lltype.malloc(rffi.SIGNEDP.TO, len(alist), flavor='raw')
             # Compute the id of all elements of the list.  The goal is
             # to not allocate memory, so that if the GC needs memory to
             # remember the ids, it will trigger some collections itself
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.