[Python-Dev] Assertion in _PyManagedBuffer_FromObject() (original) (raw)

Stefan Krah stefan at bytereef.org
Fri Mar 2 17:42:26 CET 2012


Stefan Krah <stefan at bytereef.org> wrote:

> Why would the object that bfgetbuffer() is being called on have to > be identical with the one that exports the buffer?

It doesn't have to be. This is now possible: >>> from testbuffer import * >>> exporter = b'123' >>> nd = ndarray(exporter) >>> m = memoryview(nd) >>> nd.obj b'123' >>> m.obj <ndarray object at 0x7fbef33677d8>

Stefan (Behnel), do you have an existing example object that does what you described? If I understand correctly, in the above example the ndarray would redirect the buffer request to 'exporter' and set m.obj to 'exporter'.

It would be nice to know if people are actually using this.

The reason why this scheme was not chosen for a chain of memoryviews was that 'exporter' (in theory) could implement a slideshow of buffers, which means that in the face of redirecting requests m might not be equal to nd.

Stefan Krah



More information about the Python-Dev mailing list