Nick Coghlan <ncogh...@gmail.com> added the comment:

The alternative (if we declare that clients should treat Py_buffer contents as 
completely read-only) is to update memoryview to include a separate "orig_view" 
field that would never be touched. The GetBuffer and ReleaseBuffer calls would 
then use orig_view, with dup_buffer used to copy the data into the main view 
field before modifying it.

However, this approach greatly complicates the bf_getbuffer and 
bf_releasebuffer implementations, since memoryview could no longer pass the 
supplied Py_buffer pointer straight through to the underlying implementation.

Instead, for each call to bf_getbuffer, it would need to create a new Py_buffer 
struct, use that for the GetBuffer call to the underlying object, copy the 
contents over to the passed in buffer (modifying the shape information as 
appropriate for any slicing that is in effect), then, in bf_releasebuffer, use 
the passed in pointer to find the right Py_buffer struct to use in the 
ReleaseBuffer call.

Putting the onus on exporters to be suspicious of the contents of the Py_buffer 
objects handed to bf_releasebuffer implementations actually seems like the more 
robust approach in the long run.

----------

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

Reply via email to