[Python-Dev] Assertion in _PyManagedBuffer_FromObject()

Stefan Krah stefan at bytereef.org
Fri Mar 2 16:30:57 CET 2012


Stefan Behnel <stefan_ml at behnel.de> wrote:
> I keep failing to see the interest in making this an error in the first
> place.

First, it is meant to guard against random pointers in the view.obj
field, precisely because view.obj was undocumented and exporters
might not fill in the field.

Then, as I said, the exporter is exposed on the Python level now:

>>> exporter = b'123'
>>> x = memoryview(exporter)
>>> x.obj == exporter 
True
>>> x.obj
b'123'


> Why would the object that bf_getbuffer() 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 Krah




More information about the Python-Dev mailing list