Commits

Armin Rigo  committed 2697448

verify: Function pointer as argument

  • Participants
  • Parent commits 50356aa

Comments (0)

Files changed (2)

File cffi/verifier.py

             converter = '_cffi_to_c_%s' % (tp.name.replace(' ', '_'),)
             errvalue = '-1'
         #
-        elif isinstance(tp, model.PointerType):
-            if (isinstance(tp.totype, model.PrimitiveType) and
+        elif isinstance(tp, (model.PointerType, model.FunctionPtrType)):
+            if (isinstance(tp, model.PointerType) and
+                    isinstance(tp.totype, model.PrimitiveType) and
                     tp.totype.name == 'char'):
                 converter = '_cffi_to_c_char_p'
             else:
                 extraarg = ', _cffi_type(%d)' % self.gettypenum(tp)
             errvalue = 'NULL'
         #
-        elif isinstance(tp, model.StructType):
+        elif isinstance(tp, model.StructOrUnion):
             # a struct (not a struct pointer) as a function argument
             self.prnt('  if (_cffi_to_c((char*)&%s, _cffi_type(%d), %s) < 0)'
                       % (tovar, self.gettypenum(tp), fromvar))

File testing/test_verify.py

     foochar = ffi.cast("char *(*)(void)", lib.fooptr)
     s = foochar()
     assert str(s) == "foobar"
+
+def test_funcptr_as_argument():
+    ffi = FFI()
+    ffi.cdef("""
+        void qsort(void *base, size_t nel, size_t width,
+            int (*compar)(const void *, const void *));
+    """)
+    ffi.verify("#include <stdlib.h>")