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

Guido van Rossum guido at python.org
Tue Feb 27 22:18:33 CET 2007

On 2/27/07, Travis E. Oliphant <oliphant.travis at ieee.org> wrote:
> 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 its 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?

I don't think so -- this is exactly what I was thinking of.

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

More information about the Python-3000 mailing list