[pypy-svn] r54538 - in pypy/branch/gc-tweak/pypy: module/_minimal_curses module/_rawffi objspace/std objspace/std/test rlib rlib/test rpython/lltypesystem rpython/memory/gc translator/c/src

arigo at codespeak.net arigo at codespeak.net
Wed May 7 18:54:12 CEST 2008


Author: arigo
Date: Wed May  7 18:54:11 2008
New Revision: 54538

Modified:
   pypy/branch/gc-tweak/pypy/module/_minimal_curses/fficurses.py
   pypy/branch/gc-tweak/pypy/module/_rawffi/callback.py
   pypy/branch/gc-tweak/pypy/module/_rawffi/interp_rawffi.py
   pypy/branch/gc-tweak/pypy/objspace/std/objspace.py
   pypy/branch/gc-tweak/pypy/objspace/std/test/test_longobject.py
   pypy/branch/gc-tweak/pypy/rlib/libffi.py
   pypy/branch/gc-tweak/pypy/rlib/rarithmetic.py
   pypy/branch/gc-tweak/pypy/rlib/rbigint.py
   pypy/branch/gc-tweak/pypy/rlib/test/test_rbigint.py
   pypy/branch/gc-tweak/pypy/rpython/lltypesystem/llarena.py
   pypy/branch/gc-tweak/pypy/rpython/lltypesystem/opimpl.py
   pypy/branch/gc-tweak/pypy/rpython/memory/gc/base.py
   pypy/branch/gc-tweak/pypy/rpython/memory/gc/generation.py
   pypy/branch/gc-tweak/pypy/translator/c/src/int.h
Log:
64-bit fixes from the trunk:
svn merge -r54527:54537 svn+ssh://codespeak.net/svn/pypy/dist


Modified: pypy/branch/gc-tweak/pypy/module/_minimal_curses/fficurses.py
==============================================================================
--- pypy/branch/gc-tweak/pypy/module/_minimal_curses/fficurses.py	(original)
+++ pypy/branch/gc-tweak/pypy/module/_minimal_curses/fficurses.py	Wed May  7 18:54:11 2008
@@ -28,17 +28,18 @@
                                     INT, INT, INT, INT, INT], rffi.CCHARP,
                           compilation_info=eci)
 
-ERR = rffi.CConstant('ERR', INT)
-OK = rffi.CConstant('OK', INT)
+ERR = rffi.CConstant('ERR', lltype.Signed)
+OK = rffi.CConstant('OK', lltype.Signed)
 
 def curses_setupterm(term, fd):
     intp = lltype.malloc(INTP.TO, 1, flavor='raw')
-    err = c_setupterm(term, fd, intp)
+    err = rffi.cast(lltype.Signed, c_setupterm(term, fd, intp))
     try:
         if err == ERR:
-            if intp[0] == 0:
+            errret = rffi.cast(lltype.Signed, intp[0])
+            if errret == 0:
                 msg = "setupterm: could not find terminal"
-            elif intp[0] == -1:
+            elif errret == -1:
                 msg = "setupterm: could not find terminfo database"
             else:
                 msg = "setupterm: unknown error"

Modified: pypy/branch/gc-tweak/pypy/module/_rawffi/callback.py
==============================================================================
--- pypy/branch/gc-tweak/pypy/module/_rawffi/callback.py	(original)
+++ pypy/branch/gc-tweak/pypy/module/_rawffi/callback.py	Wed May  7 18:54:11 2008
@@ -53,12 +53,12 @@
                                            callback, number)
         self.ll_buffer = rffi.cast(rffi.VOIDP, self.ll_callback.ll_closure)
         if tracker.DO_TRACING:
-            addr = rffi.cast(rffi.INT, self.ll_callback.ll_closure)
+            addr = rffi.cast(lltype.Signed, self.ll_callback.ll_closure)
             tracker.trace_allocation(addr, self)
 
     def free(self):
         if tracker.DO_TRACING:
-            addr = rffi.cast(rffi.INT, self.ll_callback.ll_closure)
+            addr = rffi.cast(lltype.Signed, self.ll_callback.ll_closure)
             tracker.trace_free(addr)
         del self.global_counter.CallbackPtr_by_number[self.number]
     free.unwrap_spec = ['self']

Modified: pypy/branch/gc-tweak/pypy/module/_rawffi/interp_rawffi.py
==============================================================================
--- pypy/branch/gc-tweak/pypy/module/_rawffi/interp_rawffi.py	(original)
+++ pypy/branch/gc-tweak/pypy/module/_rawffi/interp_rawffi.py	Wed May  7 18:54:11 2008
@@ -227,7 +227,7 @@
             self.ll_buffer = lltype.malloc(rffi.VOIDP.TO, size, flavor='raw',
                                            zero=True)
             if tracker.DO_TRACING:
