Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r1786:a6987485dc7f
Date: 2015-04-24 10:13 +0200
http://bitbucket.org/cffi/cffi/changeset/a6987485dc7f/

Log:    Skip an existing test after figuring out that it is indeed likely to
        crash in test_vgen, depending on details of the platform. Changed
        it to clearly flag this as invalid already in the cdef, and why.

diff --git a/cffi/model.py b/cffi/model.py
--- a/cffi/model.py
+++ b/cffi/model.py
@@ -140,6 +140,16 @@
         replace_with = self._base_pattern % (', '.join(reprargs),)
         self.c_name_with_marker = (
             self.result.c_name_with_marker.replace('&', replace_with))
+        #
+        if isinstance(result, StructOrUnion) and result.partial:
+            from .ffiplatform import VerificationError
+            raise VerificationError(
+                '%s: the %s is a struct with "...;", which is not '
+                'supported as return type (how to call it with '
+                'libffi depends on possibly-omitted fields).  '
+                'Workaround: write a wrapper function which takes '
+                'a pointer-to-struct as extra argument and writes '
+                'the result there' % (self, result))
 
 
 class RawFunctionType(BaseFunctionType):
diff --git a/testing/test_verify.py b/testing/test_verify.py
--- a/testing/test_verify.py
+++ b/testing/test_verify.py
@@ -1233,11 +1233,13 @@
         py.test.skip('Segfaults on mips64el')
     # XXX bad abuse of "struct { ...; }".  It only works a bit by chance
     # anyway.  XXX think about something better :-(
+    # ...in fact, it is no longer supported: likely crashes in vgen
     ffi = FFI()
-    ffi.cdef("""
+    py.test.raises(VerificationError, ffi.cdef, """
         typedef struct { ...; } myhandle_t;
         myhandle_t foo(void);
     """)
+    py.test.skip("XXX reimplement maybe?")
     lib = ffi.verify("""
         typedef short myhandle_t;
         myhandle_t foo(void) { return 42; }
@@ -1245,6 +1247,21 @@
     h = lib.foo()
     assert ffi.sizeof(h) == ffi.sizeof("short")
 
+def test_return_partial_struct():
+    py.test.skip("not implemented")
+    ffi = FFI()
+    ffi.cdef("""
+        typedef struct { int x; ...; } foo_t;
+        foo_t foo(void);
+    """)
+    lib = ffi.verify("""
+        typedef struct { int y, x; } foo_t;
+        foo_t foo(void) { foo_t r = { 45, 81 }; return r; }
+    """)
+    h = lib.foo()
+    assert ffi.sizeof(h) == 2 * ffi.sizeof("int")
+    assert h.x == 81
+
 def test_cannot_name_struct_type():
     ffi = FFI()
     ffi.cdef("typedef struct { int x; } *sp; void foo(sp);")
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to