[Python-Dev] Undocumented view==NULL argument in PyObject_GetBuffer()
Stefan Krah
stefan at bytereef.org
Tue Mar 6 11:34:59 CET 2012
Hello,
PyObject_GetBuffer() had an undocumented variant that was used internally:
PyObject_GetBuffer(obj, NULL, flags)
view==NULL has never been allowed by either PEP-3118 or the documentation:
PEP: "The first variable is the "exporting" object. The second argument
is the address to a bufferinfo structure. Both arguments must never
be NULL."
3.2 docs: "view must point to an existing Py_buffer structure
allocated by the caller."
The internal use was to bump up the export count of e.g. a bytearray
without bothering to have it fill in a complete Py_buffer. The increased
export count would then prevent the bytearray from being resized.
However, this feature appears to be unused in the source tree. The last
traces of a middle NULL argument that I found are here:
http://hg.python.org/cpython/file/df3b2b5db900/Modules/posixmodule.c#l561
So, currently the checks for NULL just slow down bytearray_getbuffer()
and a couple of other getbufferprocs. Also, due to the absence of a use
case it takes some VCS history digging to find out why the feature was
there in the first place.
The obvious question is: Will anyone need view==NULL in the future or
can we remove the special case?
Stefan Krah
More information about the Python-Dev
mailing list