[Python-Dev] An updated extended buffer PEP

Greg Ewing greg.ewing at canterbury.ac.nz
Tue Mar 27 08:43:42 CEST 2007

Here's another idea, to allow multiple views of the same
buffer with different shape/stride info to coexist, but
without extra provider objects or refcount weirdness.
Also it avoids using calls with a brazillion arguments.

   struct bufferinfo {
     void **buf;
     Py_ssize_t *len;
     int *writeable;
     char **format;
     int *ndims;
     Py_ssize_t **shape;
     Py_ssize_t **strides;
     int **isptr;

   int (*getbuffer)(PyObject *obj, struct bufferinfo *info);

   int (*releasebuffer)(PyObject *obj, struct bufferinfo *info);

If the object has constant shape/stride info, it just fills
in the info struct with pointers to its own memory, and does
nothing when releasebuffer is called (other than unlocking
its buffer).

If its shape/stride info can change, it mallocs memory for
them and copies them into the info struct. When releasebuffer
is called, it frees this memory.

It is the responsibility of the consumer to ensure that the
base object remains alive until releasebuffer has been called
on the info struct (to avoid leaking any memory that has
been malloced for shapes/strides).


More information about the Python-Dev mailing list