Author: Armin Rigo <[email protected]>
Branch: cffi-1.0
Changeset: r1871:f6e9b11edb1f
Date: 2015-04-28 12:08 +0200
http://bitbucket.org/cffi/cffi/changeset/f6e9b11edb1f/

Log:    tests and one fix

diff --git a/_cffi1/test_recompiler.py b/_cffi1/test_recompiler.py
--- a/_cffi1/test_recompiler.py
+++ b/_cffi1/test_recompiler.py
@@ -514,3 +514,65 @@
     q = lib.ff2(p)
     assert q == p
     assert p.y == 42
+
+def test_include_3():
+    ffi1 = FFI()
+    ffi1.cdef("typedef short sshort_t;")
+    verify(ffi1, "test_include_3_parent", "typedef short sshort_t;")
+    ffi = FFI()
+    ffi.include(ffi1)
+    ffi.cdef("sshort_t ff3(sshort_t);")
+    lib = verify(ffi, "test_include_3",
+                 "typedef short sshort_t; //usually from a #include\n"
+                 "sshort_t ff3(sshort_t x) { return x + 42; }")
+    assert lib.ff3(10) == 52
+    assert ffi.typeof(ffi.cast("sshort_t", 42)) is ffi.typeof("short")
+
+def test_include_4():
+    ffi1 = FFI()
+    ffi1.cdef("typedef struct { int x; } mystruct_t;")
+    verify(ffi1, "test_include_4_parent",
+           "typedef struct { int x; } mystruct_t;")
+    ffi = FFI()
+    ffi.include(ffi1)
+    ffi.cdef("mystruct_t *ff4(mystruct_t *);")
+    lib = verify(ffi, "test_include_4",
+           "typedef struct {int x; } mystruct_t; //usually from a #include\n"
+           "mystruct_t *ff4(mystruct_t *p) { p->x += 42; return p; }")
+    p = ffi.new("mystruct_t *", [10])
+    q = lib.ff4(p)
+    assert q == p
+    assert p.x == 52
+
+def test_include_5():
+    py.test.xfail("also fails in 0.9.3")
+    ffi1 = FFI()
+    ffi1.cdef("typedef struct { int x; } *mystruct_p;")
+    verify(ffi1, "test_include_5_parent",
+           "typedef struct { int x; } *mystruct_p;")
+    ffi = FFI()
+    ffi.include(ffi1)
+    ffi.cdef("mystruct_p ff5(mystruct_p);")
+    lib = verify(ffi, "test_include_5",
+           "typedef struct {int x; } *mystruct_p; //usually from a #include\n"
+           "mystruct_p ff5(mystruct_p p) { p->x += 42; return p; }")
+    p = ffi.new("mystruct_p", [10])
+    q = lib.ff5(p)
+    assert q == p
+    assert p.x == 52
+
+def test_include_6():
+    ffi1 = FFI()
+    ffi1.cdef("typedef ... mystruct_t;")
+    verify(ffi1, "test_include_6_parent",
+           "typedef struct _mystruct_s mystruct_t;")
+    ffi = FFI()
+    ffi.include(ffi1)
+    ffi.cdef("mystruct_t *ff6(void);")
+    lib = verify(ffi, "test_include_6",
+           "typedef struct _mystruct_s mystruct_t; //usually from a #include\n"
+           "struct _mystruct_s { int x; };\n"
+           "static mystruct_t result_struct = { 42 };\n"
+           "mystruct_t *ff6(void) { return &result_struct; }")
+    p = lib.ff6()
+    assert ffi.cast("int *", p)[0] == 42
diff --git a/cffi/cparser.py b/cffi/cparser.py
--- a/cffi/cparser.py
+++ b/cffi/cparser.py
@@ -608,7 +608,7 @@
     def include(self, other):
         for name, tp in other._declarations.items():
             kind = name.split(' ', 1)[0]
-            if kind in ('struct', 'union', 'enum'):
+            if kind in ('struct', 'union', 'enum', 'anonymous'):
                 self._declare(name, tp, included=True)
             elif kind == 'typedef':
                 self._declare(name, tp)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to