Commits

Armin Rigo committed 9b93e53

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

Comments (0)

Files changed (1)

pypy/translator/c/test/test_genc.py

     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)
                 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
     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