[pypy-commit] cffi cffi-1.0: Test and fix

arigo noreply at buildbot.pypy.org
Sat May 9 16:07:21 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: cffi-1.0
Changeset: r1947:6306348762c1
Date: 2015-05-09 16:07 +0200
http://bitbucket.org/cffi/cffi/changeset/6306348762c1/

Log:	Test and fix

diff --git a/_cffi1/test_recompiler.py b/_cffi1/test_recompiler.py
--- a/_cffi1/test_recompiler.py
+++ b/_cffi1/test_recompiler.py
@@ -639,6 +639,7 @@
     assert ffi.sizeof(s[0]) == 12
     assert ffi.offsetof(ffi.typeof(s), 'x') == 4
     assert lib.f(s[0]) == 42
+    assert ffi.typeof(lib.f) == ffi.typeof("int(*)(struct foo_s)")
 
 def test_incomplete_struct_as_result():
     ffi = FFI()
@@ -648,3 +649,4 @@
             "struct foo_s f(int x) { struct foo_s r; r.x = x * 2; return r; }")
     s = lib.f(21)
     assert s.x == 42
+    assert ffi.typeof(lib.f) == ffi.typeof("struct foo_s(*)(int)")
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -4215,6 +4215,8 @@
 static ffi_type *fb_fill_type(struct funcbuilder_s *fb, CTypeDescrObject *ct,
                               int is_result_type)
 {
+    const char *place = is_result_type ? "return value" : "argument";
+
     if (ct->ct_flags & CT_PRIMITIVE_ANY) {
         return (ffi_type *)ct->ct_extra;
     }
@@ -4254,10 +4256,12 @@
         if (force_lazy_struct(ct) < 0)
             return NULL;
         if (ct->ct_flags & CT_CUSTOM_FIELD_POS) {
-            PyErr_SetString(PyExc_TypeError,
-                "argument or return value is a struct (not pointer to struct) "
-                "which was declared with \"...;\" --- but the C calling "
-                "convention can depend on the missing fields");
+            /* these NotImplementedErrors may be caught and ignored until
+               a real call is made to a function of this type */
+            PyErr_Format(PyExc_NotImplementedError,
+                "ctype '%s' not supported as %s (it is a struct declared "
+                "with \"...;\", but the C calling convention may depend "
+                "on the missing fields)", ct->ct_name, place);
             return NULL;
         }
 
@@ -4273,9 +4277,9 @@
             assert(cf != NULL);
             if (cf->cf_bitshift >= 0) {
                 PyErr_Format(PyExc_NotImplementedError,
-                     "ctype '%s' not supported as argument or return value"
+                     "ctype '%s' not supported as %s"
                      " (it is a struct with bit fields)",
-                     ct->ct_name);
+                     ct->ct_name, place);
                 return NULL;
             }
             flat = 1;
@@ -4286,9 +4290,9 @@
             }
             if (flat <= 0) {
                 PyErr_Format(PyExc_NotImplementedError,
-                     "ctype '%s' not supported as argument or return value"
+                     "ctype '%s' not supported as %s"
                      " (it is a struct with a zero-length array)",
-                     ct->ct_name);
+                     ct->ct_name, place);
                 return NULL;
             }
             nflat += flat;
@@ -4327,7 +4331,6 @@
         return ffistruct;
     }
     else {
-        const char *place = is_result_type ? "return value" : "argument";
         PyErr_Format(PyExc_NotImplementedError,
                      "ctype '%s' (size %zd) not supported as %s",
                      ct->ct_name, ct->ct_size, place);


More information about the pypy-commit mailing list