[New-bugs-announce] [issue46356] [C API] Enforce usage of PyFrame_GetBack()

STINNER Victor report at bugs.python.org
Wed Jan 12 10:33:01 EST 2022


New submission from STINNER Victor <vstinner at python.org>:

C extensions written for Python 3.10 and older which access directly to the PyFrameObject.f_back member build successfully on Python 3.11, but they can fail because f_back must not be read directly. f_back can be NULL even if the frame has an outer frame.

PyFrameObject*
PyFrame_GetBack(PyFrameObject *frame)
{
    assert(frame != NULL);
    PyFrameObject *back = frame->f_back;
    if (back == NULL && frame->f_frame->previous != NULL) {
        back = _PyFrame_GetFrameObject(frame->f_frame->previous);
    }
    Py_XINCREF(back);
    return back;
}

I suggest to remove or "hide" this member from the structure. For example, rename "f_back" to "_f_back" to advice developers to not access it directly.

See also bpo-46355: Document PyFrameObject and PyThreadState changes.

----------
components: C API
messages: 410403
nosy: Mark.Shannon, vstinner
priority: normal
severity: normal
status: open
title: [C API] Enforce usage of PyFrame_GetBack()
versions: Python 3.11

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46356>
_______________________________________


More information about the New-bugs-announce mailing list