-                ll_buf = rffi.cast(rffi.INT, self.ll_buffer)
+                ll_buf = rffi.cast(lltype.Signed, self.ll_buffer)
                 tracker.trace_allocation(ll_buf, self)
 
     def getbuffer(space, self):
@@ -249,7 +249,7 @@
 
     def _free(self):
         if tracker.DO_TRACING:
-            ll_buf = rffi.cast(rffi.INT, self.ll_buffer)
+            ll_buf = rffi.cast(lltype.Signed, self.ll_buffer)
             tracker.trace_free(ll_buf)
         lltype.free(self.ll_buffer, flavor='raw')
         self.ll_buffer = lltype.nullptr(rffi.VOIDP.TO)
@@ -355,7 +355,7 @@
         if tracker.DO_TRACING:
             # XXX this is needed, because functions tend to live forever
             #     hence our testing is not performing that well
-            del tracker.alloced[rffi.cast(rffi.INT, array.ll_buffer)]
+            del tracker.alloced[rffi.cast(lltype.Signed, array.ll_buffer)]
         return space.wrap(array)
     byptr.unwrap_spec = ['self', ObjSpace]
 

Modified: pypy/branch/gc-tweak/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/branch/gc-tweak/pypy/objspace/std/objspace.py	(original)
+++ pypy/branch/gc-tweak/pypy/objspace/std/objspace.py	Wed May  7 18:54:11 2008
@@ -15,8 +15,7 @@
 from pypy.objspace.std.multimethod import FailedToImplement
 from pypy.objspace.descroperation import DescrOperation
 from pypy.objspace.std import stdtypedef
-from pypy.rlib.rarithmetic import base_int, r_int, r_uint, \
-     r_longlong, r_ulonglong
+from pypy.rlib.rarithmetic import base_int
 from pypy.rlib.objectmodel import we_are_translated
 from pypy.rlib.jit import hint, we_are_jitted
 from pypy.rlib.unroll import unrolling_iterable
@@ -477,8 +476,7 @@
             w_result = x.__spacebind__(self)
             #print 'wrapping', x, '->', w_result
             return w_result
-        if isinstance(x, r_int) or isinstance(x, r_uint) or \
-           isinstance(x, r_longlong) or isinstance(x, r_ulonglong):
+        if isinstance(x, base_int):
             return W_LongObject.fromrarith_int(x)
 
         # _____ below here is where the annotator should not get _____
@@ -500,7 +498,7 @@
 
         # The following cases are even stranger.
         # Really really only for tests.
-        if isinstance(x, long):
+        if type(x) is long:
             return W_LongObject.fromlong(x)
         if isinstance(x, slice):
             return W_SliceObject(self.wrap(x.start),

Modified: pypy/branch/gc-tweak/pypy/objspace/std/test/test_longobject.py
==============================================================================
--- pypy/branch/gc-tweak/pypy/objspace/std/test/test_longobject.py	(original)
+++ pypy/branch/gc-tweak/pypy/objspace/std/test/test_longobject.py	Wed May  7 18:54:11 2008
@@ -5,9 +5,13 @@
 from pypy.interpreter.error import OperationError
 from pypy.rlib.rarithmetic import r_uint
 from pypy.rlib.rbigint import rbigint
+from pypy.conftest import gettestobjspace
 
 class TestW_LongObject:
 
+    def setup_class(cls):
+        cls.space = gettestobjspace(**{"objspace.nofaking": True})
+
     def test_bigint_w(self):
         space = self.space
         fromlong = lobj.W_LongObject.fromlong
@@ -19,6 +23,21 @@
         w_obj = space.wrap(123.456)
         space.raises_w(space.w_TypeError, space.bigint_w, w_obj)
 
+    def test_rint_variants(self):
+        from pypy.rpython.tool.rfficache import platform
+        space = self.space
+        for r in platform.numbertype_to_rclass.values():
+            if r is int:
+                continue
+            print r
+            values = [0, -1, r.MASK>>1, -(r.MASK>>1)-1]
+            for x in values:
+                if not r.SIGNED:
+                    x &= r.MASK
+                w_obj = space.wrap(r(x))
+                assert space.bigint_w(w_obj).eq(rbigint.fromint(x))
+
+
 class AppTestLong:
     def test_add(self):
         assert int(123L + 12443L) == 123 + 12443

Modified: pypy/branch/gc-tweak/pypy/rlib/libffi.py
==============================================================================
--- pypy/branch/gc-tweak/pypy/rlib/libffi.py	(original)
+++ pypy/branch/gc-tweak/pypy/rlib/libffi.py	Wed May  7 18:54:11 2008
@@ -217,7 +217,7 @@
                                          lltype.Void))
 USERDATA_P.TO.become(lltype.Struct('userdata',
                                    ('callback', CALLBACK_TP),
-                                   ('addarg', rffi.INT),
+                                   ('addarg', lltype.Signed),
                                    hints={'callback':True}))
 
 

