Author: Armin Rigo <[email protected]>
Branch:
Changeset: r68346:cee23d5e33f9
Date: 2013-11-30 21:54 +0100
http://bitbucket.org/pypy/pypy/changeset/cee23d5e33f9/
Log: Update to cffi/de7e8aec4001 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
@@ -424,6 +424,12 @@
def get_array_length(self):
return self.length
+ def _sizeof(self):
+ from pypy.module._cffi_backend.ctypeptr import W_CTypePtrOrArray
+ ctype = self.ctype
+ assert isinstance(ctype, W_CTypePtrOrArray)
+ return self.length * ctype.ctitem.size
+
class W_CDataHandle(W_CData):
_attrs_ = ['w_keepalive']
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
@@ -3125,6 +3125,12 @@
py.test.raises(TypeError, "p + cast(new_primitive_type('int'), 42)")
py.test.raises(TypeError, "p - cast(new_primitive_type('int'), 42)")
+def test_sizeof_sliced_array():
+ BInt = new_primitive_type("int")
+ BArray = new_array_type(new_pointer_type(BInt), 10)
+ p = newp(BArray, None)
+ assert sizeof(p[2:9]) == 7 * sizeof(BInt)
+
def test_version():
# this test is here mostly for PyPy
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit