[pypy-commit] cffi cffi-1.0: hg merge default

arigo noreply at buildbot.pypy.org
Fri Apr 24 10:13:48 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: cffi-1.0
Changeset: r1787:f58471f990dd
Date: 2015-04-24 10:13 +0200
http://bitbucket.org/cffi/cffi/changeset/f58471f990dd/

Log:	hg merge default

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
@@ -657,9 +657,9 @@
     # case the 'static' is completely ignored.
     ffi.cdef("static const int AA, BB, CC, DD;")
     lib = ffi.verify("#define AA 42\n"
-                     "#define BB (-43)\n"
-                     "#define CC (22*2)\n"
-                     "#define DD ((unsigned int)142)\n")
+                     "#define BB (-43)   // blah\n"
+                     "#define CC (22*2)  /* foobar */\n"
+                     "#define DD ((unsigned int)142)  /* foo\nbar */\n")
     assert lib.AA == 42
     assert lib.BB == -43
     assert lib.CC == 44
@@ -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);")


More information about the pypy-commit mailing list