diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 8b3450ed404f21..953732addbbb40 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -949,13 +949,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 5a904bd3f08e90..71880a77a542b2 100644 --- a/Include/cpython/ceval.h +++ b/Include/cpython/ceval.h @@ -22,7 +22,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 70178e38650cf5..f675f0f2ff5591 100644 --- a/Include/internal/pycore_ceval.h +++ b/Include/internal/pycore_ceval.h @@ -47,7 +47,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); @@ -116,7 +116,7 @@ static inline void _Py_LeaveRecursiveCall_inline(void) { #define Py_LeaveRecursiveCall() _Py_LeaveRecursiveCall_inline() -struct _PyInterpreterFrame *_PyEval_GetFrame(void); +struct _Py_frame *_PyEval_GetFrame(void); PyObject *_Py_MakeCoro(PyFunctionObject *func); diff --git a/Include/internal/pycore_frame.h b/Include/internal/pycore_frame.h index e2f551ef2c0629..65dffc065bd27f 100644 --- a/Include/internal/pycore_frame.h +++ b/Include/internal/pycore_frame.h @@ -6,17 +6,66 @@ 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. + * + * Field naming conventions: + * + * * full frame object fields have an "f_*" prefix + * * frame data struct fields have no prefix + * + * 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 a 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 typically + * refers to the C stack frame data that is used to separate Python level recursion + * from C level recursive calls to the eval loop function + * + * 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 objecst 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_fdata; /* 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? */ char f_trace_opcodes; /* Emit per-opcode trace events? */ char f_owns_frame; /* This frame owns the frame */ /* The frame data, if this frame object owns the frame */ - PyObject *_f_frame_data[1]; + PyObject *_f_owned_fdata[1]; }; extern PyFrameObject* _PyFrame_New_NoTrack(PyCodeObject *code); @@ -25,7 +74,7 @@ extern PyFrameObject* _PyFrame_New_NoTrack(PyCodeObject *code); /* other API */ /* These values are chosen so that the inline functions below all - * compare f_state to zero. + * compare the current frame state to zero. */ enum _framestate { FRAME_CREATED = -2, @@ -40,78 +89,108 @@ enum _framestate { typedef signed char PyFrameState; /* - frame->f_lasti refers to the index of the last instruction, + frame->lasti refers to the index of the last instruction, unless it's -1 in which case next_instr should be first_instr. */ -typedef struct _PyInterpreterFrame { - 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 */ +typedef struct _Py_frame { + PyFunctionObject *func; /* Strong reference */ + PyObject *globals; /* Borrowed reference */ + PyObject *builtins; /* Borrowed reference */ + PyObject *locals; /* Strong reference, may be NULL */ + PyCodeObject *code; /* Strong reference */ PyFrameObject *frame_obj; /* Strong reference, may be NULL */ - struct _PyInterpreterFrame *previous; - int f_lasti; /* Last instruction if called */ + struct _Py_frame *previous; + int lasti; /* Last instruction if called */ int stacktop; /* Offset of TOS from localsplus */ - PyFrameState f_state; /* What state the frame is in */ + PyFrameState 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; - -static inline int _PyFrame_IsRunnable(_PyInterpreterFrame *f) { - return f->f_state < FRAME_EXECUTING; +} _Py_frame; + +#if !defined(_PY_FRAME_API_DISABLE_INTERIM_COMPAT_3_11a6) +/* 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 and field + * name changes for CPython maintainability without forcing yet another interim + * code update on the affected projects. Since the workaround affects symbols + * without the `Py` or `_Py` prefix, a preprocessor symbol can be declared to + * disable the workaround: _PY_FRAME_API_DISABLE_INTERIM_COMPAT_3_11a6 + */ +// Renamed frame data struct and fields +typedef _Py_frame _PyInterpreterFrame; +#define f_func func +#define f_globals globals +#define f_builtins builtins +#define f_locals locals +#define f_code code +#define f_lasti lasti +#define f_state state +// Renamed frame object fields +#define f_frame f_fdata +#define _f_frame_data _f_owned_fdata +#endif // End internal frame API compatibilty workaround + +static inline int _PyFrame_IsRunnable(_Py_frame *f) { + return f->state < FRAME_EXECUTING; } -static inline int _PyFrame_IsExecuting(_PyInterpreterFrame *f) { - return f->f_state == FRAME_EXECUTING; +static inline int _PyFrame_IsExecuting(_Py_frame *f) { + return f->state == FRAME_EXECUTING; } -static inline int _PyFrameHasCompleted(_PyInterpreterFrame *f) { - return f->f_state > FRAME_EXECUTING; +static inline int _PyFrameHasCompleted(_Py_frame *f) { + return f->state > FRAME_EXECUTING; } -static inline PyObject **_PyFrame_Stackbase(_PyInterpreterFrame *f) { - return f->localsplus + f->f_code->co_nlocalsplus; +static inline PyObject **_PyFrame_Stackbase(_Py_frame *f) { + return f->localsplus + f->code->co_nlocalsplus; } -static inline PyObject *_PyFrame_StackPeek(_PyInterpreterFrame *f) { - assert(f->stacktop > f->f_code->co_nlocalsplus); +static inline PyObject *_PyFrame_StackPeek(_Py_frame *f) { + assert(f->stacktop > f->code->co_nlocalsplus); assert(f->localsplus[f->stacktop-1] != NULL); return f->localsplus[f->stacktop-1]; } -static inline PyObject *_PyFrame_StackPop(_PyInterpreterFrame *f) { - assert(f->stacktop > f->f_code->co_nlocalsplus); +static inline PyObject *_PyFrame_StackPop(_Py_frame *f) { + assert(f->stacktop > 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; - frame->f_code = (PyCodeObject *)Py_NewRef(func->func_code); - frame->f_builtins = func->func_builtins; - frame->f_globals = func->func_globals; - frame->f_locals = Py_XNewRef(locals); + frame->func = func; + frame->code = (PyCodeObject *)Py_NewRef(func->func_code); + frame->builtins = func->func_builtins; + frame->globals = func->func_globals; + frame->locals = Py_XNewRef(locals); frame->stacktop = nlocalsplus; frame->frame_obj = NULL; - frame->f_lasti = -1; - frame->f_state = FRAME_CREATED; + frame->lasti = -1; + frame->state = FRAME_CREATED; frame->is_entry = false; frame->is_generator = false; } @@ -120,19 +199,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 +219,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 +235,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 +244,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 +267,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..a21f4d872548d0 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-03-19-21-47-36.bpo-44800.XnGKoD.rst @@ -0,0 +1,9 @@ +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). + +The ``f_`` prefix has been removed from all ``_Py_frame`` fields that previously +used it, so the presence or absence of the prefix provides a way to infer +the exact type of a frame pointer when reading an isolated snippet in a code +diff. diff --git a/Misc/gdbinit b/Misc/gdbinit index e8f62ba6476423..f416c4251a4420 100644 --- a/Misc/gdbinit +++ b/Misc/gdbinit @@ -37,9 +37,9 @@ end define pylocals set $_i = 0 - while $_i < f->f_code->co_nlocals + while $_i < f->code->co_nlocals if f->f_localsplus + $_i != 0 - set $_names = f->f_code->co_varnames + set $_names = f->code->co_varnames set $_name = PyUnicode_AsUTF8(PyTuple_GetItem($_names, $_i)) printf "%s:\n", $_name pyo f->f_localsplus[$_i] @@ -55,8 +55,8 @@ end # command language define lineno set $__continue = 1 - set $__co = f->f_code - set $__lasti = f->f_lasti + set $__co = f->code + set $__lasti = f->lasti set $__sz = ((PyVarObject *)$__co->co_lnotab)->ob_size/2 set $__p = (unsigned char *)((PyBytesObject *)$__co->co_lnotab)->ob_sval set $__li = $__co->co_firstlineno @@ -84,8 +84,8 @@ document pyframev end define pyframe - set $__fn = PyUnicode_AsUTF8(f->f_code->co_filename) - set $__n = PyUnicode_AsUTF8(f->f_code->co_name) + set $__fn = PyUnicode_AsUTF8(f->code->co_filename) + set $__n = PyUnicode_AsUTF8(f->code->co_name) printf "%s (", $__fn lineno printf "): %s\n", $__n diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c index 738d54530c9674..701cc906928530 100644 --- a/Modules/_tracemalloc.c +++ b/Modules/_tracemalloc.c @@ -305,16 +305,16 @@ 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)); + int lineno = PyCode_Addr2Line(pyframe->code, pyframe->lasti*sizeof(_Py_CODEUNIT)); if (lineno < 0) { lineno = 0; } frame->lineno = (unsigned int)lineno; - PyObject *filename = pyframe->f_code->co_filename; + PyObject *filename = pyframe->code->co_filename; if (filename == NULL) { #ifdef TRACE_DEBUG @@ -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 73b6c3d9f8ab77..752f42e095af74 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -20,13 +20,30 @@ static PyMemberDef frame_memberlist[] = { {NULL} /* Sentinel */ }; +// Compile time check of interim Python 3.11a6 API compatibility aliases +// Can be removed once the aliases are removed +static_assert(OFF(f_fdata) == OFF(f_frame), "Incorrect alias for f_frame"); +static_assert(OFF(_f_owned_fdata) == OFF(_f_frame_data), "Incorrect alias for _f_frame_data"); + +#define INTERIM_FRAME_DATA_ALIAS_CHECK(new_field) \ + static_assert(offsetof(_Py_frame, new_field) == offsetof(_PyInterpreterFrame, f_##new_field), \ + "Incorrect alias for f_" #new_field ) + +INTERIM_FRAME_DATA_ALIAS_CHECK(func); +INTERIM_FRAME_DATA_ALIAS_CHECK(builtins); +INTERIM_FRAME_DATA_ALIAS_CHECK(globals); +INTERIM_FRAME_DATA_ALIAS_CHECK(locals); +INTERIM_FRAME_DATA_ALIAS_CHECK(code); +INTERIM_FRAME_DATA_ALIAS_CHECK(lasti); +INTERIM_FRAME_DATA_ALIAS_CHECK(state); +// End compatiblity alias check static PyObject * frame_getlocals(PyFrameObject *f, void *closure) { if (PyFrame_FastToLocalsWithError(f) < 0) return NULL; - PyObject *locals = f->f_frame->f_locals; + PyObject *locals = f->f_fdata->locals; Py_INCREF(locals); return locals; } @@ -39,7 +56,7 @@ PyFrame_GetLineNumber(PyFrameObject *f) return f->f_lineno; } else { - return PyCode_Addr2Line(f->f_frame->f_code, f->f_frame->f_lasti*sizeof(_Py_CODEUNIT)); + return PyCode_Addr2Line(f->f_fdata->code, f->f_fdata->lasti*sizeof(_Py_CODEUNIT)); } } @@ -58,16 +75,16 @@ frame_getlineno(PyFrameObject *f, void *closure) static PyObject * frame_getlasti(PyFrameObject *f, void *closure) { - if (f->f_frame->f_lasti < 0) { + if (f->f_fdata->lasti < 0) { return PyLong_FromLong(-1); } - return PyLong_FromLong(f->f_frame->f_lasti*sizeof(_Py_CODEUNIT)); + return PyLong_FromLong(f->f_fdata->lasti*sizeof(_Py_CODEUNIT)); } static PyObject * frame_getglobals(PyFrameObject *f, void *closure) { - PyObject *globals = f->f_frame->f_globals; + PyObject *globals = f->f_fdata->globals; if (globals == NULL) { globals = Py_None; } @@ -78,7 +95,7 @@ frame_getglobals(PyFrameObject *f, void *closure) static PyObject * frame_getbuiltins(PyFrameObject *f, void *closure) { - PyObject *builtins = f->f_frame->f_builtins; + PyObject *builtins = f->f_fdata->builtins; if (builtins == NULL) { builtins = Py_None; } @@ -402,7 +419,7 @@ first_line_not_before(int *lines, int len, int line) static void frame_stack_pop(PyFrameObject *f) { - PyObject *v = _PyFrame_StackPop(f->f_frame); + PyObject *v = _PyFrame_StackPop(f->f_fdata); Py_DECREF(v); } @@ -442,7 +459,7 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno, void *Py_UNUSED(ignore * In addition, jumps are forbidden when not tracing, * as this is a debugging feature. */ - switch(f->f_frame->f_state) { + switch(f->f_fdata->state) { case FRAME_CREATED: PyErr_Format(PyExc_ValueError, "can't jump from the 'call' trace event of a new frame"); @@ -484,7 +501,7 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno, void *Py_UNUSED(ignore } new_lineno = (int)l_new_lineno; - if (new_lineno < f->f_frame->f_code->co_firstlineno) { + if (new_lineno < f->f_fdata->code->co_firstlineno) { PyErr_Format(PyExc_ValueError, "line %d comes before the current code block", new_lineno); @@ -493,8 +510,8 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno, void *Py_UNUSED(ignore /* PyCode_NewWithPosOnlyArgs limits co_code to be under INT_MAX so this * should never overflow. */ - int len = (int)(PyBytes_GET_SIZE(f->f_frame->f_code->co_code) / sizeof(_Py_CODEUNIT)); - int *lines = marklines(f->f_frame->f_code, len); + int len = (int)(PyBytes_GET_SIZE(f->f_fdata->code->co_code) / sizeof(_Py_CODEUNIT)); + int *lines = marklines(f->f_fdata->code, len); if (lines == NULL) { return -1; } @@ -508,7 +525,7 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno, void *Py_UNUSED(ignore return -1; } - int64_t *stacks = mark_stacks(f->f_frame->f_code, len); + int64_t *stacks = mark_stacks(f->f_fdata->code, len); if (stacks == NULL) { PyMem_Free(lines); return -1; @@ -516,7 +533,7 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno, void *Py_UNUSED(ignore int64_t best_stack = OVERFLOWED; int best_addr = -1; - int64_t start_stack = stacks[f->f_frame->f_lasti]; + int64_t start_stack = stacks[f->f_fdata->lasti]; int err = -1; const char *msg = "cannot find bytecode for specified line"; for (int i = 0; i < len; i++) { @@ -550,7 +567,7 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno, void *Py_UNUSED(ignore return -1; } /* Unwind block stack. */ - if (f->f_frame->f_state == FRAME_SUSPENDED) { + if (f->f_fdata->state == FRAME_SUSPENDED) { /* Account for value popped by yield */ start_stack = pop_value(start_stack); } @@ -560,7 +577,7 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno, void *Py_UNUSED(ignore } /* Finally set the new lasti and return OK. */ f->f_lineno = 0; - f->f_frame->f_lasti = best_addr; + f->f_fdata->lasti = best_addr; return 0; } @@ -617,7 +634,7 @@ frame_dealloc(PyFrameObject *f) { /* It is the responsibility of the owning generator/coroutine * to have cleared the generator pointer */ - assert(!f->f_frame->is_generator); + assert(!f->f_fdata->is_generator); if (_PyObject_GC_IS_TRACKED(f)) { _PyObject_GC_UNTRACK(f); @@ -629,13 +646,13 @@ 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_fdata == (_Py_frame *)f->_f_owned_fdata); + _Py_frame *frame = (_Py_frame *)f->_f_owned_fdata; /* Don't clear code object until the end */ - co = frame->f_code; - frame->f_code = NULL; - Py_CLEAR(frame->f_func); - Py_CLEAR(frame->f_locals); + co = frame->code; + frame->code = NULL; + Py_CLEAR(frame->func); + Py_CLEAR(frame->locals); PyObject **locals = _PyFrame_GetLocalsArray(frame); for (int i = 0; i < frame->stacktop; i++) { Py_CLEAR(locals[i]); @@ -656,8 +673,8 @@ frame_traverse(PyFrameObject *f, visitproc visit, void *arg) if (f->f_owns_frame == 0) { return 0; } - assert(f->f_frame->frame_obj == NULL); - return _PyFrame_Traverse(f->f_frame, visit, arg); + assert(f->f_fdata->frame_obj == NULL); + return _PyFrame_Traverse(f->f_fdata, visit, arg); } static int @@ -668,32 +685,32 @@ frame_tp_clear(PyFrameObject *f) * frame may also point to this frame, believe itself to still be * active, and try cleaning up this frame again. */ - f->f_frame->f_state = FRAME_CLEARED; + f->f_fdata->state = FRAME_CLEARED; Py_CLEAR(f->f_trace); /* locals and stack */ - PyObject **locals = _PyFrame_GetLocalsArray(f->f_frame); - assert(f->f_frame->stacktop >= 0); - for (int i = 0; i < f->f_frame->stacktop; i++) { + PyObject **locals = _PyFrame_GetLocalsArray(f->f_fdata); + assert(f->f_fdata->stacktop >= 0); + for (int i = 0; i < f->f_fdata->stacktop; i++) { Py_CLEAR(locals[i]); } - f->f_frame->stacktop = 0; + f->f_fdata->stacktop = 0; return 0; } static PyObject * frame_clear(PyFrameObject *f, PyObject *Py_UNUSED(ignored)) { - if (_PyFrame_IsExecuting(f->f_frame)) { + if (_PyFrame_IsExecuting(f->f_fdata)) { PyErr_SetString(PyExc_RuntimeError, "cannot clear an executing frame"); return NULL; } - if (f->f_frame->is_generator) { + if (f->f_fdata->is_generator) { assert(!f->f_owns_frame); size_t offset_in_gen = offsetof(PyGenObject, gi_iframe); - PyObject *gen = (PyObject *)(((char *)f->f_frame) - offset_in_gen); + PyObject *gen = (PyObject *)(((char *)f->f_fdata) - offset_in_gen); _PyGen_Finalize(gen); } (void)frame_tp_clear(f); @@ -707,8 +724,8 @@ static PyObject * frame_sizeof(PyFrameObject *f, PyObject *Py_UNUSED(ignored)) { Py_ssize_t res; - res = offsetof(PyFrameObject, _f_frame_data) + offsetof(_PyInterpreterFrame, localsplus); - PyCodeObject *code = f->f_frame->f_code; + res = offsetof(PyFrameObject, _f_owned_fdata) + offsetof(_Py_frame, localsplus); + PyCodeObject *code = f->f_fdata->code; res += (code->co_nlocalsplus+code->co_stacksize) * sizeof(PyObject *); return PyLong_FromSsize_t(res); } @@ -720,7 +737,7 @@ static PyObject * frame_repr(PyFrameObject *f) { int lineno = PyFrame_GetLineNumber(f); - PyCodeObject *code = f->f_frame->f_code; + PyCodeObject *code = f->f_fdata->code; return PyUnicode_FromFormat( "", f, code->co_filename, lineno, code->co_name); @@ -737,8 +754,8 @@ static PyMethodDef frame_methods[] = { PyTypeObject PyFrame_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "frame", - offsetof(PyFrameObject, _f_frame_data) + - offsetof(_PyInterpreterFrame, localsplus), + offsetof(PyFrameObject, _f_owned_fdata) + + offsetof(_Py_frame, localsplus), sizeof(PyObject *), (destructor)frame_dealloc, /* tp_dealloc */ 0, /* tp_vectorcall_offset */ @@ -771,7 +788,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); @@ -827,8 +844,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_owned_fdata, func, locals); + f->f_fdata = (_Py_frame *)f->_f_owned_fdata; f->f_owns_frame = 1; Py_DECREF(func); _PyObject_GC_TRACK(f); @@ -836,11 +853,11 @@ 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) { const _Py_CODEUNIT *code = - (const _Py_CODEUNIT *)PyBytes_AS_STRING(frame->f_code->co_code); - for (int i = 0; i < frame->f_lasti; i++) { + (const _Py_CODEUNIT *)PyBytes_AS_STRING(frame->code->co_code); + for (int i = 0; i < frame->lasti; i++) { if (_Py_OPCODE(code[i]) == opcode && _Py_OPARG(code[i]) == oparg) { return 1; } @@ -849,30 +866,30 @@ _PyFrame_OpAlreadyRan(_PyInterpreterFrame *frame, int opcode, int oparg) } int -_PyFrame_FastToLocalsWithError(_PyInterpreterFrame *frame) { - /* Merge fast locals into f->f_locals */ +_PyFrame_FastToLocalsWithError(_Py_frame *frame) { + /* Merge fast locals into f->locals */ PyObject *locals; PyObject **fast; PyCodeObject *co; - locals = frame->f_locals; + locals = frame->locals; if (locals == NULL) { - locals = frame->f_locals = PyDict_New(); + locals = frame->locals = PyDict_New(); if (locals == NULL) return -1; } - co = frame->f_code; + co = frame->code; fast = _PyFrame_GetLocalsArray(frame); - if (frame->f_lasti < 0 && _Py_OPCODE(co->co_firstinstr[0]) == COPY_FREE_VARS) { + if (frame->lasti < 0 && _Py_OPCODE(co->co_firstinstr[0]) == COPY_FREE_VARS) { /* Free vars have not been initialized -- Do that */ - PyCodeObject *co = frame->f_code; - PyObject *closure = frame->f_func->func_closure; + PyCodeObject *co = frame->code; + PyObject *closure = frame->func->func_closure; int offset = co->co_nlocals + co->co_nplaincellvars; for (int i = 0; i < co->co_nfreevars; ++i) { PyObject *o = PyTuple_GET_ITEM(closure, i); Py_INCREF(o); frame->localsplus[offset + i] = o; } - frame->f_lasti = 0; + frame->lasti = 0; } for (int i = 0; i < co->co_nlocalsplus; i++) { _PyLocals_Kind kind = _PyLocals_GetKind(co->co_localspluskinds, i); @@ -891,7 +908,7 @@ _PyFrame_FastToLocalsWithError(_PyInterpreterFrame *frame) { PyObject *name = PyTuple_GET_ITEM(co->co_localsplusnames, i); PyObject *value = fast[i]; - if (frame->f_state != FRAME_CLEARED) { + if (frame->state != FRAME_CLEARED) { if (kind & CO_FAST_FREE) { // The cell was set by COPY_FREE_VARS. assert(value != NULL && PyCell_Check(value)); @@ -944,7 +961,7 @@ PyFrame_FastToLocalsWithError(PyFrameObject *f) PyErr_BadInternalCall(); return -1; } - return _PyFrame_FastToLocalsWithError(f->f_frame); + return _PyFrame_FastToLocalsWithError(f->f_fdata); } void @@ -960,18 +977,18 @@ 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; PyObject **fast; PyObject *error_type, *error_value, *error_traceback; PyCodeObject *co; - locals = frame->f_locals; + locals = frame->locals; if (locals == NULL) return; fast = _PyFrame_GetLocalsArray(frame); - co = frame->f_code; + co = frame->code; PyErr_Fetch(&error_type, &error_value, &error_traceback); for (int i = 0; i < co->co_nlocalsplus; i++) { @@ -1028,10 +1045,10 @@ _PyFrame_LocalsToFast(_PyInterpreterFrame *frame, int clear) void PyFrame_LocalsToFast(PyFrameObject *f, int clear) { - if (f == NULL || f->f_frame->f_state == FRAME_CLEARED) { + if (f == NULL || f->f_fdata->state == FRAME_CLEARED) { return; } - _PyFrame_LocalsToFast(f->f_frame, clear); + _PyFrame_LocalsToFast(f->f_fdata, clear); } @@ -1039,7 +1056,7 @@ PyCodeObject * PyFrame_GetCode(PyFrameObject *frame) { assert(frame != NULL); - PyCodeObject *code = frame->f_frame->f_code; + PyCodeObject *code = frame->f_fdata->code; assert(code != NULL); Py_INCREF(code); return code; @@ -1051,8 +1068,8 @@ PyFrame_GetBack(PyFrameObject *frame) { assert(frame != NULL); PyFrameObject *back = frame->f_back; - if (back == NULL && frame->f_frame->previous != NULL) { - back = _PyFrame_GetFrameObject(frame->f_frame->previous); + if (back == NULL && frame->f_fdata->previous != NULL) { + back = _PyFrame_GetFrameObject(frame->f_fdata->previous); } Py_XINCREF(back); return back; diff --git a/Objects/genobject.c b/Objects/genobject.c index 6551b939c4590c..78d68488b1095d 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)->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,11 +152,11 @@ 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; - if (frame->f_state == FRAME_CREATED && arg && arg != Py_None) { + if (frame->state == FRAME_CREATED && arg && arg != Py_None) { const char *msg = "can't send non-None value to a " "just-started generator"; if (PyCoro_CheckExact(gen)) { @@ -348,19 +348,19 @@ _PyGen_yf(PyGenObject *gen) PyObject *yf = NULL; if (gen->gi_frame_valid) { - _PyInterpreterFrame *frame = (_PyInterpreterFrame *)gen->gi_iframe; + _Py_frame *frame = (_Py_frame *)gen->gi_iframe; PyObject *bytecode = gen->gi_code->co_code; unsigned char *code = (unsigned char *)PyBytes_AS_STRING(bytecode); - if (frame->f_lasti < 1) { + if (frame->lasti < 1) { /* Return immediately if the frame didn't start yet. SEND always come after LOAD_CONST: a code object should not start with SEND */ assert(code[0] != SEND); return NULL; } - int opcode = code[(frame->f_lasti+1)*sizeof(_Py_CODEUNIT)]; - int oparg = code[(frame->f_lasti+1)*sizeof(_Py_CODEUNIT)+1]; + int opcode = code[(frame->lasti+1)*sizeof(_Py_CODEUNIT)]; + int oparg = code[(frame->lasti+1)*sizeof(_Py_CODEUNIT)+1]; if (opcode != RESUME || oparg < 2) { /* Not in a yield from */ return NULL; @@ -380,11 +380,11 @@ gen_close(PyGenObject *gen, PyObject *args) int err = 0; if (yf) { - _PyInterpreterFrame *frame = (_PyInterpreterFrame *)gen->gi_iframe; - PyFrameState state = frame->f_state; - frame->f_state = FRAME_EXECUTING; + _Py_frame *frame = (_Py_frame *)gen->gi_iframe; + PyFrameState state = frame->state; + frame->state = FRAME_EXECUTING; err = gen_close_iter(yf); - frame->f_state = state; + frame->state = state; Py_DECREF(yf); } if (err == 0) @@ -421,7 +421,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) && @@ -431,10 +431,10 @@ _gen_throw(PyGenObject *gen, int close_on_genexit, We have to allow some awaits to work it through, hence the `close_on_genexit` parameter here. */ - PyFrameState state = frame->f_state; - frame->f_state = FRAME_EXECUTING; + PyFrameState state = frame->state; + frame->state = FRAME_EXECUTING; err = gen_close_iter(yf); - frame->f_state = state; + frame->state = state; Py_DECREF(yf); if (err < 0) return gen_send_ex(gen, Py_None, 1, 0); @@ -448,16 +448,16 @@ _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 'yield from' or awaiting on with 'await'. */ - PyFrameState state = frame->f_state; - frame->f_state = FRAME_EXECUTING; + PyFrameState state = frame->state; + frame->state = FRAME_EXECUTING; ret = _gen_throw((PyGenObject *)yf, close_on_genexit, typ, val, tb); - frame->f_state = state; + frame->state = state; tstate->cframe->current_frame = prev; frame->previous = NULL; } else { @@ -471,10 +471,10 @@ _gen_throw(PyGenObject *gen, int close_on_genexit, Py_DECREF(yf); goto throw_here; } - PyFrameState state = frame->f_state; - frame->f_state = FRAME_EXECUTING; + PyFrameState state = frame->state; + frame->state = FRAME_EXECUTING; ret = PyObject_CallFunctionObjArgs(meth, typ, val, tb, NULL); - frame->f_state = state; + frame->state = state; Py_DECREF(meth); } Py_DECREF(yf); @@ -482,18 +482,18 @@ _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); /* Termination repetition of SEND loop */ - assert(frame->f_lasti >= 0); + assert(frame->lasti >= 0); PyObject *bytecode = gen->gi_code->co_code; unsigned char *code = (unsigned char *)PyBytes_AS_STRING(bytecode); /* Backup to SEND */ - frame->f_lasti--; - assert(code[frame->f_lasti*sizeof(_Py_CODEUNIT)] == SEND); - int jump = code[frame->f_lasti*sizeof(_Py_CODEUNIT)+1]; - frame->f_lasti += jump; + frame->lasti--; + assert(code[frame->lasti*sizeof(_Py_CODEUNIT)] == SEND); + int jump = code[frame->lasti*sizeof(_Py_CODEUNIT)+1]; + frame->lasti += jump; if (_PyGen_FetchStopIterationValue(&val) == 0) { ret = gen_send(gen, val); Py_DECREF(val); @@ -760,7 +760,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 * @@ -769,7 +769,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)->state == FRAME_SUSPENDED); } static PyObject * @@ -781,7 +781,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 * @@ -812,7 +812,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); @@ -841,7 +841,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 */ @@ -915,7 +915,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) @@ -964,7 +964,7 @@ static PyObject * gen_new_with_qualname(PyTypeObject *type, PyFrameObject *f, PyObject *name, PyObject *qualname) { - PyCodeObject *code = f->f_frame->f_code; + PyCodeObject *code = f->f_fdata->code; int size = code->co_nlocalsplus + code->co_stacksize; PyGenObject *gen = PyObject_GC_NewVar(PyGenObject, type, size); if (gen == NULL) { @@ -972,14 +972,14 @@ gen_new_with_qualname(PyTypeObject *type, PyFrameObject *f, return NULL; } /* Copy the frame */ - assert(f->f_frame->frame_obj == NULL); + assert(f->f_fdata->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_owned_fdata, frame); gen->gi_frame_valid = 1; assert(frame->frame_obj == f); f->f_owns_frame = 0; - f->f_frame = frame; + f->f_fdata = frame; frame->is_generator = true; assert(PyObject_GC_IsTracked((PyObject *)f)); gen->gi_code = PyFrame_GetCode(f); @@ -1118,7 +1118,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)->state == FRAME_SUSPENDED); } static PyObject * @@ -1127,7 +1127,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 * @@ -1186,7 +1186,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 */ @@ -1325,9 +1325,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) { @@ -1341,10 +1341,10 @@ compute_cr_origin(int origin_depth, _PyInterpreterFrame *current_frame) } frame = current_frame; for (int i = 0; i < frame_count; ++i) { - PyCodeObject *code = frame->f_code; + PyCodeObject *code = frame->code; PyObject *frameinfo = Py_BuildValue("OiO", code->co_filename, - PyCode_Addr2Line(frame->f_code, frame->f_lasti*sizeof(_Py_CODEUNIT)), + PyCode_Addr2Line(frame->code, frame->lasti*sizeof(_Py_CODEUNIT)), code->co_name); if (!frameinfo) { Py_DECREF(cr_origin); @@ -1578,7 +1578,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 */ @@ -2064,7 +2064,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 78795150756130..f34379dbc75759 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->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->lasti >= 0) { assert(_Py_OPCODE(*co->co_firstinstr) == MAKE_CELL || _Py_OPCODE(*co->co_firstinstr) == COPY_FREE_VARS); assert(PyCell_Check(firstarg)); firstarg = PyCell_GET(firstarg); @@ -8968,7 +8968,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"); @@ -9026,13 +9026,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->code, &type, &obj); if (res < 0) { return -1; diff --git a/Python/_warnings.c b/Python/_warnings.c index be962e76cd8019..26760d36f30f83 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -848,8 +848,8 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno, *lineno = 1; } else { - globals = f->f_frame->f_globals; - *filename = f->f_frame->f_code->co_filename; + globals = f->f_fdata->globals; + *filename = f->f_fdata->code->co_filename; Py_INCREF(*filename); *lineno = PyFrame_GetLineNumber(f); Py_DECREF(f); diff --git a/Python/ceval.c b/Python/ceval.c index 1a120bba83f8cd..ee614fcf95fcb0 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -59,33 +59,33 @@ 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", - frame->f_lasti, opcode, oparg); + frame->lasti, opcode, oparg); } else { printf("%d: %d\n", - frame->f_lasti, opcode); + frame->lasti, opcode); } } #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" @@ -1111,14 +1111,14 @@ PyEval_EvalFrame(PyFrameObject *f) { /* Function kept for backward compatibility */ PyThreadState *tstate = _PyThreadState_GET(); - return _PyEval_EvalFrame(tstate, f->f_frame, 0); + return _PyEval_EvalFrame(tstate, f->f_fdata, 0); } PyObject * PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) { PyThreadState *tstate = _PyThreadState_GET(); - return _PyEval_EvalFrame(tstate, f->f_frame, throwflag); + return _PyEval_EvalFrame(tstate, f->f_fdata, throwflag); } @@ -1253,14 +1253,14 @@ eval_frame_handle_pending(PyThreadState *tstate) #ifdef Py_STATS #define INSTRUCTION_START(op) \ do { \ - frame->f_lasti = INSTR_OFFSET(); \ + frame->lasti = INSTR_OFFSET(); \ next_instr++; \ OPCODE_EXE_INC(op); \ _py_stats.opcode_stats[lastopcode].pair_count[op]++; \ lastopcode = op; \ } while (0) #else -#define INSTRUCTION_START(op) frame->f_lasti = INSTR_OFFSET(); next_instr++ +#define INSTRUCTION_START(op) frame->lasti = INSTR_OFFSET(); next_instr++ #endif #if USE_COMPUTED_GOTOS @@ -1327,7 +1327,7 @@ eval_frame_handle_pending(PyThreadState *tstate) /* Get opcode and oparg from original instructions, not quickened form. */ #define TRACING_NEXTOPARG() do { \ - _Py_CODEUNIT word = ((_Py_CODEUNIT *)PyBytes_AS_STRING(frame->f_code->co_code))[INSTR_OFFSET()]; \ + _Py_CODEUNIT word = ((_Py_CODEUNIT *)PyBytes_AS_STRING(frame->code->co_code))[INSTR_OFFSET()]; \ opcode = _Py_OPCODE(word); \ oparg = _Py_OPARG(word); \ } while (0) @@ -1397,20 +1397,20 @@ eval_frame_handle_pending(PyThreadState *tstate) #ifdef LLTRACE #define PUSH(v) { (void)(BASIC_PUSH(v), \ lltrace && prtrace(tstate, TOP(), "push")); \ - assert(STACK_LEVEL() <= frame->f_code->co_stacksize); } + assert(STACK_LEVEL() <= frame->code->co_stacksize); } #define POP() ((void)(lltrace && prtrace(tstate, TOP(), "pop")), \ BASIC_POP()) #define STACK_GROW(n) do { \ assert(n >= 0); \ (void)(BASIC_STACKADJ(n), \ lltrace && prtrace(tstate, TOP(), "stackadj")); \ - assert(STACK_LEVEL() <= frame->f_code->co_stacksize); \ + assert(STACK_LEVEL() <= frame->code->co_stacksize); \ } while (0) #define STACK_SHRINK(n) do { \ assert(n >= 0); \ (void)(lltrace && prtrace(tstate, TOP(), "stackadj")); \ (void)(BASIC_STACKADJ(-(n))); \ - assert(STACK_LEVEL() <= frame->f_code->co_stacksize); \ + assert(STACK_LEVEL() <= frame->code->co_stacksize); \ } while (0) #else #define PUSH(v) BASIC_PUSH(v) @@ -1441,9 +1441,9 @@ eval_frame_handle_pending(PyThreadState *tstate) #define UPDATE_PREV_INSTR_OPARG(instr, oparg) ((uint8_t*)(instr))[-1] = (oparg) -#define GLOBALS() frame->f_globals -#define BUILTINS() frame->f_builtins -#define LOCALS() frame->f_locals +#define GLOBALS() frame->globals +#define BUILTINS() frame->builtins +#define LOCALS() frame->locals /* Shared opcode macros */ @@ -1509,7 +1509,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 @@ -1548,7 +1548,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, @@ -1565,10 +1565,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; } @@ -1589,7 +1589,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); @@ -1647,13 +1647,13 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int /* Sets the above local variables from the frame */ #define SET_LOCALS_FROM_FRAME() \ { \ - PyCodeObject *co = frame->f_code; \ + PyCodeObject *co = frame->code; \ names = co->co_names; \ consts = co->co_consts; \ first_instr = co->co_firstinstr; \ } \ - assert(frame->f_lasti >= -1); \ - next_instr = first_instr + frame->f_lasti + 1; \ + assert(frame->lasti >= -1); \ + next_instr = first_instr + frame->lasti + 1; \ stack_pointer = _PyFrame_GetStackPointer(frame); \ /* Set stackdepth to -1. \ Update when returning or calling trace function. \ @@ -1722,14 +1722,14 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int } TARGET(RESUME) { - int err = _Py_IncrementCountAndMaybeQuicken(frame->f_code); + int err = _Py_IncrementCountAndMaybeQuicken(frame->code); if (err) { if (err < 0) { goto error; } /* Update first_instr and next_instr to point to newly quickened code */ int nexti = INSTR_OFFSET(); - first_instr = frame->f_code->co_firstinstr; + first_instr = frame->code->co_firstinstr; next_instr = first_instr + nexti; } JUMP_TO_INSTRUCTION(RESUME_QUICK); @@ -1739,7 +1739,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int PREDICTED(RESUME_QUICK); assert(tstate->cframe == &cframe); assert(frame == cframe.current_frame); - frame->f_state = FRAME_EXECUTING; + frame->state = FRAME_EXECUTING; if (_Py_atomic_load_relaxed(eval_breaker) && oparg < 2) { goto handle_eval_breaker; } @@ -2199,7 +2199,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; } @@ -2214,7 +2214,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int new_frame->localsplus[i] = NULL; } _PyFrame_SetStackPointer(frame, stack_pointer); - frame->f_lasti += INLINE_CACHE_ENTRIES_BINARY_SUBSCR; + frame->lasti += INLINE_CACHE_ENTRIES_BINARY_SUBSCR; new_frame->previous = frame; frame = cframe.current_frame = new_frame; CALL_STAT_INC(inlined_py_calls); @@ -2382,7 +2382,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int TARGET(RETURN_VALUE) { PyObject *retval = POP(); assert(EMPTY()); - frame->f_state = FRAME_RETURNED; + frame->state = FRAME_RETURNED; _PyFrame_SetStackPointer(frame, stack_pointer); TRACE_FUNCTION_EXIT(); DTRACE_FUNCTION_EXIT(); @@ -2581,7 +2581,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int TARGET(ASYNC_GEN_WRAP) { PyObject *v = TOP(); - assert(frame->f_code->co_flags & CO_ASYNC_GENERATOR); + assert(frame->code->co_flags & CO_ASYNC_GENERATOR); PyObject *w = _PyAsyncGenValueWrapperNew(v); if (w == NULL) { goto error; @@ -2594,7 +2594,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int TARGET(YIELD_VALUE) { assert(frame->is_entry); PyObject *retval = POP(); - frame->f_state = FRAME_SUSPENDED; + frame->state = FRAME_SUSPENDED; _PyFrame_SetStackPointer(frame, stack_pointer); TRACE_FUNCTION_EXIT(); DTRACE_FUNCTION_EXIT(); @@ -2619,7 +2619,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int if (oparg) { PyObject *lasti = PEEK(oparg + 1); if (PyLong_Check(lasti)) { - frame->f_lasti = PyLong_AsLong(lasti); + frame->lasti = PyLong_AsLong(lasti); assert(!_PyErr_Occurred(tstate)); } else { @@ -3091,15 +3091,15 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int Py_DECREF(oldobj); DISPATCH(); } - format_exc_unbound(tstate, frame->f_code, oparg); + format_exc_unbound(tstate, frame->code, oparg); goto error; } TARGET(LOAD_CLASSDEREF) { PyObject *name, *value, *locals = LOCALS(); assert(locals); - assert(oparg >= 0 && oparg < frame->f_code->co_nlocalsplus); - name = PyTuple_GET_ITEM(frame->f_code->co_localsplusnames, oparg); + assert(oparg >= 0 && oparg < frame->code->co_nlocalsplus); + name = PyTuple_GET_ITEM(frame->code->co_localsplusnames, oparg); if (PyDict_CheckExact(locals)) { value = PyDict_GetItemWithError(locals, name); if (value != NULL) { @@ -3122,7 +3122,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int PyObject *cell = GETLOCAL(oparg); value = PyCell_GET(cell); if (value == NULL) { - format_exc_unbound(tstate, frame->f_code, oparg); + format_exc_unbound(tstate, frame->code, oparg); goto error; } Py_INCREF(value); @@ -3135,7 +3135,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int PyObject *cell = GETLOCAL(oparg); PyObject *value = PyCell_GET(cell); if (value == NULL) { - format_exc_unbound(tstate, frame->f_code, oparg); + format_exc_unbound(tstate, frame->code, oparg); goto error; } Py_INCREF(value); @@ -3154,8 +3154,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int TARGET(COPY_FREE_VARS) { /* Copy closure variables to free variables */ - PyCodeObject *co = frame->f_code; - PyObject *closure = frame->f_func->func_closure; + PyCodeObject *co = frame->code; + PyObject *closure = frame->func->func_closure; int offset = co->co_nlocals + co->co_nplaincellvars; assert(oparg == co->co_nfreevars); for (int i = 0; i < oparg; ++i) { @@ -4067,14 +4067,14 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int TARGET(JUMP_ABSOLUTE) { PREDICTED(JUMP_ABSOLUTE); - int err = _Py_IncrementCountAndMaybeQuicken(frame->f_code); + int err = _Py_IncrementCountAndMaybeQuicken(frame->code); if (err) { if (err < 0) { goto error; } /* Update first_instr and next_instr to point to newly quickened code */ int nexti = INSTR_OFFSET(); - first_instr = frame->f_code->co_firstinstr; + first_instr = frame->code->co_firstinstr; next_instr = first_instr + nexti; } JUMP_TO_INSTRUCTION(JUMP_ABSOLUTE_QUICK); @@ -4086,7 +4086,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int * generator or coroutine, so we deliberately do not check it here. * (see bpo-30039). */ - frame->f_state = FRAME_EXECUTING; + frame->state = FRAME_EXECUTING; JUMPTO(oparg); DISPATCH(); } @@ -4191,7 +4191,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int PyObject *iter; if (PyCoro_CheckExact(iterable)) { /* `iterable` is a coroutine */ - if (!(frame->f_code->co_flags & (CO_COROUTINE | CO_ITERABLE_COROUTINE))) { + if (!(frame->code->co_flags & (CO_COROUTINE | CO_ITERABLE_COROUTINE))) { /* and it is used in a 'yield from' expression of a regular generator. */ Py_DECREF(iterable); @@ -4629,7 +4629,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 ); @@ -4641,7 +4641,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int goto error; } _PyFrame_SetStackPointer(frame, stack_pointer); - frame->f_lasti += INLINE_CACHE_ENTRIES_CALL; + frame->lasti += INLINE_CACHE_ENTRIES_CALL; new_frame->previous = frame; cframe.current_frame = frame = new_frame; CALL_STAT_INC(inlined_py_calls); @@ -4732,7 +4732,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; } @@ -4746,7 +4746,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int } STACK_SHRINK(2-is_meth); _PyFrame_SetStackPointer(frame, stack_pointer); - frame->f_lasti += INLINE_CACHE_ENTRIES_CALL; + frame->lasti += INLINE_CACHE_ENTRIES_CALL; new_frame->previous = frame; frame = cframe.current_frame = new_frame; goto start_frame; @@ -4766,7 +4766,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; } @@ -4786,7 +4786,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int } STACK_SHRINK(2-is_meth); _PyFrame_SetStackPointer(frame, stack_pointer); - frame->f_lasti += INLINE_CACHE_ENTRIES_CALL; + frame->lasti += INLINE_CACHE_ENTRIES_CALL; new_frame->previous = frame; frame = cframe.current_frame = new_frame; goto start_frame; @@ -5262,21 +5262,21 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int } TARGET(RETURN_GENERATOR) { - PyGenObject *gen = (PyGenObject *)_Py_MakeCoro(frame->f_func); + PyGenObject *gen = (PyGenObject *)_Py_MakeCoro(frame->func); if (gen == NULL) { goto error; } 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; gen_frame->is_generator = true; - gen_frame->f_state = FRAME_CREATED; + gen_frame->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); @@ -5284,9 +5284,9 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int } /* Make sure that frame is in a valid state */ frame->stacktop = 0; - frame->f_locals = NULL; - Py_INCREF(frame->f_func); - Py_INCREF(frame->f_code); + frame->locals = NULL; + Py_INCREF(frame->func); + Py_INCREF(frame->code); /* Restore previous cframe and return. */ tstate->cframe = cframe.previous; tstate->cframe->use_tracing = cframe.use_tracing; @@ -5443,8 +5443,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int #endif { if (tstate->tracing == 0) { - int instr_prev = frame->f_lasti; - frame->f_lasti = INSTR_OFFSET(); + int instr_prev = frame->lasti; + frame->lasti = INSTR_OFFSET(); TRACING_NEXTOPARG(); if (opcode == RESUME) { if (oparg < 2) { @@ -5454,7 +5454,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int TRACE_FUNCTION_ENTRY(); DTRACE_FUNCTION_ENTRY(); } - else if (frame->f_state > FRAME_CREATED) { + else if (frame->state > FRAME_CREATED) { /* line-by-line tracing support */ if (PyDTrace_LINE_ENABLED()) { maybe_dtrace_line(frame, &tstate->trace_info, instr_prev); @@ -5476,7 +5476,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int goto error; } /* Reload possibly changed frame fields */ - JUMPTO(frame->f_lasti); + JUMPTO(frame->lasti); stack_pointer = _PyFrame_GetStackPointer(frame); frame->stacktop = -1; @@ -5495,7 +5495,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int #endif fprintf(stderr, "XXX lineno: %d, opcode: %d\n", - PyCode_Addr2Line(frame->f_code, frame->f_lasti*sizeof(_Py_CODEUNIT)), + PyCode_Addr2Line(frame->code, frame->lasti*sizeof(_Py_CODEUNIT)), opcode); _PyErr_SetString(tstate, PyExc_SystemError, "unknown opcode"); goto error; @@ -5550,7 +5550,7 @@ MISS_WITH_INLINE_CACHE(STORE_SUBSCR) { format_exc_check_arg(tstate, PyExc_UnboundLocalError, UNBOUNDLOCAL_ERROR_MSG, - PyTuple_GetItem(frame->f_code->co_localsplusnames, oparg) + PyTuple_GetItem(frame->code->co_localsplusnames, oparg) ); goto error; } @@ -5575,17 +5575,17 @@ MISS_WITH_INLINE_CACHE(STORE_SUBSCR) if (tstate->c_tracefunc != NULL) { /* Make sure state is set to FRAME_UNWINDING for tracing */ - frame->f_state = FRAME_UNWINDING; + frame->state = FRAME_UNWINDING; call_exc_trace(tstate->c_tracefunc, tstate->c_traceobj, tstate, frame); } exception_unwind: - frame->f_state = FRAME_UNWINDING; - /* We can't use frame->f_lasti here, as RERAISE may have set it */ + frame->state = FRAME_UNWINDING; + /* We can't use frame->lasti here, as RERAISE may have set it */ int offset = INSTR_OFFSET()-1; int level, handler, lasti; - if (get_exception_handler(frame->f_code, offset, &level, &handler, &lasti) == 0) { + if (get_exception_handler(frame->code, offset, &level, &handler, &lasti) == 0) { // No handlers, so exit. assert(_PyErr_Occurred(tstate)); @@ -5597,7 +5597,7 @@ MISS_WITH_INLINE_CACHE(STORE_SUBSCR) } assert(STACK_LEVEL() == 0); _PyFrame_SetStackPointer(frame, stack_pointer); - frame->f_state = FRAME_RAISED; + frame->state = FRAME_RAISED; TRACE_FUNCTION_UNWIND(); DTRACE_FUNCTION_EXIT(); goto exit_unwind; @@ -5611,7 +5611,7 @@ MISS_WITH_INLINE_CACHE(STORE_SUBSCR) } PyObject *exc, *val, *tb; if (lasti) { - PyObject *lasti = PyLong_FromLong(frame->f_lasti); + PyObject *lasti = PyLong_FromLong(frame->lasti); if (lasti == NULL) { goto exception_unwind; } @@ -5632,7 +5632,7 @@ MISS_WITH_INLINE_CACHE(STORE_SUBSCR) PUSH(val); JUMPTO(handler); /* Resume normal execution */ - frame->f_state = FRAME_EXECUTING; + frame->state = FRAME_EXECUTING; DISPATCH(); } @@ -6179,7 +6179,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) @@ -6187,7 +6187,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; } @@ -6217,7 +6217,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); @@ -6244,7 +6244,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; @@ -6613,7 +6613,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; @@ -6643,7 +6643,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; @@ -6664,9 +6664,9 @@ 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; + PyCodeObject *code = frame->code; if (trace_info->code != code) { trace_info->code = code; _PyCode_InitAddressRange(code, &trace_info->bounds); @@ -6687,7 +6687,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; @@ -6699,9 +6699,9 @@ call_trace(Py_tracefunc func, PyObject *obj, return -1; } PyThreadState_EnterTracing(tstate); - assert (frame->f_lasti >= 0); + assert (frame->lasti >= 0); initialize_trace_info(&tstate->trace_info, frame); - f->f_lineno = _PyCode_CheckLineNumber(frame->f_lasti*sizeof(_Py_CODEUNIT), &tstate->trace_info.bounds); + f->f_lineno = _PyCode_CheckLineNumber(frame->lasti*sizeof(_Py_CODEUNIT), &tstate->trace_info.bounds); result = func(obj, f, what, arg); f->f_lineno = 0; PyThreadState_LeaveTracing(tstate); @@ -6726,7 +6726,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; @@ -6736,7 +6736,7 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj, */ initialize_trace_info(&tstate->trace_info, frame); int entry_point = 0; - _Py_CODEUNIT *code = (_Py_CODEUNIT *)PyBytes_AS_STRING(frame->f_code->co_code); + _Py_CODEUNIT *code = (_Py_CODEUNIT *)PyBytes_AS_STRING(frame->code->co_code); while (_Py_OPCODE(code[entry_point]) != RESUME) { entry_point++; } @@ -6747,7 +6747,7 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj, else { lastline = _PyCode_CheckLineNumber(instr_prev*sizeof(_Py_CODEUNIT), &tstate->trace_info.bounds); } - int line = _PyCode_CheckLineNumber(frame->f_lasti*sizeof(_Py_CODEUNIT), &tstate->trace_info.bounds); + int line = _PyCode_CheckLineNumber(frame->lasti*sizeof(_Py_CODEUNIT), &tstate->trace_info.bounds); PyFrameObject *f = _PyFrame_GetFrameObject(frame); if (f == NULL) { return -1; @@ -6755,8 +6755,8 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj, if (line != -1 && f->f_trace_lines) { /* Trace backward edges (except in 'yield from') or if line number has changed */ int trace = line != lastline || - (frame->f_lasti < instr_prev && - _Py_OPCODE(frame->f_code->co_firstinstr[frame->f_lasti]) != SEND); + (frame->lasti < instr_prev && + _Py_OPCODE(frame->code->co_firstinstr[frame->lasti]) != SEND); if (trace) { result = call_trace(func, obj, tstate, frame, PyTrace_LINE, Py_None); } @@ -6908,7 +6908,7 @@ _PyEval_GetAsyncGenFinalizer(void) return tstate->async_gen_finalizer; } -_PyInterpreterFrame * +_Py_frame * _PyEval_GetFrame(void) { PyThreadState *tstate = _PyThreadState_GET(); @@ -6932,9 +6932,9 @@ 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; + return frame->builtins; } return tstate->interp->builtins; } @@ -6971,7 +6971,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; @@ -6981,7 +6981,7 @@ PyEval_GetLocals(void) return NULL; } - PyObject *locals = current_frame->f_locals; + PyObject *locals = current_frame->locals; assert(locals != NULL); return locals; } @@ -6990,22 +6990,22 @@ 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; } - return current_frame->f_globals; + return current_frame->globals; } 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) { - const int codeflags = current_frame->f_code->co_flags; + const int codeflags = current_frame->code->co_flags; const int compilerflags = codeflags & PyCF_MASK; if (compilerflags) { result = 1; @@ -7199,20 +7199,20 @@ _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; PyObject* stack[5]; - import_func = _PyDict_GetItemWithError(frame->f_builtins, &_Py_ID(__import__)); + import_func = _PyDict_GetItemWithError(frame->builtins, &_Py_ID(__import__)); if (import_func == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_SetString(tstate, PyExc_ImportError, "__import__ not found"); } return NULL; } - PyObject *locals = frame->f_locals; + PyObject *locals = frame->locals; /* Fast path for not overloaded __import__. */ if (import_func == tstate->interp->import_func) { int ilevel = _PyLong_AsInt(level); @@ -7221,7 +7221,7 @@ import_name(PyThreadState *tstate, _PyInterpreterFrame *frame, } res = PyImport_ImportModuleLevelObject( name, - frame->f_globals, + frame->globals, locals == NULL ? Py_None :locals, fromlist, ilevel); @@ -7231,7 +7231,7 @@ import_name(PyThreadState *tstate, _PyInterpreterFrame *frame, Py_INCREF(import_func); stack[0] = name; - stack[1] = frame->f_globals; + stack[1] = frame->globals; stack[2] = locals == NULL ? Py_None : locals; stack[3] = fromlist; stack[4] = level; @@ -7673,38 +7673,38 @@ _PyEval_RequestCodeExtraIndex(freefunc free) } static void -dtrace_function_entry(_PyInterpreterFrame *frame) +dtrace_function_entry(_Py_frame *frame) { const char *filename; const char *funcname; int lineno; - PyCodeObject *code = frame->f_code; + PyCodeObject *code = frame->code; filename = PyUnicode_AsUTF8(code->co_filename); funcname = PyUnicode_AsUTF8(code->co_name); - lineno = PyCode_Addr2Line(frame->f_code, frame->f_lasti*sizeof(_Py_CODEUNIT)); + lineno = PyCode_Addr2Line(frame->code, frame->lasti*sizeof(_Py_CODEUNIT)); PyDTrace_FUNCTION_ENTRY(filename, funcname, lineno); } static void -dtrace_function_return(_PyInterpreterFrame *frame) +dtrace_function_return(_Py_frame *frame) { const char *filename; const char *funcname; int lineno; - PyCodeObject *code = frame->f_code; + PyCodeObject *code = frame->code; filename = PyUnicode_AsUTF8(code->co_filename); funcname = PyUnicode_AsUTF8(code->co_name); - lineno = PyCode_Addr2Line(frame->f_code, frame->f_lasti*sizeof(_Py_CODEUNIT)); + lineno = PyCode_Addr2Line(frame->code, frame->lasti*sizeof(_Py_CODEUNIT)); PyDTrace_FUNCTION_RETURN(filename, funcname, lineno); } /* 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) { @@ -7715,17 +7715,17 @@ maybe_dtrace_line(_PyInterpreterFrame *frame, */ initialize_trace_info(trace_info, frame); int lastline = _PyCode_CheckLineNumber(instr_prev*sizeof(_Py_CODEUNIT), &trace_info->bounds); - int line = _PyCode_CheckLineNumber(frame->f_lasti*sizeof(_Py_CODEUNIT), &trace_info->bounds); + int line = _PyCode_CheckLineNumber(frame->lasti*sizeof(_Py_CODEUNIT), &trace_info->bounds); if (line != -1) { /* Trace backward edges or first instruction of a new line */ - if (frame->f_lasti < instr_prev || - (line != lastline && frame->f_lasti*sizeof(_Py_CODEUNIT) == (unsigned int)trace_info->bounds.ar_start)) + if (frame->lasti < instr_prev || + (line != lastline && frame->lasti*sizeof(_Py_CODEUNIT) == (unsigned int)trace_info->bounds.ar_start)) { - co_filename = PyUnicode_AsUTF8(frame->f_code->co_filename); + co_filename = PyUnicode_AsUTF8(frame->code->co_filename); if (!co_filename) { co_filename = "?"; } - co_name = PyUnicode_AsUTF8(frame->f_code->co_name); + co_name = PyUnicode_AsUTF8(frame->code->co_name); if (!co_name) { co_name = "?"; } diff --git a/Python/frame.c b/Python/frame.c index 20b4f81425bc8b..2c8db7daba3d11 100644 --- a/Python/frame.c +++ b/Python/frame.c @@ -7,12 +7,12 @@ #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); - Py_VISIT(frame->f_func); - Py_VISIT(frame->f_code); + Py_VISIT(frame->locals); + Py_VISIT(frame->func); + Py_VISIT(frame->code); /* locals */ PyObject **locals = _PyFrame_GetLocalsArray(frame); int i = 0; @@ -24,13 +24,13 @@ _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; PyErr_Fetch(&error_type, &error_value, &error_traceback); - PyFrameObject *f = _PyFrame_New_NoTrack(frame->f_code); + PyFrameObject *f = _PyFrame_New_NoTrack(frame->code); if (f == NULL) { Py_XDECREF(error_type); Py_XDECREF(error_value); @@ -38,7 +38,7 @@ _PyFrame_MakeAndSetFrameObject(_PyInterpreterFrame *frame) } else { f->f_owns_frame = 0; - f->f_frame = frame; + f->f_fdata = frame; frame->frame_obj = f; PyErr_Restore(error_type, error_value, error_traceback); } @@ -46,26 +46,26 @@ _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); + assert(src->stacktop >= src->code->co_nlocalsplus); Py_ssize_t size = ((char*)&src->localsplus[src->stacktop]) - (char *)src; memcpy(dest, src, size); } 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_owned_fdata, frame, size); + frame = (_Py_frame *)f->_f_owned_fdata; f->f_owns_frame = 1; - f->f_frame = frame; + f->f_fdata = 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. */ @@ -104,19 +104,19 @@ _PyFrame_Clear(_PyInterpreterFrame *frame) Py_XDECREF(frame->localsplus[i]); } Py_XDECREF(frame->frame_obj); - Py_XDECREF(frame->f_locals); - Py_DECREF(frame->f_func); - Py_DECREF(frame->f_code); + Py_XDECREF(frame->locals); + Py_DECREF(frame->func); + Py_DECREF(frame->code); } /* 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/suggestions.c b/Python/suggestions.c index d9e69fa7e0db21..6d598e6cfb23df 100644 --- a/Python/suggestions.c +++ b/Python/suggestions.c @@ -240,7 +240,7 @@ offer_suggestions_for_name_error(PyNameErrorObject *exc) return suggestions; } - dir = PySequence_List(frame->f_frame->f_globals); + dir = PySequence_List(frame->f_fdata->globals); if (dir == NULL) { return NULL; } @@ -250,7 +250,7 @@ offer_suggestions_for_name_error(PyNameErrorObject *exc) return suggestions; } - dir = PySequence_List(frame->f_frame->f_builtins); + dir = PySequence_List(frame->f_fdata->builtins); if (dir == NULL) { return NULL; } diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 99540b09c1f465..16dbd0bb2a881b 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" // _Py_RecursionLimitLowerWaterMark() #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() @@ -1771,7 +1771,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..56c502cd2523b7 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -240,7 +240,7 @@ _PyTraceBack_FromFrame(PyObject *tb_next, PyFrameObject *frame) assert(tb_next == NULL || PyTraceBack_Check(tb_next)); assert(frame != NULL); - return tb_create_raw((PyTracebackObject *)tb_next, frame, frame->f_frame->f_lasti*sizeof(_Py_CODEUNIT), + return tb_create_raw((PyTracebackObject *)tb_next, frame, frame->f_fdata->lasti*sizeof(_Py_CODEUNIT), PyFrame_GetLineNumber(frame)); } @@ -791,7 +791,7 @@ tb_displayline(PyTracebackObject* tb, PyObject *f, PyObject *filename, int linen } int code_offset = tb->tb_lasti; - PyCodeObject* code = frame->f_frame->f_code; + PyCodeObject* code = frame->f_fdata->code; int start_line; int end_line; @@ -1167,9 +1167,9 @@ _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; + PyCodeObject *code = frame->code; PUTS(fd, " File "); if (code->co_filename != NULL && PyUnicode_Check(code->co_filename)) @@ -1181,7 +1181,7 @@ dump_frame(int fd, _PyInterpreterFrame *frame) PUTS(fd, "???"); } - int lineno = PyCode_Addr2Line(code, frame->f_lasti*sizeof(_Py_CODEUNIT)); + int lineno = PyCode_Addr2Line(code, frame->lasti*sizeof(_Py_CODEUNIT)); PUTS(fd, ", line "); if (lineno >= 0) { _Py_DumpDecimal(fd, (size_t)lineno); @@ -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) { diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py index 00cdcca084e742..fa9db4bdd06e0e 100755 --- a/Tools/gdb/libpython.py +++ b/Tools/gdb/libpython.py @@ -890,7 +890,7 @@ def __init__(self, gdbval, cast_to=None): PyObjectPtr.__init__(self, gdbval, cast_to) if not self.is_optimized_out(): - self._frame = PyFramePtr(self.field('f_frame')) + self._frame = PyFramePtr(self.field('f_fdata')) def iter_locals(self): ''' @@ -971,7 +971,7 @@ def __init__(self, gdbval): self.co_name = self.co.pyop_field('co_name') self.co_filename = self.co.pyop_field('co_filename') - self.f_lasti = self._f_lasti() + self.lasti = self._f_lasti() self.co_nlocals = int_from_int(self.co.field('co_nlocals')) pnames = self.co.field('co_localsplusnames') self.co_localsplusnames = PyTupleObjectPtr.from_pyobject_ptr(pnames) @@ -1003,19 +1003,19 @@ def _f_special(self, name, convert=PyObjectPtr.from_pyobject_ptr): return convert(self._gdbval[name]) def _f_globals(self): - return self._f_special("f_globals") + return self._f_special("globals") def _f_builtins(self): - return self._f_special("f_builtins") + return self._f_special("builtins") def _f_code(self): - return self._f_special("f_code", PyCodeObjectPtr.from_pyobject_ptr) + return self._f_special("code", PyCodeObjectPtr.from_pyobject_ptr) def _f_nlocalsplus(self): return self._f_special("nlocalsplus", int_from_int) def _f_lasti(self): - return self._f_special("f_lasti", int_from_int) + return self._f_special("lasti", int_from_int) def is_entry(self): return self._f_special("is_entry", bool) @@ -1079,7 +1079,7 @@ def current_line_num(self): if self.is_optimized_out(): return None try: - return self.co.addr2line(self.f_lasti*2) + return self.co.addr2line(self.lasti*2) except Exception: # bpo-34989: addr2line() is a complex function, it can fail in many # ways. For example, it fails with a TypeError on "FakeRepr" if