Author: Alex Gaynor <alex.gay...@gmail.com>
Branch: detect-immutable-fields
Changeset: r68881:215ae189f2ae
Date: 2014-01-23 15:14 -0600
http://bitbucket.org/pypy/pypy/changeset/215ae189f2ae/

Log:    merged default in

diff --git a/pypy/interpreter/pyparser/test/test_parsestring.py 
b/pypy/interpreter/pyparser/test/test_parsestring.py
--- a/pypy/interpreter/pyparser/test/test_parsestring.py
+++ b/pypy/interpreter/pyparser/test/test_parsestring.py
@@ -2,9 +2,9 @@
 import py, sys
 
 class TestParsetring:
-    def parse_and_compare(self, literal, value):
+    def parse_and_compare(self, literal, value, encoding=None):
         space = self.space
-        w_ret = parsestring.parsestr(space, None, literal)
+        w_ret = parsestring.parsestr(space, encoding, literal)
         if isinstance(value, str):
             assert space.type(w_ret) == space.w_str
             assert space.str_w(w_ret) == value
diff --git a/pypy/module/cpyext/test/test_ztranslation.py 
b/pypy/module/cpyext/test/test_ztranslation.py
--- a/pypy/module/cpyext/test/test_ztranslation.py
+++ b/pypy/module/cpyext/test/test_ztranslation.py
@@ -1,4 +1,4 @@
 from pypy.objspace.fake.checkmodule import checkmodule
 
 def test_cpyext_translates():
-    checkmodule('cpyext')
+    checkmodule('cpyext', '_rawffi')
diff --git a/pypy/module/pypyjit/policy.py b/pypy/module/pypyjit/policy.py
--- a/pypy/module/pypyjit/policy.py
+++ b/pypy/module/pypyjit/policy.py
@@ -98,7 +98,8 @@
                 modname == '__builtin__.functional' or
                 modname == '__builtin__.descriptor' or
                 modname == 'thread.os_local' or
-                modname == 'thread.os_thread'):
+                modname == 'thread.os_thread' or
+                modname.startswith('_rawffi.alt')):
             return True
         if '.' in modname:
             modname, rest = modname.split('.', 1)
diff --git a/pypy/module/pypyjit/test_pypy_c/test_weakref.py 
b/pypy/module/pypyjit/test_pypy_c/test_weakref.py
--- a/pypy/module/pypyjit/test_pypy_c/test_weakref.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_weakref.py
@@ -30,13 +30,13 @@
         guard_not_invalidated(descr=...)
         p64 = getfield_gc(ConstPtr(ptr40), descr=<FieldP 
pypy.objspace.std.dictmultiobject.W_DictMultiObject.inst_strategy \d+>)
         guard_value(p64, ConstPtr(ptr42), descr=...)
-        p65 = getfield_gc(p14, descr=<FieldP 
pypy.objspace.std.mapdict.W_ObjectObjectSize5.inst_map 48>)
+        p65 = getfield_gc(p14, descr=<FieldP 
pypy.objspace.std.mapdict.W_ObjectObjectSize5.inst_map \d+>)
         guard_value(p65, ConstPtr(ptr45), descr=...)
         p66 = getfield_gc(p14, descr=<FieldP 
pypy.objspace.std.mapdict.W_ObjectObjectSize5.inst__value0 \d+>)
         guard_nonnull_class(p66, ..., descr=...)
         p67 = force_token()
         setfield_gc(p0, p67, descr=<FieldP 
pypy.interpreter.pyframe.PyFrame.vable_token \d+>)
-        p68 = 
call_may_force(ConstClass(WeakrefLifelineWithCallbacks.make_weakref_with_callback),
 p66, ConstPtr(ptr50), p14, ConstPtr(ptr51), descr=<Callr 8 rrrr EF=6>)
+        p68 = 
call_may_force(ConstClass(WeakrefLifelineWithCallbacks.make_weakref_with_callback),
 p66, ConstPtr(ptr50), p14, ConstPtr(ptr51), descr=<Callr \d rrrr EF=6>)
         guard_not_forced(descr=...)
         guard_no_exception(descr=...)
         guard_nonnull_class(p68, ..., descr=...)
