8000 WIP bpo-44800: Rename `_PyInterpreterFrame` to `_Py_framedata` by ncoghlan · Pull Request #27525 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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
Closed
Show file tree
Hide file tree
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 Aug 1, 2021
d8858aa
'frame' and 'frame data' replaces introspection and execution frames
ncoghlan Aug 14, 2021
cd340b0
Merge remote-tracking branch 'origin/main' into bpo-44800-rename-inte…
ncoghlan Aug 14, 2021
ccf953b
Tweak some comments
ncoghlan Aug 14, 2021
4a097bd
Another comment fix
ncoghlan Aug 14, 2021
bd00490
Fix LLTRACE macro compile error
ncoghlan Aug 14, 2021
04aa7e8
Revert unintended function name changes
ncoghlan Aug 14, 2021
e9018e7
Fix comment alignment
ncoghlan Aug 14, 2021
0ce41c8
Follow proposed new naming conventions in gdb hooks
ncoghlan Aug 14, 2021
c269e1f
Merge remote-tracking branch 'origin/main' into bpo-44800-rename-inte…
ncoghlan Aug 21, 2021
4eeff9a
Reduce conflicts for main branch merge
ncoghlan Mar 6, 2022
6fa0f53
Fix bad search & replace
ncoghlan Mar 6, 2022
776ca80
main branch has no underscore
ncoghlan Mar 6, 2022 8000
682af23
Reduce function header conflicts
ncoghlan Mar 6, 2022
c76e63b
Yet more merge conflict reduction
ncoghlan Mar 6, 2022
b1d1438
Merged and compiles, naming is inconsistent
ncoghlan Mar 6, 2022
cae935d
Reinstate _Py_framedata struct rename
ncoghlan Mar 6, 2022
2866bfa
Fix type declaration for gen/coro frame data
ncoghlan Mar 6, 2022
239a62f
Document frame related naming conventions
ncoghlan Mar 6, 2022
2680f35
Migrate gen/coro iframe field to fdata naming convention
ncoghlan Mar 6, 2022
ebda1d3
Use fdata for frame data locals and parameters
ncoghlan Mar 12, 2022
269a4a0
frame -> fdata in ceval.c & allow compilation
ncoghlan Mar 12, 2022
34cf023
Disambiguate f_fdata and f_frame_data
ncoghlan Mar 12, 2022
55d9276
Merge remote-tracking branch 'origin/main' into bpo-44800-rename-inte…
ncoghlan Mar 12, 2022
3eba918
Document the currently implemented conventions
ncoghlan Mar 12, 2022
e8a4adf
Note the 'current_frame' exception
ncoghlan Mar 12, 2022
3d654a0
Fix test_gdb
ncoghlan Mar 12, 2022
b09b114
Fix header file include guard var
ncoghlan Mar 12, 2022
9b51976
Distinguish frame state error messages
ncoghlan Mar 12, 2022
0a3611c
super() does not access C frame structs
ncoghlan Mar 12, 2022
08410cc
new_frame -> new_fdata in frame push
ncoghlan Mar 12, 2022
c694768
Add missing error check in PyImport_Import
ncoghlan Mar 12, 2022
ba87ef3
No Python frame seems legit for PyImport_Import()
ncoghlan Mar 12, 2022
7168f7d
Get test_gdb passing locally
ncoghlan Mar 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
main branch has no underscore
  • Loading branch information
ncoghlan committed Mar 6, 2022
commit 776ca80b19e04d1d8ded5a589c0634c2234223e8
2 changes: 1 addition & 1 deletion Include/cpython/ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ PyAPI_FUNC(PyObject *) _PyEval_GetBuiltinId(_Py_Identifier *);
flag was set, else return 0. */
PyAPI_FUNC(int) PyEval_MergeCompilerFlags(PyCompilerFlags *cf);

PyAPI_FUNC(PyObject *) _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_InterpreterFrame *fdata, int exc);
PyAPI_FUNC(PyObject *) _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *fdata, int exc);

PyAPI_FUNC(void) _PyEval_SetSwitchInterval(unsigned long microseconds);
PyAPI_FUNC(unsigned long) _PyEval_GetSwitchInterval(void);
Expand Down
4 changes: 2 additions & 2 deletions Include/cpython/frameobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
* over the previous approach of using full Python objects for both
* introspection and code execution.
*/
// Declaration of _Py_InterpreterFrame is in cpython/pystate.h for use in PyThreadState
// Declaration of _PyInterpreterFrame is in cpython/pystate.h for use in PyThreadState

