Author mark.dickinson
Recipients kermode, loewis, mark.dickinson, ncoghlan, pitrou, rupole, teoliphant
Date 2011-01-07.10:41:14
SpamBayes Score 9.11438e-06
Marked as misclassified No
Message-id <>
> 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)) {
            "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) {
        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.
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: <>
2011-01-07 10:41:14mark.dickinsonlinkissue10181 messages
2011-01-07 10:41:14mark.dickinsoncreate