diff --git a/rpython/rtyper/raisingops.py b/rpython/rtyper/raisingops.py
--- a/rpython/rtyper/raisingops.py
+++ b/rpython/rtyper/raisingops.py
@@ -87,7 +87,7 @@
         if ((r^(x)) >= 0 || (r^(y)) >= 0); \
         else FAIL_OVF(err, "integer addition")
     '''
-    r = x + y
+    r = intmask(r_uint(x) + r_uint(y))
     if r^x >= 0 or r^y >= 0:
         return r
     else:
@@ -99,7 +99,7 @@
     if (r >= (x)); \
     else FAIL_OVF("integer addition")
     '''
-    r = x + y
+    r = intmask(r_uint(x) + r_uint(y))
     if r >= x:
         return r
     else:
@@ -111,7 +111,7 @@
         if ((r^(x)) >= 0 || (r^~(y)) >= 0); \
         else FAIL_OVF(err, "integer subtraction")
     '''
-    r = x - y
+    r = intmask(r_uint(x) - r_uint(y))
     if r^x >= 0 or r^~y >= 0:
         return r
     else:
diff --git a/rpython/translator/c/test/test_backendoptimized.py 
b/rpython/translator/c/test/test_backendoptimized.py
--- a/rpython/translator/c/test/test_backendoptimized.py
+++ b/rpython/translator/c/test/test_backendoptimized.py
@@ -1,6 +1,4 @@
-from rpython.conftest import option
 from rpython.rlib.rarithmetic import r_uint, r_longlong, r_ulonglong
-from rpython.translator.backendopt.all import backend_optimizations
 from rpython.translator.c.test.test_typed import TestTypedTestCase as 
_TestTypedTestCase
 from rpython.translator.c.test.test_genc import compile
 
@@ -77,12 +75,8 @@
         assert res == 42
 
 class TestTypedOptimizedSwitchTestCase:
-
-    class CodeGenerator(_TestTypedTestCase):
-        def process(self, t):
-            _TestTypedTestCase.process(self, t)
-            self.t = t
-            backend_optimizations(t, merge_if_blocks=True)
+    def getcompiled(self, func, argtypes):
+        return compile(func, argtypes, merge_if_blocks=True)
 
     def test_int_switch(self):
         def f(x):
@@ -93,8 +87,7 @@
             elif x == 27:
                 return 3
             return 0
-        codegenerator = self.CodeGenerator()
-        fn = codegenerator.getcompiled(f, [int])
+        fn = self.getcompiled(f, [int])
         for x in (0,1,2,3,9,27,48, -9):
             assert fn(x) == f(x)
 
@@ -107,8 +100,7 @@
             elif x == 3:
                 return 3
             return 0
-        codegenerator = self.CodeGenerator()
-        fn = codegenerator.getcompiled(f, [int])
+        fn = self.getcompiled(f, [int])
         for x in (0,1,2,3,9,27,48, -9):
             assert fn(x) == f(x)
 
@@ -121,8 +113,7 @@
             elif x == 3:
                 return 3
             return 0
-        codegenerator = self.CodeGenerator()
-        fn = codegenerator.getcompiled(f, [int])
+        fn = self.getcompiled(f, [int])
         for x in (0,1,2,3,9,27,48, -9):
             assert fn(x) == f(x)
 
@@ -135,8 +126,7 @@
             elif x == r_uint(27):
                 return 3
             return 0
-        codegenerator = self.CodeGenerator()
-        fn = codegenerator.getcompiled(f, [r_uint])
+        fn = self.getcompiled(f, [r_uint])
         for x in (0,1,2,3,9,27,48):
             assert fn(r_uint(x)) == f(r_uint(x))
 
@@ -149,8 +139,7 @@
             elif x == r_longlong(27):
                 return 3
             return 0
-        codegenerator = self.CodeGenerator()
-        fn = codegenerator.getcompiled(f, [r_longlong])
+        fn = self.getcompiled(f, [r_longlong])
         for x in (0,1,2,3,9,27,48, -9):
             assert fn(r_longlong(x)) == f(r_longlong(x))
 
@@ -163,8 +152,7 @@
             elif x == r_ulonglong(27):
                 return 3
             return 0
-        codegenerator = self.CodeGenerator()
-        fn = codegenerator.getcompiled(f, [r_ulonglong])
+        fn = self.getcompiled(f, [r_ulonglong])
         for x in (0,1,2,3,9,27,48, r_ulonglong(-9)):
             assert fn(r_ulonglong(x)) == f(r_ulonglong(x))
 
@@ -178,8 +166,7 @@
             elif x == 'c':
                 return 'd'
             return '@'
-        codegenerator = self.CodeGenerator()
-        fn = codegenerator.getcompiled(f, [int])
+        fn = self.getcompiled(f, [int])
         for x in 'ABCabc@':
             y = ord(x)
             assert fn(y) == f(y)
@@ -194,8 +181,7 @@
             if case == '\xFB': return 5
             if case == '\xFA': return 6
             return 7
-        codegenerator = self.CodeGenerator()
-        fn = codegenerator.getcompiled(f, [int])
+        fn = self.getcompiled(f, [int])
         for input, expected in [(255, 1), (253, 3), (251, 5), (161, 7)]:
             res = fn(input)
             assert res == expected
@@ -210,20 +196,15 @@
             elif x == u'c':
                 return 'd'
             return '@'
-        codegenerator = self.CodeGenerator()
-        fn = codegenerator.getcompiled(f, [int])
+        fn = self.getcompiled(f, [int])
         for x in u'ABCabc@':
             y = ord(x)
             assert fn(y) == f(y)
 
 
 class TestTypedOptimizedRaisingOps:
-
-    class CodeGenerator(_TestTypedTestCase):
-        def process(self, t):
-            _TestTypedTestCase.process(self, t)
-            self.t = t
-            backend_optimizations(t, raisingop2direct_call=True)
+    def getcompiled(self, func, argtypes):
+        return compile(func, argtypes, raisingop2direct_call=True)
 
     def test_int_floordiv_zer(self):
         def f(x):
@@ -232,7 +213,25 @@
             except:
                 y = 456
             return y
-        codegenerator = self.CodeGenerator()
-        fn = codegenerator.getcompiled(f, [int])
+        fn = self.getcompiled(f, [int])
         for x in (0,1,2,3,9,27,48, -9):
             assert fn(x) == f(x)
+
+    def test_ovf_op_in_loop(self):
+        # This checks whether the raising operations are implemented using
+        # unsigned arithmetic. The problem with using signed arithmetic is that
+        # signed overflow is undefined in C and the optimizer is allowed to
+        # remove the overflow check.
+        from sys import maxint
+        from rpython.rlib.rarithmetic import ovfcheck
+        def f(x, y):
+            ret = 0
+            for i in range(y):
+                try:
+                    ret = ovfcheck(x + i)
+                except OverflowError:
+                    break
+            return ret
+        fc = self.getcompiled(f, [int, int])
+        assert fc(10, 10) == 19
+        assert fc(maxint, 10) == maxint
diff --git a/rpython/translator/c/test/test_genc.py 
b/rpython/translator/c/test/test_genc.py
--- a/rpython/translator/c/test/test_genc.py
+++ b/rpython/translator/c/test/test_genc.py
@@ -50,7 +50,7 @@
                                            unsigned_ffffffff)
 
 def compile(fn, argtypes, view=False, gcpolicy="none", backendopt=True,
-            annotatorpolicy=None, thread=False):
+            annotatorpolicy=None, thread=False, **kwds):
     argtypes_unroll = unrolling_iterable(enumerate(argtypes))
 
     for argtype in argtypes:
@@ -98,7 +98,7 @@
         return 0
 
     t = Translation(entry_point, None, gc=gcpolicy, backend="c",
-                    policy=annotatorpolicy, thread=thread)
+                    policy=annotatorpolicy, thread=thread, **kwds)
     if not backendopt:
         t.disable(["backendopt_lltype"])
     t.driver.config.translation.countmallocs = True
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to