[issue10181] Problems with Py_buffer management in memoryobject.c (and elsewhere?)

Pauli Virtanen report at bugs.python.org
Mon Jul 4 12:59:07 CEST 2011


Pauli Virtanen <pav at iki.fi> added the comment:

@skrah:

Yes, Numpy exposes only a single buffer per object. Making this a requirement in the PEP would probably be a sane change, as there is probably little real-world need to allow it behave otherwise.

Comment on the patch: it seems you do not track the re-export count in memory_getbuf:

    a = memoryview(obj)
    b = numpy.asarray(a)
    a.release()
    b[0] = 123 # <-- BOOM: the buffer was already released

Could be fixed by Py_INCREF(self->mbuf) in getbuffer and DECREF in releasebuffer. In this design, the only choice is to make the `release()` call to fail. (I had some code for n-dim slicing etc. in my first patch that could be useful to have too; I'll see if I find time to dig them out here.)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10181>
_______________________________________


More information about the Python-bugs-list mailing list