Modified: pypy/branch/gc-tweak/pypy/rlib/rarithmetic.py
==============================================================================
--- pypy/branch/gc-tweak/pypy/rlib/rarithmetic.py	(original)
+++ pypy/branch/gc-tweak/pypy/rlib/rarithmetic.py	Wed May  7 18:54:11 2008
@@ -21,6 +21,11 @@
          like r_int but double word size
 r_ulonglong
          like r_uint but double word size
+widen(x)
+         if x is of a type smaller than lltype.Signed or
+         lltype.Unsigned, widen it to lltype.Signed.
+         Useful because the translator doesn't support
+         arithmetic on the smaller types.
 
 These are meant to be erased by translation, r_uint
 in the process should mark unsigned values, ovfcheck should
@@ -68,6 +73,25 @@
         n -= 2*LONG_TEST
     return int(n)
 
+def widen(n):
+    from pypy.rpython.lltypesystem import lltype
+    if _should_widen_type(lltype.typeOf(n)):
+        return int(n)
+    else:
+        return n
+widen._annspecialcase_ = 'specialize:argtype(0)'
+
+def _should_widen_type(tp):
+    from pypy.rpython.lltypesystem import lltype, rffi
+    if tp is lltype.Bool:
+        return True
+    if tp is lltype.Signed:
+        return False
+    r_class = rffi.platform.numbertype_to_rclass[tp]
+    assert issubclass(r_class, base_int)
+    return r_class.BITS < LONG_BIT
+_should_widen_type._annspecialcase_ = 'specialize:memo'
+
 del _bits, _itest, _Ltest
 
 def ovfcheck(r):

Modified: pypy/branch/gc-tweak/pypy/rlib/rbigint.py
==============================================================================
--- pypy/branch/gc-tweak/pypy/rlib/rbigint.py	(original)
+++ pypy/branch/gc-tweak/pypy/rlib/rbigint.py	Wed May  7 18:54:11 2008
@@ -1,5 +1,5 @@
 from pypy.rlib.rarithmetic import LONG_BIT, intmask, r_uint, r_ulonglong
-from pypy.rlib.rarithmetic import ovfcheck, r_longlong
+from pypy.rlib.rarithmetic import ovfcheck, r_longlong, widen
 
 import math, sys
 
@@ -613,7 +613,7 @@
     return digits
 digits_for_most_neg_long._annspecialcase_ = "specialize:argtype(0)"
 
-def args_from_rarith_int(x):
+def args_from_rarith_int1(x):
     if x > 0:
         return digits_from_nonneg_long(x), 1
     elif x == 0:
@@ -631,6 +631,10 @@
         else:
             # the most negative integer! hacks needed...
             return digits_for_most_neg_long(x), -1
+args_from_rarith_int1._annspecialcase_ = "specialize:argtype(0)"
+
+def args_from_rarith_int(x):
+    return args_from_rarith_int1(widen(x))
 args_from_rarith_int._annspecialcase_ = "specialize:argtype(0)"
 # ^^^ specialized by the precise type of 'x', which is typically a r_xxx
 #     instance from rlib.rarithmetic

Modified: pypy/branch/gc-tweak/pypy/rlib/test/test_rbigint.py
==============================================================================
--- pypy/branch/gc-tweak/pypy/rlib/test/test_rbigint.py	(original)
+++ pypy/branch/gc-tweak/pypy/rlib/test/test_rbigint.py	Wed May  7 18:54:11 2008
@@ -434,15 +434,25 @@
 
     def test_args_from_rarith_int(self):
         from pypy.rpython.test.test_llinterp import interpret
-        def fn(x):
-            n1 = rbigint.fromrarith_int(x)
-            n2 = rbigint.fromrarith_int(r_uint(x))
-            return '%s %s' % (n1.str(), n2.str())
-        res = interpret(fn, [0])
-        assert ''.join(res.chars) == '0 0'
-        res = interpret(fn, [sys.maxint])
-        assert ''.join(res.chars) == '%d %d' % (sys.maxint, sys.maxint)
-        res = interpret(fn, [-sys.maxint-1])
-        assert ''.join(res.chars) == '%d %d' % (-sys.maxint-1, sys.maxint+1)
-        res = interpret(fn, [-17])
-        assert ''.join(res.chars) == '%d %d' % (-17, 2*sys.maxint+2-17)
+        from pypy.rpython.tool.rfficache import platform
+        classlist = platform.numbertype_to_rclass.values()
+        fnlist = []
+        for r in classlist:
+            if r is int:
+                mask = sys.maxint*2+1
+                signed = True
+            else:
+                mask = r.MASK
+                signed = r.SIGNED
+            values = [0, -1, mask>>1, -(mask>>1)-1]
+            if not signed:
+                values = [x & mask for x in values]
+            values = [r(x) for x in values]
+
+            def fn(i):
+                n = rbigint.fromrarith_int(values[i])
+                return n.str()
+
+            for i in range(len(values)):
+                res = interpret(fn, [i])
+                assert ''.join(res.chars) == str(long(values[i]))

