[pypy-svn] r63849 - in pypy/trunk/pypy/translator/c: . test
afa at codespeak.net
afa at codespeak.net
Wed Apr 8 17:37:52 CEST 2009
Author: afa
Date: Wed Apr 8 17:37:52 2009
New Revision: 63849
Modified:
pypy/trunk/pypy/translator/c/support.py
pypy/trunk/pypy/translator/c/test/test_genc.py
Log:
Fix translation of empty arrays of Chars.
Microsoft compilers at least do not like empty initializers:
char pypy_g_array_15777[1] = { };
Modified: pypy/trunk/pypy/translator/c/support.py
==============================================================================
--- pypy/trunk/pypy/translator/c/support.py (original)
+++ pypy/trunk/pypy/translator/c/support.py Wed Apr 8 17:37:52 2009
@@ -117,8 +117,8 @@
where N is exactly len(s). This is either a " "-delimited
string or a { }-delimited array of small integers.
'''
- if s.endswith('\x00') and len(s) < 1024:
- # C++ is stricted than C: we can only use a " " literal
+ if s.endswith('\x00') and 1 < len(s) < 1024:
+ # C++ is stricter than C: we can only use a " " literal
# if the last character is NULL, because such a literal
# always has an extra implicit NULL terminator.
return c_string_constant(s[:-1])
Modified: pypy/trunk/pypy/translator/c/test/test_genc.py
==============================================================================
--- pypy/trunk/pypy/translator/c/test/test_genc.py (original)
+++ pypy/trunk/pypy/translator/c/test/test_genc.py Wed Apr 8 17:37:52 2009
@@ -135,6 +135,13 @@
assert f1(5, 123) == 123
assert f1(12, "hello") == "hello"
+def test_empty_string():
+ A = Array(Char, hints={'nolength': True})
+ p = malloc(A, 1, immortal=True)
+ def f():
+ return p[0]
+ f1 = compile(f, [])
+ assert f1() == '\x00'
def test_runtime_type_info():
S = GcStruct('s', ('is_actually_s1', Bool))
More information about the Pypy-commit
mailing list