Commits

Armin Rigo committed f8a3d8f

Generic test, and fix for the ctypes backend.

  • Participants
  • Parent commits b1a1eb9
  • Branches cpy-extension

Comments (0)

Files changed (2)

cffi/backend_ctypes.py

     __slots__ = []
 
 
+class CTypesGenericArray(CTypesData):
+    __slots__ = []
+
+
 class CTypesGenericPtr(CTypesData):
     __slots__ = ['_address', '_as_ctype_ptr']
     _automatic_casts = False
                 _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)
         else:
             kind = 'generic'
         #
-        class CTypesArray(CTypesData):
+        class CTypesArray(CTypesGenericArray):
             __slots__ = ['_blob', '_own']
             if length is not None:
                 _ctype = BItem._ctype * length

testing/backend_tests.py

         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; };")