#define PyTrace_C_RETURN 6
#define PyTrace_OPCODE 7
-// Internal structure: you should not use it directly, but use public functions
-// like PyThreadState_EnterTracing() and PyThreadState_LeaveTracing().
-typedef struct _PyCFrame {
- /* This struct will be threaded through the C stack
- * allowing fast access to per-thread state that needs
- * to be accessed quickly by the interpreter, but can
- * be modified outside of the interpreter.
- *
- * WARNING: This makes data on the C stack accessible from
- * heap objects. Care must be taken to maintain stack
- * discipline and make sure that instances of this struct cannot
- * accessed outside of their lifetime.
- */
- /* Pointer to the currently executing frame (it can be NULL) */
- struct _PyInterpreterFrame *current_frame;
- struct _PyCFrame *previous;
-} _PyCFrame;
-
typedef struct _err_stackitem {
/* This struct represents a single execution context where we might
* be currently handling an exception. It is a per-coroutine state
int tracing;
int what_event; /* The event currently being monitored, if any. */
- /* Pointer to current _PyCFrame in the C stack frame of the currently,
- * or most recently, executing _PyEval_EvalFrameDefault. */
- _PyCFrame *cframe;
+ /* Pointer to currently executing frame. */
+ struct _PyInterpreterFrame *current_frame;
Py_tracefunc c_profilefunc;
Py_tracefunc c_tracefunc;
/* The thread's exception stack entry. (Always the last entry.) */
_PyErr_StackItem exc_state;
- /* The bottom-most frame on the stack. */
- _PyCFrame root_cframe;
};
/* WASI has limited call stack. Python's recursion limit depends on code
static inline _PyInterpreterFrame *
_PyThreadState_GetFrame(PyThreadState *tstate)
{
- return _PyFrame_GetFirstComplete(tstate->cframe->current_frame);
+ return _PyFrame_GetFirstComplete(tstate->current_frame);
}
/* For use by _PyFrame_GetFrameObject
off_t prev;
off_t next;
off_t interp;
- off_t cframe;
+ off_t current_frame;
off_t thread_id;
off_t native_thread_id;
} thread_state;
.prev = offsetof(PyThreadState, prev), \
.next = offsetof(PyThreadState, next), \
.interp = offsetof(PyThreadState, interp), \
- .cframe = offsetof(PyThreadState, cframe), \
+ .current_frame = offsetof(PyThreadState, current_frame), \
.thread_id = offsetof(PyThreadState, thread_id), \
.native_thread_id = offsetof(PyThreadState, native_thread_id), \
}, \
.localsplus = offsetof(_PyInterpreterFrame, localsplus), \
.owner = offsetof(_PyInterpreterFrame, owner), \
}, \
- .cframe = { \
- .current_frame = offsetof(_PyCFrame, current_frame), \
- .previous = offsetof(_PyCFrame, previous), \
- }, \
.code_object = { \
.filename = offsetof(PyCodeObject, co_filename), \
.name = offsetof(PyCodeObject, co_name), \
--- /dev/null
+Remove the ``_PyCFrame`` struct, moving the pointer to the current intepreter frame
+back to the threadstate, as it was for 3.10 and earlier. The ``_PyCFrame``
+existed as a performance optimization for tracing. Since PEP 669 has been
+implemented, this optimization no longer applies.
}
assert(!PyErr_Occurred());
- struct _PyInterpreterFrame *frame = tstate->cframe->current_frame;
+ struct _PyInterpreterFrame *frame = tstate->current_frame;
if (frame == NULL) {
return 0;
}
will be reported correctly to the user. */
/* XXX We should probably be updating the current frame
somewhere in ceval.c. */
- _PyInterpreterFrame *prev = tstate->cframe->current_frame;
+ _PyInterpreterFrame *prev = tstate->current_frame;
frame->previous = prev;
- tstate->cframe->current_frame = frame;
+ tstate->current_frame = frame;
/* Close the generator that we are currently iterating with
'yield from' or awaiting on with 'await'. */
PyFrameState state = gen->gi_frame_state;
ret = _gen_throw((PyGenObject *)yf, close_on_genexit,
typ, val, tb);
gen->gi_frame_state = state;
- tstate->cframe->current_frame = prev;
+ tstate->current_frame = prev;
frame->previous = NULL;
} else {
/* `yf` is an iterator or a coroutine-like object. */
if (origin_depth == 0) {
((PyCoroObject *)coro)->cr_origin_or_finalizer = NULL;
} else {
- _PyInterpreterFrame *frame = tstate->cframe->current_frame;
+ _PyInterpreterFrame *frame = tstate->current_frame;
assert(frame);
assert(_PyFrame_IsIncomplete(frame));
frame = _PyFrame_GetFirstComplete(frame->previous);
static PyObject *
caller(void)
{
- _PyInterpreterFrame *f = _PyThreadState_GET()->cframe->current_frame;
+ _PyInterpreterFrame *f = _PyThreadState_GET()->current_frame;
if (f == NULL) {
Py_RETURN_NONE;
}
_PyInterpreterFrame *frame,
unsigned char opcode,
unsigned int oparg,
- _PyCFrame cframe,
_Py_CODEUNIT *next_instr,
PyObject **stack_pointer,
PyObject *kwnames,
}
inst(RESUME, (--)) {
- assert(tstate->cframe == &cframe);
- assert(frame == cframe.current_frame);
+ assert(frame == tstate->current_frame);
/* Possibly combine this with eval breaker */
if (_PyFrame_GetCode(frame)->_co_instrumentation_version != tstate->interp->monitoring_version) {
int err = _Py_Instrument(_PyFrame_GetCode(frame), tstate->interp);
inst(INTERPRETER_EXIT, (retval --)) {
assert(frame == &entry_frame);
assert(_PyFrame_IsIncomplete(frame));
- /* Restore previous cframe and return. */
- tstate->cframe = cframe.previous;
- assert(tstate->cframe->current_frame == frame->previous);
+ /* Restore previous frame and return. */
+ tstate->current_frame = frame->previous;
assert(!_PyErr_Occurred(tstate));
tstate->c_recursion_remaining += PY_EVAL_C_STACK_UNITS;
return retval;
assert(frame != &entry_frame);
// GH-99729: We need to unlink the frame *before* clearing it:
_PyInterpreterFrame *dying = frame;
- frame = cframe.current_frame = dying->previous;
+ frame = tstate->current_frame = dying->previous;
_PyEvalFrameClearAndPop(tstate, dying);
frame->prev_instr += frame->return_offset;
_PyFrame_StackPush(frame, retval);
assert(frame != &entry_frame);
// GH-99729: We need to unlink the frame *before* clearing it:
_PyInterpreterFrame *dying = frame;
- frame = cframe.current_frame = dying->previous;
+ frame = tstate->current_frame = dying->previous;
_PyEvalFrameClearAndPop(tstate, dying);
frame->prev_instr += frame->return_offset;
_PyFrame_StackPush(frame, retval);
assert(frame != &entry_frame);
// GH-99729: We need to unlink the frame *before* clearing it:
_PyInterpreterFrame *dying = frame;
- frame = cframe.current_frame = dying->previous;
+ frame = tstate->current_frame = dying->previous;
_PyEvalFrameClearAndPop(tstate, dying);
frame->prev_instr += frame->return_offset;
_PyFrame_StackPush(frame, retval);
assert(frame != &entry_frame);
// GH-99729: We need to unlink the frame *before* clearing it:
_PyInterpreterFrame *dying = frame;
- frame = cframe.current_frame = dying->previous;
+ frame = tstate->current_frame = dying->previous;
_PyEvalFrameClearAndPop(tstate, dying);
frame->prev_instr += frame->return_offset;
_PyFrame_StackPush(frame, retval);
gen->gi_exc_state.previous_item = NULL;
_Py_LeaveRecursiveCallPy(tstate);
_PyInterpreterFrame *gen_frame = frame;
- frame = cframe.current_frame = frame->previous;
+ frame = tstate->current_frame = frame->previous;
gen_frame->previous = NULL;
_PyFrame_StackPush(frame, retval);
goto resume_frame;
gen->gi_exc_state.previous_item = NULL;
_Py_LeaveRecursiveCallPy(tstate);
_PyInterpreterFrame *gen_frame = frame;
- frame = cframe.current_frame = frame->previous;
+ frame = tstate->current_frame = frame->previous;
gen_frame->previous = NULL;
_PyFrame_StackPush(frame, retval);
goto resume_frame;
OBJECT_STAT_INC(optimization_attempts);
frame = _PyOptimizer_BackEdge(frame, here, next_instr, stack_pointer);
if (frame == NULL) {
- frame = cframe.current_frame;
+ frame = tstate->current_frame;
goto resume_with_error;
}
- assert(frame == cframe.current_frame);
+ assert(frame == tstate->current_frame);
here[1].cache &= ((1 << OPTIMIZER_BITS_IN_COUNTER) -1);
goto resume_frame;
}
Py_INCREF(executor);
frame = executor->execute(executor, frame, stack_pointer);
if (frame == NULL) {
- frame = cframe.current_frame;
+ frame = tstate->current_frame;
goto resume_with_error;
}
goto resume_frame;
_PyFrame_SetStackPointer(frame, stack_pointer);
new_frame->previous = frame;
CALL_STAT_INC(inlined_py_calls);
+ frame = tstate->current_frame = new_frame;
#if TIER_ONE
- frame = cframe.current_frame = new_frame;
goto start_frame;
#endif
#if TIER_TWO
- frame = tstate->cframe->current_frame = new_frame;
ERROR_IF(_Py_EnterRecursivePy(tstate), exit_unwind);
stack_pointer = _PyFrame_GetStackPointer(frame);
ip_offset = (_Py_CODEUNIT *)_PyFrame_GetCode(frame)->co_code_adaptive;
/* Link frames */
init_frame->previous = shim;
shim->previous = frame;
- frame = cframe.current_frame = init_frame;
+ frame = tstate->current_frame = init_frame;
CALL_STAT_INC(inlined_py_calls);
/* Account for pushing the extra frame.
* We don't check recursion depth here,
assert(frame != &entry_frame);
_PyInterpreterFrame *prev = frame->previous;
_PyThreadState_PopFrame(tstate, frame);
- frame = cframe.current_frame = prev;
+ frame = tstate->current_frame = prev;
_PyFrame_StackPush(frame, (PyObject *)gen);
goto resume_frame;
}
int lltrace = 0;
#endif
- _PyCFrame cframe;
_PyInterpreterFrame entry_frame;
PyObject *kwnames = NULL; // Borrowed reference. Reset by CALL instructions.
- /* WARNING: Because the _PyCFrame lives on the C stack,
- * but can be accessed from a heap allocated object (tstate)
- * strict stack discipline must be maintained.
- */
- _PyCFrame *prev_cframe = tstate->cframe;
- cframe.previous = prev_cframe;
- tstate->cframe = &cframe;
+
#ifdef Py_DEBUG
/* Set these to invalid but identifiable values for debugging. */
entry_frame.owner = FRAME_OWNED_BY_CSTACK;
entry_frame.return_offset = 0;
/* Push frame */
- entry_frame.previous = prev_cframe->current_frame;
+ entry_frame.previous = tstate->current_frame;
frame->previous = &entry_frame;
- cframe.current_frame = frame;
+ tstate->current_frame = frame;
tstate->c_recursion_remaining -= (PY_EVAL_C_STACK_UNITS - 1);
if (_Py_EnterRecursiveCallTstate(tstate, "")) {
assert(frame != &entry_frame);
// GH-99729: We need to unlink the frame *before* clearing it:
_PyInterpreterFrame *dying = frame;
- frame = cframe.current_frame = dying->previous;
+ frame = tstate->current_frame = dying->previous;
_PyEvalFrameClearAndPop(tstate, dying);
frame->return_offset = 0;
if (frame == &entry_frame) {
- /* Restore previous cframe and exit */
- tstate->cframe = cframe.previous;
- assert(tstate->cframe->current_frame == frame->previous);
+ /* Restore previous frame and exit */
+ tstate->current_frame = frame->previous;
tstate->c_recursion_remaining += PY_EVAL_C_STACK_UNITS;
return NULL;
}
PyEval_MergeCompilerFlags(PyCompilerFlags *cf)
{
PyThreadState *tstate = _PyThreadState_GET();
- _PyInterpreterFrame *current_frame = tstate->cframe->current_frame;
+ _PyInterpreterFrame *current_frame = tstate->current_frame;
int result = cf->cf_flags != 0;
if (current_frame != NULL) {
_PyFrame_SetStackPointer(frame, stack_pointer); \
frame->prev_instr = next_instr - 1; \
(NEW_FRAME)->previous = frame; \
- frame = cframe.current_frame = (NEW_FRAME); \
+ frame = tstate->current_frame = (NEW_FRAME); \
CALL_STAT_INC(inlined_py_calls); \
goto start_frame; \
} while (0)
STACK_SHRINK(1);
error:
// On ERROR_IF we return NULL as the frame.
- // The caller recovers the frame from cframe.current_frame.
+ // The caller recovers the frame from tstate->current_frame.
DPRINTF(2, "Error: [Opcode %d, operand %" PRIu64 "]\n", opcode, operand);
_PyFrame_SetStackPointer(frame, stack_pointer);
Py_DECREF(self);
_PyFrame_SetStackPointer(frame, stack_pointer);
new_frame->previous = frame;
CALL_STAT_INC(inlined_py_calls);
+ frame = tstate->current_frame = new_frame;
#if TIER_ONE
- frame = cframe.current_frame = new_frame;
goto start_frame;
#endif
#if TIER_TWO
- frame = tstate->cframe->current_frame = new_frame;
if (_Py_EnterRecursivePy(tstate)) goto pop_1_exit_unwind;
stack_pointer = _PyFrame_GetStackPointer(frame);
ip_offset = (_Py_CODEUNIT *)_PyFrame_GetCode(frame)->co_code_adaptive;
_PyFrame_GetGenerator(frame)->gi_frame_state == FRAME_CLEARED);
// GH-99729: Clearing this frame can expose the stack (via finalizers). It's
// crucial that this frame has been unlinked, and is no longer visible:
- assert(_PyThreadState_GET()->cframe->current_frame != frame);
+ assert(_PyThreadState_GET()->current_frame != frame);
if (frame->frame_obj) {
PyFrameObject *f = frame->frame_obj;
frame->frame_obj = NULL;
}
TARGET(RESUME) {
- assert(tstate->cframe == &cframe);
- assert(frame == cframe.current_frame);
+ assert(frame == tstate->current_frame);
/* Possibly combine this with eval breaker */
if (_PyFrame_GetCode(frame)->_co_instrumentation_version != tstate->interp->monitoring_version) {
int err = _Py_Instrument(_PyFrame_GetCode(frame), tstate->interp);
retval = stack_pointer[-1];
assert(frame == &entry_frame);
assert(_PyFrame_IsIncomplete(frame));
- /* Restore previous cframe and return. */
- tstate->cframe = cframe.previous;
- assert(tstate->cframe->current_frame == frame->previous);
+ /* Restore previous frame and return. */
+ tstate->current_frame = frame->previous;
assert(!_PyErr_Occurred(tstate));
tstate->c_recursion_remaining += PY_EVAL_C_STACK_UNITS;
return retval;
assert(frame != &entry_frame);
// GH-99729: We need to unlink the frame *before* clearing it:
_PyInterpreterFrame *dying = frame;
- frame = cframe.current_frame = dying->previous;
+ frame = tstate->current_frame = dying->previous;
_PyEvalFrameClearAndPop(tstate, dying);
frame->prev_instr += frame->return_offset;
_PyFrame_StackPush(frame, retval);
assert(frame != &entry_frame);
// GH-99729: We need to unlink the frame *before* clearing it:
_PyInterpreterFrame *dying = frame;
- frame = cframe.current_frame = dying->previous;
+ frame = tstate->current_frame = dying->previous;
_PyEvalFrameClearAndPop(tstate, dying);
frame->prev_instr += frame->return_offset;
_PyFrame_StackPush(frame, retval);
assert(frame != &entry_frame);
// GH-99729: We need to unlink the frame *before* clearing it:
_PyInterpreterFrame *dying = frame;
- frame = cframe.current_frame = dying->previous;
+ frame = tstate->current_frame = dying->previous;
_PyEvalFrameClearAndPop(tstate, dying);
frame->prev_instr += frame->return_offset;
_PyFrame_StackPush(frame, retval);
assert(frame != &entry_frame);
// GH-99729: We need to unlink the frame *before* clearing it:
_PyInterpreterFrame *dying = frame;
- frame = cframe.current_frame = dying->previous;
+ frame = tstate->current_frame = dying->previous;
_PyEvalFrameClearAndPop(tstate, dying);
frame->prev_instr += frame->return_offset;
_PyFrame_StackPush(frame, retval);
gen->gi_exc_state.previous_item = NULL;
_Py_LeaveRecursiveCallPy(tstate);
_PyInterpreterFrame *gen_frame = frame;
- frame = cframe.current_frame = frame->previous;
+ frame = tstate->current_frame = frame->previous;
gen_frame->previous = NULL;
_PyFrame_StackPush(frame, retval);
goto resume_frame;
gen->gi_exc_state.previous_item = NULL;
_Py_LeaveRecursiveCallPy(tstate);
_PyInterpreterFrame *gen_frame = frame;
- frame = cframe.current_frame = frame->previous;
+ frame = tstate->current_frame = frame->previous;
gen_frame->previous = NULL;
_PyFrame_StackPush(frame, retval);
goto resume_frame;
OBJECT_STAT_INC(optimization_attempts);
frame = _PyOptimizer_BackEdge(frame, here, next_instr, stack_pointer);
if (frame == NULL) {
- frame = cframe.current_frame;
+ frame = tstate->current_frame;
goto resume_with_error;
}
- assert(frame == cframe.current_frame);
+ assert(frame == tstate->current_frame);
here[1].cache &= ((1 << OPTIMIZER_BITS_IN_COUNTER) -1);
goto resume_frame;
}
Py_INCREF(executor);
frame = executor->execute(executor, frame, stack_pointer);
if (frame == NULL) {
- frame = cframe.current_frame;
+ frame = tstate->current_frame;
goto resume_with_error;
}
goto resume_frame;
_PyFrame_SetStackPointer(frame, stack_pointer);
new_frame->previous = frame;
CALL_STAT_INC(inlined_py_calls);
+ frame = tstate->current_frame = new_frame;
#if TIER_ONE
- frame = cframe.current_frame = new_frame;
goto start_frame;
#endif
#if TIER_TWO
- frame = tstate->cframe->current_frame = new_frame;
if (_Py_EnterRecursivePy(tstate)) goto pop_1_exit_unwind;
stack_pointer = _PyFrame_GetStackPointer(frame);
ip_offset = (_Py_CODEUNIT *)_PyFrame_GetCode(frame)->co_code_adaptive;
/* Link frames */
init_frame->previous = shim;
shim->previous = frame;
- frame = cframe.current_frame = init_frame;
+ frame = tstate->current_frame = init_frame;
CALL_STAT_INC(inlined_py_calls);
/* Account for pushing the extra frame.
* We don't check recursion depth here,
assert(frame != &entry_frame);
_PyInterpreterFrame *prev = frame->previous;
_PyThreadState_PopFrame(tstate, frame);
- frame = cframe.current_frame = prev;
+ frame = tstate->current_frame = prev;
_PyFrame_StackPush(frame, (PyObject *)gen);
goto resume_frame;
}
PyThreadState* ts = PyInterpreterState_ThreadHead(interp);
HEAD_UNLOCK(runtime);
while (ts) {
- _PyInterpreterFrame *frame = ts->cframe->current_frame;
+ _PyInterpreterFrame *frame = ts->current_frame;
while (frame) {
if (frame->owner != FRAME_OWNED_BY_CSTACK) {
if (_Py_Instrument(_PyFrame_GetCode(frame), interp)) {
static PyObject *
import_star(PyThreadState* tstate, PyObject *from)
{
- _PyInterpreterFrame *frame = tstate->cframe->current_frame;
+ _PyInterpreterFrame *frame = tstate->current_frame;
if (_PyFrame_FastToLocalsWithError(frame) < 0) {
return NULL;
}
static PyObject *
stopiteration_error(PyThreadState* tstate, PyObject *exc)
{
- _PyInterpreterFrame *frame = tstate->cframe->current_frame;
+ _PyInterpreterFrame *frame = tstate->current_frame;
assert(frame->owner == FRAME_OWNED_BY_GENERATOR);
assert(PyExceptionInstance_Check(exc));
const char *msg = NULL;
if (tstate != _PyThreadState_GET()) {
Py_FatalError("thread is not current");
}
- if (tstate->cframe->current_frame != NULL) {
+ if (tstate->current_frame != NULL) {
Py_FatalError("thread still has a frame");
}
interp->finalizing = 1;
// This is cleared when PyGILState_Ensure() creates the thread state.
tstate->gilstate_counter = 1;
- tstate->cframe = &tstate->root_cframe;
+ tstate->current_frame = NULL;
tstate->datastack_chunk = NULL;
tstate->datastack_top = NULL;
tstate->datastack_limit = NULL;
int verbose = _PyInterpreterState_GetConfig(tstate->interp)->verbose;
- if (verbose && tstate->cframe->current_frame != NULL) {
+ if (verbose && tstate->current_frame != NULL) {
/* bpo-20526: After the main thread calls
_PyInterpreterState_SetFinalizing() in Py_FinalizeEx()
(or in Py_EndInterpreter() for subinterpreters),
for (i = runtime->interpreters.head; i != NULL; i = i->next) {
PyThreadState *t;
for (t = i->threads.head; t != NULL; t = t->next) {
- _PyInterpreterFrame *frame = t->cframe->current_frame;
+ _PyInterpreterFrame *frame = t->current_frame;
frame = _PyFrame_GetFirstComplete(frame);
if (frame == NULL) {
continue;
/*[clinic end generated code: output=d438776c04d59804 input=c1be8a6464b11ee5]*/
{
PyThreadState *tstate = _PyThreadState_GET();
- _PyInterpreterFrame *frame = tstate->cframe->current_frame;
+ _PyInterpreterFrame *frame = tstate->current_frame;
if (frame != NULL) {
while (depth > 0) {
if (PySys_Audit("sys._getframemodulename", "i", depth) < 0) {
return NULL;
}
- _PyInterpreterFrame *f = _PyThreadState_GET()->cframe->current_frame;
+ _PyInterpreterFrame *f = _PyThreadState_GET()->current_frame;
while (f && (_PyFrame_IsIncomplete(f) || depth-- > 0)) {
f = f->previous;
}
PUTS(fd, "Stack (most recent call first):\n");
}
- frame = tstate->cframe->current_frame;
+ frame = tstate->current_frame;
if (frame == NULL) {
PUTS(fd, " <no Python frame>\n");
return;