[Python-Dev] Deprecate the buffer object?

Neil Schemenauer nas-python at python.ca
Sat Nov 1 22:36:57 EST 2003

On Fri, Oct 31, 2003 at 09:21:06AM +1100, Mark Hammond wrote:
> Thus, my preference is to fix the buffer object by fixing the interface as
> much as possible.
> Here is a sketch of a solution, incorporating both Neil and Greg's ideas:
> * Type object gets a new flag - TP_HAS_BUFFER_INFO, corresponding to a new
> 'getbufferinfoproc' slot in the PyBufferProcs structure (note - a function
> pointer, not static flags as Neil suggested)
> * New function 'getbufferinfoproc' returns a bitmask - Py_BUFFER_FIXED is
> one (and currently the only) flag that can be returned.

What does this flag mean?  To my mind, there are several different
types of memory buffers and the buffer interface does not
distinguish between all of them.  Is the size and position of the
buffer fixed?  Is the buffer immutable (it may be readonly by the
buffer object but writable via some other mechanism)?

The first question can be avoided by using Greg's idea of always
refreshing the size and position.  The second question cannot be
answered using the current interface.  I supposed if the buffer is
immutable then it is implied that the its size and position is

> * New buffer functions PyObject_AsFixedCharBuffer, etc.  These check the new
> flag (and a type lacking TP_HAS_BUFFER_INFO is assumed to *not* be fixed)
> * Buffer object keeps a reference to the existing object (as it does now).
> Its getbufferinfoproc delegates to the underlying object.
> * Buffer object *never* keeps a pointer to the buffer - only to the object.
> Functions like tp_hash always re-fetch the buffer on demand.  The buffer
> returned by the buffer object is then guaranteed to be as reliable as the
> underlying object.  (This may be a semantic issue with hash(), but
> conceptually seems fine.  Potential solution here - add Py_BUFFER_READONLY
> as a buffer flag, then hash() semantics could do the right thing)

You can't use the base objects hash if the buffer has a explicit size
of offset.


More information about the Python-Dev mailing list