Author: Armin Rigo <[email protected]>
Branch: kill-someobject
Changeset: r58074:9b93e53bec31
Date: 2012-10-12 18:52 +0200
http://bitbucket.org/pypy/pypy/changeset/9b93e53bec31/

Log:    Fix properly, with a test, the escaping. Argh.

diff --git a/pypy/translator/c/test/test_genc.py 
b/pypy/translator/c/test/test_genc.py
--- a/pypy/translator/c/test/test_genc.py
+++ b/pypy/translator/c/test/test_genc.py
@@ -26,7 +26,10 @@
     elif isinstance(v, float):
         return repr(v)    # extra precision than str(v)
     elif isinstance(v, str):
-        return v + '.'
+        if v.isalnum():
+            return v
+        else:   # escape the string
+            return '/' + ','.join([str(ord(c)) for c in v])
     return str(v)
 
 @specialize.argtype(0)
@@ -83,7 +86,13 @@
                 else:
                     args += (float(a),)
             else:
-                args += (a[:-1],)
+                if a.startswith('/'):     # escaped string
+                    if len(a) == 1:
+                        a = ''
+                    else:
+                        l = a[1:].split(',')
+                        a = ''.join([chr(int(x)) for x in l])
+                args += (a,)
         res = fn(*args)
         print "THE RESULT IS:", llrepr_out(res), ";"
         return 0
@@ -196,6 +205,20 @@
     py.test.raises(Exception, f1, "world")  # check that it's really typed
 
 
+def test_string_arg():
+    def f(s):
+        total = 0
+        for c in s:
+            total += ord(c)
+        return total + len(s)
+
+    f1 = compile(f, [str])
+
+    for check in ['x', '', '\x00', '\x01', '\n', '\x7f', '\xff',
+                  '\x00\x00', '\x00\x01']:
+        assert f1(check) == len(check) + sum(map(ord, check))
+
+
 def test_dont_write_source_files():
     def f(x):
         return x*2
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to