Modified: pypy/branch/gc-tweak/pypy/rpython/lltypesystem/llarena.py
==============================================================================
--- pypy/branch/gc-tweak/pypy/rpython/lltypesystem/llarena.py	(original)
+++ pypy/branch/gc-tweak/pypy/rpython/lltypesystem/llarena.py	Wed May  7 18:54:11 2008
@@ -391,7 +391,7 @@
                   sandboxsafe=True)
 
 llimpl_round_up_for_allocation = rffi.llexternal('ROUND_UP_FOR_ALLOCATION',
-                                                 [rffi.INT], rffi.INT,
+                                                 [lltype.Signed], lltype.Signed,
                                                  sandboxsafe=True,
                                                  _nowrapper=True)
 register_external(round_up_for_allocation, [int], int,

Modified: pypy/branch/gc-tweak/pypy/rpython/lltypesystem/opimpl.py
==============================================================================
--- pypy/branch/gc-tweak/pypy/rpython/lltypesystem/opimpl.py	(original)
+++ pypy/branch/gc-tweak/pypy/rpython/lltypesystem/opimpl.py	Wed May  7 18:54:11 2008
@@ -289,8 +289,7 @@
 
 def op_truncate_longlong_to_int(b):
     assert type(b) is r_longlong
-    assert -sys.maxint-1 <= b <= sys.maxint
-    return int(b)
+    return intmask(b)
 
 def op_cast_pointer(RESTYPE, obj):
     checkptr(obj)

Modified: pypy/branch/gc-tweak/pypy/rpython/memory/gc/base.py
==============================================================================
--- pypy/branch/gc-tweak/pypy/rpython/memory/gc/base.py	(original)
+++ pypy/branch/gc-tweak/pypy/rpython/memory/gc/base.py	Wed May  7 18:54:11 2008
@@ -12,7 +12,7 @@
     # collection.  It is automatically set to True by test_gc.py.  The
     # checking logic is translatable, so the flag can be set to True
     # here before translation.
-    DEBUG = False
+    DEBUG = True
 
     def set_query_functions(self, is_varsize, has_gcptr_in_varsize,
                             is_gcarrayofgcptr,

Modified: pypy/branch/gc-tweak/pypy/rpython/memory/gc/generation.py
==============================================================================
--- pypy/branch/gc-tweak/pypy/rpython/memory/gc/generation.py	(original)
+++ pypy/branch/gc-tweak/pypy/rpython/memory/gc/generation.py	Wed May  7 18:54:11 2008
@@ -337,7 +337,7 @@
             llarena.arena_reset(self.nursery, self.nursery_size, True)
             if DEBUG_PRINT:
                 llop.debug_print(lltype.Void, "percent survived:", float(scan - beginning) / self.nursery_size)
-            self.debug_check_consistency()
+            #self.debug_check_consistency()
         else:
             # no nursery - this occurs after a full collect, triggered either
             # just above or by some previous non-nursery-based allocation.

Modified: pypy/branch/gc-tweak/pypy/translator/c/src/int.h
==============================================================================
--- pypy/branch/gc-tweak/pypy/translator/c/src/int.h	(original)
+++ pypy/branch/gc-tweak/pypy/translator/c/src/int.h	Wed May  7 18:54:11 2008
@@ -72,7 +72,13 @@
 
 #define OP_INT_MUL(x,y,r)     r = (x) * (y)
 
-#ifndef HAVE_LONG_LONG
+#if defined(HAVE_LONG_LONG) && SIZE_OF_LONG_LONG < SIZE_OF_LONG
+#  define OP_INT_MUL_OVF_LL      1
+#lse
+#  define OP_INT_MUL_OVF_LL      0
+#endif
+
+#if !OP_INT_MUL_OVF_LL
 
 #define OP_INT_MUL_OVF(x,y,r) \
 	if (op_int_mul_ovf(x,y,&r)); \
@@ -230,7 +236,7 @@
 
 /* _________________ certain implementations __________________ */
 
-#ifndef HAVE_LONG_LONG
+#if !OP_INT_MUL_OVF_LL
 /* adjusted from intobject.c, Python 2.3.3 */
 
 /* prototypes */
@@ -276,7 +282,7 @@
 
 #endif /* PYPY_NOT_MAIN_FILE */
 
-#endif /* HAVE_LONG_LONG */
+#endif /* !OP_INT_MUL_OVF_LL */
 
 /* implementations */
 



More information about the Pypy-commit mailing list