[pypy-commit] cffi cpy-extension: Generic test, and fix for the ctypes backend.

arigo noreply at buildbot.pypy.org
Wed Jun 13 21:27:50 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: cpy-extension
Changeset: r311:f8a3d8fcd13a
Date: 2012-06-13 21:27 +0200
http://bitbucket.org/cffi/cffi/changeset/f8a3d8fcd13a/

Log:	Generic test, and fix for the ctypes backend.

diff --git a/cffi/backend_ctypes.py b/cffi/backend_ctypes.py
--- a/cffi/backend_ctypes.py
+++ b/cffi/backend_ctypes.py
@@ -77,6 +77,10 @@
     __slots__ = []
 
 
+class CTypesGenericArray(CTypesData):
+    __slots__ = []
+
+
 class CTypesGenericPtr(CTypesData):
     __slots__ = ['_address', '_as_ctype_ptr']
     _automatic_casts = False
@@ -366,7 +370,10 @@
                 _bitem_size = ctypes.sizeof(BItem._ctype)
             else:
                 _ctype = ctypes.c_void_p
-            _reftypename = BItem._get_c_name(' * &')
+            if issubclass(BItem, CTypesGenericArray):
+                _reftypename = BItem._get_c_name('(* &)')
+            else:
+                _reftypename = BItem._get_c_name(' * &')
 
             def __init__(self, init):
                 ctypeobj = BItem._create_ctype_obj(init)
@@ -436,7 +443,7 @@
         else:
             kind = 'generic'
         #
-        class CTypesArray(CTypesData):
+        class CTypesArray(CTypesGenericArray):
             __slots__ = ['_blob', '_own']
             if length is not None:
                 _ctype = BItem._ctype * length
diff --git a/testing/backend_tests.py b/testing/backend_tests.py
--- a/testing/backend_tests.py
+++ b/testing/backend_tests.py
@@ -686,6 +686,11 @@
         assert s[0].b == 412
         py.test.raises(IndexError, 's[1]')
 
+    def test_pointer_to_array(self):
+        ffi = FFI(backend=self.Backend())
+        p = ffi.new("int(*)[5]")
+        assert repr(p) == "<cdata 'int(* *)[5]' owning %d bytes>" % SIZE_OF_INT
+
     def test_offsetof(self):
         ffi = FFI(backend=self.Backend())
         ffi.cdef("struct foo { int a, b, c; };")


More information about the pypy-commit mailing list