[Python-Dev] Deprecate the buffer object?

Neil Schemenauer nas-python at python.ca
Wed Oct 29 17:44:55 EST 2003


On Wed, Oct 29, 2003 at 02:41:54PM +1300, Greg Ewing wrote:
> There's no doubt that the current implementation of it is
> unacceptably dangerous, but I haven't yet seen an argument
> that convinces me that it couldn't be fixed if desired.

Okay.  Perhaps I am missing something but would fixing it be as
simple as adding another field to the tp_as_buffer struct?

    /* references returned by the buffer functins are valid while
     * the object remains alive */
    #define PyBuffer_FLAG_SAFE 1

Then in stringobject.c (and elsewhere as appropriate):

    static PyBufferProcs buffer_as_buffer = {
        (getreadbufferproc)buffer_getreadbuf,
        (getwritebufferproc)buffer_getwritebuf,
        (getsegcountproc)buffer_getsegcount,
        (getcharbufferproc)buffer_getcharbuf,
        PyBuffer_FLAG_SAFE,
    };

Then change bufferobject so that it can only be created from objects
that set PyBuffer_FLAG_SAFE.

  Neil



More information about the Python-Dev mailing list