Author: Armin Rigo <[email protected]>
Branch: ffi-backend
Changeset: r55959:da2e70d24059
Date: 2012-07-07 12:25 +0200
http://bitbucket.org/pypy/pypy/changeset/da2e70d24059/
Log: Test and fix
diff --git a/pypy/module/_cffi_backend/cdataobj.py
b/pypy/module/_cffi_backend/cdataobj.py
--- a/pypy/module/_cffi_backend/cdataobj.py
+++ b/pypy/module/_cffi_backend/cdataobj.py
@@ -223,6 +223,12 @@
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
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py
b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -1293,3 +1293,9 @@
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>"
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit