Martin Panter added the comment:

Before the Issue 22896 changes, PyObject_AsWriteBuffer() was used, which 
requests a buffer with the PyBUF_WRITABLE flag. Currently we use “w*” argument 
parsing format, which also uses PyBUF_WRITABLE. (Incidentally, I suspect the 
C-contiguity check is redundant for “w*”; non-contiguous buffers trigger the 
“read-write” error instead.)

Now Eryksun’s patch changes to PyMemoryView_FromObject(), which requests a 
buffer with the PyBUF_FULL_RO flag (the most liberal), and only then checks for 
writability and contiguity. Could this be a problem for some kind of object 
that returns different buffers depending on the request flags?

I agree that the existing buffer and memory view APIs don’t seem to be very 
practical and well understood. PyMemoryView_FromBuffer() is also used in the 
“io” module. It doesn’t even try to save a reference to the underlying buffers, 
meaning it is possible for Python code to write into freed memory by saving the 
memory view object passed to the readinto() method.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25498>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to