-
-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[C API] Document PyFrameObject and PyThreadState changes and explain how to port code to Python 3.11 #90513
Comments
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.
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 ==
== 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:
|
Oh I was wrong, PyFrame_GetLineNumber() code is the same in Python 3.10. It was already a bad idea to read directly the f_lineno member in Python 3.10: PyFrame_GetLineNumber() should always be called. |
Are there any C programming guides we can link to, that explain API use? If the advice for something is "use Python", we should probably add an API function. |
I merged my PR so the doc can be reviewed online at https://docs.python.org/dev/whatsnew/3.11.html once it will be rendered ;-) |
Tread carefully when changing decades-old API, documented or not. The docs weren't always as useful and complete as they are now.
Not really. If PyObject_GetAttrString doesn't add too much overhead, IMO it's fine to use it. |
I created bpo-46836: "[C API] Move PyFrameObject to the internal C API". |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: