Author: tlynn
Branch:
Changeset: r474:f6fcecf576f6
Date: 2012-06-19 19:28 +0100
http://bitbucket.org/cffi/cffi/changeset/f6fcecf576f6/
Log: Fix void* callback return types in ctypes backend.
diff --git a/cffi/backend_ctypes.py b/cffi/backend_ctypes.py
--- a/cffi/backend_ctypes.py
+++ b/cffi/backend_ctypes.py
@@ -672,7 +672,11 @@
for arg, BArg in zip(args, BArgs):
args2.append(BArg._from_ctypes(arg))
res2 = init(*args2)
- return BResult._to_ctypes(res2)
+ res2 = BResult._to_ctypes(res2)
+ if isinstance(res2, ctypes.c_void_p):
+ # workaround for http://bugs.python.org/issue1574593
+ res2 = res2.value
+ return res2
self._as_ctype_ptr = CTypesFunction._ctype(callback)
self._address = ctypes.cast(self._as_ctype_ptr,
ctypes.c_void_p).value
diff --git a/testing/backend_tests.py b/testing/backend_tests.py
--- a/testing/backend_tests.py
+++ b/testing/backend_tests.py
@@ -550,6 +550,22 @@
t = ffi.typeof("int(*(*)(int))(int)")
assert repr(t) == self.TypeRepr % "int(*(*)(int))(int)"
+ def test_functionptr_voidptr_return(self):
+ ffi = FFI(backend=self.Backend())
+ def cb():
+ return None
+ p = ffi.callback("void*(*)()", cb)
+ res = p()
+ assert res is None
+ int_ptr = ffi.new('int')
+ void_ptr = ffi.cast('void*', int_ptr)
+ def cb():
+ return void_ptr
+ p = ffi.callback("void*(*)()", cb)
+ res = p()
+ assert repr(res) == "<cdata 'void *'>"
+ assert ffi.cast("long", res) != 0
+
def test_char_cast(self):
ffi = FFI(backend=self.Backend())
p = ffi.cast("int", '\x01')
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit