[pypy-svn] pypy default: Don't print a TypeError when a "void f()" callback function returns None.

amauryfa commits-noreply at bitbucket.org
Wed Feb 9 15:54:09 CET 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: 
Changeset: r41736:b6997048efb8
Date: 2011-02-09 15:50 +0100
http://bitbucket.org/pypy/pypy/changeset/b6997048efb8/

Log:	Don't print a TypeError when a "void f()" callback function returns
	None.

diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_callbacks.py b/pypy/module/test_lib_pypy/ctypes_tests/test_callbacks.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_callbacks.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_callbacks.py
@@ -205,4 +205,19 @@
         cfunc.restype = c_int
         res = cfunc(CTP(callback), lambda : 3)
         assert res == 3
-        
+
+    def test_callback_void(self, capsys):
+        import conftest
+        _ctypes_test = str(conftest.sofile)
+        dll = CDLL(_ctypes_test)
+
+        def callback():
+            pass
+
+        CTP = CFUNCTYPE(None)
+        cfunc = dll._testfunc_callback_void
+        cfunc.argtypes = [CTP]
+        cfunc(CTP(callback))
+        out, err = capsys.readouterr()
+        assert (out, err) == ("", "")
+

diff --git a/lib_pypy/_ctypes/function.py b/lib_pypy/_ctypes/function.py
--- a/lib_pypy/_ctypes/function.py
+++ b/lib_pypy/_ctypes/function.py
@@ -124,6 +124,8 @@
             # A callback into python
             self.callable = argument
             ffiargs, ffires = self._ffishapes(self._argtypes_, self._restype_)
+            if self._restype_ is None:
+                ffires = None
             self._ptr = _rawffi.CallbackPtr(self._wrap_callable(argument,
                                                                 self.argtypes),
                                             ffiargs, ffires, self._flags_)

diff --git a/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c b/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c
--- a/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c
+++ b/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c
@@ -166,6 +166,12 @@
   return (*func)(arg);
 }
 
+EXPORT(int) _testfunc_callback_void(void (*func)(void))
+{
+    func();
+    return 0;
+}
+
 #ifdef HAVE_LONG_LONG
 EXPORT(LONG_LONG) _testfunc_q_bhilfdq(signed char b, short h, int i, long l, float f,
 				     double d, LONG_LONG q)


More information about the Pypy-commit mailing list