Message410398
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() |
|
Date |
User |
Action |
Args |
2022-01-12 14:11:25 | vstinner | set | recipients:
+ vstinner |
2022-01-12 14:11:24 | vstinner | set | messageid: <1641996684.93.0.427230565464.issue46355@roundup.psfhosted.org> |
2022-01-12 14:11:24 | vstinner | link | issue46355 messages |
2022-01-12 14:11:24 | vstinner | create | |
|