--- Todd Miller email@example.com wrote:
I don't understand what you say, but I believe you.
I meant we call PyBuffer_FromReadWriteObject and the resulting buffer lives longer than the extension function call that created it. I have heard that it is possible for the original object to "move" leaving the buffer object pointer to it dangling.
Yes. The PyBufferObject grabs the pointer from the PyBufferProcs supporting object when the PyBufferObject is created. If the PyBufferProcs supporting object reallocates the memory (possibly from a resize) the PyBufferObject can be left with a bad pointer. This is easily possible if you try to use the array module arrays as a buffer.
I've submitted a patch to fix this particular problem (among others), but there are still enough things that the buffer object can't do that something new is needed.
Maybe instead of the buffer() function/type, there should be a way to allocate raw memory?
Yes. It would also be nice to be able to:
- Know (at the python level) that a type supports the buffer C-API.
Good idea. (I guess right now you can see if calling buffer() with an instance as argument works. :-)
- Copy bytes from one buffer to another (writeable buffer).
And the copy operations shouldn't create any large temporaries:
buf1 = memory(50000) buf2 = memory(50000) # no 10K temporary should be created in the next line buf1[10000:20000] = buf2[30000:40000]
The current buffer object could be used like this, but it would create a temporary string.
So getting an efficient copy operation seems to require that slices just create new "views" to the same memory.
Maybe you would like to work on a requirements gathering for a memory object
Sure. I'd be willing to poll comp.lang.python (python-list?) and collate the results of any discussion that ensues. Is that what you had in mind?
In the PEP that I'm drafting, I've been calling the new object "bytes" (since it is just a simple array of bytes). Now that you guys are referring to it as the "memory object", should I change the name? Doesn't really matter, but it might avoid confusion to know we're all talking about the same thing.
__________________________________________________ Do You Yahoo!? Yahoo! Autos - Get free new car price quotes http://autos.yahoo.com