[pypy-svn] r53123 - in pypy/dist/pypy/lib: _ctypes app_test/ctypes

fijal at codespeak.net fijal at codespeak.net
Sun Mar 30 04:13:22 CEST 2008


Author: fijal
Date: Sun Mar 30 04:13:20 2008
New Revision: 53123

Modified:
   pypy/dist/pypy/lib/_ctypes/function.py
   pypy/dist/pypy/lib/app_test/ctypes/test_cast.py
Log:
support for casting functions. still impossible to call a result


Modified: pypy/dist/pypy/lib/_ctypes/function.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/function.py	(original)
+++ pypy/dist/pypy/lib/_ctypes/function.py	Sun Mar 30 04:13:20 2008
@@ -12,6 +12,9 @@
     def _alignmentofinstances(self):
         return _rawffi.alignment('P')
 
+    def _is_pointer_like(self):
+        return True
+
 class CFuncPtr(_CData):
     __metaclass__ = CFuncPtrType
 
@@ -67,6 +70,8 @@
             # we need to check dll anyway
             self._getfuncptr([], ctypes.c_int)
         elif argument is None:
+            self._buffer = _rawffi.Array('P')(1)
+            self._needs_free = True
             return # needed for test..
         else:
             raise TypeError("Unknown constructor %s" % (argument,))
@@ -139,6 +144,7 @@
         if self._needs_free:
             self._buffer.free()
             self._buffer = None
-            self._ptr.free()
-            self._ptr = None
-            self._needs_free = False
+            if hasattr(self, '_ptr'):
+                self._ptr.free()
+                self._ptr = None
+                self._needs_free = False

Modified: pypy/dist/pypy/lib/app_test/ctypes/test_cast.py
==============================================================================
--- pypy/dist/pypy/lib/app_test/ctypes/test_cast.py	(original)
+++ pypy/dist/pypy/lib/app_test/ctypes/test_cast.py	Sun Mar 30 04:13:20 2008
@@ -74,3 +74,8 @@
             s = c_wchar_p("hiho")
             assert cast(cast(s, c_void_p), c_wchar_p).value == (
                                  "hiho")
+
+    def test_cast_functype(self):
+        # make sure we can cast function type
+        P = CFUNCTYPE(c_int)
+        cast(1, P)



More information about the Pypy-commit mailing list