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

Stefan Behnel stefan_ml at behnel.de
Fri Mar 2 11:19:37 CET 2012


Hi,

I just stumbled over this assertion in _PyManagedBuffer_FromObject() in the latest Py3.3 branch:

""" static PyObject * _PyManagedBuffer_FromObject(PyObject *base) { _PyManagedBufferObject *mbuf;

mbuf = mbuf_alloc();
if (mbuf == NULL)
    return NULL;

if (PyObject_GetBuffer(base, &mbuf->master, PyBUF_FULL_RO) < 0) {
    /* mbuf->master.obj must be NULL. */
    Py_DECREF(mbuf);
    return NULL;
}

/* Assume that master.obj is a new reference to base. */
assert(mbuf->master.obj == base);

return (PyObject *)mbuf;

} """

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 ...

Given that the buffer will eventually get released by the object pointed to by the view->obj field in the Py_buffer struct, is there a reason why it should be asserted that this is the same as the object that originally provided the buffer?

Stefan



More information about the Python-Dev mailing list