Message12189
Actually, this isn't quite the problem I thought. PyArray supports the buffer interface because in CPython you can write:
>>> ab = array.array('b', [65, 66, 67])
>>> list(buffer(ab))
['A', 'B', 'C']
>>> ai = array.array('i', [65, 66, 67])
>>> list(buffer(ai))
['A', '\x00', '\x00', '\x00', 'B', '\x00', '\x00', '\x00', 'C', '\x00', '\x00', '\x00']
(Little-endian machine: YMMV, and Java is big-endian.)
In Jython we have only one (internal) BufferProtocol so the side-effect of supporting buffer() as we should is that array.array also responds to memoryview().
However, if array.array were to respond to memoryview(), as it does in Python 3, it should do so with a properly structured buffer, that is:
>>> mi = memoryview(ai)
>>> mi.itemsize, mi.format, mi.shape
(4, 'i', (3,))
For compatibility with CPython 2, it probably shouldn't try. |
|
Date |
User |
Action |
Args |
2018-11-28 21:21:02 | jeff.allen | set | messageid: <1543440062.8.0.788709270274.issue2715@psf.upfronthosting.co.za> |
2018-11-28 21:21:02 | jeff.allen | set | recipients:
+ jeff.allen, rferguson@devendortech.com |
2018-11-28 21:21:02 | jeff.allen | link | issue2715 messages |
2018-11-28 21:21:02 | jeff.allen | create | |
|