This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients kermode, loewis, mark.dickinson, ncoghlan, pitrou, rupole, teoliphant
Date 2011-01-07.10:41:14
SpamBayes Score 9.114382e-06
Marked as misclassified No
Message-id <1294396875.99.0.782468779691.issue10181@psf.upfronthosting.co.za>
In-reply-to
Content
> by the time the relevant C stack frame goes away, ReleaseBuffer should 
> already have been called.

Hmm. I'm not sure I understand how/when that would happen.  Looking at the current py3k code, in Objects/memoryobject.c at line 92, we have:

PyObject *
PyMemoryView_FromObject(PyObject *base)
{
    PyMemoryViewObject *mview;
    Py_buffer view;

    if (!PyObject_CheckBuffer(base)) {
        PyErr_SetString(PyExc_TypeError,
            "cannot make memory view because object does "
            "not have the buffer interface");
        return NULL;
    }

    if (PyObject_GetBuffer(base, &view, PyBUF_FULL_RO) < 0)
        return NULL;

    mview = (PyMemoryViewObject *)PyMemoryView_FromBuffer(&view);
    if (mview == NULL) {
        PyBuffer_Release(&view);
        return NULL;
    }

    return (PyObject *)mview;
}

So here 'view' is being allocated on the stack, and its address passed to PyObject_GetBuffer;  PyBuffer_Release isn't called (except when an error happens) before the function exits and the stack frame becomes invalid.

Sorry for the odd questions;  it's clear to me that I'm misunderstanding something fundamental, but I'm struggling to figure out what.
History
Date User Action Args
2011-01-07 10:41:16mark.dickinsonsetrecipients: + mark.dickinson, loewis, teoliphant, ncoghlan, rupole, kermode, pitrou
2011-01-07 10:41:15mark.dickinsonsetmessageid: <1294396875.99.0.782468779691.issue10181@psf.upfronthosting.co.za>
2011-01-07 10:41:14mark.dickinsonlinkissue10181 messages
2011-01-07 10:41:14mark.dickinsoncreate