[Python-Dev] Deprecate the buffer object?

Guido van Rossum guido at python.org
Wed Oct 29 18:11:49 EST 2003

> 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.

I don't know if this is enough, but if it is, I'd recommend adding the
flag bitto tp_flags rather than extending the buffer structure (since
you'd need to allocate an extra bit for tp_flags anyway to indicate
the longer buffer struct).

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list