bpo-45256: Don't track the exact depth of each `InterpreterFrame` by brandtbucher · Pull Request #30372 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions Include/internal/pycore_frame.h
4 changes: 2 additions & 2 deletions Lib/test/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@ class C(object): pass
def func():
return sys._getframe()
x = func()
check(x, size('3Pi3c8P2iciP'))
check(x, size('3Pi3c8P2ic?P'))
# function
def func(): pass
check(func, size('14Pi'))
Expand All @@ -1340,7 +1340,7 @@ def bar(cls):
check(bar, size('PP'))
# generator
def get_gen(): yield 1
check(get_gen(), size('P2P4P4c8P2iciP'))
check(get_gen(), size('P2P4P4c8P2ic?P'))
# iterator
check(iter('abc'), size('lP'))
# callable-iterator
Expand Down
13 changes: 5 additions & 8 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -1683,7 +1683,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
cframe.previous = prev_cframe;
tstate->cframe = &cframe;

assert(frame->depth == 0);
frame->is_entry = true;
/* Push frame */
frame->previous = prev_cframe->current_frame;
cframe.current_frame = frame;
Expand Down Expand Up @@ -2310,7 +2310,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
_PyFrame_SetStackPointer(frame, stack_pointer);
new_frame->previous = frame;
frame = cframe.current_frame = new_frame;
new_frame->depth = frame->depth + 1;
goto start_frame;
}

Expand Down Expand Up @@ -2475,7 +2474,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
TRACE_FUNCTION_EXIT();
DTRACE_FUNCTION_EXIT();
_Py_LeaveRecursiveCall(tstate);
if (frame->depth) {
if (!frame->is_entry) {
frame = cframe.current_frame = pop_frame(tstate, frame);
_PyFrame_StackPush(frame, retval);
goto resume_frame;
Expand Down Expand Up @@ -2625,7 +2624,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
}

TARGET(SEND) {
assert(frame->depth == 0);
assert(frame->is_entry);
assert(STACK_LEVEL() >= 2);
PyObject *v = POP();
PyObject *receiver = TOP();
Expand Down Expand Up @@ -2684,7 +2683,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
}

TARGET(YIELD_VALUE) {
assert(frame->depth == 0);
assert(frame->is_entry);
PyObject *retval = POP();

if (frame->f_code->co_flags & CO_ASYNC_GENERATOR) {
Expand Down Expand Up @@ -4620,7 +4619,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
_PyFrame_SetStackPointer(frame, stack_pointer);
new_frame->previous = frame;
cframe.current_frame = frame = new_frame;
new_frame->depth = frame->depth + 1;
goto start_frame;
}
}
Expand Down Expand Up @@ -4714,7 +4712,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
_PyFrame_SetStackPointer(frame, stack_pointer);
new_frame->previous = frame;
frame = cframe.current_frame = new_frame;
new_frame->depth = frame->depth + 1;
goto start_frame;
}

Expand Down Expand Up @@ -5390,7 +5387,7 @@ MISS_WITH_OPARG_COUNTER(STORE_SUBSCR)
exit_unwind:
assert(_PyErr_Occurred(tstate));
_Py_LeaveRecursiveCall(tstate);
if (frame->depth == 0) {
if (frame->is_entry) {
/* Restore previous cframe and exit */
tstate->cframe = cframe.previous;
tstate->cframe->use_tracing = cframe.use_tracing;
Expand Down
10 changes: 5 additions & 5 deletions Tools/gdb/libpython.py