Py_INCREF(result);
_PyFrame_StackPush(frame, result);
- frame->previous = tstate->frame;
+ frame->previous = tstate->cframe->current_frame;
gen->gi_exc_state.previous_item = tstate->exc_info;
tstate->exc_info = &gen->gi_exc_state;
tstate->exc_info = gen->gi_exc_state.previous_item;
gen->gi_exc_state.previous_item = NULL;
- assert(tstate->frame == frame->previous);
+ assert(tstate->cframe->current_frame == frame->previous);
/* Don't keep the reference to previous any longer than necessary. It
* may keep a chain of frames alive or it could create a reference
* cycle. */
will be reported correctly to the user. */
/* XXX We should probably be updating the current frame
somewhere in ceval.c. */
- InterpreterFrame *prev = tstate->frame;
+ InterpreterFrame *prev = tstate->cframe->current_frame;
frame->previous = prev;
- tstate->frame = frame;
+ tstate->cframe->current_frame = frame;
/* Close the generator that we are currently iterating with
'yield from' or awaiting on with 'await'. */
PyFrameState state = gen->gi_xframe->f_state;
ret = _gen_throw((PyGenObject *)yf, close_on_genexit,
typ, val, tb);
gen->gi_xframe->f_state = state;
- tstate->frame = prev;
+ tstate->cframe->current_frame = prev;
frame->previous = NULL;
} else {
/* `yf` is an iterator or a coroutine-like object. */
tstate->cframe = &cframe;
assert(frame->depth == 0);
- /* push frame */
- tstate->frame = frame;
+ /* Push frame */
+ frame->previous = prev_cframe->current_frame;
+ cframe.current_frame = frame;
start_frame:
if (_Py_EnterRecursiveCall(tstate, "")) {
goto exit_eval_frame;
}
- assert(frame == tstate->frame);
+ assert(tstate->cframe == &cframe);
+ assert(frame == cframe.current_frame);
if (cframe.use_tracing) {
if (trace_function_entry(tstate, frame)) {
goto error;
}
_PyFrame_SetStackPointer(frame, stack_pointer);
+ new_frame->previous = frame;
+ cframe.current_frame = frame = new_frame;
new_frame->depth = frame->depth + 1;
- tstate->frame = frame = new_frame;
goto start_frame;
}
}
STACK_SHRINK(1);
Py_DECREF(func);
_PyFrame_SetStackPointer(frame, stack_pointer);
- new_frame->previous = tstate->frame;
+ new_frame->previous = frame;
+ frame = cframe.current_frame = new_frame;
new_frame->depth = frame->depth + 1;
- tstate->frame = frame = new_frame;
goto start_frame;
}
_Py_LeaveRecursiveCall(tstate);
if (frame->depth) {
- _PyFrame_StackPush(frame->previous, retval);
+ cframe.current_frame = frame->previous;
+ _PyFrame_StackPush(cframe.current_frame, retval);
if (_PyEvalFrameClearAndPop(tstate, frame)) {
retval = NULL;
}
- frame = tstate->frame;
+ frame = cframe.current_frame;
if (retval == NULL) {
assert(_PyErr_Occurred(tstate));
throwflag = 1;
retval = NULL;
goto resume_frame;
}
- tstate->frame = frame->previous;
- /* Restore previous cframe */
+ /* Restore previous cframe. */
tstate->cframe = cframe.previous;
tstate->cframe->use_tracing = cframe.use_tracing;
+ assert(tstate->cframe->current_frame == frame->previous);
return _Py_CheckFunctionResult(tstate, NULL, retval, __func__);
}
_PyFrame_Clear(frame, 0);
return NULL;
}
- frame->previous = tstate->frame;
- tstate->frame = frame;
return frame;
}
return -1;
}
--tstate->recursion_depth;
- tstate->frame = frame->previous;
_PyThreadState_PopFrame(tstate, frame);
return 0;
}
_PyEval_GetFrame(void)
{
PyThreadState *tstate = _PyThreadState_GET();
- return tstate->frame;
+ return tstate->cframe->current_frame;
}
PyFrameObject *
PyEval_GetFrame(void)
{
PyThreadState *tstate = _PyThreadState_GET();
- if (tstate->frame == NULL) {
+ if (tstate->cframe->current_frame == NULL) {
return NULL;
}
- PyFrameObject *f = _PyFrame_GetFrameObject(tstate->frame);
+ PyFrameObject *f = _PyFrame_GetFrameObject(tstate->cframe->current_frame);
if (f == NULL) {
PyErr_Clear();
}
PyObject *
_PyEval_GetBuiltins(PyThreadState *tstate)
{
- InterpreterFrame *frame = tstate->frame;
+ InterpreterFrame *frame = tstate->cframe->current_frame;
if (frame != NULL) {
return frame->f_builtins;
}
PyEval_GetLocals(void)
{
PyThreadState *tstate = _PyThreadState_GET();
- InterpreterFrame *current_frame = tstate->frame;
+ InterpreterFrame *current_frame = tstate->cframe->current_frame;
if (current_frame == NULL) {
_PyErr_SetString(tstate, PyExc_SystemError, "frame does not exist");
return NULL;
PyEval_GetGlobals(void)
{
PyThreadState *tstate = _PyThreadState_GET();
- InterpreterFrame *current_frame = tstate->frame;
+ InterpreterFrame *current_frame = tstate->cframe->current_frame;
if (current_frame == NULL) {
return NULL;
}
PyEval_MergeCompilerFlags(PyCompilerFlags *cf)
{
PyThreadState *tstate = _PyThreadState_GET();
- InterpreterFrame *current_frame = tstate->frame;
+ InterpreterFrame *current_frame = tstate->cframe->current_frame;
int result = cf->cf_flags != 0;
if (current_frame != NULL) {
#define C_TRACE(x, call) \
if (use_tracing && tstate->c_profilefunc) { \
if (call_trace(tstate->c_profilefunc, tstate->c_profileobj, \
- tstate, tstate->frame, \
+ tstate, tstate->cframe->current_frame, \
PyTrace_C_CALL, func)) { \
x = NULL; \
} \
if (x == NULL) { \
call_trace_protected(tstate->c_profilefunc, \
tstate->c_profileobj, \
- tstate, tstate->frame, \
+ tstate, tstate->cframe->current_frame, \
PyTrace_C_EXCEPTION, func); \
/* XXX should pass (type, value, tb) */ \
} else { \
if (call_trace(tstate->c_profilefunc, \
tstate->c_profileobj, \
- tstate, tstate->frame, \
+ tstate, tstate->cframe->current_frame, \
PyTrace_C_RETURN, func)) { \
Py_DECREF(x); \
x = NULL; \
tstate->interp = interp;
- tstate->frame = NULL;
tstate->recursion_depth = 0;
tstate->recursion_headroom = 0;
tstate->stackcheck_counter = 0;
tstate->tracing = 0;
tstate->root_cframe.use_tracing = 0;
+ tstate->root_cframe.current_frame = NULL;
tstate->cframe = &tstate->root_cframe;
tstate->gilstate_counter = 0;
tstate->async_exc = NULL;
{
int verbose = _PyInterpreterState_GetConfig(tstate->interp)->verbose;
- if (verbose && tstate->frame != NULL) {
+ if (verbose && tstate->cframe->current_frame != NULL) {
/* bpo-20526: After the main thread calls
_PyRuntimeState_SetFinalizing() in Py_FinalizeEx(), threads must
exit when trying to take the GIL. If a thread exit in the middle of
PyThreadState_GetFrame(PyThreadState *tstate)
{
assert(tstate != NULL);
- if (tstate->frame == NULL) {
+ if (tstate->cframe->current_frame == NULL) {
return NULL;
}
- PyFrameObject *frame = _PyFrame_GetFrameObject(tstate->frame);
+ PyFrameObject *frame = _PyFrame_GetFrameObject(tstate->cframe->current_frame);
if (frame == NULL) {
PyErr_Clear();
}
for (i = runtime->interpreters.head; i != NULL; i = i->next) {
PyThreadState *t;
for (t = i->tstate_head; t != NULL; t = t->next) {
- InterpreterFrame *frame = t->frame;
+ InterpreterFrame *frame = t->cframe->current_frame;
if (frame == NULL) {
continue;
}