struct _frame {
PyObject_HEAD
struct _frame *f_back; /* previous frame, or NULL */
_Py_InterpreterFrame *f_fdata; /* points to the frame runtime data */
_PyInterpreterFrame *f_fdata; /* points to the frame runtime data */
PyObject *f_trace; /* Trace function */
int f_lineno; /* Current line number. Only valid if non-zero */
char f_trace_lines; /* Emit per-line trace events? */
Expand Down
6 changes: 3 additions & 3 deletions Include/cpython/pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ typedef struct _stack_chunk {
// Declared here so the thread state can use it without creating an include loop
// See cpython/frameobject.h for an explanation of the type
// See internal/pycore_frame.h for the struct definition
typedef struct _Py_execution_frame _Py_InterpreterFrame;
typedef struct _Py_execution_frame _PyInterpreterFrame;

// The PyThreadState typedef is in Include/pystate.h.
struct _ts {
Expand All @@ -84,7 +84,7 @@ struct _ts {
PyInterpreterState *interp;

/* Borrowed reference to the current execution frame's data (it can be NULL) */
_Py_InterpreterFrame *fdata;
_PyInterpreterFrame *fdata;
int recursion_depth;
int recursion_headroom; /* Allow 50 more calls to handle any errors. */
int stackcheck_counter;
Expand Down Expand Up @@ -229,7 +229,7 @@ PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void);

/* Frame evaluation API */

typedef PyObject* (*_PyFrameEvalFunction)(PyThreadState *tstate, _Py_InterpreterFrame *, int);
typedef PyObject* (*_PyFrameEvalFunction)(PyThreadState *tstate, _PyInterpreterFrame *, int);

PyAPI_FUNC(_PyFrameEvalFunction) _PyInterpreterState_GetEvalFrameFunc(
PyInterpreterState *interp);
Expand Down
2 changes: 1 addition & 1 deletion Include/genobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extern "C" {
#define _PyGenObject_HEAD(prefix) \
PyObject_HEAD \
/* Note: gi_fdata can be NULL if the generator is "finished" */ \
_Py_InterpreterFrame *prefix##_fdata; \
_PyInterpreterFrame *prefix##_fdata; \
/* The code object backing the generator */ \
PyCodeObject *prefix##_code; \
/* List of weak reference. */ \
Expand Down
6 changes: 3 additions & 3 deletions Include/internal/pycore_ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extern PyObject *_PyEval_BuiltinsFromGlobals(


static inline PyObject*
_PyEval_EvalFrame(PyThreadState *tstate, _Py_InterpreterFrame *fdata, int throwflag)
_PyEval_EvalFrame(PyThreadState *tstate, _PyInterpreterFrame *fdata, int throwflag)
{
return tstate->interp->eval_frame(tstate, fdata, throwflag);
}
Expand Do A935 wn Expand Up @@ -107,9 +107,9 @@ static inline void _Py_LeaveRecursiveCall_inline(void) {

#define Py_LeaveRecursiveCall() _Py_LeaveRecursiveCall_inline()

_Py_InterpreterFrame *_PyEval_GetFrameData(void);
_PyInterpreterFrame *_PyEval_GetFrameData(void);

PyObject *_Py_MakeCoro(PyFrameConstructor *, _Py_InterpreterFrame *);
PyObject *_Py_MakeCoro(PyFrameConstructor *, _PyInterpreterFrame *);

#ifdef __cplusplus
}
Expand Down
44 changes: 22 additions & 22 deletions Include/internal/pycore_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern "C" {

/* Internal-use-only frame object constructor */
PyFrameObject*
_PyFrame_New_NoTrack(_Py_InterpreterFrame *, int);
_PyFrame_New_NoTrack(_PyInterpreterFrame *, int);

/* These values are chosen so that the inline functions below all
* compare fdata->state to zero.
Expand All @@ -23,7 +23,7 @@ enum _framestate {

typedef signed char PyFrameState;

// The _Py_InterpreterFrame typedef is in Include/pyframeobject.h
// The _PyInterpreterFrame typedef is in Include/pyframeobject.h
struct _Py_execution_frame {
PyObject *globals;
PyObject *builtins;
Expand All @@ -32,34 +32,34 @@ struct _Py_execution_frame {
PyFrameObject *frame_obj; // Full frame object (if created)
/* Borrowed reference to a generator, or NULL */
PyObject *generator;
_Py_InterpreterFrame *previous;
_PyInterpreterFrame *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_InterpreterFrame_IsRunnable(_Py_InterpreterFrame *fdata) {
static inline int _PyInterpreterFrame_IsRunnable(_PyInterpreterFrame *fdata) {
return fdata->state < FRAME_EXECUTING;
}

static inline int _Py_InterpreterFrame_IsExecuting(_Py_InterpreterFrame *fdata) {
static inline int _PyInterpreterFrame_IsExecuting(_PyInterpreterFrame *fdata) {
return fdata->state == FRAME_EXECUTING;
}

static inline int _Py_InterpreterFrame_HasCompleted(_Py_InterpreterFrame *fdata) {
static inline int _PyInterpreterFrame_HasCompleted(_PyInterpreterFrame *fdata) {
return fdata->state > FRAME_EXECUTING;
}

#define FRAME_SPECIALS_SIZE ((sizeof(_Py_InterpreterFrame)-1)/sizeof(PyObject *))
#define FRAME_SPECIALS_SIZE ((sizeof(_PyInterpreterFrame)-1)/sizeof(PyObject *))

_Py_InterpreterFrame *
_Py_InterpreterFrame_HeapAlloc(PyFrameConstructor *con, PyObject *locals);
_PyInterpreterFrame *
_PyInterpreterFrame_HeapAlloc(PyFrameConstructor *con, PyObject *locals);

static inline void
_Py_InterpreterFrame_InitializeSpecials(
_Py_InterpreterFrame *fdata, PyFrameConstructor *con,
_PyInterpreterFrame_InitializeSpecials(
_PyInterpreterFrame *fdata, PyFrameConstructor *con,
PyObject *locals, int nlocalsplus)
{
fdata->code = (PyCodeObject *)Py_NewRef(con->fc_code);
Expand All @@ -78,27 +78,27 @@ _Py_InterpreterFrame_InitializeSpecials(
* that precedes this frame.
*/
static inline PyObject**
_Py_InterpreterFrame_GetLocalsArray(_Py_InterpreterFrame *fdata)
_PyInterpreterFrame_GetLocalsArray(_PyInterpreterFrame *fdata)
{
return ((PyObject **)fdata) - fdata->nlocalsplus;
}

/* For use by _Py_InterpreterFrame_GetFrameObject
/* For use by _PyInterpreterFrame_GetFrameObject
Do not call directly. */
PyFrameObject *
_Py_InterpreterFrame_MakeAndSetFrameObject(_Py_InterpreterFrame *fdata);
_PyInterpreterFrame_MakeAndSetFrameObject(_PyInterpreterFrame *fdata);

/* Gets the PyFrameObject for this frame, lazily
* creating it if necessary.
* Returns a borrowed referennce */
static inline PyFrameObject *
_Py_InterpreterFrame_GetFrameObject(_Py_InterpreterFrame *fdata)
_PyInterpreterFrame_GetFrameObject(_PyInterpreterFrame *fdata)
{
PyFrameObject *res = fdata->frame_obj;
if (res != NULL) {
return res;
}
return _Py_InterpreterFrame_MakeAndSetFrameObject(fdata);
return _PyInterpreterFrame_MakeAndSetFrameObject(fdata);
}

/* Clears all references in the frame.
Expand All @@ -111,21 +111,21 @@ _Py_InterpreterFrame_GetFrameObject(_Py_InterpreterFrame *fdata)
* frames like the ones in generators and coroutines.
*/
int
_Py_InterpreterFrame_Clear(_Py_InterpreterFrame *fdata, int take);
_PyInterpreterFrame_Clear(_PyInterpreterFrame *fdata, int take);

int
_Py_InterpreterFrame_Traverse(_Py_InterpreterFrame *fdata, visitproc visit, void *arg);
_PyInterpreterFrame_Traverse(_PyInterpreterFrame *fdata, visitproc visit, void *arg);

int
_Py_InterpreterFrame_FastToLocalsWithError(_Py_InterpreterFrame *frame);
_PyInterpreterFrame_FastToLocalsWithError(_PyInterpreterFrame *frame);

void
_Py_InterpreterFrame_LocalsToFast(_Py_InterpreterFrame *frame, int clear);
_PyInterpreterFrame_LocalsToFast(_PyInterpreterFrame *frame, int clear);

_Py_InterpreterFrame *_PyThreadState_PushFrame(
_PyInterpreterFrame *_PyThreadState_PushFrame(
PyThreadState *tstate, PyFrameConstructor *con, PyObject *locals);

void _PyThreadState_PopFrame(PyThreadState *tstate, _Py_InterpreterFrame *frame);
void _PyThreadState_PopFrame(PyThreadState *tstate, _PyInterpreterFrame *frame);

#ifdef __cplusplus
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Refactored internal APIs for the new lazy frame object creation to more
consistently distinguish between the full ``PyFrameObject`` Python object
implementation that is still used in the Python and C runtime state
introspection APIs (function prefix ``PyFrame``, field prefix ``f_``, typical
variable names ``frame`` and ``f``) and the new ``_Py_InterpreterFrame`` internal
variable names ``frame`` and ``f``) and the new ``_PyInterpreterFrame`` internal
frame data storage (C structs with no intrinsic instance lifecycle management)
that is now used for code execution (function prefix ``_Py_InterpreterFrame``, no
that is now used for code execution (function prefix ``_PyInterpreterFrame``, no
field prefix, typical variable name ``fdata``).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blurb details and date still need to be updated

4 changes: 2 additions & 2 deletions Misc/gdbinit
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ end
define pylocals
set $_i = 0
while $_i < f->f_fdata->code->co_nlocals
if _Py_InterpreterFrame_GetLocalsArray(f->f_fdata) + $_i != 0
if _PyInterpreterFrame_GetLocalsArray(f->f_fdata) + $_i != 0
set $_names = f->f_fdata->code->co_varnames
set $_name = PyUnicode_AsUTF8(PyTuple_GetItem($_names, $_i))
printf "%s:\n", $_name
pyo _Py_InterpreterFrame_GetLocalsArray(f->f_fdata)[$_i]
pyo _PyInterpreterFrame_GetLocalsArray(f->f_fdata)[$_i]
end
set $_i = $_i + 1
end
Expand Down
6 changes: 3 additions & 3 deletions Modules/_tracemalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ hashtable_compare_traceback(const void *key1, const void *key2)


static void
tracemalloc_get_frame(_Py_InterpreterFrame *fdata, frame_t *frame)
tracemalloc_get_frame(_PyInterpreterFrame *fdata, frame_t *frame)
{
frame->filename = unknown_filename;
int lineno = PyCode_Addr2Line(fdata->code, fdata->lasti*2);
Expand Down Expand Up @@ -393,7 +393,7 @@ traceback_get_frames(traceback_t *traceback)
return;
}

_Py_InterpreterFrame *fdata = tstate->fdata;
_PyInterpreterFrame *fdata = tstate->fdata;
for (; fdata != NULL;) {
if (traceback->nframe < _Py_tracemalloc_config.max_nframe) {
tracemalloc_get_frame(fdata, &traceback->frames[traceback->nframe]);
Expand All @@ -404,7 +404,7 @@ traceback_get_frames(traceback_t *traceback)
traceback->total_nframe++;
}

_Py_InterpreterFrame *back = fdata->previous;
_PyInterpreterFrame *back = fdata->previous;
fdata = back;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Modules/_xxsubinterpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1835,12 +1835,12 @@ _is_running(PyInterpreterState *interp)
}

assert(!PyErr_Occurred());
_Py_InterpreterFrame *fdata = tstate->fdata;
_PyInterpreterFrame *fdata = tstate->fdata;
if (fdata == NULL) {
return 0;
}

int executing = _Py_InterpreterFrame_IsExecuting(fdata);
int executing = _PyInterpreterFrame_IsExecuting(fdata);

return executing;
}
Expand Down
4 changes: 2 additions & 2 deletions Modules/signalmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1787,7 +1787,7 @@ _PyErr_CheckSignalsTstate(PyThreadState *tstate)
*/
_Py_atomic_store(&is_tripped, 0);

_Py_InterpreterFrame *fdata = tstate->fdata;
_PyInterpreterFrame *fdata = tstate->fdata;
signal_state_t *state = &signal_global_state;
for (int i = 1; i < NSIG; i++) {
if (!_Py_atomic_load_relaxed(&Handlers[i].tripped)) {
Expand Down Expand Up @@ -1823,7 +1823,7 @@ _PyErr_CheckSignalsTstate(PyThreadState *tstate)
arglist = Py_BuildValue("(iO)", i, Py_None);
}
else {
PyFrameObject *f = _Py_InterpreterFrame_GetFrameObject(fdata);
PyFrameObject *f = _PyInterpreterFrame_GetFrameObject(fdata);
if (f != NULL) {
arglist = Py_BuildValue("(iO)", i, f);
}
Expand Down
Loading
0