-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
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 3 commits
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_FRAMEDATA_H | ||
#define Py_INTERNAL_FRAMEDATA_H | ||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/* Internal-use-only frame object constructor */ | ||
PyFrameObject* | ||
_PyFrame_New_NoTrack(_Py_framedata *, 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 _Py_framedata typedef is in Include/pyframeobject.h | ||
struct _Py_execution_frame { | ||
PyObject *globals; | ||
PyObject *builtins; | ||
PyObject *locals; | ||
PyCodeObject *code; | ||
PyFrameObject *frame_obj; // Full frame object (if created) | ||
/* Borrowed reference to a generator, or NULL */ | ||
PyObject *generator; | ||
_Py_framedata *previous; | ||
int lasti; /* Last instruction if called */ | ||
int stackdepth; /* Depth of value stack */ | ||
int nlocalsplus; | ||
PyFrameState state; /* What state the frame is in */ | ||
PyObject *stack[1]; | ||
}; | ||
|
||
static inline int _Py_framedata_IsRunnable(_Py_framedata *fdata) { | ||
return fdata->state < FRAME_EXECUTING; | ||
} | ||
|
||
static inline int _Py_framedata_IsExecuting(_Py_framedata *fdata) { | ||
return fdata->state == FRAME_EXECUTING; | ||
} | ||
|
||
static inline int _Py_framedata_HasCompleted(_Py_framedata *fdata) { | ||
return fdata->state > FRAME_EXECUTING; | ||
} | ||
|
||
#define FRAME_SPECIALS_SIZE ((sizeof(_Py_framedata)-1)/sizeof(PyObject *)) | ||
|
||
_Py_framedata * | ||
_Py_framedata_HeapAlloc(PyFrameConstructor *con, PyObject *locals); | ||
|
||
static inline void | ||
_Py_framedata_InitializeSpecials( | ||
_Py_framedata *fdata, PyFrameConstructor *con, | ||
PyObject *locals, int nlocalsplus) | ||
{ | ||
fdata->code = (PyCodeObject *)Py_NewRef(con->fc_code); | ||
fdata->builtins = Py_NewRef(con->fc_builtins); | ||
fdata->globals = Py_NewRef(con->fc_globals); | ||
fdata->locals = Py_XNewRef(locals); | ||
fdata->nlocalsplus = nlocalsplus; | ||
fdata->stackdepth = 0; | ||
fdata->frame_obj = NULL; | ||
fdata->generator = NULL; | ||
fdata->lasti = -1; | ||
fdata->state = FRAME_CREATED; | ||
} | ||
|
||
/* Gets the pointer to the locals array | ||
* that precedes this frame. | ||
*/ | ||
static inline PyObject** | ||
_Py_framedata_GetLocalsArray(_Py_framedata *fdata) | ||
{ | ||
return ((PyObject **)fdata) - fdata->nlocalsplus; | ||
} | ||
|
||
/* For use by _Py_framedata_GetFrameObject | ||
Do not call directly. */ | ||
PyFrameObject * | ||
_Py_framedata_MakeAndSetFrameObject(_Py_framedata *fdata); | ||
|
||
/* Gets the PyFrameObject for this frame, lazily | ||
* creating it if necessary. | ||
* Returns a borrowed referennce */ | ||
static inline PyFrameObject * | ||
_Py_framedata_GetFrameObject(_Py_framedata *fdata) | ||
{ | ||
PyFrameObject *res = fdata->frame_obj; | ||
if (res != NULL) { | ||
return res; | ||
} | ||
return _Py_framedata_MakeAndSetFrameObject(fdata); | ||
} | ||
|
||
/* 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 | ||
_Py_framedata_Clear(_Py_framedata *fdata, int take); | ||
|
||
int | ||
_Py_framedata_Traverse(_Py_framedata *fdata, visitproc visit, void *arg); | ||
|
||
int | ||
_Py_framedata_FastToLocalsWithError(_Py_framedata *frame); | ||
|
||
void | ||
_Py_framedata_LocalsToFast(_Py_framedata *frame, int clear); | ||
|
||
_Py_framedata *_PyThreadState_Push_framedata( | ||
PyThreadState *tstate, PyFrameConstructor *con, PyObject *locals); | ||
|
||
void _PyThreadState_Pop_framedata(PyThreadState *tstate, _Py_framedata *frame); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif /* !Py_INTERNAL_FRAMEDATA_H */ |
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 |
---|---|---|
|
@@ -2090,11 +2090,11 @@ def _testSendFrame(self): | |
self.cf = self.build_can_frame(0x00, b'\x01\x02\x03\x04\x05') | ||
self.cli.send(self.cf) | ||
|
||
def testSendMaxFrame(self): | ||
def testSendMafdata(self): | ||
cf, addr = self.s.recvfrom(self.bufsize) | ||
self.assertEqual(self.cf, cf) | ||
|
||
def _testSendMaxFrame(self): | ||
def _testSendMafdata(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are false positives There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reverted this unintended change. |
||
self.cf = self.build_can_frame(0x00, b'\x07' * 8) | ||
self.cli.send(self.cf) | ||
|
||
|
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.
The file name change obscures the changes to the field names here, where the following previously had the
f_
prefix:globals
builtins
locals
code
lasti
state
To reduce the diff size, while still ensuring that the field prefix was consistently different between
PyFrameObject
and_Py_framedata
, I went with the option of standardising the data struct on "no field prefix" (it was previously split 50/50 between that and thef_
prefix), rather than introducing a new prefix the way I did in the original PR.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.
Reverted this file rename from the PR - the internal header now remains
pycore_frame.h
, with both the full frame object and frame data struct field definitions in it.