diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index b7e9dc6e9e37f8..7cf0e8d6df8d06 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -954,13 +954,13 @@ Porting to Python 3.11 * ``f_lineno``: use :c:func:`PyFrame_GetLineNumber` * ``f_locals``: use ``PyObject_GetAttrString((PyObject*)frame, "f_locals")``. * ``f_stackdepth``: removed. - * ``f_state``: no public API (renamed to ``f_frame.f_state``). + * ``f_state``: no public API. * ``f_trace``: no public API. * ``f_trace_lines``: use ``PyObject_GetAttrString((PyObject*)frame, "f_trace_lines")`` (it also be modified). * ``f_trace_opcodes``: use ``PyObject_GetAttrString((PyObject*)frame, "f_trace_opcodes")`` (it also be modified). - * ``f_localsplus``: no public API (renamed to ``f_frame.localsplus``). + * ``f_localsplus``: no public API. * ``f_valuestack``: removed. The Python frame object is now created lazily. A side effect is that the diff --git a/Include/cpython/ceval.h b/Include/cpython/ceval.h index 9d4eeafb427eb2..300401935075cc 100644 --- a/Include/cpython/ceval.h +++ b/Include/cpython/ceval.h @@ -15,7 +15,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, struct _PyInterpreterFrame *f, int exc); +PyAPI_FUNC(PyObject *) _PyEval_EvalFrameDefault(PyThreadState *tstate, struct _Py_frame *f, int exc); PyAPI_FUNC(void) _PyEval_SetSwitchInterval(unsigned long microseconds); PyAPI_FUNC(unsigned long) _PyEval_GetSwitchInterval(void); diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h index 26d6f7576e524f..a168bf68e2d4a3 100644 --- a/Include/cpython/pystate.h +++ b/Include/cpython/pystate.h @@ -48,7 +48,7 @@ typedef struct _PyCFrame { */ int use_tracing; /* Pointer to the currently executing frame (it can be NULL) */ - struct _PyInterpreterFrame *current_frame; + struct _Py_frame *current_frame; struct _PyCFrame *previous; } _PyCFrame; @@ -260,7 +260,7 @@ PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void); /* Frame evaluation API */ -typedef PyObject* (*_PyFrameEvalFunction)(PyThreadState *tstate, struct _PyInterpreterFrame *, int); +typedef PyObject* (*_PyFrameEvalFunction)(PyThreadState *tstate, struct _Py_frame *, int); PyAPI_FUNC(_PyFrameEvalFunction) _PyInterpreterState_GetEvalFrameFunc( PyInterpreterState *interp); diff --git a/Include/internal/pycore_ceval.h b/Include/internal/pycore_ceval.h index 45d26a37a34c69..2a07985cc728ef 100644 --- a/Include/internal/pycore_ceval.h +++ b/Include/internal/pycore_ceval.h @@ -60,7 +60,7 @@ extern PyObject* _PyEval_BuiltinsFromGlobals( static inline PyObject* -_PyEval_EvalFrame(PyThreadState *tstate, struct _PyInterpreterFrame *frame, int throwflag) +_PyEval_EvalFrame(PyThreadState *tstate, struct _Py_frame *frame, int throwflag) { if (tstate->interp->eval_frame == NULL) { return _PyEval_EvalFrameDefault(tstate, frame, throwflag); @@ -129,7 +129,7 @@ static inline void _Py_LeaveRecursiveCall_inline(void) { #define Py_LeaveRecursiveCall() _Py_LeaveRecursiveCall_inline() -extern struct _PyInterpreterFrame* _PyEval_GetFrame(void); +extern struct _Py_frame* _PyEval_GetFrame(void); extern PyObject* _Py_MakeCoro(PyFunctionObject *func); diff --git a/Include/internal/pycore_frame.h b/Include/internal/pycore_frame.h index e2f551ef2c0629..c9e7f79a66f247 100644 --- a/Include/internal/pycore_frame.h +++ b/Include/internal/pycore_frame.h @@ -6,10 +6,83 @@ extern "C" { #include +/* Starting in CPython 3.11, CPython separates the frame state between the + * full frame objects exposed by the Python and C runtime state introspection + * APIs, and internal lighter weight frame data structs, which are simple C + * structures owned by either the interpreter eval loop (while executing + * ordinary functions), by a generator or coroutine object (for frames that + * are able to be suspended), or by their corresponding full frame object (if + * a state instrospection API has been invoked and the full frame object has + * taken responsibility for the lifecycle of the frame data storage). + * + * This split storage eliminates a lot of allocation and deallocation of full + * Python objects during code execution, providing a significant speed gain + * over the previous approach of using full Python objects for both + * introspection and code execution. + * + * Struct names: + * + * * PyFrameObject: the full Python frame object + * * _Py_frame: the lightweight frame data struct + * * _PyInterpreterFrame is an interim alias for this (see comment below) + * * _PyCFrame: a struct that lives on the C stack and allows Python level + * recursive evaluation to be decoupled from recursive C level invocation + * of the bytecode eval loop + * * See pystate.h for more details on this struct + * + * Field naming conventions: + * + * * full frame object fields have an "f_*" prefix + * * new frame data struct fields have no prefix + * * Several frame data struct fields have the "f_*" prefix as a result of + * trying to keep diffs as small as was feasible when splitting the original + * frame struct definition in two. The following are all frame data struct + * fields, NOT full frame object fields: + * * f_func + * * f_globals + * * f_builtins + * * f_locals + * * f_code + * * f_lasti + * * f_state + * * Renaming those fields was considered but ultimately deemed too disruptive + * to key third party projects that were trying to keep up with the Python + * 3.11 code evaluation changes during the alpha release cycle + * (see bpo-44800 for details) + * + * Naming conventions for local variables, function parameters and fields in other structs: + * + * * "frame", and "f" may refer to either full frame objects or frame data structs + * * the field naming convention usually makes the type unambiguous in code reviews + * * the following alternative names are used when more clarity is needed: + * * full frame objects: "frame_obj" (and variants like "frameobj" or "fobj") + * * frame data structs: "fdata" + * * the "iframe" name is still used in the generator & coroutine structs. It + * comes from the period where frame data structs were called "interpreter frames" + * (which implied a larger distinction between full frame objects and their + * associated lightweight frame data structs than is actually the case). + * * "current frame" should NOT be abbreviated as "cframe", as the latter now + * typically refers to _PyCFrame structs + * + * Function/macro parameter types: + * + * * "PyFrame_*" functions and other public C API functions that relate to + * frames accept full frame objects + * * "_PyFrame_*" functions and other private C API functions that relate to + * frames accept either full frame objects or frame data structs. Check + * the specific function signatures for details. + * + * Function return types: + * + * * Public C API functions will only ever return full frame objects + * * Private C API functions with an underscore prefix may return frame + * data structs instead. Check the specific function signatures for details. + */ + struct _frame { PyObject_HEAD PyFrameObject *f_back; /* previous frame, or NULL */ - struct _PyInterpreterFrame *f_frame; /* points to the frame data */ + struct _Py_frame *f_frame; /* points to the frame 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? */ @@ -44,63 +117,78 @@ typedef signed char PyFrameState; unless it's -1 in which case next_instr should be first_instr. */ -typedef struct _PyInterpreterFrame { +typedef struct _Py_frame { PyFunctionObject *f_func; /* Strong reference */ PyObject *f_globals; /* Borrowed reference */ PyObject *f_builtins; /* Borrowed reference */ PyObject *f_locals; /* Strong reference, may be NULL */ PyCodeObject *f_code; /* Strong reference */ PyFrameObject *frame_obj; /* Strong reference, may be NULL */ - struct _PyInterpreterFrame *previous; + struct _Py_frame *previous; int f_lasti; /* Last instruction if called */ int stacktop; /* Offset of TOS from localsplus */ PyFrameState f_state; /* What state the frame is in */ bool is_entry; // Whether this is the "root" frame for the current _PyCFrame. bool is_generator; PyObject *localsplus[1]; -} _PyInterpreterFrame; +} _Py_frame; + +/* Interim compatibility for the internal frame API as shipped in 3.11a6 + * Some projects (Cython, gevent, greenlet) are known to access the private + * frame API in CPython. This API has already changed twice for 3.11 (first + * with the structural split, then with the full object structure becoming + * opaque and internal struct gaining the `_Py` prefix). The recommended + * resolution is expected to change again once a proper public API for the + * required frame operations is defined (as discussed in + * https://github.com/faster-cpython/ideas/issues/309). + * + * This interim compatibility workaround enables the bpo-44800 struct name + * change for CPython maintainability without forcing yet another interim + * code update on the affected projects. + */ +typedef _Py_frame _PyInterpreterFrame; -static inline int _PyFrame_IsRunnable(_PyInterpreterFrame *f) { +static inline int _PyFrame_IsRunnable(_Py_frame *f) { return f->f_state < FRAME_EXECUTING; } -static inline int _PyFrame_IsExecuting(_PyInterpreterFrame *f) { +static inline int _PyFrame_IsExecuting(_Py_frame *f) { return f->f_state == FRAME_EXECUTING; } -static inline int _PyFrameHasCompleted(_PyInterpreterFrame *f) { +static inline int _PyFrameHasCompleted(_Py_frame *f) { return f->f_state > FRAME_EXECUTING; } -static inline PyObject **_PyFrame_Stackbase(_PyInterpreterFrame *f) { +static inline PyObject **_PyFrame_Stackbase(_Py_frame *f) { return f->localsplus + f->f_code->co_nlocalsplus; } -static inline PyObject *_PyFrame_StackPeek(_PyInterpreterFrame *f) { +static inline PyObject *_PyFrame_StackPeek(_Py_frame *f) { assert(f->stacktop > f->f_code->co_nlocalsplus); assert(f->localsplus[f->stacktop-1] != NULL); return f->localsplus[f->stacktop-1]; } -static inline PyObject *_PyFrame_StackPop(_PyInterpreterFrame *f) { +static inline PyObject *_PyFrame_StackPop(_Py_frame *f) { assert(f->stacktop > f->f_code->co_nlocalsplus); f->stacktop--; return f->localsplus[f->stacktop]; } -static inline void _PyFrame_StackPush(_PyInterpreterFrame *f, PyObject *value) { +static inline void _PyFrame_StackPush(_Py_frame *f, PyObject *value) { f->localsplus[f->stacktop] = value; f->stacktop++; } -#define FRAME_SPECIALS_SIZE ((sizeof(_PyInterpreterFrame)-1)/sizeof(PyObject *)) +#define FRAME_SPECIALS_SIZE ((sizeof(_Py_frame)-1)/sizeof(PyObject *)) -void _PyFrame_Copy(_PyInterpreterFrame *src, _PyInterpreterFrame *dest); +void _PyFrame_Copy(_Py_frame *src, _Py_frame *dest); /* Consumes reference to func */ static inline void _PyFrame_InitializeSpecials( - _PyInterpreterFrame *frame, PyFunctionObject *func, + _Py_frame *frame, PyFunctionObject *func, PyObject *locals, int nlocalsplus) { frame->f_func = func; @@ -120,19 +208,19 @@ _PyFrame_InitializeSpecials( * that precedes this frame. */ static inline PyObject** -_PyFrame_GetLocalsArray(_PyInterpreterFrame *frame) +_PyFrame_GetLocalsArray(_Py_frame *frame) { return frame->localsplus; } static inline PyObject** -_PyFrame_GetStackPointer(_PyInterpreterFrame *frame) +_PyFrame_GetStackPointer(_Py_frame *frame) { return frame->localsplus+frame->stacktop; } static inline void -_PyFrame_SetStackPointer(_PyInterpreterFrame *frame, PyObject **stack_pointer) +_PyFrame_SetStackPointer(_Py_frame *frame, PyObject **stack_pointer) { frame->stacktop = (int)(stack_pointer - frame->localsplus); } @@ -140,13 +228,13 @@ _PyFrame_SetStackPointer(_PyInterpreterFrame *frame, PyObject **stack_pointer) /* For use by _PyFrame_GetFrameObject Do not call directly. */ PyFrameObject * -_PyFrame_MakeAndSetFrameObject(_PyInterpreterFrame *frame); +_PyFrame_MakeAndSetFrameObject(_Py_frame *frame); /* Gets the PyFrameObject for this frame, lazily * creating it if necessary. * Returns a borrowed referennce */ static inline PyFrameObject * -_PyFrame_GetFrameObject(_PyInterpreterFrame *frame) +_PyFrame_GetFrameObject(_Py_frame *frame) { PyFrameObject *res = frame->frame_obj; if (res != NULL) { @@ -156,7 +244,7 @@ _PyFrame_GetFrameObject(_PyInterpreterFrame *frame) } /* Clears all references in the frame. - * If take is non-zero, then the _PyInterpreterFrame frame + * If take is non-zero, then the _Py_frame frame * may be transferred to the frame object it references * instead of being cleared. Either way * the caller no longer owns the references @@ -165,21 +253,21 @@ _PyFrame_GetFrameObject(_PyInterpreterFrame *frame) * frames like the ones in generators and coroutines. */ void -_PyFrame_Clear(_PyInterpreterFrame * frame); +_PyFrame_Clear(_Py_frame * frame); int -_PyFrame_Traverse(_PyInterpreterFrame *frame, visitproc visit, void *arg); +_PyFrame_Traverse(_Py_frame *frame, visitproc visit, void *arg); int -_PyFrame_FastToLocalsWithError(_PyInterpreterFrame *frame); +_PyFrame_FastToLocalsWithError(_Py_frame *frame); void -_PyFrame_LocalsToFast(_PyInterpreterFrame *frame, int clear); +_PyFrame_LocalsToFast(_Py_frame *frame, int clear); -extern _PyInterpreterFrame * +extern _Py_frame * _PyThreadState_BumpFramePointerSlow(PyThreadState *tstate, size_t size); -static inline _PyInterpreterFrame * +static inline _Py_frame * _PyThreadState_BumpFramePointer(PyThreadState *tstate, size_t size) { PyObject **base = tstate->datastack_top; @@ -188,16 +276,16 @@ _PyThreadState_BumpFramePointer(PyThreadState *tstate, size_t size) assert(tstate->datastack_limit); if (top < tstate->datastack_limit) { tstate->datastack_top = top; - return (_PyInterpreterFrame *)base; + return (_Py_frame *)base; } } return _PyThreadState_BumpFramePointerSlow(tstate, size); } -void _PyThreadState_PopFrame(PyThreadState *tstate, _PyInterpreterFrame *frame); +void _PyThreadState_PopFrame(PyThreadState *tstate, _Py_frame *frame); /* Consume reference to func */ -_PyInterpreterFrame * +_Py_frame * _PyFrame_Push(PyThreadState *tstate, PyFunctionObject *func); #ifdef __cplusplus diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-03-19-21-47-36.bpo-44800.XnGKoD.rst b/Misc/NEWS.d/next/Core and Builtins/2022-03-19-21-47-36.bpo-44800.XnGKoD.rst new file mode 100644 index 00000000000000..5d6313360f6c89 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-03-19-21-47-36.bpo-44800.XnGKoD.rst @@ -0,0 +1,5 @@ +Renamed ``_PyInterpreterFrame`` as ``_Py_frame`` to emphasise its close +association with ``PyFrameObject`` (they're conceptually the same thing, but +split into a Python object struct and a C data struct as a performance +optimisation). ``_PyInterpreterFrame`` is retained as a compatibility alias +to avoid any disruption to the Python 3.11 performance improvement work. diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c index 738d54530c9674..87b847855e5ae4 100644 --- a/Modules/_tracemalloc.c +++ b/Modules/_tracemalloc.c @@ -305,7 +305,7 @@ hashtable_compare_traceback(const void *key1, const void *key2) static void -tracemalloc_get_frame(_PyInterpreterFrame *pyframe, frame_t *frame) +tracemalloc_get_frame(_Py_frame *pyframe, frame_t *frame) { frame->filename = &_Py_STR(anon_unknown); int lineno = PyCode_Addr2Line(pyframe->f_code, pyframe->f_lasti*sizeof(_Py_CODEUNIT)); @@ -399,7 +399,7 @@ traceback_get_frames(traceback_t *traceback) return; } - _PyInterpreterFrame *pyframe = tstate->cframe->current_frame; + _Py_frame *pyframe = tstate->cframe->current_frame; for (; pyframe != NULL;) { if (traceback->nframe < _Py_tracemalloc_config.max_nframe) { tracemalloc_get_frame(pyframe, &traceback->frames[traceback->nframe]); @@ -410,7 +410,7 @@ traceback_get_frames(traceback_t *traceback) traceback->total_nframe++; } - _PyInterpreterFrame *back = pyframe->previous; + _Py_frame *back = pyframe->previous; pyframe = back; } } diff --git a/Modules/_xxsubinterpretersmodule.c b/Modules/_xxsubinterpretersmodule.c index 846b24d5efa9a6..d7c7580f4442a3 100644 --- a/Modules/_xxsubinterpretersmodule.c +++ b/Modules/_xxsubinterpretersmodule.c @@ -1839,7 +1839,7 @@ _is_running(PyInterpreterState *interp) } assert(!PyErr_Occurred()); - _PyInterpreterFrame *frame = tstate->cframe->current_frame; + _Py_frame *frame = tstate->cframe->current_frame; if (frame == NULL) { return 0; } diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c index 9566263a0dd87e..9bdcf874354840 100644 --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -8,7 +8,7 @@ #include "pycore_call.h" // _PyObject_Call() #include "pycore_ceval.h" // _PyEval_SignalReceived() #include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH -#include "pycore_frame.h" // _PyInterpreterFrame +#include "pycore_frame.h" // _Py_frame #include "pycore_moduleobject.h" // _PyModule_GetState() #include "pycore_pyerrors.h" // _PyErr_SetString() #include "pycore_pylifecycle.h" // NSIG @@ -1817,7 +1817,7 @@ _PyErr_CheckSignalsTstate(PyThreadState *tstate) */ _Py_atomic_store(&is_tripped, 0); - _PyInterpreterFrame *frame = tstate->cframe->current_frame; + _Py_frame *frame = tstate->cframe->current_frame; signal_state_t *state = &signal_global_state; for (int i = 1; i < NSIG; i++) { if (!_Py_atomic_load_relaxed(&Handlers[i].tripped)) { diff --git a/Objects/frameobject.c b/Objects/frameobject.c index 7ccd300e2b4548..93e7e303834792 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -20,7 +20,6 @@ static PyMemberDef frame_memberlist[] = { {NULL} /* Sentinel */ }; - static PyObject * frame_getlocals(PyFrameObject *f, void *closure) { @@ -635,8 +634,8 @@ frame_dealloc(PyFrameObject *f) /* Kill all local variables including specials, if we own them */ if (f->f_owns_frame) { f->f_owns_frame = 0; - assert(f->f_frame == (_PyInterpreterFrame *)f->_f_frame_data); - _PyInterpreterFrame *frame = (_PyInterpreterFrame *)f->_f_frame_data; + assert(f->f_frame == (_Py_frame *)f->_f_frame_data); + _Py_frame *frame = (_Py_frame *)f->_f_frame_data; /* Don't clear code object until the end */ co = frame->f_code; frame->f_code = NULL; @@ -713,7 +712,7 @@ static PyObject * frame_sizeof(PyFrameObject *f, PyObject *Py_UNUSED(ignored)) { Py_ssize_t res; - res = offsetof(PyFrameObject, _f_frame_data) + offsetof(_PyInterpreterFrame, localsplus); + res = offsetof(PyFrameObject, _f_frame_data) + offsetof(_Py_frame, localsplus); PyCodeObject *code = f->f_frame->f_code; res += (code->co_nlocalsplus+code->co_stacksize) * sizeof(PyObject *); return PyLong_FromSsize_t(res); @@ -744,7 +743,7 @@ PyTypeObject PyFrame_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "frame", offsetof(PyFrameObject, _f_frame_data) + - offsetof(_PyInterpreterFrame, localsplus), + offsetof(_Py_frame, localsplus), sizeof(PyObject *), (destructor)frame_dealloc, /* tp_dealloc */ 0, /* tp_vectorcall_offset */ @@ -777,7 +776,7 @@ PyTypeObject PyFrame_Type = { }; static void -init_frame(_PyInterpreterFrame *frame, PyFunctionObject *func, PyObject *locals) +init_frame(_Py_frame *frame, PyFunctionObject *func, PyObject *locals) { /* _PyFrame_InitializeSpecials consumes reference to func */ Py_INCREF(func); @@ -833,8 +832,8 @@ PyFrame_New(PyThreadState *tstate, PyCodeObject *code, Py_DECREF(func); return NULL; } - init_frame((_PyInterpreterFrame *)f->_f_frame_data, func, locals); - f->f_frame = (_PyInterpreterFrame *)f->_f_frame_data; + init_frame((_Py_frame *)f->_f_frame_data, func, locals); + f->f_frame = (_Py_frame *)f->_f_frame_data; f->f_owns_frame = 1; Py_DECREF(func); _PyObject_GC_TRACK(f); @@ -842,7 +841,7 @@ PyFrame_New(PyThreadState *tstate, PyCodeObject *code, } static int -_PyFrame_OpAlreadyRan(_PyInterpreterFrame *frame, int opcode, int oparg) +_PyFrame_OpAlreadyRan(_Py_frame *frame, int opcode, int oparg) { // This only works when opcode is a non-quickened form: assert(_PyOpcode_Deopt[opcode] == opcode); @@ -866,7 +865,7 @@ _PyFrame_OpAlreadyRan(_PyInterpreterFrame *frame, int opcode, int oparg) } int -_PyFrame_FastToLocalsWithError(_PyInterpreterFrame *frame) { +_PyFrame_FastToLocalsWithError(_Py_frame *frame) { /* Merge fast locals into f->f_locals */ PyObject *locals; PyObject **fast; @@ -981,7 +980,7 @@ PyFrame_FastToLocals(PyFrameObject *f) } void -_PyFrame_LocalsToFast(_PyInterpreterFrame *frame, int clear) +_PyFrame_LocalsToFast(_Py_frame *frame, int clear) { /* Merge locals into fast locals */ PyObject *locals; diff --git a/Objects/genobject.c b/Objects/genobject.c index 3ad8dc1c459420..39363ea0daaf4d 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -7,7 +7,7 @@ #include "pycore_object.h" // _PyObject_GC_UNTRACK() #include "pycore_pyerrors.h" // _PyErr_ClearExcState() #include "pycore_pystate.h" // _PyThreadState_GET() -#include "pycore_frame.h" // _PyInterpreterFrame +#include "pycore_frame.h" // _Py_frame #include "frameobject.h" // PyFrameObject #include "structmember.h" // PyMemberDef #include "opcode.h" // SEND @@ -36,7 +36,7 @@ gen_traverse(PyGenObject *gen, visitproc visit, void *arg) Py_VISIT(gen->gi_name); Py_VISIT(gen->gi_qualname); if (gen->gi_frame_valid) { - _PyInterpreterFrame *frame = (_PyInterpreterFrame *)(gen->gi_iframe); + _Py_frame *frame = (_Py_frame *)(gen->gi_iframe); assert(frame->frame_obj == NULL || frame->frame_obj->f_owns_frame == 0); int err = _PyFrame_Traverse(frame, visit, arg); if (err) { @@ -55,7 +55,7 @@ _PyGen_Finalize(PyObject *self) PyObject *res = NULL; PyObject *error_type, *error_value, *error_traceback; - if (gen->gi_frame_valid == 0 || _PyFrameHasCompleted((_PyInterpreterFrame *)gen->gi_iframe)) { + if (gen->gi_frame_valid == 0 || _PyFrameHasCompleted((_Py_frame *)gen->gi_iframe)) { /* Generator isn't paused, so no need to close */ return; } @@ -87,7 +87,7 @@ _PyGen_Finalize(PyObject *self) issue a RuntimeWarning. */ if (gen->gi_code != NULL && ((PyCodeObject *)gen->gi_code)->co_flags & CO_COROUTINE && - ((_PyInterpreterFrame *)gen->gi_iframe)->f_state == FRAME_CREATED) + ((_Py_frame *)gen->gi_iframe)->f_state == FRAME_CREATED) { _PyErr_WarnUnawaitedCoroutine((PyObject *)gen); } @@ -131,7 +131,7 @@ gen_dealloc(PyGenObject *gen) Py_CLEAR(((PyAsyncGenObject*)gen)->ag_origin_or_finalizer); } if (gen->gi_frame_valid) { - _PyInterpreterFrame *frame = (_PyInterpreterFrame *)gen->gi_iframe; + _Py_frame *frame = (_Py_frame *)gen->gi_iframe; gen->gi_frame_valid = 0; frame->is_generator = false; frame->previous = NULL; @@ -152,7 +152,7 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult, int exc, int closing) { PyThreadState *tstate = _PyThreadState_GET(); - _PyInterpreterFrame *frame = (_PyInterpreterFrame *)gen->gi_iframe; + _Py_frame *frame = (_Py_frame *)gen->gi_iframe; PyObject *result; *presult = NULL; @@ -348,7 +348,7 @@ _PyGen_yf(PyGenObject *gen) PyObject *yf = NULL; if (gen->gi_frame_valid) { - _PyInterpreterFrame *frame = (_PyInterpreterFrame *)gen->gi_iframe; + _Py_frame *frame = (_PyInterpreterFrame *)gen->gi_iframe; if (frame->f_lasti < 1) { /* Return immediately if the frame didn't start yet. SEND @@ -378,7 +378,7 @@ gen_close(PyGenObject *gen, PyObject *args) int err = 0; if (yf) { - _PyInterpreterFrame *frame = (_PyInterpreterFrame *)gen->gi_iframe; + _Py_frame *frame = (_Py_frame *)gen->gi_iframe; PyFrameState state = frame->f_state; frame->f_state = FRAME_EXECUTING; err = gen_close_iter(yf); @@ -419,7 +419,7 @@ _gen_throw(PyGenObject *gen, int close_on_genexit, PyObject *yf = _PyGen_yf(gen); if (yf) { - _PyInterpreterFrame *frame = (_PyInterpreterFrame *)gen->gi_iframe; + _Py_frame *frame = (_Py_frame *)gen->gi_iframe; PyObject *ret; int err; if (PyErr_GivenExceptionMatches(typ, PyExc_GeneratorExit) && @@ -446,7 +446,7 @@ _gen_throw(PyGenObject *gen, int close_on_genexit, 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; + _Py_frame *prev = tstate->cframe->current_frame; frame->previous = prev; tstate->cframe->current_frame = frame; /* Close the generator that we are currently iterating with @@ -480,7 +480,7 @@ _gen_throw(PyGenObject *gen, int close_on_genexit, PyObject *val; /* Pop subiterator from stack */ assert(gen->gi_frame_valid); - ret = _PyFrame_StackPop((_PyInterpreterFrame *)gen->gi_iframe); + ret = _PyFrame_StackPop((_Py_frame *)gen->gi_iframe); assert(ret == yf); Py_DECREF(ret); // XXX: Performing this jump ourselves is awkward and problematic. @@ -759,7 +759,7 @@ gen_getrunning(PyGenObject *gen, void *Py_UNUSED(ignored)) if (gen->gi_frame_valid == 0) { Py_RETURN_FALSE; } - return PyBool_FromLong(_PyFrame_IsExecuting((_PyInterpreterFrame *)gen->gi_iframe)); + return PyBool_FromLong(_PyFrame_IsExecuting((_Py_frame *)gen->gi_iframe)); } static PyObject * @@ -768,7 +768,7 @@ gen_getsuspended(PyGenObject *gen, void *Py_UNUSED(ignored)) if (gen->gi_frame_valid == 0) { Py_RETURN_FALSE; } - return PyBool_FromLong(((_PyInterpreterFrame *)gen->gi_iframe)->f_state == FRAME_SUSPENDED); + return PyBool_FromLong(((_Py_frame *)gen->gi_iframe)->f_state == FRAME_SUSPENDED); } static PyObject * @@ -780,7 +780,7 @@ _gen_getframe(PyGenObject *gen, const char *const name) if (gen->gi_frame_valid == 0) { Py_RETURN_NONE; } - return _Py_XNewRef((PyObject *)_PyFrame_GetFrameObject((_PyInterpreterFrame *)gen->gi_iframe)); + return _Py_XNewRef((PyObject *)_PyFrame_GetFrameObject((_Py_frame *)gen->gi_iframe)); } static PyObject * @@ -811,7 +811,7 @@ static PyObject * gen_sizeof(PyGenObject *gen, PyObject *Py_UNUSED(ignored)) { Py_ssize_t res; - res = offsetof(PyGenObject, gi_iframe) + offsetof(_PyInterpreterFrame, localsplus); + res = offsetof(PyGenObject, gi_iframe) + offsetof(_Py_frame, localsplus); PyCodeObject *code = gen->gi_code; res += (code->co_nlocalsplus+code->co_stacksize) * sizeof(PyObject *); return PyLong_FromSsize_t(res); @@ -840,7 +840,7 @@ PyTypeObject PyGen_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "generator", /* tp_name */ offsetof(PyGenObject, gi_iframe) + - offsetof(_PyInterpreterFrame, localsplus), /* tp_basicsize */ + offsetof(_Py_frame, localsplus), /* tp_basicsize */ sizeof(PyObject *), /* tp_itemsize */ /* methods */ (destructor)gen_dealloc, /* tp_dealloc */ @@ -914,7 +914,7 @@ make_gen(PyTypeObject *type, PyFunctionObject *func) } static PyObject * -compute_cr_origin(int origin_depth, _PyInterpreterFrame *current_frame); +compute_cr_origin(int origin_depth, _Py_frame *current_frame); PyObject * _Py_MakeCoro(PyFunctionObject *func) @@ -973,8 +973,8 @@ gen_new_with_qualname(PyTypeObject *type, PyFrameObject *f, /* Copy the frame */ assert(f->f_frame->frame_obj == NULL); assert(f->f_owns_frame); - _PyInterpreterFrame *frame = (_PyInterpreterFrame *)gen->gi_iframe; - _PyFrame_Copy((_PyInterpreterFrame *)f->_f_frame_data, frame); + _Py_frame *frame = (_Py_frame *)gen->gi_iframe; + _PyFrame_Copy((_Py_frame *)f->_f_frame_data, frame); gen->gi_frame_valid = 1; assert(frame->frame_obj == f); f->f_owns_frame = 0; @@ -1117,7 +1117,7 @@ cr_getsuspended(PyCoroObject *coro, void *Py_UNUSED(ignored)) if (coro->cr_frame_valid == 0) { Py_RETURN_FALSE; } - return PyBool_FromLong(((_PyInterpreterFrame *)coro->cr_iframe)->f_state == FRAME_SUSPENDED); + return PyBool_FromLong(((_Py_frame *)coro->cr_iframe)->f_state == FRAME_SUSPENDED); } static PyObject * @@ -1126,7 +1126,7 @@ cr_getrunning(PyCoroObject *coro, void *Py_UNUSED(ignored)) if (coro->cr_frame_valid == 0) { Py_RETURN_FALSE; } - return PyBool_FromLong(_PyFrame_IsExecuting((_PyInterpreterFrame *)coro->cr_iframe)); + return PyBool_FromLong(_PyFrame_IsExecuting((_Py_frame *)coro->cr_iframe)); } static PyObject * @@ -1185,7 +1185,7 @@ PyTypeObject PyCoro_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "coroutine", /* tp_name */ offsetof(PyCoroObject, cr_iframe) + - offsetof(_PyInterpreterFrame, localsplus), /* tp_basicsize */ + offsetof(_Py_frame, localsplus), /* tp_basicsize */ sizeof(PyObject *), /* tp_itemsize */ /* methods */ (destructor)gen_dealloc, /* tp_dealloc */ @@ -1324,9 +1324,9 @@ PyTypeObject _PyCoroWrapper_Type = { }; static PyObject * -compute_cr_origin(int origin_depth, _PyInterpreterFrame *current_frame) +compute_cr_origin(int origin_depth, _Py_frame *current_frame) { - _PyInterpreterFrame *frame = current_frame; + _Py_frame *frame = current_frame; /* First count how many frames we have */ int frame_count = 0; for (; frame && frame_count < origin_depth; ++frame_count) { @@ -1577,7 +1577,7 @@ PyTypeObject PyAsyncGen_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "async_generator", /* tp_name */ offsetof(PyAsyncGenObject, ag_iframe) + - offsetof(_PyInterpreterFrame, localsplus), /* tp_basicsize */ + offsetof(_Py_frame, localsplus), /* tp_basicsize */ sizeof(PyObject *), /* tp_itemsize */ /* methods */ (destructor)gen_dealloc, /* tp_dealloc */ @@ -2063,7 +2063,7 @@ static PyObject * async_gen_athrow_send(PyAsyncGenAThrow *o, PyObject *arg) { PyGenObject *gen = (PyGenObject*)o->agt_gen; - _PyInterpreterFrame *frame = (_PyInterpreterFrame *)gen->gi_iframe; + _Py_frame *frame = (_Py_frame *)gen->gi_iframe; PyObject *retval; if (o->agt_state == AWAITABLE_STATE_CLOSED) { diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 4bed3ef49289ae..922c3e95a501f6 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -12,7 +12,7 @@ #include "pycore_typeobject.h" // struct type_cache #include "pycore_unionobject.h" // _Py_union_type_or #include "frameobject.h" // PyFrameObject -#include "pycore_frame.h" // _PyInterpreterFrame +#include "pycore_frame.h" // _Py_frame #include "opcode.h" // MAKE_CELL #include "structmember.h" // PyMemberDef @@ -8933,7 +8933,7 @@ super_descr_get(PyObject *self, PyObject *obj, PyObject *type) } static int -super_init_without_args(_PyInterpreterFrame *cframe, PyCodeObject *co, +super_init_without_args(_Py_frame *frame, PyCodeObject *co, PyTypeObject **type_p, PyObject **obj_p) { if (co->co_argcount == 0) { @@ -8942,13 +8942,13 @@ super_init_without_args(_PyInterpreterFrame *cframe, PyCodeObject *co, return -1; } - assert(cframe->f_code->co_nlocalsplus > 0); - PyObject *firstarg = _PyFrame_GetLocalsArray(cframe)[0]; + assert(frame->f_code->co_nlocalsplus > 0); + PyObject *firstarg = _PyFrame_GetLocalsArray(frame)[0]; // The first argument might be a cell. if (firstarg != NULL && (_PyLocals_GetKind(co->co_localspluskinds, 0) & CO_FAST_CELL)) { // "firstarg" is a cell here unless (very unlikely) super() // was called from the C-API before the first MAKE_CELL op. - if (cframe->f_lasti >= 0) { + if (frame->f_lasti >= 0) { // MAKE_CELL and COPY_FREE_VARS have no quickened forms, so no need // to use _PyOpcode_Deopt here: assert(_Py_OPCODE(_PyCode_CODE(co)[0]) == MAKE_CELL || @@ -8971,7 +8971,7 @@ super_init_without_args(_PyInterpreterFrame *cframe, PyCodeObject *co, PyObject *name = PyTuple_GET_ITEM(co->co_localsplusnames, i); assert(PyUnicode_Check(name)); if (_PyUnicode_Equal(name, &_Py_ID(__class__))) { - PyObject *cell = _PyFrame_GetLocalsArray(cframe)[i]; + PyObject *cell = _PyFrame_GetLocalsArray(frame)[i]; if (cell == NULL || !PyCell_Check(cell)) { PyErr_SetString(PyExc_RuntimeError, "super(): bad __class__ cell"); @@ -9029,13 +9029,13 @@ super_init_impl(PyObject *self, PyTypeObject *type, PyObject *obj) { /* Call super(), without args -- fill in from __class__ and first local variable on the stack. */ PyThreadState *tstate = _PyThreadState_GET(); - _PyInterpreterFrame *cframe = tstate->cframe->current_frame; - if (cframe == NULL) { + _Py_frame *frame = tstate->cframe->current_frame; + if (frame == NULL) { PyErr_SetString(PyExc_RuntimeError, "super(): no current frame"); return -1; } - int res = super_init_without_args(cframe, cframe->f_code, &type, &obj); + int res = super_init_without_args(frame, frame->f_code, &type, &obj); if (res < 0) { return -1; diff --git a/Python/ceval.c b/Python/ceval.c index 7c6bfd46900e6a..45d7437138c4ca 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -59,7 +59,7 @@ static PyObject * do_call_core( #ifdef LLTRACE static int lltrace; static int prtrace(PyThreadState *, PyObject *, const char *); -static void lltrace_instruction(_PyInterpreterFrame *frame, int opcode, int oparg) +static void lltrace_instruction(_Py_frame *frame, int opcode, int oparg) { if (HAS_ARG(opcode)) { printf("%d: %d, %d\n", @@ -72,20 +72,20 @@ static void lltrace_instruction(_PyInterpreterFrame *frame, int opcode, int opar } #endif static int call_trace(Py_tracefunc, PyObject *, - PyThreadState *, _PyInterpreterFrame *, + PyThreadState *, _Py_frame *, int, PyObject *); static int call_trace_protected(Py_tracefunc, PyObject *, - PyThreadState *, _PyInterpreterFrame *, + PyThreadState *, _Py_frame *, int, PyObject *); static void call_exc_trace(Py_tracefunc, PyObject *, - PyThreadState *, _PyInterpreterFrame *); + PyThreadState *, _Py_frame *); static int maybe_call_line_trace(Py_tracefunc, PyObject *, - PyThreadState *, _PyInterpreterFrame *, int); -static void maybe_dtrace_line(_PyInterpreterFrame *, PyTraceInfo *, int); -static void dtrace_function_entry(_PyInterpreterFrame *); -static void dtrace_function_return(_PyInterpreterFrame *); + PyThreadState *, _Py_frame *, int); +static void maybe_dtrace_line(_Py_frame *, PyTraceInfo *, int); +static void dtrace_function_entry(_Py_frame *); +static void dtrace_function_return(_Py_frame *); -static PyObject * import_name(PyThreadState *, _PyInterpreterFrame *, +static PyObject * import_name(PyThreadState *, _Py_frame *, PyObject *, PyObject *, PyObject *); static PyObject * import_from(PyThreadState *, PyObject *, PyObject *); static int import_all_from(PyThreadState *, PyObject *, PyObject *); @@ -97,12 +97,12 @@ static int check_except_star_type_valid(PyThreadState *tstate, PyObject* right); static void format_kwargs_error(PyThreadState *, PyObject *func, PyObject *kwargs); static void format_awaitable_error(PyThreadState *, PyTypeObject *, int); static int get_exception_handler(PyCodeObject *, int, int*, int*, int*); -static _PyInterpreterFrame * +static _Py_frame * _PyEvalFramePushAndInit(PyThreadState *tstate, PyFunctionObject *func, PyObject *locals, PyObject* const* args, size_t argcount, PyObject *kwnames); static void -_PyEvalFrameClearAndPop(PyThreadState *tstate, _PyInterpreterFrame *frame); +_PyEvalFrameClearAndPop(PyThreadState *tstate, _Py_frame *frame); #define NAME_ERROR_MSG \ "name '%.200s' is not defined" @@ -1508,7 +1508,7 @@ eval_frame_handle_pending(PyThreadState *tstate) static int -trace_function_entry(PyThreadState *tstate, _PyInterpreterFrame *frame) +trace_function_entry(PyThreadState *tstate, _Py_frame *frame) { if (tstate->c_tracefunc != NULL) { /* tstate->c_tracefunc, if defined, is a @@ -1547,7 +1547,7 @@ trace_function_entry(PyThreadState *tstate, _PyInterpreterFrame *frame) } static int -trace_function_exit(PyThreadState *tstate, _PyInterpreterFrame *frame, PyObject *retval) +trace_function_exit(PyThreadState *tstate, _Py_frame *frame, PyObject *retval) { if (tstate->c_tracefunc) { if (call_trace_protected(tstate->c_tracefunc, tstate->c_traceobj, @@ -1564,10 +1564,10 @@ trace_function_exit(PyThreadState *tstate, _PyInterpreterFrame *frame, PyObject return 0; } -static _PyInterpreterFrame * -pop_frame(PyThreadState *tstate, _PyInterpreterFrame *frame) +static _Py_frame * +pop_frame(PyThreadState *tstate, _Py_frame *frame) { - _PyInterpreterFrame *prev_frame = frame->previous; + _Py_frame *prev_frame = frame->previous; _PyEvalFrameClearAndPop(tstate, frame); return prev_frame; } @@ -1588,7 +1588,7 @@ is_method(PyObject **stack_pointer, int args) { (call_shape.kwnames == NULL ? 0 : ((int)PyTuple_GET_SIZE(call_shape.kwnames))) PyObject* _Py_HOT_FUNCTION -_PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int throwflag) +_PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_frame *frame, int throwflag) { _Py_EnsureTstateNotNULL(tstate); CALL_STAT_INC(pyeval_calls); @@ -2190,7 +2190,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int PyCodeObject *code = (PyCodeObject *)getitem->func_code; size_t size = code->co_nlocalsplus + code->co_stacksize + FRAME_SPECIALS_SIZE; assert(code->co_argcount == 2); - _PyInterpreterFrame *new_frame = _PyThreadState_BumpFramePointer(tstate, size); + _Py_frame *new_frame = _PyThreadState_BumpFramePointer(tstate, size); if (new_frame == NULL) { goto error; } @@ -4611,7 +4611,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int int code_flags = ((PyCodeObject*)PyFunction_GET_CODE(function))->co_flags; PyObject *locals = code_flags & CO_OPTIMIZED ? NULL : PyFunction_GET_GLOBALS(function); STACK_SHRINK(total_args); - _PyInterpreterFrame *new_frame = _PyEvalFramePushAndInit( + _Py_frame *new_frame = _PyEvalFramePushAndInit( tstate, (PyFunctionObject *)function, locals, stack_pointer, positional_args, call_shape.kwnames ); @@ -4714,7 +4714,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int PyCodeObject *code = (PyCodeObject *)func->func_code; DEOPT_IF(code->co_argcount != argcount, CALL); STAT_INC(CALL, hit); - _PyInterpreterFrame *new_frame = _PyFrame_Push(tstate, func); + _Py_frame *new_frame = _PyFrame_Push(tstate, func); if (new_frame == NULL) { goto error; } @@ -4748,7 +4748,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int int minargs = cache->min_args; DEOPT_IF(argcount < minargs, CALL); STAT_INC(CALL, hit); - _PyInterpreterFrame *new_frame = _PyFrame_Push(tstate, func); + _Py_frame *new_frame = _PyFrame_Push(tstate, func); if (new_frame == NULL) { goto error; } @@ -5250,7 +5250,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int } assert(EMPTY()); _PyFrame_SetStackPointer(frame, stack_pointer); - _PyInterpreterFrame *gen_frame = (_PyInterpreterFrame *)gen->gi_iframe; + _Py_frame *gen_frame = (_Py_frame *)gen->gi_iframe; _PyFrame_Copy(frame, gen_frame); assert(frame->frame_obj == NULL); gen->gi_frame_valid = 1; @@ -5258,7 +5258,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int gen_frame->f_state = FRAME_CREATED; _Py_LeaveRecursiveCall(tstate); if (!frame->is_entry) { - _PyInterpreterFrame *prev = frame->previous; + _Py_frame *prev = frame->previous; _PyThreadState_PopFrame(tstate, frame); frame = cframe.current_frame = prev; _PyFrame_StackPush(frame, (PyObject *)gen); @@ -6162,7 +6162,7 @@ initialize_locals(PyThreadState *tstate, PyFunctionObject *func, } /* Consumes references to func and all the args */ -static _PyInterpreterFrame * +static _Py_frame * _PyEvalFramePushAndInit(PyThreadState *tstate, PyFunctionObject *func, PyObject *locals, PyObject* const* args, size_t argcount, PyObject *kwnames) @@ -6170,7 +6170,7 @@ _PyEvalFramePushAndInit(PyThreadState *tstate, PyFunctionObject *func, PyCodeObject * code = (PyCodeObject *)func->func_code; size_t size = code->co_nlocalsplus + code->co_stacksize + FRAME_SPECIALS_SIZE; CALL_STAT_INC(frames_pushed); - _PyInterpreterFrame *frame = _PyThreadState_BumpFramePointer(tstate, size); + _Py_frame *frame = _PyThreadState_BumpFramePointer(tstate, size); if (frame == NULL) { goto fail; } @@ -6200,7 +6200,7 @@ _PyEvalFramePushAndInit(PyThreadState *tstate, PyFunctionObject *func, } static void -_PyEvalFrameClearAndPop(PyThreadState *tstate, _PyInterpreterFrame * frame) +_PyEvalFrameClearAndPop(PyThreadState *tstate, _Py_frame * frame) { tstate->recursion_remaining--; assert(frame->frame_obj == NULL || frame->frame_obj->f_owns_frame == 0); @@ -6227,7 +6227,7 @@ _PyEval_Vector(PyThreadState *tstate, PyFunctionObject *func, Py_INCREF(args[i+argcount]); } } - _PyInterpreterFrame *frame = _PyEvalFramePushAndInit( + _Py_frame *frame = _PyEvalFramePushAndInit( tstate, func, locals, args, argcount, kwnames); if (frame == NULL) { return NULL; @@ -6596,7 +6596,7 @@ prtrace(PyThreadState *tstate, PyObject *v, const char *str) static void call_exc_trace(Py_tracefunc func, PyObject *self, PyThreadState *tstate, - _PyInterpreterFrame *f) + _Py_frame *f) { PyObject *type, *value, *traceback, *orig_traceback, *arg; int err; @@ -6626,7 +6626,7 @@ call_exc_trace(Py_tracefunc func, PyObject *self, static int call_trace_protected(Py_tracefunc func, PyObject *obj, - PyThreadState *tstate, _PyInterpreterFrame *frame, + PyThreadState *tstate, _Py_frame *frame, int what, PyObject *arg) { PyObject *type, *value, *traceback; @@ -6647,7 +6647,7 @@ call_trace_protected(Py_tracefunc func, PyObject *obj, } static void -initialize_trace_info(PyTraceInfo *trace_info, _PyInterpreterFrame *frame) +initialize_trace_info(PyTraceInfo *trace_info, _Py_frame *frame) { PyCodeObject *code = frame->f_code; if (trace_info->code != code) { @@ -6670,7 +6670,7 @@ PyThreadState_LeaveTracing(PyThreadState *tstate) static int call_trace(Py_tracefunc func, PyObject *obj, - PyThreadState *tstate, _PyInterpreterFrame *frame, + PyThreadState *tstate, _Py_frame *frame, int what, PyObject *arg) { int result; @@ -6712,7 +6712,7 @@ _PyEval_CallTracing(PyObject *func, PyObject *args) /* See Objects/lnotab_notes.txt for a description of how tracing works. */ static int maybe_call_line_trace(Py_tracefunc func, PyObject *obj, - PyThreadState *tstate, _PyInterpreterFrame *frame, int instr_prev) + PyThreadState *tstate, _Py_frame *frame, int instr_prev) { int result = 0; @@ -6902,7 +6902,7 @@ _PyEval_GetAsyncGenFinalizer(void) return tstate->async_gen_finalizer; } -_PyInterpreterFrame * +_Py_frame * _PyEval_GetFrame(void) { PyThreadState *tstate = _PyThreadState_GET(); @@ -6926,7 +6926,7 @@ PyEval_GetFrame(void) PyObject * _PyEval_GetBuiltins(PyThreadState *tstate) { - _PyInterpreterFrame *frame = tstate->cframe->current_frame; + _Py_frame *frame = tstate->cframe->current_frame; if (frame != NULL) { return frame->f_builtins; } @@ -6965,7 +6965,7 @@ PyObject * PyEval_GetLocals(void) { PyThreadState *tstate = _PyThreadState_GET(); - _PyInterpreterFrame *current_frame = tstate->cframe->current_frame; + _Py_frame *current_frame = tstate->cframe->current_frame; if (current_frame == NULL) { _PyErr_SetString(tstate, PyExc_SystemError, "frame does not exist"); return NULL; @@ -6984,7 +6984,7 @@ PyObject * PyEval_GetGlobals(void) { PyThreadState *tstate = _PyThreadState_GET(); - _PyInterpreterFrame *current_frame = tstate->cframe->current_frame; + _Py_frame *current_frame = tstate->cframe->current_frame; if (current_frame == NULL) { return NULL; } @@ -6995,7 +6995,7 @@ int PyEval_MergeCompilerFlags(PyCompilerFlags *cf) { PyThreadState *tstate = _PyThreadState_GET(); - _PyInterpreterFrame *current_frame = tstate->cframe->current_frame; + _Py_frame *current_frame = tstate->cframe->current_frame; int result = cf->cf_flags != 0; if (current_frame != NULL) { @@ -7193,7 +7193,7 @@ _PyEval_SliceIndexNotNone(PyObject *v, Py_ssize_t *pi) } static PyObject * -import_name(PyThreadState *tstate, _PyInterpreterFrame *frame, +import_name(PyThreadState *tstate, _Py_frame *frame, PyObject *name, PyObject *fromlist, PyObject *level) { PyObject *import_func, *res; @@ -7667,7 +7667,7 @@ _PyEval_RequestCodeExtraIndex(freefunc free) } static void -dtrace_function_entry(_PyInterpreterFrame *frame) +dtrace_function_entry(_Py_frame *frame) { const char *filename; const char *funcname; @@ -7682,7 +7682,7 @@ dtrace_function_entry(_PyInterpreterFrame *frame) } static void -dtrace_function_return(_PyInterpreterFrame *frame) +dtrace_function_return(_Py_frame *frame) { const char *filename; const char *funcname; @@ -7698,7 +7698,7 @@ dtrace_function_return(_PyInterpreterFrame *frame) /* DTrace equivalent of maybe_call_line_trace. */ static void -maybe_dtrace_line(_PyInterpreterFrame *frame, +maybe_dtrace_line(_Py_frame *frame, PyTraceInfo *trace_info, int instr_prev) { diff --git a/Python/frame.c b/Python/frame.c index 20b4f81425bc8b..d43acbacf5bbfe 100644 --- a/Python/frame.c +++ b/Python/frame.c @@ -7,7 +7,7 @@ #include "opcode.h" int -_PyFrame_Traverse(_PyInterpreterFrame *frame, visitproc visit, void *arg) +_PyFrame_Traverse(_Py_frame *frame, visitproc visit, void *arg) { Py_VISIT(frame->frame_obj); Py_VISIT(frame->f_locals); @@ -24,7 +24,7 @@ _PyFrame_Traverse(_PyInterpreterFrame *frame, visitproc visit, void *arg) } PyFrameObject * -_PyFrame_MakeAndSetFrameObject(_PyInterpreterFrame *frame) +_PyFrame_MakeAndSetFrameObject(_Py_frame *frame) { assert(frame->frame_obj == NULL); PyObject *error_type, *error_value, *error_traceback; @@ -46,7 +46,7 @@ _PyFrame_MakeAndSetFrameObject(_PyInterpreterFrame *frame) } void -_PyFrame_Copy(_PyInterpreterFrame *src, _PyInterpreterFrame *dest) +_PyFrame_Copy(_Py_frame *src, _Py_frame *dest) { assert(src->stacktop >= src->f_code->co_nlocalsplus); Py_ssize_t size = ((char*)&src->localsplus[src->stacktop]) - (char *)src; @@ -55,17 +55,17 @@ _PyFrame_Copy(_PyInterpreterFrame *src, _PyInterpreterFrame *dest) static void -take_ownership(PyFrameObject *f, _PyInterpreterFrame *frame) +take_ownership(PyFrameObject *f, _Py_frame *frame) { assert(f->f_owns_frame == 0); Py_ssize_t size = ((char*)&frame->localsplus[frame->stacktop]) - (char *)frame; - memcpy((_PyInterpreterFrame *)f->_f_frame_data, frame, size); - frame = (_PyInterpreterFrame *)f->_f_frame_data; + memcpy((_Py_frame *)f->_f_frame_data, frame, size); + frame = (_Py_frame *)f->_f_frame_data; f->f_owns_frame = 1; f->f_frame = frame; assert(f->f_back == NULL); if (frame->previous != NULL) { - /* Link PyFrameObjects.f_back and remove link through _PyInterpreterFrame.previous */ + /* Link PyFrameObjects.f_back and remove link through _Py_frame.previous */ PyFrameObject *back = _PyFrame_GetFrameObject(frame->previous); if (back == NULL) { /* Memory error here. */ @@ -84,7 +84,7 @@ take_ownership(PyFrameObject *f, _PyInterpreterFrame *frame) } void -_PyFrame_Clear(_PyInterpreterFrame *frame) +_PyFrame_Clear(_Py_frame *frame) { /* It is the responsibility of the owning generator/coroutine * to have cleared the enclosing generator, if any. */ @@ -110,13 +110,13 @@ _PyFrame_Clear(_PyInterpreterFrame *frame) } /* Consumes reference to func */ -_PyInterpreterFrame * +_Py_frame * _PyFrame_Push(PyThreadState *tstate, PyFunctionObject *func) { PyCodeObject *code = (PyCodeObject *)func->func_code; size_t size = code->co_nlocalsplus + code->co_stacksize + FRAME_SPECIALS_SIZE; CALL_STAT_INC(frames_pushed); - _PyInterpreterFrame *new_frame = _PyThreadState_BumpFramePointer(tstate, size); + _Py_frame *new_frame = _PyThreadState_BumpFramePointer(tstate, size); if (new_frame == NULL) { Py_DECREF(func); return NULL; diff --git a/Python/pystate.c b/Python/pystate.c index 1b4e31b95cd0bb..aa16c6259e7557 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -1393,7 +1393,7 @@ _PyThread_CurrentFrames(void) 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; + _Py_frame *frame = t->cframe->current_frame; if (frame == NULL) { continue; } @@ -2180,7 +2180,7 @@ push_chunk(PyThreadState *tstate, int size) return res; } -_PyInterpreterFrame * +_Py_frame * _PyThreadState_BumpFramePointerSlow(PyThreadState *tstate, size_t size) { assert(size < INT_MAX/sizeof(PyObject *)); @@ -2192,11 +2192,11 @@ _PyThreadState_BumpFramePointerSlow(PyThreadState *tstate, size_t size) else { tstate->datastack_top = top; } - return (_PyInterpreterFrame *)base; + return (_Py_frame *)base; } void -_PyThreadState_PopFrame(PyThreadState *tstate, _PyInterpreterFrame * frame) +_PyThreadState_PopFrame(PyThreadState *tstate, _Py_frame * frame) { assert(tstate->datastack_chunk); PyObject **base = (PyObject **)frame; diff --git a/Python/sysmodule.c b/Python/sysmodule.c index c89f81f689f7e3..a58e7c77c22ca2 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -18,7 +18,7 @@ Data members: #include "pycore_call.h" // _PyObject_CallNoArgs() #include "pycore_ceval.h" // _PyEval_SetAsyncGenFinalizer() #include "pycore_code.h" // _Py_QuickenedCount -#include "pycore_frame.h" // _PyInterpreterFrame +#include "pycore_frame.h" // _Py_frame #include "pycore_initconfig.h" // _PyStatus_EXCEPTION() #include "pycore_namespace.h" // _PyNamespace_New() #include "pycore_object.h" // _PyObject_IS_GC() @@ -1768,7 +1768,7 @@ sys__getframe_impl(PyObject *module, int depth) /*[clinic end generated code: output=d438776c04d59804 input=c1be8a6464b11ee5]*/ { PyThreadState *tstate = _PyThreadState_GET(); - _PyInterpreterFrame *frame = tstate->cframe->current_frame; + _Py_frame *frame = tstate->cframe->current_frame; if (_PySys_Audit(tstate, "sys._getframe", NULL) < 0) { return NULL; diff --git a/Python/traceback.c b/Python/traceback.c index 6a721cf9097573..b4b76af8eebb8d 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -1167,7 +1167,7 @@ _Py_DumpASCII(int fd, PyObject *text) This function is signal safe. */ static void -dump_frame(int fd, _PyInterpreterFrame *frame) +dump_frame(int fd, _Py_frame *frame) { PyCodeObject *code = frame->f_code; PUTS(fd, " File "); @@ -1205,7 +1205,7 @@ dump_frame(int fd, _PyInterpreterFrame *frame) static void dump_traceback(int fd, PyThreadState *tstate, int write_header) { - _PyInterpreterFrame *frame; + _Py_frame *frame; unsigned int depth; if (write_header) {