-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
WIP bpo-44800: Rename _PyInterpreterFrame to _Py_framedata
#27525
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
Closed
ncoghlan
wants to merge
34
commits into
python:main
from
ncoghlan:bpo-44800-rename-interpreter-frames
Closed
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
a133e0d
bpo-44800: Clearly distinguish execution & introspection frames
ncoghlan d8858aa
'frame' and 'frame data' replaces introspection and execution frames
ncoghlan cd340b0
Merge remote-tracking branch 'origin/main' into bpo-44800-rename-inte…
ncoghlan ccf953b
Tweak some comments
ncoghlan 4a097bd
Another comment fix
ncoghlan bd00490
Fix LLTRACE macro compile error
ncoghlan 04aa7e8
Revert unintended function name changes
ncoghlan e9018e7
Fix comment alignment
ncoghlan 0ce41c8
Follow proposed new naming conventions in gdb hooks
ncoghlan c269e1f
Merge remote-tracking branch 'origin/main' into bpo-44800-rename-inte…
ncoghlan 4eeff9a
Reduce conflicts for main branch merge
ncoghlan 6fa0f53
Fix bad search & replace
ncoghlan 776ca80
main branch has no underscore
ncoghlan 682af23
Reduce function header conflicts
ncoghlan c76e63b
Yet more merge conflict reduction
ncoghlan b1d1438
Merged and compiles, naming is inconsistent
ncoghlan cae935d
Reinstate _Py_framedata struct rename
ncoghlan 2866bfa
Fix type declaration for gen/coro frame data
ncoghlan 239a62f
Document frame related naming conventions
ncoghlan 2680f35
Migrate gen/coro iframe field to fdata naming convention
ncoghlan ebda1d3
Use fdata for frame data locals and parameters
ncoghlan 269a4a0
frame -> fdata in ceval.c & allow compilation
ncoghlan 34cf023
Disambiguate f_fdata and f_frame_data
ncoghlan 55d9276
Merge remote-tracking branch 'origin/main' into bpo-44800-rename-inte…
ncoghlan 3eba918
Document the currently implemented conventions
ncoghlan e8a4adf
Note the 'current_frame' exception
ncoghlan 3d654a0
Fix test_gdb
ncoghlan b09b114
Fix header file include guard var
ncoghlan 9b51976
Distinguish frame state error messages
ncoghlan 0a3611c
super() does not access C frame structs
ncoghlan 08410cc
new_frame -> new_fdata in frame push
ncoghlan c694768
Add missing error check in PyImport_Import
ncoghlan ba87ef3
No Python frame seems legit for PyImport_Import()
ncoghlan 7168f7d
Get test_gdb passing locally
ncoghlan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| #ifndef Py_INTERNAL_XFRAME_H | ||
| #define Py_INTERNAL_XFRAME_H | ||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /* Internal-use-only introspection frame constructor */ | ||
| PyFrameObject* | ||
| _PyFrame_New_NoTrack(_PyExecFrame *, int); | ||
|
|
||
| /* These values are chosen so that the inline functions below all | ||
| * compare f_state to zero. | ||
| */ | ||
| enum _framestate { | ||
| FRAME_CREATED = -2, | ||
| FRAME_SUSPENDED = -1, | ||
| FRAME_EXECUTING = 0, | ||
| FRAME_RETURNED = 1, | ||
| FRAME_UNWINDING = 2, | ||
| FRAME_RAISED = 3, | ||
| FRAME_CLEARED = 4 | ||
| }; | ||
|
|
||
| typedef signed char PyFrameState; | ||
|
|
||
| // The _PyExecFrame typedef is in Include/pyframeobject.h | ||
| struct _Py_execution_frame { | ||
| PyObject *xf_globals; | ||
| PyObject *xf_builtins; | ||
| PyObject *xf_locals; | ||
| PyCodeObject *xf_code; | ||
| PyFrameObject *xf_frame_obj; // Introspection frame (if created) | ||
| /* Borrowed reference to a generator, or NULL */ | ||
| PyObject *xf_generator; | ||
| _PyExecFrame *xf_previous; | ||
| int xf_lasti; /* Last instruction if called */ | ||
| int xf_stackdepth; /* Depth of value stack */ | ||
| int xf_nlocalsplus; | ||
| PyFrameState xf_state; /* What state the frame is in */ | ||
| PyObject *xf_stack[1]; | ||
| }; | ||
|
|
||
| static inline int _PyExecFrame_IsRunnable(_PyExecFrame *xf) { | ||
| return xf->xf_state < FRAME_EXECUTING; | ||
| } | ||
|
|
||
| static inline int _PyExecFrame_IsExecuting(_PyExecFrame *xf) { | ||
| return xf->xf_state == FRAME_EXECUTING; | ||
| } | ||
|
|
||
| static inline int _PyExecFrame_HasCompleted(_PyExecFrame *xf) { | ||
| return xf->xf_state > FRAME_EXECUTING; | ||
| } | ||
|
|
||
| #define FRAME_SPECIALS_SIZE ((sizeof(_PyExecFrame)-1)/sizeof(PyObject *)) | ||
|
|
||
| _PyExecFrame * | ||
| _PyExecFrame_HeapAlloc(PyFrameConstructor *con, PyObject *locals); | ||
|
|
||
| static inline void | ||
| _PyExecFrame_InitializeSpecials( | ||
| _PyExecFrame *xframe, PyFrameConstructor *con, | ||
| PyObject *locals, int nlocalsplus) | ||
| { | ||
| xframe->xf_code = (PyCodeObject *)Py_NewRef(con->fc_code); | ||
| xframe->xf_builtins = Py_NewRef(con->fc_builtins); | ||
| xframe->xf_globals = Py_NewRef(con->fc_globals); | ||
| xframe->xf_locals = Py_XNewRef(locals); | ||
| xframe->xf_nlocalsplus = nlocalsplus; | ||
| xframe->xf_stackdepth = 0; | ||
| xframe->xf_frame_obj = NULL; | ||
| xframe->xf_generator = NULL; | ||
| xframe->xf_lasti = -1; | ||
| xframe->xf_state = FRAME_CREATED; | ||
| } | ||
|
|
||
| /* Gets the pointer to the locals array | ||
| * that precedes this frame. | ||
| */ | ||
| static inline PyObject** | ||
| _PyExecFrame_GetLocalsArray(_PyExecFrame *xframe) | ||
| { | ||
| return ((PyObject **)xframe) - xframe->xf_nlocalsplus; | ||
| } | ||
|
|
||
| /* For use by _PyExecFrame_GetFrameObject | ||
| Do not call directly. */ | ||
| PyFrameObject * | ||
| _PyExecFrame_MakeAndSetFrameObject(_PyExecFrame *xframe); | ||
|
|
||
| /* Gets the PyFrameObject for this frame, lazily | ||
| * creating it if necessary. | ||
| * Returns a borrowed referennce */ | ||
| static inline PyFrameObject * | ||
| _PyExecFrame_GetFrameObject(_PyExecFrame *xframe) | ||
| { | ||
| PyFrameObject *res = xframe->xf_frame_obj; | ||
| if (res != NULL) { | ||
| return res; | ||
| } | ||
| return _PyExecFrame_MakeAndSetFrameObject(xframe); | ||
| } | ||
|
|
||
| /* Clears all references in the frame. | ||
| * If take is non-zero, then the execution frame | ||
| * may be transfered to the frame object it references | ||
| * instead of being cleared. Either way | ||
| * the caller no longer owns the references | ||
| * in the frame. | ||
| * take should be set to 1 for heap allocated | ||
| * frames like the ones in generators and coroutines. | ||
| */ | ||
| int | ||
| _PyExecFrame_Clear(_PyExecFrame *xframe, int take); | ||
|
|
||
| int | ||
| _PyExecFrame_Traverse(_PyExecFrame *xframe, visitproc visit, void *arg); | ||
|
|
||
| int | ||
| _PyExecFrame_FastToLocalsWithError(_PyExecFrame *frame); | ||
|
|
||
| void | ||
| _PyExecFrame_LocalsToFast(_PyExecFrame *frame, int clear); | ||
|
|
||
| _PyExecFrame *_PyThreadState_PushExecFrame( | ||
| PyThreadState *tstate, PyFrameConstructor *con, PyObject *locals); | ||
|
|
||
| void _PyThreadState_PopExecFrame(PyThreadState *tstate, _PyExecFrame *frame); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
| #endif /* !Py_INTERNAL_XFRAME_H */ |
4 changes: 4 additions & 0 deletions
4
Misc/NEWS.d/next/Core and Builtins/2021-08-01-18-18-51.bpo-44800.TCsfH3.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Refactored internal APIs for the new lazy introspection frame creation to | ||
| consistently distinguish between the classic introspection frames (full | ||
| Python objects) and the new lighter weight internal execution frames (C | ||
| structs with no intrinsic instance lifecycle management) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@markshannon This new comment needs review to make sure I've accurately captured the way the new frame implementation works.