[Python-Dev] buffer interface considered harmful

Jack Jansen jack@oratrix.nl
Mon, 16 Aug 1999 15:45:31 +0200


> A while ago I asked for some documentation on the Buffer
> interface.  I basically got silence.  At this point, I 
> don't have a good idea what buffers are for and I don't see alot
> of evidence that there *is* a design. I assume that there was
> a design, but I can't see it.  This whole discussion makes me
> very queasy.  

Okay, as I'm apparently not the only one who is queasy let's start from 
scratch.

First, there is the old buffer _interface_. This is a C interface that allows 
extension (and builtin) modules and functions a unified way to access objects 
if they want to write the object to file and similar things. It is also what 
the PyArg_ParseTuple "s#" returns. This is, in C, the 
getreadbuffer/getwritebuffer interface.

Second, there's the extension the the buffer interface as of 1.5.2. This is 
again only available in C, and it allows C programmers to get an object _as an 
ASCII string_. This is meant for things like regexp modules, to access any 
"textual" object as an ASCII string. This is the getcharbuffer interface, and 
bound to the "t#" specifier in PyArg_ParseTuple.

Third, there is the buffer _object_, also new in 1.5.2. This sort-of exports 
the functionality of the buffer interface to Python, but it does a bit more as 
well, because the buffer objects have a sort of copy-on-write semantics that 
means they may or may not be "attached" to a python object through the buffer 
interface.

<personal opinion>
I think that the C interface and the object should be treated completely 
separately. I definitely want the C interface, but I personally don't use the 
Python buffer objects, so I don't really care all that much about those. Also, 
I think that the buffer objects might become easier to understand if we don't 
think of it as "the buffer interface exported to python", but as "Python 
buffer objects, that may share memory with other Python objects as an 
optimization".
</personal opinion>
--
Jack Jansen             | ++++ stop the execution of Mumia Abu-Jamal ++++
Jack.Jansen@oratrix.com | ++++ if you agree copy these lines to your sig ++++
www.oratrix.nl/~jack    | see http://www.xs4all.nl/~tank/spg-l/sigaction.htm