[Python-Dev] Undocumented view==NULL argument in PyObject_GetBuffer()

Stefan Krah stefan at bytereef.org
Tue Mar 6 16:15:12 CET 2012


Nick Coghlan <ncoghlan at gmail.com> wrote:
> On Tue, Mar 6, 2012 at 8:34 PM, Stefan Krah <stefan at bytereef.org> wrote:
> > The obvious question is: Will anyone need view==NULL in the future or
> > can we remove the special case?
> 
> The public API will still need a guard (to report an error), but +1
> for otherwise eliminating the undocumented special case.

I'm looking at other getbufferprocs apart from bytearray_getbuffer()
and the public API seems pretty dangerous to me:

For example, bytes_buffer_getbuffer() just calls PyBuffer_FillInfo(),
which instantly returns 0 (success). Now the reference count to
the bytes object is *not* incremented, so it might disappear while
the consumer still thinks it's valid.

The same happens in _ctypes.c:PyCData_NewGetBuffer().

For array_buffer_getbuf() it looks different: The export count
is increased, but not the reference count. So while the array
is protected against resizing, it's not immediately obvious to
me if it's protected against being deallocated (but I just skimmed
the code).


It seems to me that bytearray was the only place where the
view==NULL scheme obviously worked.


Stefan Krah




More information about the Python-Dev mailing list