New submission from STINNER Victor <vstin...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue46356>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to