[issue10181] Problems with Py_buffer management in memoryobject.c (and elsewhere?)
Stefan Krah
report at bugs.python.org
Mon Jul 4 12:28:58 CEST 2011
Stefan Krah <stefan-usenet at bytereef.org> added the comment:
In order to have a basis for discussion, I've set up a repo at
http://hg.python.org/features/pep-3118#memoryview
with an implementation of PyManagedBuffer. The whole test suite
passes, also with refleak counting and Valgrind.
Review is most welcome. If you think that this is roughly what
PyManagedBuffer is supposed to look like, I can add some tests
and documentation.
A couple of remarks:
o I have used refcounting assumptions that appear to be valid
for the Python codebase, but that need to be documented.
o The docs state that if an underlying object supports writable
views, the memoryview will be readable and writable. I use this
in PyManagedBuffer_FromObject(). In fact there are tests that
write to the original exporting object.
o Releasing a view raises if more than one view is active.
o get_shape0() is used in memory_length(). This does not seem
correct if ndim > 1.
o memory_getbuf() is still not a real getbufferproc, since it
disregards almost all flags.
o PyMemoryView_GetContiguous() needs to create a view with an
underlying PyManagedBuffer. If the obj parameter is already
a memoryview, the existing PyManagedBuffer has to be used,
so I just do a check if the requested buffertype agrees with
view->readonly.
It would be possible to complicate the code further by having
a PyMemoryView_FromObjectAndFlags().
o In the non-contiguous case, PyMemoryView_GetContiguous() creates
a new buffer, but the returned view does not use that buffer.
----------
hgrepos: +36
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10181>
_______________________________________
More information about the Python-bugs-list
mailing list