[issue9602] PyObject_AsCharBuffer() should only accept read-only objects

Lenard Lindstrom report at bugs.python.org
Tue Sep 28 18:45:59 CEST 2010

Lenard Lindstrom <len-l at telus.net> added the comment:

>I don't know why you're saying that. The purpose of PyBuffer_Release is
>precisely to solve these kinds of use cases (where you want timely
>release of a resource rather than rely on the garbage collector).

Yes, I was unclear. This refers to Python 3.2, not the 2.x series. PyObject_AsReadBuffer (defined at line 270 in abstract.c, code of routine attached) calls bf_getbuffer with the PyBUF_SIMPLE flag to retrieve a bytes buffer. It then calls bf_releasebuffer before returning the buffer to the caller. PyObject_AsCharBuffer and PyObject_AsWriteBuffer do the same. It is not be exactly the same issue discussed so far, but is closely related.

Deprecating PyObject_AsReadBuffer is extreme, and doesn't solve the early release problem. Redefining the PyBUF_SIMPLE flag to be like the old buffer protocol warns those implementing a new buffer interface to  avoid processing PyBUF_SIMPLE requests when locking is required.

Added file: http://bugs.python.org/file19048/PyObject_AsReadBuffer.c

Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list