[pypy-commit] cffi cffi-1.0: Test and fix: don't write <ctype '1 *'> but <ctype 'struct $1 *'>

arigo noreply at buildbot.pypy.org
Sun May 10 13:10:48 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: cffi-1.0
Changeset: r1960:7edd07598a1e
Date: 2015-05-10 12:42 +0200
http://bitbucket.org/cffi/cffi/changeset/7edd07598a1e/

Log:	Test and fix: don't write <ctype '1 *'> but <ctype 'struct $1 *'>

diff --git a/_cffi1/realize_c_type.c b/_cffi1/realize_c_type.c
--- a/_cffi1/realize_c_type.c
+++ b/_cffi1/realize_c_type.c
@@ -263,8 +263,10 @@
 {
     /* "xyz" => "struct xyz"
        "$xyz" => "xyz"
+       "$1" => "struct $1"
     */
-    if (srcname[0] == '$' && srcname[1] != '$') {
+    if (srcname[0] == '$' && srcname[1] != '$' &&
+            !('0' <= srcname[1] && srcname[1] <= '9')) {
         strcpy(target, &srcname[1]);
     }
     else {
diff --git a/_cffi1/test_recompiler.py b/_cffi1/test_recompiler.py
--- a/_cffi1/test_recompiler.py
+++ b/_cffi1/test_recompiler.py
@@ -668,3 +668,16 @@
         "struct foo_s(*)(int, struct bar_s)")
     s = lib.f(14, {'y': -3})
     assert s.x == -42
+
+def test_name_of_unnamed_struct():
+    ffi = FFI()
+    ffi.cdef("typedef struct { int x; } foo_t;\n"
+             "typedef struct { int y; } *bar_p;\n"
+             "typedef struct { int y; } **baz_pp;\n")
+    verify(ffi, "test_name_of_unnamed_struct",
+             "typedef struct { int x; } foo_t;\n"
+             "typedef struct { int y; } *bar_p;\n"
+             "typedef struct { int y; } **baz_pp;\n")
+    assert repr(ffi.typeof("foo_t")) == "<ctype 'foo_t'>"
+    assert repr(ffi.typeof("bar_p")) == "<ctype 'struct $1 *'>"
+    assert repr(ffi.typeof("baz_pp")) == "<ctype 'struct $2 * *'>"


More information about the pypy-commit mailing list