This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

作者 skrah
收信人 ncoghlan, pitrou, skrah
日期 2011-08-22.11:13:30
SpamBayes Score 3.6600667e-09
Marked as misclassified
Message-id <1314011611.8.0.941911218938.issue12817@psf.upfronthosting.co.za>
In-reply-to
内容
Hello,

in my private repo I've changed memoryview's getbufferproc to be PEP-3118
compliant. test_multiprocessing does the equivalent of the following sequence,
which is not allowed by PEP-3118:


>>> import array, io
>>> a = array.array('i', [1,2,3,4,5])
>>> m = memoryview(a)
>>> m.format
'i'
>>> buf = io.BytesIO(bytearray(5))
>>> buf.readinto(m)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: expected an object with a writable buffer interface
>>>


The error occurs in Objects/abstract.c:315:

   ((*pb->bf_getbuffer)(obj, &view, PyBUF_WRITABLE) != 0))


Here, PyObject_AsWriteBuffer() requests a simple writable buffer of unsigned
bytes *without format information* from the memoryview. The memoryview's
getbufferproc is required to return an error:

"If format is not explicitly requested then the format must be returned
 as NULL (which means "B", or unsigned bytes)."

But the underlying buffer has format 'i' and not 'B', hence the error.


Antoine, is it correct that io.BytesIO should only be used with bytearray
buffers?

If so, this is a bug in the tests (patch attached).
历史
日期 用户 动作 参数
2011-08-22 11:13:31skrah修改recipients: + skrah, ncoghlan, pitrou
2011-08-22 11:13:31skrah修改messageid: <1314011611.8.0.941911218938.issue12817@psf.upfronthosting.co.za>
2011-08-22 11:13:31skrah链接issue12817 messages
2011-08-22 11:13:30skrah创建