New submission from STINNER Victor <vstin...@python.org>:
Python 3.11 made many changes in PyFrameObject and PyThreadState structures. Code which accessed directly structure members doesn't build anymore. For example, "frame->f_code" is now fails because PyFrameObject.f_code member is done. I propose to document these changes and explain how to port code. I will write a documentation PR. == PyFrameObject changes == PyFrameObject now only creates a Python frame object on demand. * f_code: removed, use PyFrame_GetCode() instead, warning: it returns a strong reference (Py_DECREF is needed) * f_lineno: changed, use PyFrame_GetLineNumber() * f_back: changed, use PyFrame_GetBack() * f_builtins: removed, get the "f_builtins" attribute in Python * f_globals: removed, get the "f_globals" attribute in Python * f_locals: removed, get the "f_locals" attribute in Python * f_valuesstack: removed * f_stackdepth: removed * f_gen: removed * f_lasti: removed, get the "f_lasti" attribute in Python? * f_iblock: removed * f_state: removed * f_blockstack: removed * f_localsplus: removed Accessing f_lineno and f_back doesn't fail with a compiler error, but these members are filled lazily. If PyFrame_GetLineNumber() is not called, it can return 0 even if the frame is running and has a line number. If PyFrame_GetBack() is not called, f_back is NULL even if the frame has a next outer frame. == PyThreadState changes == * frame: removed, use PyThreadState_GetFrame(), warning: it returns a strong reference (Py_DECREF is needed) * recursion_depth: removed, use (tstate->recursion_limit - tstate->recursion_remaining) instead * stackcheck_counter: removed * tracing: changed, use PyThreadState_EnterTracing() and PyThreadState_LeaveTracing(), added by bpo-43760 == Notes == We should also explain how to get new C API functions, like PyFrame_GetCode(), on older Python, and maybe suggest to use pythoncapi_compat to get them: https://github.com/pythoncapi/pythoncapi_compat See also: * bpo-39947: "[C API] Make the PyThreadState structure opaque (move it to the internal C API)" * bpo-40421: "[C API] Add getter functions for PyFrameObject and maybe move PyFrameObject to the internal C API" * bpo-43760: "The DISPATCH() macro is not as efficient as it could be (move PyThreadState.use_tracing)" -- add PyThreadState_EnterTracing() ---------- components: C API messages: 410398 nosy: vstinner priority: normal severity: normal status: open title: [C API] Document PyFrameObject and PyThreadState changes and explain how to port code to Python 3.11 versions: Python 3.11 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue46355> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com