Commits

Armin Rigo committed da2e70d

Test and fix

Comments (0)

Files changed (2)

pypy/module/_cffi_backend/cdataobj.py

         W_CDataNewOwning.__init__(self, space, size, ctype)
         self.length = length
 
+    def _owning_num_bytes(self):
+        from pypy.module._cffi_backend import ctypearray
+        ctype = self.ctype
+        assert isinstance(ctype, ctypearray.W_CTypeArray)
+        return self.length * ctype.ctitem.size
+
     def get_array_length(self):
         return self.length
 

pypy/module/_cffi_backend/test/_backend_test_c.py

     pp[0] = p
     s = pp[0][0]
     assert repr(s).startswith("<cdata 'struct foo' 0x")
+
+def test_owning_repr():
+    BInt = new_primitive_type("int")
+    BArray = new_array_type(new_pointer_type(BInt), None)   # int[]
+    p = newp(BArray, 7)
+    assert repr(p) == "<cdata 'int[]' owning 28 bytes>"