[pypy-svn] r50624 - in pypy/branch/applevel-ctypes2/pypy/module/_rawffi: . test
arigo at codespeak.net
arigo at codespeak.net
Tue Jan 15 13:00:10 CET 2008
Author: arigo
Date: Tue Jan 15 13:00:09 2008
New Revision: 50624
Modified:
pypy/branch/applevel-ctypes2/pypy/module/_rawffi/array.py
pypy/branch/applevel-ctypes2/pypy/module/_rawffi/test/test_nested.py
Log:
(fijal, arigo)
Array of arrays.
Modified: pypy/branch/applevel-ctypes2/pypy/module/_rawffi/array.py
==============================================================================
--- pypy/branch/applevel-ctypes2/pypy/module/_rawffi/array.py (original)
+++ pypy/branch/applevel-ctypes2/pypy/module/_rawffi/array.py Tue Jan 15 13:00:09 2008
@@ -54,6 +54,12 @@
return space.wrap(W_ArrayInstance(space, self, length, address))
fromaddress.unwrap_spec = ['self', ObjSpace, int, int]
+ def descr_gettypecode(self, space, length):
+ _, itemsize, alignment = self.itemtp
+ return space.newtuple([space.wrap(itemsize * length),
+ space.wrap(alignment)])
+ descr_gettypecode.unwrap_spec = ['self', ObjSpace, int]
+
class ArrayCache:
def __init__(self, space):
self.space = space
@@ -83,7 +89,7 @@
__call__ = interp2app(W_Array.descr_call,
unwrap_spec=['self', ObjSpace, int, W_Root]),
fromaddress = interp2app(W_Array.fromaddress),
- of = interp_attrproperty('of', W_Array),
+ gettypecode = interp2app(W_Array.descr_gettypecode),
)
W_Array.typedef.acceptable_as_base_class = False
Modified: pypy/branch/applevel-ctypes2/pypy/module/_rawffi/test/test_nested.py
==============================================================================
--- pypy/branch/applevel-ctypes2/pypy/module/_rawffi/test/test_nested.py (original)
+++ pypy/branch/applevel-ctypes2/pypy/module/_rawffi/test/test_nested.py Tue Jan 15 13:00:09 2008
@@ -63,3 +63,23 @@
assert rawbuf[1*S.size+ofs] == 'A'
assert rawbuf[2*S.size+ofs] == 'Z'
a.free()
+
+ def test_array_of_array(self):
+ import _rawffi, struct
+ B = _rawffi.Array('i')
+ sizeofint = struct.calcsize("i")
+ assert B.gettypecode(100) == (sizeofint * 100, sizeofint)
+ A = _rawffi.Array(B.gettypecode(4))
+ a = A(2)
+ b0 = B.fromaddress(a.itemaddress(0), 4)
+ b0[0] = 3
+ b0[3] = 7
+ b1 = B.fromaddress(a.itemaddress(1), 4)
+ b1[0] = 13
+ b1[3] = 17
+ rawbuf = _rawffi.Array('i').fromaddress(a.buffer, 2 * 4)
+ assert rawbuf[0] == 3
+ assert rawbuf[3] == 7
+ assert rawbuf[4] == 13
+ assert rawbuf[7] == 17
+ a.free()
More information about the Pypy-commit
mailing list