[Python-Dev] Wierd buffer "add" behaviour.

Mark Hammond MarkH@ActiveState.com
Mon, 16 Oct 2000 20:38:26 +1100

> IMHO, the whole buffer interface is weird.

I'm not sure that weird is the correct term for your points (it is for my
spelling, though :-)

> - Only the Buffer_FromObject() function is exposed to the
> - No way a python class can expose the buffer interface

These are simply oversights, I would suggest.  Nothing in the design
prevents this.

> - There is a bug in the buffer interface (which
> prevented recently that I could use buffer objects
> at all, I had to implement my own)

This looks like quite a simple bug.  bufferobject.c, line 77:

	/* if the base object is another buffer, then "deref" it */
	if ( PyBuffer_Check(base) )
		base = ((PyBufferObject *)base)->b_base;

if the condition was changed to:

	if ( PyBuffer_Check(base) && ((PyBufferObject *)base)->b_base)

Then I think this one would be solved?

A more serious design flaw is the one Fredrik pointed out quite some time
ago.  If you have (eg.) an "array" object and query for its buffer, life is
good.  If the array then resizes itself, your pointer is now dangling.  The
simplest solution to this is probably to simply define the lifetimes of
these pointers as very very short ;-)