Commits

Armin Rigo  committed b3f7783

Reorganize the repr of cdata objects, with a test-and-fix.

  • Participants
  • Parent commits e7ba61e
  • Branches ffi-backend

Comments (0)

Files changed (2)

File pypy/module/_cffi_backend/cdataobj.py

     _attrs_ = ['_lifeline_']    # for weakrefs
     _immutable_ = True
 
-    def _owning_num_bytes(self):
-        return self.ctype.size
-
     def _repr_extra(self):
-        return 'owning %d bytes' % self._owning_num_bytes()
+        from pypy.module._cffi_backend.ctypeptr import W_CTypePointer
+        ctype = self.ctype
+        if isinstance(ctype, W_CTypePointer):
+            num_bytes = ctype.ctitem.size
+        else:
+            num_bytes = self._sizeof()
+        return 'owning %d bytes' % num_bytes
 
 
 class W_CDataNewOwning(W_CDataApplevelOwning):
         assert isinstance(ctype, ctypearray.W_CTypeArray)
         return self.length * ctype.ctitem.size
 
-    def _owning_num_bytes(self):
-        return self._sizeof()
-
     def get_array_length(self):
         return self.length
 
         W_CDataApplevelOwning.__init__(self, space, cdata, ctype)
         self.structobj = structobj
 
-    def _owning_num_bytes(self):
-        from pypy.module._cffi_backend.ctypeptr import W_CTypePtrBase
-        ctype = self.ctype
-        assert isinstance(ctype, W_CTypePtrBase)
-        return ctype.ctitem.size
-
     def _do_getitem(self, i):
         return self.structobj
 

File pypy/module/_cffi_backend/test/_backend_test_c.py

     p = newp(BArray, 7)
     assert repr(p) == "<cdata 'int[]' owning 28 bytes>"
     assert sizeof(p) == 28
+    #
+    BArray = new_array_type(new_pointer_type(BInt), 7)   # int[7]
+    p = newp(BArray, None)
+    assert repr(p) == "<cdata 'int[7]' owning 28 bytes>"
+    assert sizeof(p) == 28
 
 def test_cannot_dereference_void():
     BVoidP = new_pointer_type(new_void_type())