[pypy-svn] pypy default: Implement _ctypes.call_function() and fix on test in test_random_things

amauryfa commits-noreply at bitbucket.org
Mon Mar 14 20:21:57 CET 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: 
Changeset: r42635:869b900efc11
Date: 2011-03-14 13:53 +0100
http://bitbucket.org/pypy/pypy/changeset/869b900efc11/

Log:	Implement _ctypes.call_function() and fix on test in
	test_random_things

diff --git a/lib_pypy/_ctypes/__init__.py b/lib_pypy/_ctypes/__init__.py
--- a/lib_pypy/_ctypes/__init__.py
+++ b/lib_pypy/_ctypes/__init__.py
@@ -4,7 +4,7 @@
 from _ctypes.primitive import _SimpleCData
 from _ctypes.pointer import _Pointer, _cast_addr
 from _ctypes.pointer import POINTER, pointer, _pointer_type_cache
-from _ctypes.function import CFuncPtr
+from _ctypes.function import CFuncPtr, call_function
 from _ctypes.dll import dlopen
 from _ctypes.structure import Structure
 from _ctypes.array import Array

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
@@ -29,6 +29,12 @@
     from _ctypes import COMError
     return COMError(errcode, None, None)
 
+def call_function(func, args):
+    "Only for debugging so far: So that we can call CFunction instances"
+    funcptr = CFuncPtr(func)
+    funcptr.restype = int
+    return funcptr(*args)
+
 class CFuncPtrType(_CDataMeta):
     # XXX write down here defaults and such things
 
@@ -160,6 +166,8 @@
     errcheck = property(_geterrcheck, _seterrcheck, _delerrcheck)
 
     def _ffishapes(self, args, restype):
+        if args is None:
+            args = []
         argtypes = [arg._ffiargshape for arg in args]
         if restype is not None:
             if not isinstance(restype, SimpleType):


More information about the Pypy-commit mailing list