[pypy-commit] pypy default: When the no_nul check is disabled, correctly transform the signature

amauryfa noreply at buildbot.pypy.org
Sat Feb 4 21:59:33 CET 2012


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: 
Changeset: r52105:1c332c518153
Date: 2012-02-04 21:59 +0100
http://bitbucket.org/pypy/pypy/changeset/1c332c518153/

Log:	When the no_nul check is disabled, correctly transform the signature
	when the function takes a list of strings.

diff --git a/pypy/annotation/model.py b/pypy/annotation/model.py
--- a/pypy/annotation/model.py
+++ b/pypy/annotation/model.py
@@ -741,6 +741,14 @@
     return s_obj
 
 def remove_no_nul(s_obj):
+    if isinstance(s_obj, SomeList):
+        s_item = s_obj.listdef.read_item()
+        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__)
diff --git a/pypy/rpython/test/test_extfunc.py b/pypy/rpython/test/test_extfunc.py
--- a/pypy/rpython/test/test_extfunc.py
+++ b/pypy/rpython/test/test_extfunc.py
@@ -187,3 +187,23 @@
         raises(Exception, a.build_types, g, [str])
         a.build_types(g, [str0])  # Does not raise
 
+    def test_list_of_str0(self):
+        str0 = annmodel.SomeString(no_nul=True)
+        def os_execve(l):
+            pass
+        register_external(os_execve, [[str0]], None)
+        def f(l):
+            return os_execve(l)
+        policy = AnnotatorPolicy()
+        policy.allow_someobjects = False
+        a = RPythonAnnotator(policy=policy)
+        a.build_types(f, [[str]])  # Does not raise
+        assert a.translator.config.translation.check_str_without_nul == False
+        # Now enable the str0 check, and try again with a similar function
+        a.translator.config.translation.check_str_without_nul=True
+        def g(l):
+            return os_execve(l)
+        raises(Exception, a.build_types, g, [[str]])
+        a.build_types(g, [[str0]])  # Does not raise
+        
+


More information about the pypy-commit mailing list