[Python-Dev] buffer objects
Greg Ewing
greg@cosc.canterbury.ac.nz
Fri, 03 May 2002 12:00:52 +1200 (NZST)
Mark Hammond <mhammond@skippinet.com.au>:
> It turns out that the buffer *interface* has a design flaw, best described
> by using the array object as an example. The real possibility exists that
> code can use the buffer interfaces to get a pointer to writable memory for
> the array. The array may then be resized, thereby moving the buffer but
> leaving the buffer pointer dangling.
If you do that using the (C-level) buffer interface,
you're misusing it. You shouldn't be keeping a pointer
to the internals of an object across any operation which
could cause it to move, however that pointer is obtained.
The design flaw is in the Python-level buffer *object*,
which misuses the buffer interface in exactly that way.
This is so insane that I can't understand why the
buffer object hasn't either been fixed or ripped
out by now.
The fix seems obvious to me -- don't cache the pointer
in the buffer object, but use the buffer interface to
re-fetch it on each Python-level call which needs it.
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
greg@cosc.canterbury.ac.nz +--------------------------------------+