[Python-Dev] Assertion in _PyManagedBuffer_FromObject()

Nick Coghlan ncoghlan at gmail.com
Fri Mar 2 13:25:08 CET 2012


On Fri, Mar 2, 2012 at 8:19 PM, Stefan Behnel <stefan_ml at behnel.de> wrote:
> I'm not saying that this is likely to happen, but I could imagine code that
> wants to use a different object for the cleanup than itself, possibly for
> keeping a certain kind of state when it delivers more than one buffer, or
> for remembering what kind of allocation was used, or ...

Supporting that kind of behaviour is what the "internal" field is for.

However, given the lack of control, an assert() isn't the appropriate
tool here - PyObject_GetBuffer itself should be *checking* the
constraint and then reporting an error if the check fails. Otherwise a
misbehaving extension module could trivially crash the Python
interpreter by returning a bad Py_buffer.

Regards,
Nick

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-Dev mailing list