[pypy-commit] pypy default: Tweak tests to enable 'no_nul', and add another direct test. Fix

arigo noreply at buildbot.pypy.org
Wed Aug 8 23:51:40 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r56659:bbe5addb9452
Date: 2012-08-08 23:51 +0200
http://bitbucket.org/pypy/pypy/changeset/bbe5addb9452/

Log:	Tweak tests to enable 'no_nul', and add another direct test. Fix
	them by adding no_nul support in the loaders of pypy.rlib.rmarshal.
	(thanks sunetos for reporting it)

diff --git a/pypy/rlib/rmarshal.py b/pypy/rlib/rmarshal.py
--- a/pypy/rlib/rmarshal.py
+++ b/pypy/rlib/rmarshal.py
@@ -9,6 +9,7 @@
 from pypy.rlib.rarithmetic import r_longlong, intmask, LONG_BIT
 from pypy.rlib.rfloat import formatd, rstring_to_float
 from pypy.rlib.unroll import unrolling_iterable
+from pypy.rlib.rstring import assert_str0
 
 class CannotMarshal(Exception):
     pass
@@ -223,12 +224,33 @@
     return readchr(loader)
 add_loader(annmodel.SomeChar(), load_single_char)
 
+def load_string_nonul(loader):
+    if readchr(loader) != TYPE_STRING:
+        raise ValueError("expected a string")
+    length = readlong(loader)
+    return assert_str0(readstr(loader, length))
+add_loader(annmodel.SomeString(can_be_None=False, no_nul=True),
+           load_string_nonul)
+
 def load_string(loader):
     if readchr(loader) != TYPE_STRING:
         raise ValueError("expected a string")
     length = readlong(loader)
     return readstr(loader, length)
-add_loader(annmodel.SomeString(can_be_None=False), load_string)
+add_loader(annmodel.SomeString(can_be_None=False, no_nul=False),
+           load_string)
+
+def load_string_or_none_nonul(loader):
+    t = readchr(loader)
+    if t == TYPE_STRING:
+        length = readlong(loader)
+        return assert_str0(readstr(loader, length))
+    elif t == TYPE_NONE:
+        return None
+    else:
+        raise ValueError("expected a string or None")
+add_loader(annmodel.SomeString(can_be_None=True, no_nul=True),
+           load_string_or_none_nonul)
 
 def load_string_or_none(loader):
     t = readchr(loader)
@@ -239,7 +261,8 @@
         return None
     else:
         raise ValueError("expected a string or None")
-add_loader(annmodel.SomeString(can_be_None=True), load_string_or_none)
+add_loader(annmodel.SomeString(can_be_None=True, no_nul=False),
+           load_string_or_none)
 
 # ____________________________________________________________
 #
diff --git a/pypy/translator/sandbox/test/test_sandbox.py b/pypy/translator/sandbox/test/test_sandbox.py
--- a/pypy/translator/sandbox/test/test_sandbox.py
+++ b/pypy/translator/sandbox/test/test_sandbox.py
@@ -21,7 +21,8 @@
         g.flush()
 
 def compile(f, gc='ref'):
-    t = Translation(f, backend='c', standalone=True, sandbox=True, gc=gc)
+    t = Translation(f, backend='c', standalone=True, sandbox=True, gc=gc,
+                    check_str_without_nul=True)
     return str(t.compile())
 
 
@@ -115,6 +116,21 @@
     f.close()
     assert tail == ""
 
+def test_getcwd():
+    def entry_point(argv):
+        t = os.getcwd()
+        os.dup(len(t))
+        return 0
+
+    exe = compile(entry_point)
+    g, f = os.popen2(exe, "t", 0)
+    expect(f, g, "ll_os.ll_os_getcwd", (), "/tmp/foo/bar")
+    expect(f, g, "ll_os.ll_os_dup", (len("/tmp/foo/bar"),), 3)
+    g.close()
+    tail = f.read()
+    f.close()
+    assert tail == ""
+
 def test_oserror():
     def entry_point(argv):
         try:


More information about the pypy-commit mailing list