[pypy-commit] pypy null_byte_after_str: Cancel the changes to the annotator, causing verye obscure rare

arigo pypy.commits at gmail.com
Sun Jul 31 05:22:37 EDT 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: null_byte_after_str
Changeset: r85947:30dbb1cd63dd
Date: 2016-07-31 11:24 +0200
http://bitbucket.org/pypy/pypy/changeset/30dbb1cd63dd/

Log:	Cancel the changes to the annotator, causing verye obscure rare
	problems. Implement it differently inside rffi.llexternal().

diff --git a/rpython/annotator/binaryop.py b/rpython/annotator/binaryop.py
--- a/rpython/annotator/binaryop.py
+++ b/rpython/annotator/binaryop.py
@@ -201,8 +201,8 @@
         return SomeInteger(nonneg=int1.nonneg and int2.nonneg,
                            knowntype=knowntype)
 
-    or_ = xor = mul = _clone(union, [])
-    mul_ovf = _clone(union, [OverflowError])
+    or_ = xor = add = mul = _clone(union, [])
+    add_ovf = mul_ovf = _clone(union, [OverflowError])
     div = floordiv = mod = _clone(union, [ZeroDivisionError])
     div_ovf= floordiv_ovf = mod_ovf = _clone(union, [ZeroDivisionError, OverflowError])
 
@@ -214,16 +214,6 @@
     inplace_div = div
     inplace_truediv = truediv
 
-    def add((int1, int2)):
-        # propagate const-ness to help 'tup[j + 1]'
-        result = pair(int1, int2)._add_base()
-        if int1.is_immutable_constant() and int2.is_immutable_constant():
-            result.const = int1.const + int2.const
-        return result
-    add.can_only_throw = []
-    _add_base = union    # and not another union() from a subclass
-    add_ovf = _clone(add, [OverflowError])
-
     def sub((int1, int2)):
         knowntype = rarithmetic.compute_restype(int1.knowntype, int2.knowntype)
         return SomeInteger(knowntype=knowntype)
diff --git a/rpython/annotator/test/test_annrpython.py b/rpython/annotator/test/test_annrpython.py
--- a/rpython/annotator/test/test_annrpython.py
+++ b/rpython/annotator/test/test_annrpython.py
@@ -1004,22 +1004,6 @@
             a.build_types(f, [])
         # if you want to get a r_uint, you have to be explicit about it
 
-    def test_add_constant(self):
-        def f(a):
-            return a + 5
-        a = self.RPythonAnnotator()
-        s = annmodel.SomeInteger(nonneg=True)
-        s.const = 12
-        s = a.build_types(f, [s])
-        assert s.const == 17
-
-    def test_add_bools(self):
-        def f(a):
-            return (a > 2) + (a < 6)
-        a = self.RPythonAnnotator()
-        s = a.build_types(f, [int])
-        assert s.knowntype is int
-
     def test_add_different_ints(self):
         def f(a, b):
             return a + b
diff --git a/rpython/rtyper/lltypesystem/rffi.py b/rpython/rtyper/lltypesystem/rffi.py
--- a/rpython/rtyper/lltypesystem/rffi.py
+++ b/rpython/rtyper/lltypesystem/rffi.py
@@ -280,22 +280,21 @@
                         arg = cast(TARGET, arg)
             real_args = real_args + (arg,)
         res = call_external_function(*real_args)
-        j = 0
         for i, TARGET in unrolling_arg_tps:
             arg = args[i]
             if TARGET == CCHARP or TARGET is VOIDP:
                 if arg is None:
-                    j = j + 2
+                    to_free = to_free[2:]
                 elif isinstance(arg, str):
-                    free_nonmovingbuffer(arg, to_free[j], to_free[j+1])
-                    j = j + 2
+                    free_nonmovingbuffer(arg, to_free[0], to_free[1])
+                    to_free = to_free[2:]
             elif TARGET == CWCHARP:
                 if arg is None:
-                    j = j + 1
+                    to_free = to_free[1:]
                 elif isinstance(arg, unicode):
-                    free_wcharp(to_free[j])
-                    j = j + 1
-        assert j == len(to_free)
+                    free_wcharp(to_free[0])
+                    to_free = to_free[1:]
+        assert len(to_free) == 0
         if rarithmetic.r_int is not r_int:
             if result is INT:
                 return cast(lltype.Signed, res)


More information about the pypy-commit mailing list