[pypy-commit] pypy default: Fix for "translator/c/test/test_extfunc.py -k exec":

arigo noreply at buildbot.pypy.org
Sun Feb 5 19:11:40 CET 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r52111:5cc21b20455b
Date: 2012-02-05 19:11 +0100
http://bitbucket.org/pypy/pypy/changeset/5cc21b20455b/

Log:	Fix for "translator/c/test/test_extfunc.py -k exec": don't use
	remove_no_nul(), which doesn't know what to return if a SomeList is
	passed; instead, temporarily disable checking for 'no_nul' when
	comparing SomeStrings.

diff --git a/pypy/annotation/model.py b/pypy/annotation/model.py
--- a/pypy/annotation/model.py
+++ b/pypy/annotation/model.py
@@ -225,9 +225,7 @@
     def __init__(self):
         pass
 
-class SomeString(SomeObject):
-    "Stands for an object which is known to be a string."
-    knowntype = str
+class SomeStringOrUnicode(SomeObject):
     immutable = True
     can_be_None=False
     no_nul = False  # No NUL character in the string.
@@ -241,27 +239,29 @@
     def can_be_none(self):
         return self.can_be_None
 
+    def __eq__(self, other):
+        if self.__class__ is not other.__class__:
+            return False
+        d1 = self.__dict__
+        d2 = other.__dict__
+        if getattr(TLS, 'ignore_no_nul', False):
+            d1 = d1.copy(); d1['no_nul'] = 0
+            d2 = d2.copy(); d2['no_nul'] = 0
+        return d1 == d2
+
+class SomeString(SomeStringOrUnicode):
+    "Stands for an object which is known to be a string."
+    knowntype = str
+
     def nonnoneify(self):
         return SomeString(can_be_None=False, no_nul=self.no_nul)
 
-class SomeUnicodeString(SomeObject):
+class SomeUnicodeString(SomeStringOrUnicode):
     "Stands for an object which is known to be an unicode string"
     knowntype = unicode
-    immutable = True
-    can_be_None=False
-    no_nul = False
-
-    def __init__(self, can_be_None=False, no_nul=False):
-        if can_be_None:
-            self.can_be_None = True
-        if no_nul:
-            self.no_nul = True
-
-    def can_be_none(self):
-        return self.can_be_None
 
     def nonnoneify(self):
-        return SomeUnicodeString(can_be_None=False)
+        return SomeUnicodeString(can_be_None=False, no_nul=self.no_nul)
 
 class SomeChar(SomeString):
     "Stands for an object known to be a string of length 1."
@@ -740,23 +740,6 @@
         s_obj = new_s_obj
     return s_obj
 
-def remove_no_nul(s_obj):
-    if isinstance(s_obj, SomeList):
-        s_item = s_obj.listdef.listitem.s_value
-        new_s_item = remove_no_nul(s_item)
-        from pypy.annotation.listdef import ListDef
-        if s_item is not new_s_item:
-            return SomeList(ListDef(None, new_s_item,
-                                    resized=True))
-
-    if not getattr(s_obj, 'no_nul', False):
-        return s_obj
-    new_s_obj = SomeObject.__new__(s_obj.__class__)
-    new_s_obj.__dict__ = s_obj.__dict__.copy()
-    del new_s_obj.no_nul
-    return new_s_obj
-    
-
 # ____________________________________________________________
 # internal
 
diff --git a/pypy/rpython/extfunc.py b/pypy/rpython/extfunc.py
--- a/pypy/rpython/extfunc.py
+++ b/pypy/rpython/extfunc.py
@@ -152,26 +152,25 @@
         assert len(args_s) == len(signature_args),\
                "Argument number mismatch"
 
-        check_no_nul = False
         config = self.bookkeeper.annotator.translator.config
-        if config.translation.check_str_without_nul:
-            check_no_nul = True
-
-        for i, expected in enumerate(signature_args):
-            if not check_no_nul:
-                expected = annmodel.remove_no_nul(expected)
-            arg = annmodel.unionof(args_s[i], expected)
-            if not expected.contains(arg):
-                name = getattr(self, 'name', None)
-                if not name:
-                    try:
-                        name = self.instance.__name__
-                    except AttributeError:
-                        name = '?'
-                raise Exception("In call to external function %r:\n"
-                                "arg %d must be %s,\n"
-                                "          got %s" % (
-                    name, i+1, expected, args_s[i]))
+        if not config.translation.check_str_without_nul:
+            annmodel.TLS.ignore_no_nul = True
+        try:
+            for i, expected in enumerate(signature_args):
+                arg = annmodel.unionof(args_s[i], expected)
+                if not expected.contains(arg):
+                    name = getattr(self, 'name', None)
+                    if not name:
+                        try:
+                            name = self.instance.__name__
+                        except AttributeError:
+                            name = '?'
+                    raise Exception("In call to external function %r:\n"
+                                    "arg %d must be %s,\n"
+                                    "          got %s" % (
+                        name, i+1, expected, args_s[i]))
+        finally:
+            annmodel.TLS.ignore_no_nul = False
         return signature_args
 
     def compute_result_annotation(self, *args_s):


More information about the pypy-commit mailing list