[Python-3000] pre-PEP: Enhancing buffer protocol (tp_as_buffer)

Travis E. Oliphant oliphant.travis at ieee.org
Tue Feb 27 22:14:11 CET 2007


Guido van Rossum wrote:
> On 2/26/07, Travis Oliphant <oliphant.travis at ieee.org> wrote:
>> Guido van Rossum wrote:
>> Great.  I have no problem with this.  Is your idea of locking the same
>> as mine (i.e. a function in the API for release?)
> 
> Right.

My understanding of this locking mechanism would require objects that 
wish to use it to keep track of how many views they have "exported" and 
refuse to re-allocate memory until the views have all been released.

In my understanding this would require the addition of at least one 
integer to the object structure.

So, for example, the bytesobject would need to at least add

int ob_views

to it's C-structure:

/* Object layout */
typedef struct {
     PyObject_VAR_HEAD
     Py_ssize_t ob_alloc; /* How many bytes allocated */
     int ob_views; /* Number of views to these bytes */
     char *ob_bytes;
} PyBytesObject;


On creation, ob_views would be initialized to 0 and whenever getbuffer 
was called it would increase this number and whenever releasebuffer was 
called it would decrease this number.

Am I missing something here?

-Travis



More information about the Python-3000 mailing list