[Python-Dev] PEP 296 - The Buffer Problem
Thomas Heller
thomas.heller@ion-tof.com
Thu, 25 Jul 2002 10:07:43 +0200
What if we would 'fix' the buffer interface?
Extend the PyBufferProcs structure by new fields:
typedef size_t (*getlargereadbufferproc)(PyObject *, void **);
typedef size_t (*getlargewritebufferproc)(PyObject *, void **);
typedef struct {
getreadbufferproc bf_getreadbuffer;
getwritebufferproc bf_getwritebuffer;
getsegcountproc bf_getsegcount;
getcharbufferproc bf_getcharbuffer;
/* new fields */
getlargereadbufferproc bf_getlargereadbufferproc;
getlargewritebufferproc bf_getlargewritebufferproc;
} PyBufferProcs;
The new fields are present if the Py_TPFLAGS_HAVE_GETLARGEBUFFER flag
is set in the object's type. Py_TPFLAGS_HAVE_GETLARGEBUFFER implies
the Py_TPFLAGS_HAVE_GETCHARBUFFER flag.
These functions have the same semantics Scott describes: they must
only be implemented by types only return addresses which are valid as
long as the Python 'source' object is alive.
Python strings, unicode strings, mmap objects, and maybe other types
would expose the large buffer interface, but the array type would
*not*. We could also change the name from 'large buffer interface'
to something more sensible, currently I don't have a better name.
Thomas