[pypy-svn] pypy jitypes2: allow the fast path also for pointers

antocuni commits-noreply at bitbucket.org
Mon Jan 31 18:27:39 CET 2011


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: jitypes2
Changeset: r41501:34c7edae3c44
Date: 2011-01-28 15:54 +0100
http://bitbucket.org/pypy/pypy/changeset/34c7edae3c44/

Log:	allow the fast path also for pointers

diff --git a/lib_pypy/_ctypes/pointer.py b/lib_pypy/_ctypes/pointer.py
--- a/lib_pypy/_ctypes/pointer.py
+++ b/lib_pypy/_ctypes/pointer.py
@@ -114,6 +114,9 @@
 
     contents = property(getcontents, setcontents)
 
+    def _as_ffi_pointer_(self):
+        return self._get_buffer_value()
+
 def _cast_addr(obj, _, tp):
     if not (isinstance(tp, _CDataMeta) and tp._is_pointer_like()):
         raise TypeError("cast() argument 2 must be a pointer type, not %s"

diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_fastpath.py b/pypy/module/test_lib_pypy/ctypes_tests/test_fastpath.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_fastpath.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_fastpath.py
@@ -1,4 +1,4 @@
-from ctypes import CDLL, c_byte
+from ctypes import CDLL, POINTER, pointer, c_byte, c_int
 import sys
 import py
 from support import BaseCTypesTestChecker
@@ -35,3 +35,12 @@
         tf_b.restype = c_byte
         tf_b.argtypes = (c_byte,)
         assert tf_b(-126) == -42
+
+    def test_pointer_args(self):
+        f = dll._testfunc_p_p
+        f.restype = POINTER(c_int)
+        f.argtypes = [POINTER(c_int)]
+        v = c_int(42)
+        result = f(pointer(v))
+        assert type(result) == POINTER(c_int)
+        assert result.contents.value == 42


More information about the Pypy-commit mailing list