Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Move depth to frame structure for easier retrieval in debugging tools
  • Loading branch information
pablogsal committed Sep 21, 2021
commit 306e29f1bafe5023c913aebaa3f7b2f520e93091
1 change: 0 additions & 1 deletion Include/cpython/pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ typedef struct _cframe {
*/
int use_tracing;
struct _cframe *previous;
int depth;
} CFrame;

typedef struct _err_stackitem {
Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ _PyFrame_InitializeSpecials(
frame->generator = NULL;
frame->f_lasti = -1;
frame->f_state = FRAME_CREATED;
frame->depth = 0;
}

/* Gets the pointer to the locals array
Expand Down
8 changes: 3 additions & 5 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -1549,9 +1549,9 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
CFrame *prev_cframe = tstate->cframe;
cframe.use_tracing = prev_cframe->use_tracing;
cframe.previous = prev_cframe;
cframe.depth = 0;
tstate->cframe = &cframe;

assert(frame->depth == 0);
/* push frame */
tstate->frame = frame;

Expand Down Expand Up @@ -1585,7 +1585,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
}

resume_frame:
frame->depth = cframe.depth;
co = frame->f_code;
PyObject *names = co->co_names;
PyObject *consts = co->co_consts;
Expand Down Expand Up @@ -4668,8 +4667,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
STACK_SHRINK(oparg + 1);
// TODO: Transform the following into a goto
_PyFrame_SetStackPointer(frame, stack_pointer);
new_frame->depth = frame->depth + 1;
tstate->frame = frame = new_frame;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Note to self, no need to pop frame here because it's done on eval frame exit at exit_eval_frame.

cframe.depth++;
goto start_frame;
// res = _PyEval_EvalFrame(tstate, new_frame, 0);
// assert(_PyFrame_GetStackPointer(new_frame) == _PyFrame_Stackbase(new_frame));
Expand Down Expand Up @@ -5068,13 +5067,12 @@ MISS_WITH_OPARG_COUNTER(BINARY_ADD)
dtrace_function_return(frame);
_Py_LeaveRecursiveCall(tstate);

if (cframe.depth) {
if (frame->depth) {
_PyFrame_StackPush(frame->previous, retval);
if (_PyEvalFrameClearAndPop(tstate, frame)) {
retval = NULL;
}
frame = tstate->frame;
cframe.depth--;
if (retval == NULL) {
assert(_PyErr_Occurred(tstate));
throwflag = 1;
Expand Down