[issue10181] Problems with Py_buffer management in memoryobject.c (and elsewhere?)
Stefan Krah
report at bugs.python.org
Mon Jun 27 18:47:36 CEST 2011
Stefan Krah <stefan-usenet at bytereef.org> added the comment:
Pauli Virtanen <report at bugs.python.org> wrote:
> skrah writes:
> > For example, an exporting object could provide a sliced view by adding
> > a getslicedbufferproc to PyBufferProcs:
> >
> > int PyObject_GetSlicedBuffer(PyObject *obj, Py_buffer *view,
> > int flags, PyObject *key);
>
> The same thing can be done via
>
> PyObject_GetBuffer(obj, &view, flags);
> PyBuffer_Slice(&view, &sliced_view, flags, key);
>
> given an implementation of PyBuffer_Slice. The logic in PyBuffer_Slice does
> not depend on where the buffer comes from, and every buffer can be sliced.
Ok, that sounds good. I came across a comment that base objects can change
their memory layout:
http://mail.python.org/pipermail/python-dev/2007-April/072606.html
Is that something that must be taken care of?
> > o The invariant that all allocated memory in the buffer belongs
> > to the exporting object remains intact.
>
> Numpy arrays do not have this invariant, and they happily re-export memory
> owned by someone else.
I'm not sure if we use the same terminology. By "exporting object" I meant
the original base object and this is the invariant I wanted:
m1 = memoryview(base) # directly from base
m2 = memoryview(m1) # redirects getbuffer/releasebuffer to base
m3 = memoryview(m2) # redirects getbuffer/releasebuffer to base
s1 = m3[1::2, 1::2] # redirects getslicedbuffer/releasebuffer to base
That's also what you mean by "re-exporting", right?
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10181>
_______________________________________
More information about the Python-bugs-list
mailing list