Message12189

Author jeff.allen
Recipients jeff.allen, rferguson@devendortech.com
Date 2018-11-28.21:21:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1543440062.8.0.788709270274.issue2715@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2018-11-28 21:21:02jeff.allensetmessageid: <1543440062.8.0.788709270274.issue2715@psf.upfronthosting.co.za>
2018-11-28 21:21:02jeff.allensetrecipients: + jeff.allen, rferguson@devendortech.com
2018-11-28 21:21:02jeff.allenlinkissue2715 messages
2018-11-28 21:21:02jeff.allencreate