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

--
Greg
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to