From a133e0d18c5a626240828caacbe782c587fa82b1 Mon Sep 17 00:00:00 2001 From: Nick Coghlan <ncoghlan@gmail.com> Date: Sun, 1 Aug 2021 18:05:27 +1000 Subject: [PATCH 01/30] bpo-44800: Clearly distinguish execution & introspection frames bpo-44590 significantly improved execution speed by delaying creation of full Python objects for frames until they were needed for tracing or other introspection purposes. This follow-up commit doesn't include any further functions changes, it just changes variable, attribute, and function names to make it less ambiguous as to whether different sections of code are dealing with the classic introspection frames (full Python objects) or the new lighter weight execution frames (C structs with no intrinsic instance lifecycle management). --- Include/cpython/ceval.h | 2 +- Include/cpython/frameobject.h | 23 +- Include/cpython/pystate.h | 12 +- Include/genobject.h | 4 +- Include/internal/pycore_ceval.h | 8 +- Include/internal/pycore_frame.h | 128 ------- Include/internal/pycore_xframe.h | 133 +++++++ .../2021-08-01-18-18-51.bpo-44800.TCsfH3.rst | 4 + Misc/gdbinit | 30 +- Modules/_tracemalloc.c | 18 +- Modules/_xxsubinterpretersmodule.c | 8 +- Modules/signalmodule.c | 8 +- Objects/frameobject.c | 158 ++++---- Objects/genobject.c | 158 ++++---- Objects/typeobject.c | 10 +- Python/_warnings.c | 6 +- Python/ceval.c | 342 +++++++++--------- Python/frame.c | 96 ++--- Python/pylifecycle.c | 2 +- Python/pystate.c | 34 +- Python/suggestions.c | 6 +- Python/sysmodule.c | 12 +- Python/traceback.c | 24 +- Tools/gdb/libpython.py | 62 ++-- 24 files changed, 659 insertions(+), 629 deletions(-) delete mode 100644 Include/internal/pycore_frame.h create mode 100644 Include/internal/pycore_xframe.h create mode 100644 Misc/NEWS.d/next/Core and Builtins/2021-08-01-18-18-51.bpo-44800.TCsfH3.rst diff --git a/Include/cpython/ceval.h b/Include/cpython/ceval.h index 44b78f6d223120..d7b74ed0498c5f 100644 --- a/Include/cpython/ceval.h +++ b/Include/cpython/ceval.h @@ -19,7 +19,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 _interpreter_frame *f, int exc); +PyAPI_FUNC(PyObject *) _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyExecFrame *xf, int exc); PyAPI_FUNC(void) _PyEval_SetSwitchInterval(unsigned long microseconds); PyAPI_FUNC(unsigned long) _PyEval_GetSwitchInterval(void); diff --git a/Include/cpython/frameobject.h b/Include/cpython/frameobject.h index e4cfac518bb58c..75135e75af7666 100644 --- a/Include/cpython/frameobject.h +++ b/Include/cpython/frameobject.h @@ -4,10 +4,26 @@ # error "this header file must not be included directly" #endif +/* Starting in CPython 3.11, CPython separates the frame state between the + * full "introspection frames" exposed by the Python and C runtime state + * introspection APIs, and internal lighter weight "execution frames", 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 + * introspection frame (if an instrospection API has been invoked and the + * introspection frame created). + * + * 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. + */ +// Declaration of _PyExecFrame is in cpython/pystate.h for use in PyThreadState + struct _frame { PyObject_HEAD struct _frame *f_back; /* previous frame, or NULL */ - struct _interpreter_frame *f_frame; /* points to the frame data */ + _PyExecFrame *f_xframe; /* points to the frame runtime 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? */ @@ -24,11 +40,6 @@ PyAPI_DATA(PyTypeObject) PyFrame_Type; PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *, PyObject *, PyObject *); -/* only internal use */ -PyFrameObject* -_PyFrame_New_NoTrack(struct _interpreter_frame *, int); - - /* The rest of the interface is specific for frame objects */ /* Conversions between "fast locals" and locals in dictionary */ diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h index ab4bf8bf8483c7..cb42333bda3e48 100644 --- a/Include/cpython/pystate.h +++ b/Include/cpython/pystate.h @@ -69,6 +69,12 @@ typedef struct _stack_chunk { PyObject * data[1]; /* Variable sized */ } _PyStackChunk; + +// Declared here so the thread state can use it without creating an include loop +// See cpython/frameobject.h for an explanation of the type +// See internal/pycore_xframe.h for the struct definition +typedef struct _Py_execution_frame _PyExecFrame; + // The PyThreadState typedef is in Include/pystate.h. struct _ts { /* See Python/ceval.c for comments explaining most fields */ @@ -77,8 +83,8 @@ struct _ts { struct _ts *next; PyInterpreterState *interp; - /* Borrowed reference to the current frame (it can be NULL) */ - struct _interpreter_frame *frame; + /* Borrowed reference to the current execution frame (it can be NULL) */ + _PyExecFrame *xframe; int recursion_depth; int recursion_headroom; /* Allow 50 more calls to handle any errors. */ int stackcheck_counter; @@ -223,7 +229,7 @@ PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void); /* Frame evaluation API */ -typedef PyObject* (*_PyFrameEvalFunction)(PyThreadState *tstate, struct _interpreter_frame *, int); +typedef PyObject* (*_PyFrameEvalFunction)(PyThreadState *tstate, _PyExecFrame *, int); PyAPI_FUNC(_PyFrameEvalFunction) _PyInterpreterState_GetEvalFrameFunc( PyInterpreterState *interp); diff --git a/Include/genobject.h b/Include/genobject.h index 55a8b34afd60ed..65adc0d5ea623e 100644 --- a/Include/genobject.h +++ b/Include/genobject.h @@ -15,8 +15,8 @@ extern "C" { and coroutine objects. */ #define _PyGenObject_HEAD(prefix) \ PyObject_HEAD \ - /* Note: gi_frame can be NULL if the generator is "finished" */ \ - struct _interpreter_frame *prefix##_xframe; \ + /* Note: gi_xframe can be NULL if the generator is "finished" */ \ + _PyExecFrame *prefix##_xframe; \ /* The code object backing the generator */ \ PyCodeObject *prefix##_code; \ /* List of weak reference. */ \ diff --git a/Include/internal/pycore_ceval.h b/Include/internal/pycore_ceval.h index 66ddc991a9b11a..f87a37fbd53dad 100644 --- a/Include/internal/pycore_ceval.h +++ b/Include/internal/pycore_ceval.h @@ -41,9 +41,9 @@ extern PyObject *_PyEval_BuiltinsFromGlobals( static inline PyObject* -_PyEval_EvalFrame(PyThreadState *tstate, struct _interpreter_frame *frame, int throwflag) +_PyEval_EvalFrame(PyThreadState *tstate, _PyExecFrame *xframe, int throwflag) { - return tstate->interp->eval_frame(tstate, frame, throwflag); + return tstate->interp->eval_frame(tstate, xframe, throwflag); } extern PyObject * @@ -107,9 +107,9 @@ static inline void _Py_LeaveRecursiveCall_inline(void) { #define Py_LeaveRecursiveCall() _Py_LeaveRecursiveCall_inline() -struct _interpreter_frame *_PyEval_GetFrame(void); +_PyExecFrame *_PyEval_GetExecFrame(void); -PyObject *_Py_MakeCoro(PyFrameConstructor *, struct _interpreter_frame *); +PyObject *_Py_MakeCoro(PyFrameConstructor *, _PyExecFrame *); #ifdef __cplusplus } diff --git a/Include/internal/pycore_frame.h b/Include/internal/pycore_frame.h deleted file mode 100644 index cd465d73bc6bdb..00000000000000 --- a/Include/internal/pycore_frame.h +++ /dev/null @@ -1,128 +0,0 @@ -#ifndef Py_INTERNAL_FRAME_H -#define Py_INTERNAL_FRAME_H -#ifdef __cplusplus -extern "C" { -#endif - -/* These values are chosen so that the inline functions below all - * compare f_state to zero. - */ -enum _framestate { - FRAME_CREATED = -2, - FRAME_SUSPENDED = -1, - FRAME_EXECUTING = 0, - FRAME_RETURNED = 1, - FRAME_UNWINDING = 2, - FRAME_RAISED = 3, - FRAME_CLEARED = 4 -}; - -typedef signed char PyFrameState; - -typedef struct _interpreter_frame { - PyObject *f_globals; - PyObject *f_builtins; - PyObject *f_locals; - PyCodeObject *f_code; - PyFrameObject *frame_obj; - /* Borrowed reference to a generator, or NULL */ - PyObject *generator; - struct _interpreter_frame *previous; - int f_lasti; /* Last instruction if called */ - int stackdepth; /* Depth of value stack */ - int nlocalsplus; - PyFrameState f_state; /* What state the frame is in */ - PyObject *stack[1]; -} InterpreterFrame; - -static inline int _PyFrame_IsRunnable(InterpreterFrame *f) { - return f->f_state < FRAME_EXECUTING; -} - -static inline int _PyFrame_IsExecuting(InterpreterFrame *f) { - return f->f_state == FRAME_EXECUTING; -} - -static inline int _PyFrameHasCompleted(InterpreterFrame *f) { - return f->f_state > FRAME_EXECUTING; -} - -#define FRAME_SPECIALS_SIZE ((sizeof(InterpreterFrame)-1)/sizeof(PyObject *)) - -InterpreterFrame * -_PyInterpreterFrame_HeapAlloc(PyFrameConstructor *con, PyObject *locals); - -static inline void -_PyFrame_InitializeSpecials( - InterpreterFrame *frame, PyFrameConstructor *con, - PyObject *locals, int nlocalsplus) -{ - frame->f_code = (PyCodeObject *)Py_NewRef(con->fc_code); - frame->f_builtins = Py_NewRef(con->fc_builtins); - frame->f_globals = Py_NewRef(con->fc_globals); - frame->f_locals = Py_XNewRef(locals); - frame->nlocalsplus = nlocalsplus; - frame->stackdepth = 0; - frame->frame_obj = NULL; - frame->generator = NULL; - frame->f_lasti = -1; - frame->f_state = FRAME_CREATED; -} - -/* Gets the pointer to the locals array - * that precedes this frame. - */ -static inline PyObject** -_PyFrame_GetLocalsArray(InterpreterFrame *frame) -{ - return ((PyObject **)frame) - frame->nlocalsplus; -} - -/* For use by _PyFrame_GetFrameObject - Do not call directly. */ -PyFrameObject * -_PyFrame_MakeAndSetFrameObject(InterpreterFrame *frame); - -/* Gets the PyFrameObject for this frame, lazily - * creating it if necessary. - * Returns a borrowed referennce */ -static inline PyFrameObject * -_PyFrame_GetFrameObject(InterpreterFrame *frame) -{ - PyFrameObject *res = frame->frame_obj; - if (res != NULL) { - return res; - } - return _PyFrame_MakeAndSetFrameObject(frame); -} - -/* Clears all references in the frame. - * If take is non-zero, then the InterpreterFrame frame - * may be transfered to the frame object it references - * instead of being cleared. Either way - * the caller no longer owns the references - * in the frame. - * take should be set to 1 for heap allocated - * frames like the ones in generators and coroutines. - */ -int -_PyFrame_Clear(InterpreterFrame * frame, int take); - -int -_PyFrame_Traverse(InterpreterFrame *frame, visitproc visit, void *arg); - -int -_PyFrame_FastToLocalsWithError(InterpreterFrame *frame); - -void -_PyFrame_LocalsToFast(InterpreterFrame *frame, int clear); - -InterpreterFrame *_PyThreadState_PushFrame( - PyThreadState *tstate, PyFrameConstructor *con, PyObject *locals); - -void _PyThreadState_PopFrame(PyThreadState *tstate, InterpreterFrame *frame); - -#ifdef __cplusplus -} -#endif -#endif /* !Py_INTERNAL_FRAME_H */ diff --git a/Include/internal/pycore_xframe.h b/Include/internal/pycore_xframe.h new file mode 100644 index 00000000000000..4550801f003220 --- /dev/null +++ b/Include/internal/pycore_xframe.h @@ -0,0 +1,133 @@ +#ifndef Py_INTERNAL_XFRAME_H +#define Py_INTERNAL_XFRAME_H +#ifdef __cplusplus +extern "C" { +#endif + +/* Internal-use-only introspection frame constructor */ +PyFrameObject* +_PyFrame_New_NoTrack(_PyExecFrame *, int); + +/* These values are chosen so that the inline functions below all + * compare f_state to zero. + */ +enum _framestate { + FRAME_CREATED = -2, + FRAME_SUSPENDED = -1, + FRAME_EXECUTING = 0, + FRAME_RETURNED = 1, + FRAME_UNWINDING = 2, + FRAME_RAISED = 3, + FRAME_CLEARED = 4 +}; + +typedef signed char PyFrameState; + +// The _PyExecFrame typedef is in Include/pyframeobject.h +struct _Py_execution_frame { + PyObject *xf_globals; + PyObject *xf_builtins; + PyObject *xf_locals; + PyCodeObject *xf_code; + PyFrameObject *xf_frame_obj; // Introspection frame (if created) + /* Borrowed reference to a generator, or NULL */ + PyObject *xf_generator; + _PyExecFrame *xf_previous; + int xf_lasti; /* Last instruction if called */ + int xf_stackdepth; /* Depth of value stack */ + int xf_nlocalsplus; + PyFrameState xf_state; /* What state the frame is in */ + PyObject *xf_stack[1]; +}; + +static inline int _PyExecFrame_IsRunnable(_PyExecFrame *xf) { + return xf->xf_state < FRAME_EXECUTING; +} + +static inline int _PyExecFrame_IsExecuting(_PyExecFrame *xf) { + return xf->xf_state == FRAME_EXECUTING; +} + +static inline int _PyExecFrame_HasCompleted(_PyExecFrame *xf) { + return xf->xf_state > FRAME_EXECUTING; +} + +#define FRAME_SPECIALS_SIZE ((sizeof(_PyExecFrame)-1)/sizeof(PyObject *)) + +_PyExecFrame * +_PyExecFrame_HeapAlloc(PyFrameConstructor *con, PyObject *locals); + +static inline void +_PyExecFrame_InitializeSpecials( + _PyExecFrame *xframe, PyFrameConstructor *con, + PyObject *locals, int nlocalsplus) +{ + xframe->xf_code = (PyCodeObject *)Py_NewRef(con->fc_code); + xframe->xf_builtins = Py_NewRef(con->fc_builtins); + xframe->xf_globals = Py_NewRef(con->fc_globals); + xframe->xf_locals = Py_XNewRef(locals); + xframe->xf_nlocalsplus = nlocalsplus; + xframe->xf_stackdepth = 0; + xframe->xf_frame_obj = NULL; + xframe->xf_generator = NULL; + xframe->xf_lasti = -1; + xframe->xf_state = FRAME_CREATED; +} + +/* Gets the pointer to the locals array + * that precedes this frame. + */ +static inline PyObject** +_PyExecFrame_GetLocalsArray(_PyExecFrame *xframe) +{ + return ((PyObject **)xframe) - xframe->xf_nlocalsplus; +} + +/* For use by _PyExecFrame_GetFrameObject + Do not call directly. */ +PyFrameObject * +_PyExecFrame_MakeAndSetFrameObject(_PyExecFrame *xframe); + +/* Gets the PyFrameObject for this frame, lazily + * creating it if necessary. + * Returns a borrowed referennce */ +static inline PyFrameObject * +_PyExecFrame_GetFrameObject(_PyExecFrame *xframe) +{ + PyFrameObject *res = xframe->xf_frame_obj; + if (res != NULL) { + return res; + } + return _PyExecFrame_MakeAndSetFrameObject(xframe); +} + +/* Clears all references in the frame. + * If take is non-zero, then the execution frame + * may be transfered to the frame object it references + * instead of being cleared. Either way + * the caller no longer owns the references + * in the frame. + * take should be set to 1 for heap allocated + * frames like the ones in generators and coroutines. + */ +int +_PyExecFrame_Clear(_PyExecFrame *xframe, int take); + +int +_PyExecFrame_Traverse(_PyExecFrame *xframe, visitproc visit, void *arg); + +int +_PyExecFrame_FastToLocalsWithError(_PyExecFrame *frame); + +void +_PyExecFrame_LocalsToFast(_PyExecFrame *frame, int clear); + +_PyExecFrame *_PyThreadState_PushExecFrame( + PyThreadState *tstate, PyFrameConstructor *con, PyObject *locals); + +void _PyThreadState_PopExecFrame(PyThreadState *tstate, _PyExecFrame *frame); + +#ifdef __cplusplus +} +#endif +#endif /* !Py_INTERNAL_XFRAME_H */ diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-08-01-18-18-51.bpo-44800.TCsfH3.rst b/Misc/NEWS.d/next/Core and Builtins/2021-08-01-18-18-51.bpo-44800.TCsfH3.rst new file mode 100644 index 00000000000000..fbd49db71f6f6d --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2021-08-01-18-18-51.bpo-44800.TCsfH3.rst @@ -0,0 +1,4 @@ +Refactored internal APIs for the new lazy introspection frame creation to +consistently distinguish between the classic introspection frames (full +Python objects) and the new lighter weight internal execution frames (C +structs with no intrinsic instance lifecycle management) diff --git a/Misc/gdbinit b/Misc/gdbinit index e8f62ba6476423..06887c35d94093 100644 --- a/Misc/gdbinit +++ b/Misc/gdbinit @@ -37,14 +37,14 @@ end define pylocals set $_i = 0 - while $_i < f->f_code->co_nlocals - if f->f_localsplus + $_i != 0 - set $_names = f->f_code->co_varnames - set $_name = PyUnicode_AsUTF8(PyTuple_GetItem($_names, $_i)) - printf "%s:\n", $_name - pyo f->f_localsplus[$_i] - end - set $_i = $_i + 1 + while $_i < f->f_xframe->xf_code->co_nlocals + if _PyExecFrame_GetLocalsArray(f->f_xframe) + $_i != 0 + set $_names = f->f_xframe->xf_code->co_varnames + set $_name = PyUnicode_AsUTF8(PyTuple_GetItem($_names, $_i)) + printf "%s:\n", $_name + pyo _PyExecFrame_GetLocalsArray(f->f_xframe)[$_i] + end + set $_i = $_i + 1 end end document pylocals @@ -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->f_xframe->xf_code + set $__lasti = f->f_xframe->xf_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 @@ -66,7 +66,7 @@ define lineno set $__ad = $__ad + *$__p set $__p = $__p + 1 if ($__ad > $__lasti) - set $__continue = 0 + set $__continue = 0 else set $__li = $__li + *$__p set $__p = $__p + 1 @@ -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->f_xframe->xf_code->co_filename) + set $__n = PyUnicode_AsUTF8(f->f_xframe->xf_code->co_name) printf "%s (", $__fn lineno printf "): %s\n", $__n @@ -134,6 +134,10 @@ end # the interpreter you may will have to change the functions you compare with # $pc. +# Python 3.11 TODO: once all the interpreter optimisation changes settle down, +# revisit the checks in these example hooks, as the correct symbols to look for +# are likely to have changed. + define pystack while $pc < Py_Main || $pc > Py_GetArgcArgv if $pc > PyEval_EvalFrameEx && $pc < _PyEval_EvalFrameDefault diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c index fc3d7f51ee29a1..769bb3d7aa8d9a 100644 --- a/Modules/_tracemalloc.c +++ b/Modules/_tracemalloc.c @@ -3,7 +3,7 @@ #include "pycore_pymem.h" // _Py_tracemalloc_config #include "pycore_traceback.h" #include "pycore_hashtable.h" -#include <pycore_frame.h> +#include <pycore_xframe.h> #include "clinic/_tracemalloc.c.h" /*[clinic input] @@ -299,16 +299,16 @@ hashtable_compare_traceback(const void *key1, const void *key2) static void -tracemalloc_get_frame(InterpreterFrame *pyframe, frame_t *frame) +tracemalloc_get_frame(_PyExecFrame *xframe, frame_t *frame) { frame->filename = unknown_filename; - int lineno = PyCode_Addr2Line(pyframe->f_code, pyframe->f_lasti*2); + int lineno = PyCode_Addr2Line(xframe->xf_code, xframe->xf_lasti*2); if (lineno < 0) { lineno = 0; } frame->lineno = (unsigned int)lineno; - PyObject *filename = pyframe->f_code->co_filename; + PyObject *filename = xframe->xf_code->co_filename; if (filename == NULL) { #ifdef TRACE_DEBUG @@ -393,10 +393,10 @@ traceback_get_frames(traceback_t *traceback) return; } - InterpreterFrame *pyframe = tstate->frame; - for (; pyframe != NULL;) { + _PyExecFrame *xframe = tstate->xframe; + for (; xframe != NULL;) { if (traceback->nframe < _Py_tracemalloc_config.max_nframe) { - tracemalloc_get_frame(pyframe, &traceback->frames[traceback->nframe]); + tracemalloc_get_frame(xframe, &traceback->frames[traceback->nframe]); assert(traceback->frames[traceback->nframe].filename != NULL); traceback->nframe++; } @@ -404,8 +404,8 @@ traceback_get_frames(traceback_t *traceback) traceback->total_nframe++; } - InterpreterFrame *back = pyframe->previous; - pyframe = back; + _PyExecFrame *back = xframe->xf_previous; + xframe = back; } } diff --git a/Modules/_xxsubinterpretersmodule.c b/Modules/_xxsubinterpretersmodule.c index 11b55f7f0c7d1b..c6f986d654a639 100644 --- a/Modules/_xxsubinterpretersmodule.c +++ b/Modules/_xxsubinterpretersmodule.c @@ -4,7 +4,7 @@ #include "Python.h" #include "frameobject.h" -#include "pycore_frame.h" +#include "pycore_xframe.h" #include "interpreteridobject.h" @@ -1835,12 +1835,12 @@ _is_running(PyInterpreterState *interp) } assert(!PyErr_Occurred()); - InterpreterFrame *frame = tstate->frame; - if (frame == NULL) { + _PyExecFrame *xframe = tstate->xframe; + if (xframe == NULL) { return 0; } - int executing = _PyFrame_IsExecuting(frame); + int executing = _PyExecFrame_IsExecuting(xframe); return executing; } diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c index 243c8c82cdc647..9834ee968f4ae3 100644 --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -7,7 +7,7 @@ #include "pycore_atomic.h" // _Py_atomic_int #include "pycore_call.h" // _PyObject_Call() #include "pycore_ceval.h" // _PyEval_SignalReceived() -#include "pycore_frame.h" +#include "pycore_xframe.h" #include "pycore_moduleobject.h" // _PyModule_GetState() #include "pycore_pyerrors.h" // _PyErr_SetString() #include "pycore_pylifecycle.h" // NSIG @@ -1787,7 +1787,7 @@ _PyErr_CheckSignalsTstate(PyThreadState *tstate) */ _Py_atomic_store(&is_tripped, 0); - InterpreterFrame *frame = tstate->frame; + _PyExecFrame *xframe = tstate->xframe; signal_state_t *state = &signal_global_state; for (int i = 1; i < NSIG; i++) { if (!_Py_atomic_load_relaxed(&Handlers[i].tripped)) { @@ -1819,11 +1819,11 @@ _PyErr_CheckSignalsTstate(PyThreadState *tstate) continue; } PyObject *arglist = NULL; - if (frame == NULL) { + if (xframe == NULL) { arglist = Py_BuildValue("(iO)", i, Py_None); } else { - PyFrameObject *f = _PyFrame_GetFrameObject(frame); + PyFrameObject *f = _PyExecFrame_GetFrameObject(xframe); if (f != NULL) { arglist = Py_BuildValue("(iO)", i, f); } diff --git a/Objects/frameobject.c b/Objects/frameobject.c index d1b8048fceadf7..f16e4f87313331 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -7,7 +7,7 @@ #include "pycore_code.h" // CO_FAST_LOCAL, etc. #include "frameobject.h" // PyFrameObject -#include "pycore_frame.h" +#include "pycore_xframe.h" #include "opcode.h" // EXTENDED_ARG #include "structmember.h" // PyMemberDef @@ -32,7 +32,7 @@ frame_getlocals(PyFrameObject *f, void *closure) { if (PyFrame_FastToLocalsWithError(f) < 0) return NULL; - PyObject *locals = f->f_frame->f_locals; + PyObject *locals = f->f_xframe->xf_locals; Py_INCREF(locals); return locals; } @@ -45,7 +45,7 @@ PyFrame_GetLineNumber(PyFrameObject *f) return f->f_lineno; } else { - return PyCode_Addr2Line(f->f_frame->f_code, f->f_frame->f_lasti*2); + return PyCode_Addr2Line(f->f_xframe->xf_code, f->f_xframe->xf_lasti*2); } } @@ -64,16 +64,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_xframe->xf_lasti < 0) { return PyLong_FromLong(-1); } - return PyLong_FromLong(f->f_frame->f_lasti*2); + return PyLong_FromLong(f->f_xframe->xf_lasti*2); } static PyObject * frame_getglobals(PyFrameObject *f, void *closure) { - PyObject *globals = f->f_frame->f_globals; + PyObject *globals = f->f_xframe->xf_globals; if (globals == NULL) { globals = Py_None; } @@ -84,7 +84,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_xframe->xf_builtins; if (builtins == NULL) { builtins = Py_None; } @@ -397,9 +397,9 @@ first_line_not_before(int *lines, int len, int line) static void frame_stack_pop(PyFrameObject *f) { - assert(f->f_frame->stackdepth > 0); - f->f_frame->stackdepth--; - PyObject *v = f->f_frame->stack[f->f_frame->stackdepth]; + assert(f->f_xframe->xf_stackdepth > 0); + f->f_xframe->xf_stackdepth--; + PyObject *v = f->f_xframe->xf_stack[f->f_xframe->xf_stackdepth]; Py_DECREF(v); } @@ -439,7 +439,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_xframe->xf_state) { case FRAME_CREATED: PyErr_Format(PyExc_ValueError, "can't jump from the 'call' trace event of a new frame"); @@ -481,7 +481,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_xframe->xf_code->co_firstlineno) { PyErr_Format(PyExc_ValueError, "line %d comes before the current code block", new_lineno); @@ -490,8 +490,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_xframe->xf_code->co_code) / sizeof(_Py_CODEUNIT)); + int *lines = marklines(f->f_xframe->xf_code, len); if (lines == NULL) { return -1; } @@ -505,7 +505,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_xframe->xf_code, len); if (stacks == NULL) { PyMem_Free(lines); return -1; @@ -513,7 +513,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_xframe->xf_lasti]; int err = -1; const char *msg = "cannot find bytecode for specified line"; for (int i = 0; i < len; i++) { @@ -547,7 +547,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_xframe->xf_state == FRAME_SUSPENDED) { /* Account for value popped by yield */ start_stack = pop_value(start_stack); } @@ -557,7 +557,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_xframe->xf_lasti = best_addr; return 0; } @@ -625,20 +625,20 @@ frame_dealloc(PyFrameObject *f) /* Kill all local variables including specials, if we own them */ if (f->f_own_locals_memory) { f->f_own_locals_memory = 0; - InterpreterFrame *frame = f->f_frame; + _PyExecFrame *xframe = f->f_xframe; /* Don't clear code object until the end */ - co = frame->f_code; - frame->f_code = NULL; - Py_CLEAR(frame->f_globals); - Py_CLEAR(frame->f_builtins); - Py_CLEAR(frame->f_locals); - PyObject **locals = _PyFrame_GetLocalsArray(frame); + co = xframe->xf_code; + xframe->xf_code = NULL; + Py_CLEAR(xframe->xf_globals); + Py_CLEAR(xframe->xf_builtins); + Py_CLEAR(xframe->xf_locals); + PyObject **locals = _PyExecFrame_GetLocalsArray(xframe); for (int i = 0; i < co->co_nlocalsplus; i++) { Py_CLEAR(locals[i]); } /* stack */ - for (int i = 0; i < frame->stackdepth; i++) { - Py_CLEAR(frame->stack[i]); + for (int i = 0; i < xframe->xf_stackdepth; i++) { + Py_CLEAR(xframe->xf_stack[i]); } PyMem_Free(locals); } @@ -670,8 +670,8 @@ frame_traverse(PyFrameObject *f, visitproc visit, void *arg) if (f->f_own_locals_memory == 0) { return 0; } - assert(f->f_frame->frame_obj == NULL); - return _PyFrame_Traverse(f->f_frame, visit, arg); + assert(f->f_xframe->xf_frame_obj == NULL); + return _PyExecFrame_Traverse(f->f_xframe, visit, arg); } static int @@ -682,35 +682,35 @@ 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_xframe->xf_state = FRAME_CLEARED; Py_CLEAR(f->f_trace); /* locals */ - PyObject **locals = _PyFrame_GetLocalsArray(f->f_frame); - for (int i = 0; i < f->f_frame->nlocalsplus; i++) { + PyObject **locals = _PyExecFrame_GetLocalsArray(f->f_xframe); + for (int i = 0; i < f->f_xframe->xf_nlocalsplus; i++) { Py_CLEAR(locals[i]); } /* stack */ - for (int i = 0; i < f->f_frame->stackdepth; i++) { - Py_CLEAR(f->f_frame->stack[i]); + for (int i = 0; i < f->f_xframe->xf_stackdepth; i++) { + Py_CLEAR(f->f_xframe->xf_stack[i]); } - f->f_frame->stackdepth = 0; + f->f_xframe->xf_stackdepth = 0; return 0; } static PyObject * frame_clear(PyFrameObject *f, PyObject *Py_UNUSED(ignored)) { - if (_PyFrame_IsExecuting(f->f_frame)) { + if (_PyExecFrame_IsExecuting(f->f_xframe)) { PyErr_SetString(PyExc_RuntimeError, "cannot clear an executing frame"); return NULL; } - if (f->f_frame->generator) { - _PyGen_Finalize(f->f_frame->generator); - assert(f->f_frame->generator == NULL); + if (f->f_xframe->xf_generator) { + _PyGen_Finalize(f->f_xframe->xf_generator); + assert(f->f_xframe->xf_generator == NULL); } (void)frame_tp_clear(f); Py_RETURN_NONE; @@ -725,7 +725,7 @@ frame_sizeof(PyFrameObject *f, PyObject *Py_UNUSED(ignored)) Py_ssize_t res; res = sizeof(PyFrameObject); if (f->f_own_locals_memory) { - PyCodeObject *code = f->f_frame->f_code; + PyCodeObject *code = f->f_xframe->xf_code; res += (code->co_nlocalsplus+code->co_stacksize) * sizeof(PyObject *); } return PyLong_FromSsize_t(res); @@ -738,7 +738,7 @@ static PyObject * frame_repr(PyFrameObject *f) { int lineno = PyFrame_GetLineNumber(f); - PyCodeObject *code = f->f_frame->f_code; + PyCodeObject *code = f->f_xframe->xf_code; return PyUnicode_FromFormat( "<frame at %p, file %R, line %d, code %S>", f, code->co_filename, lineno, code->co_name); @@ -789,7 +789,7 @@ PyTypeObject PyFrame_Type = { _Py_IDENTIFIER(__builtins__); -static InterpreterFrame * +static _PyExecFrame * allocate_heap_frame(PyFrameConstructor *con, PyObject *locals) { PyCodeObject *code = (PyCodeObject *)con->fc_code; @@ -802,13 +802,13 @@ allocate_heap_frame(PyFrameConstructor *con, PyObject *locals) for (Py_ssize_t i=0; i < code->co_nlocalsplus; i++) { localsarray[i] = NULL; } - InterpreterFrame *frame = (InterpreterFrame *)(localsarray + code->co_nlocalsplus); - _PyFrame_InitializeSpecials(frame, con, locals, code->co_nlocalsplus); - return frame; + _PyExecFrame *xframe = (_PyExecFrame *)(localsarray + code->co_nlocalsplus); + _PyExecFrame_InitializeSpecials(xframe, con, locals, code->co_nlocalsplus); + return xframe; } static inline PyFrameObject* -frame_alloc(InterpreterFrame *frame, int owns) +frame_alloc(_PyExecFrame *xframe, int owns) { PyFrameObject *f; struct _Py_frame_state *state = get_frame_state(); @@ -817,11 +817,11 @@ frame_alloc(InterpreterFrame *frame, int owns) f = PyObject_GC_New(PyFrameObject, &PyFrame_Type); if (f == NULL) { if (owns) { - Py_XDECREF(frame->f_code); - Py_XDECREF(frame->f_builtins); - Py_XDECREF(frame->f_globals); - Py_XDECREF(frame->f_locals); - PyMem_Free(frame); + Py_XDECREF(xframe->xf_code); + Py_XDECREF(xframe->xf_builtins); + Py_XDECREF(xframe->xf_globals); + Py_XDECREF(xframe->xf_locals); + PyMem_Free(xframe); } return NULL; } @@ -837,15 +837,15 @@ frame_alloc(InterpreterFrame *frame, int owns) state->free_list = state->free_list->f_back; _Py_NewReference((PyObject *)f); } - f->f_frame = frame; + f->f_xframe = xframe; f->f_own_locals_memory = owns; return f; } PyFrameObject* _Py_HOT_FUNCTION -_PyFrame_New_NoTrack(InterpreterFrame *frame, int owns) +_PyFrame_New_NoTrack(_PyExecFrame *xframe, int owns) { - PyFrameObject *f = frame_alloc(frame, owns); + PyFrameObject *f = frame_alloc(xframe, owns); if (f == NULL) { return NULL; } @@ -876,11 +876,11 @@ PyFrame_New(PyThreadState *tstate, PyCodeObject *code, .fc_kwdefaults = NULL, .fc_closure = NULL }; - InterpreterFrame *frame = allocate_heap_frame(&desc, locals); - if (frame == NULL) { + _PyExecFrame *xframe = allocate_heap_frame(&desc, locals); + if (xframe == NULL) { return NULL; } - PyFrameObject *f = _PyFrame_New_NoTrack(frame, 1); + PyFrameObject *f = _PyFrame_New_NoTrack(xframe, 1); if (f) { _PyObject_GC_TRACK(f); } @@ -888,11 +888,11 @@ PyFrame_New(PyThreadState *tstate, PyCodeObject *code, } static int -_PyFrame_OpAlreadyRan(InterpreterFrame *frame, int opcode, int oparg) +_PyExecFrame_OpAlreadyRan(_PyExecFrame *xframe, 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(xframe->xf_code->co_code); + for (int i = 0; i < xframe->xf_lasti; i++) { if (_Py_OPCODE(code[i]) == opcode && _Py_OPARG(code[i]) == oparg) { return 1; } @@ -901,19 +901,19 @@ _PyFrame_OpAlreadyRan(InterpreterFrame *frame, int opcode, int oparg) } int -_PyFrame_FastToLocalsWithError(InterpreterFrame *frame) { - /* Merge fast locals into f->f_locals */ +_PyExecFrame_FastToLocalsWithError(_PyExecFrame *xframe) { + /* Merge fast locals into xframe->xf_locals */ PyObject *locals; PyObject **fast; PyCodeObject *co; - locals = frame->f_locals; + locals = xframe->xf_locals; if (locals == NULL) { - locals = frame->f_locals = PyDict_New(); + locals = xframe->xf_locals = PyDict_New(); if (locals == NULL) return -1; } - co = frame->f_code; - fast = _PyFrame_GetLocalsArray(frame); + co = xframe->xf_code; + fast = _PyExecFrame_GetLocalsArray(xframe); for (int i = 0; i < co->co_nlocalsplus; i++) { _PyLocals_Kind kind = _PyLocals_GetKind(co->co_localspluskinds, i); @@ -931,7 +931,7 @@ _PyFrame_FastToLocalsWithError(InterpreterFrame *frame) { PyObject *name = PyTuple_GET_ITEM(co->co_localsplusnames, i); PyObject *value = fast[i]; - if (frame->f_state != FRAME_CLEARED) { + if (xframe->xf_state != FRAME_CLEARED) { if (kind & CO_FAST_FREE) { // The cell was set when the frame was created from // the function's closure. @@ -945,7 +945,7 @@ _PyFrame_FastToLocalsWithError(InterpreterFrame *frame) { // run yet. if (value != NULL) { if (PyCell_Check(value) && - _PyFrame_OpAlreadyRan(frame, MAKE_CELL, i)) { + _PyExecFrame_OpAlreadyRan(xframe, MAKE_CELL, i)) { // (likely) MAKE_CELL must have executed already. value = PyCell_GET(value); } @@ -985,7 +985,7 @@ PyFrame_FastToLocalsWithError(PyFrameObject *f) PyErr_BadInternalCall(); return -1; } - return _PyFrame_FastToLocalsWithError(f->f_frame); + return _PyExecFrame_FastToLocalsWithError(f->f_xframe); } void @@ -1001,18 +1001,18 @@ PyFrame_FastToLocals(PyFrameObject *f) } void -_PyFrame_LocalsToFast(InterpreterFrame *frame, int clear) +_PyExecFrame_LocalsToFast(_PyExecFrame *xframe, 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 = xframe->xf_locals; if (locals == NULL) return; - fast = _PyFrame_GetLocalsArray(frame); - co = frame->f_code; + fast = _PyExecFrame_GetLocalsArray(xframe); + co = xframe->xf_code; PyErr_Fetch(&error_type, &error_value, &error_traceback); for (int i = 0; i < co->co_nlocalsplus; i++) { @@ -1042,7 +1042,7 @@ _PyFrame_LocalsToFast(InterpreterFrame *frame, int clear) else if (kind & CO_FAST_CELL && oldvalue != NULL) { /* Same test as in PyFrame_FastToLocals() above. */ if (PyCell_Check(oldvalue) && - _PyFrame_OpAlreadyRan(frame, MAKE_CELL, i)) { + _PyExecFrame_OpAlreadyRan(xframe, MAKE_CELL, i)) { // (likely) MAKE_CELL must have executed already. cell = oldvalue; } @@ -1069,10 +1069,10 @@ _PyFrame_LocalsToFast(InterpreterFrame *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_xframe->xf_state == FRAME_CLEARED) { return; } - _PyFrame_LocalsToFast(f->f_frame, clear); + _PyExecFrame_LocalsToFast(f->f_xframe, clear); } /* Clear out the free list */ @@ -1114,7 +1114,7 @@ PyCodeObject * PyFrame_GetCode(PyFrameObject *frame) { assert(frame != NULL); - PyCodeObject *code = frame->f_frame->f_code; + PyCodeObject *code = frame->f_xframe->xf_code; assert(code != NULL); Py_INCREF(code); return code; @@ -1126,8 +1126,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_xframe->xf_previous != NULL) { + back = _PyExecFrame_GetFrameObject(frame->f_xframe->xf_previous); } Py_XINCREF(back); return back; diff --git a/Objects/genobject.c b/Objects/genobject.c index 86cd9cf7254589..dbb4f4ffbeef21 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -6,7 +6,7 @@ #include "pycore_pyerrors.h" // _PyErr_ClearExcState() #include "pycore_pystate.h" // _PyThreadState_GET() #include "frameobject.h" -#include "pycore_frame.h" +#include "pycore_xframe.h" #include "structmember.h" // PyMemberDef #include "opcode.h" @@ -35,10 +35,10 @@ gen_traverse(PyGenObject *gen, visitproc visit, void *arg) Py_VISIT(gen->gi_code); Py_VISIT(gen->gi_name); Py_VISIT(gen->gi_qualname); - InterpreterFrame *frame = gen->gi_xframe; - if (frame != NULL) { - assert(frame->frame_obj == NULL || frame->frame_obj->f_own_locals_memory == 0); - int err = _PyFrame_Traverse(frame, visit, arg); + _PyExecFrame *xframe = gen->gi_xframe; + if (xframe != NULL) { + assert(xframe->xf_frame_obj == NULL || xframe->xf_frame_obj->f_own_locals_memory == 0); + int err = _PyExecFrame_Traverse(xframe, visit, arg); if (err) { return err; } @@ -55,7 +55,7 @@ _PyGen_Finalize(PyObject *self) PyObject *res = NULL; PyObject *error_type, *error_value, *error_traceback; - if (gen->gi_xframe == NULL || _PyFrameHasCompleted(gen->gi_xframe)) { + if (gen->gi_xframe == NULL || _PyExecFrame_HasCompleted(gen->gi_xframe)) { /* 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 && - gen->gi_xframe->f_lasti == -1) + gen->gi_xframe->xf_lasti == -1) { _PyErr_WarnUnawaitedCoroutine((PyObject *)gen); } @@ -130,11 +130,11 @@ gen_dealloc(PyGenObject *gen) and GC_Del. */ Py_CLEAR(((PyAsyncGenObject*)gen)->ag_finalizer); } - InterpreterFrame *frame = gen->gi_xframe; - if (frame != NULL) { + _PyExecFrame *xframe = gen->gi_xframe; + if (xframe != NULL) { gen->gi_xframe = NULL; - frame->previous = NULL; - _PyFrame_Clear(frame, 1); + xframe->xf_previous = NULL; + _PyExecFrame_Clear(xframe, 1); } if (((PyCodeObject *)gen->gi_code)->co_flags & CO_COROUTINE) { Py_CLEAR(((PyCoroObject *)gen)->cr_origin); @@ -151,11 +151,11 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult, int exc, int closing) { PyThreadState *tstate = _PyThreadState_GET(); - InterpreterFrame *frame = gen->gi_xframe; + _PyExecFrame *xframe = gen->gi_xframe; PyObject *result; *presult = NULL; - if (frame != NULL && _PyFrame_IsExecuting(frame)) { + if (xframe != NULL && _PyExecFrame_IsExecuting(xframe)) { const char *msg = "generator already executing"; if (PyCoro_CheckExact(gen)) { msg = "coroutine already executing"; @@ -166,7 +166,7 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult, PyErr_SetString(PyExc_ValueError, msg); return PYGEN_ERROR; } - if (frame == NULL || _PyFrameHasCompleted(frame)) { + if (xframe == NULL || _PyExecFrame_HasCompleted(xframe)) { if (PyCoro_CheckExact(gen) && !closing) { /* `gen` is an exhausted coroutine: raise an error, except when called from gen_close(), which should @@ -185,15 +185,15 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult, return PYGEN_ERROR; } - assert(_PyFrame_IsRunnable(frame)); - assert(frame->f_lasti >= 0 || ((unsigned char *)PyBytes_AS_STRING(gen->gi_code->co_code))[0] == GEN_START); + assert(_PyExecFrame_IsRunnable(xframe)); + assert(xframe->xf_lasti >= 0 || ((unsigned char *)PyBytes_AS_STRING(gen->gi_code->co_code))[0] == GEN_START); /* Push arg onto the frame's value stack */ result = arg ? arg : Py_None; Py_INCREF(result); - frame->stack[frame->stackdepth] = result; - frame->stackdepth++; + xframe->xf_stack[xframe->xf_stackdepth] = result; + xframe->xf_stackdepth++; - frame->previous = tstate->frame; + xframe->xf_previous = tstate->xframe; gen->gi_exc_state.previous_item = tstate->exc_info; tstate->exc_info = &gen->gi_exc_state; @@ -203,20 +203,20 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult, _PyErr_ChainStackItem(NULL); } - result = _PyEval_EvalFrame(tstate, frame, exc); + result = _PyEval_EvalFrame(tstate, xframe, exc); tstate->exc_info = gen->gi_exc_state.previous_item; gen->gi_exc_state.previous_item = NULL; - assert(tstate->frame == frame->previous); + assert(tstate->xframe == xframe->xf_previous); /* Don't keep the reference to previous any longer than necessary. It * may keep a chain of frames alive or it could create a reference * cycle. */ - frame->previous = NULL; + xframe->xf_previous = NULL; /* If the generator just returned (as opposed to yielding), signal * that the generator is exhausted. */ if (result) { - if (!_PyFrameHasCompleted(frame)) { + if (!_PyExecFrame_HasCompleted(xframe)) { *presult = result; return PYGEN_NEXT; } @@ -252,9 +252,9 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult, /* first clean reference cycle through stored exception traceback */ _PyErr_ClearExcState(&gen->gi_exc_state); - frame->generator = NULL; + xframe->xf_generator = NULL; gen->gi_xframe = NULL; - _PyFrame_Clear(frame, 1); + _PyExecFrame_Clear(xframe, 1); *presult = result; return result ? PYGEN_RETURN : PYGEN_ERROR; } @@ -336,11 +336,11 @@ _PyGen_yf(PyGenObject *gen) PyObject *yf = NULL; if (gen->gi_xframe) { - InterpreterFrame *frame = gen->gi_xframe; + _PyExecFrame *xframe = gen->gi_xframe; PyObject *bytecode = gen->gi_code->co_code; unsigned char *code = (unsigned char *)PyBytes_AS_STRING(bytecode); - if (frame->f_lasti < 0) { + if (xframe->xf_lasti < 0) { /* Return immediately if the frame didn't start yet. YIELD_FROM always come after LOAD_CONST: a code object should not start with YIELD_FROM */ @@ -348,10 +348,10 @@ _PyGen_yf(PyGenObject *gen) return NULL; } - if (code[(frame->f_lasti+1)*sizeof(_Py_CODEUNIT)] != YIELD_FROM) + if (code[(xframe->xf_lasti+1)*sizeof(_Py_CODEUNIT)] != YIELD_FROM) return NULL; - assert(frame->stackdepth > 0); - yf = frame->stack[frame->stackdepth-1]; + assert(xframe->xf_stackdepth > 0); + yf = xframe->xf_stack[xframe->xf_stackdepth-1]; Py_INCREF(yf); } @@ -366,10 +366,10 @@ gen_close(PyGenObject *gen, PyObject *args) int err = 0; if (yf) { - PyFrameState state = gen->gi_xframe->f_state; - gen->gi_xframe->f_state = FRAME_EXECUTING; + PyFrameState state = gen->gi_xframe->xf_state; + gen->gi_xframe->xf_state = FRAME_EXECUTING; err = gen_close_iter(yf); - gen->gi_xframe->f_state = state; + gen->gi_xframe->xf_state = state; Py_DECREF(yf); } if (err == 0) @@ -416,10 +416,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 = gen->gi_xframe->f_state; - gen->gi_xframe->f_state = FRAME_EXECUTING; + PyFrameState state = gen->gi_xframe->xf_state; + gen->gi_xframe->xf_state = FRAME_EXECUTING; err = gen_close_iter(yf); - gen->gi_xframe->f_state = state; + gen->gi_xframe->xf_state = state; Py_DECREF(yf); if (err < 0) return gen_send_ex(gen, Py_None, 1, 0); @@ -428,7 +428,7 @@ _gen_throw(PyGenObject *gen, int close_on_genexit, if (PyGen_CheckExact(yf) || PyCoro_CheckExact(yf)) { /* `yf` is a generator or a coroutine. */ PyThreadState *tstate = _PyThreadState_GET(); - InterpreterFrame *frame = gen->gi_xframe; + _PyExecFrame *xframe = gen->gi_xframe; /* Since we are fast-tracking things by skipping the eval loop, @@ -436,18 +436,18 @@ _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. */ - InterpreterFrame *prev = tstate->frame; - frame->previous = prev; - tstate->frame = frame; + _PyExecFrame *prev = tstate->xframe; + xframe->xf_previous = prev; + tstate->xframe = xframe; /* Close the generator that we are currently iterating with 'yield from' or awaiting on with 'await'. */ - PyFrameState state = gen->gi_xframe->f_state; - gen->gi_xframe->f_state = FRAME_EXECUTING; + PyFrameState state = gen->gi_xframe->xf_state; + gen->gi_xframe->xf_state = FRAME_EXECUTING; ret = _gen_throw((PyGenObject *)yf, close_on_genexit, typ, val, tb); - gen->gi_xframe->f_state = state; - tstate->frame = prev; - frame->previous = NULL; + gen->gi_xframe->xf_state = state; + tstate->xframe = prev; + xframe->xf_previous = NULL; } else { /* `yf` is an iterator or a coroutine-like object. */ PyObject *meth; @@ -459,24 +459,24 @@ _gen_throw(PyGenObject *gen, int close_on_genexit, Py_DECREF(yf); goto throw_here; } - PyFrameState state = gen->gi_xframe->f_state; - gen->gi_xframe->f_state = FRAME_EXECUTING; + PyFrameState state = gen->gi_xframe->xf_state; + gen->gi_xframe->xf_state = FRAME_EXECUTING; ret = PyObject_CallFunctionObjArgs(meth, typ, val, tb, NULL); - gen->gi_xframe->f_state = state; + gen->gi_xframe->xf_state = state; Py_DECREF(meth); } Py_DECREF(yf); if (!ret) { PyObject *val; /* Pop subiterator from stack */ - assert(gen->gi_xframe->stackdepth > 0); - gen->gi_xframe->stackdepth--; - ret = gen->gi_xframe->stack[gen->gi_xframe->stackdepth]; + assert(gen->gi_xframe->xf_stackdepth > 0); + gen->gi_xframe->xf_stackdepth--; + ret = gen->gi_xframe->xf_stack[gen->gi_xframe->xf_stackdepth]; assert(ret == yf); Py_DECREF(ret); /* Termination repetition of YIELD_FROM */ - assert(gen->gi_xframe->f_lasti >= 0); - gen->gi_xframe->f_lasti += 1; + assert(gen->gi_xframe->xf_lasti >= 0); + gen->gi_xframe->xf_lasti += 1; if (_PyGen_FetchStopIterationValue(&val) == 0) { ret = gen_send(gen, val); Py_DECREF(val); @@ -736,7 +736,7 @@ gen_getrunning(PyGenObject *gen, void *Py_UNUSED(ignored)) if (gen->gi_xframe == NULL) { Py_RETURN_FALSE; } - return PyBool_FromLong(_PyFrame_IsExecuting(gen->gi_xframe)); + return PyBool_FromLong(_PyExecFrame_IsExecuting(gen->gi_xframe)); } static PyObject * @@ -748,7 +748,7 @@ _gen_getframe(PyGenObject *gen, const char *const name) if (gen->gi_xframe == NULL) { Py_RETURN_NONE; } - return _Py_XNewRef((PyObject *)_PyFrame_GetFrameObject(gen->gi_xframe)); + return _Py_XNewRef((PyObject *)_PyExecFrame_GetFrameObject(gen->gi_xframe)); } static PyObject * @@ -843,17 +843,17 @@ PyTypeObject PyGen_Type = { }; static PyObject * -make_gen(PyTypeObject *type, PyFrameConstructor *con, InterpreterFrame *frame) +make_gen(PyTypeObject *type, PyFrameConstructor *con, _PyExecFrame *xframe) { PyGenObject *gen = PyObject_GC_New(PyGenObject, type); if (gen == NULL) { - assert(frame->frame_obj == NULL); - _PyFrame_Clear(frame, 1); + assert(xframe->xf_frame_obj == NULL); + _PyExecFrame_Clear(xframe, 1); return NULL; } - gen->gi_xframe = frame; - frame->generator = (PyObject *)gen; - gen->gi_code = frame->f_code; + gen->gi_xframe = xframe; + xframe->xf_generator = (PyObject *)gen; + gen->gi_code = xframe->xf_code; Py_INCREF(gen->gi_code); gen->gi_weakreflist = NULL; gen->gi_exc_state.exc_type = NULL; @@ -878,17 +878,17 @@ static PyObject * compute_cr_origin(int origin_depth); PyObject * -_Py_MakeCoro(PyFrameConstructor *con, InterpreterFrame *frame) +_Py_MakeCoro(PyFrameConstructor *con, _PyExecFrame *xframe) { int coro_flags = ((PyCodeObject *)con->fc_code)->co_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR); assert(coro_flags); if (coro_flags == CO_GENERATOR) { - return make_gen(&PyGen_Type, con, frame); + return make_gen(&PyGen_Type, con, xframe); } if (coro_flags == CO_ASYNC_GENERATOR) { PyAsyncGenObject *o; - o = (PyAsyncGenObject *)make_gen(&PyAsyncGen_Type, con, frame); + o = (PyAsyncGenObject *)make_gen(&PyAsyncGen_Type, con, xframe); if (o == NULL) { return NULL; } @@ -899,7 +899,7 @@ _Py_MakeCoro(PyFrameConstructor *con, InterpreterFrame *frame) return (PyObject*)o; } assert (coro_flags == CO_COROUTINE); - PyObject *coro = make_gen(&PyCoro_Type, con, frame); + PyObject *coro = make_gen(&PyCoro_Type, con, xframe); if (!coro) { return NULL; } @@ -931,12 +931,12 @@ gen_new_with_qualname(PyTypeObject *type, PyFrameObject *f, } /* Take ownership of the frame */ - assert(f->f_frame->frame_obj == NULL); + assert(f->f_xframe->xf_frame_obj == NULL); assert(f->f_own_locals_memory); - gen->gi_xframe = f->f_frame; - gen->gi_xframe->frame_obj = f; + gen->gi_xframe = f->f_xframe; + gen->gi_xframe->xf_frame_obj = f; f->f_own_locals_memory = 0; - gen->gi_xframe->generator = (PyObject *) gen; + gen->gi_xframe->xf_generator = (PyObject *) gen; assert(PyObject_GC_IsTracked((PyObject *)f)); gen->gi_code = PyFrame_GetCode(f); @@ -1075,7 +1075,7 @@ cr_getrunning(PyCoroObject *coro, void *Py_UNUSED(ignored)) if (coro->cr_xframe == NULL) { Py_RETURN_FALSE; } - return PyBool_FromLong(_PyFrame_IsExecuting(coro->cr_xframe)); + return PyBool_FromLong(_PyExecFrame_IsExecuting(coro->cr_xframe)); } static PyObject * @@ -1271,11 +1271,11 @@ PyTypeObject _PyCoroWrapper_Type = { static PyObject * compute_cr_origin(int origin_depth) { - InterpreterFrame *frame = _PyEval_GetFrame(); + _PyExecFrame *xframe = _PyEval_GetExecFrame(); /* First count how many frames we have */ int frame_count = 0; - for (; frame && frame_count < origin_depth; ++frame_count) { - frame = frame->previous; + for (; xframe && frame_count < origin_depth; ++frame_count) { + xframe = xframe->xf_previous; } /* Now collect them */ @@ -1283,19 +1283,19 @@ compute_cr_origin(int origin_depth) if (cr_origin == NULL) { return NULL; } - frame = _PyEval_GetFrame(); + xframe = _PyEval_GetExecFrame(); for (int i = 0; i < frame_count; ++i) { - PyCodeObject *code = frame->f_code; + PyCodeObject *code = xframe->xf_code; PyObject *frameinfo = Py_BuildValue("OiO", code->co_filename, - PyCode_Addr2Line(frame->f_code, frame->f_lasti*2), + PyCode_Addr2Line(xframe->xf_code, xframe->xf_lasti*2), code->co_name); if (!frameinfo) { Py_DECREF(cr_origin); return NULL; } PyTuple_SET_ITEM(cr_origin, i, frameinfo); - frame = frame->previous; + xframe = xframe->xf_previous; } return cr_origin; @@ -1990,7 +1990,7 @@ static PyObject * async_gen_athrow_send(PyAsyncGenAThrow *o, PyObject *arg) { PyGenObject *gen = (PyGenObject*)o->agt_gen; - InterpreterFrame *frame = gen->gi_xframe; + _PyExecFrame *xframe = gen->gi_xframe; PyObject *retval; if (o->agt_state == AWAITABLE_STATE_CLOSED) { @@ -2000,7 +2000,7 @@ async_gen_athrow_send(PyAsyncGenAThrow *o, PyObject *arg) return NULL; } - if (frame == NULL || _PyFrameHasCompleted(frame)) { + if (xframe == NULL || _PyExecFrame_HasCompleted(xframe)) { o->agt_state = AWAITABLE_STATE_CLOSED; PyErr_SetNone(PyExc_StopIteration); return NULL; diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 2240f780bb9ceb..426f3ed850c659 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -11,7 +11,7 @@ #include "pycore_pystate.h" // _PyThreadState_GET() #include "pycore_unionobject.h" // _Py_union_type_or #include "frameobject.h" -#include "pycore_frame.h" +#include "pycore_xframe.h" #include "opcode.h" // MAKE_CELL #include "structmember.h" // PyMemberDef @@ -8874,13 +8874,13 @@ super_init_without_args(PyFrameObject *f, PyCodeObject *co, return -1; } - assert(f->f_frame->nlocalsplus > 0); - PyObject *firstarg = _PyFrame_GetLocalsArray(f->f_frame)[0]; + assert(f->f_xframe->xf_nlocalsplus > 0); + PyObject *firstarg = _PyExecFrame_GetLocalsArray(f->f_xframe)[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 (f->f_frame->f_lasti >= 0) { + if (f->f_xframe->xf_lasti >= 0) { assert(_Py_OPCODE(*co->co_firstinstr) == MAKE_CELL); assert(PyCell_Check(firstarg)); firstarg = PyCell_GET(firstarg); @@ -8900,7 +8900,7 @@ super_init_without_args(PyFrameObject *f, PyCodeObject *co, PyObject *name = PyTuple_GET_ITEM(co->co_localsplusnames, i); assert(PyUnicode_Check(name)); if (_PyUnicode_EqualToASCIIId(name, &PyId___class__)) { - PyObject *cell = _PyFrame_GetLocalsArray(f->f_frame)[i]; + PyObject *cell = _PyExecFrame_GetLocalsArray(f->f_xframe)[i]; if (cell == NULL || !PyCell_Check(cell)) { PyErr_SetString(PyExc_RuntimeError, "super(): bad __class__ cell"); diff --git a/Python/_warnings.c b/Python/_warnings.c index cf2110d31c3b5e..def70d6bf1c25c 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -5,7 +5,7 @@ #include "pycore_pyerrors.h" #include "pycore_pystate.h" // _PyThreadState_GET() #include "frameobject.h" // PyFrame_GetBack() -#include "pycore_frame.h" +#include "pycore_xframe.h" #include "clinic/_warnings.c.h" #define MODULE_NAME "_warnings" @@ -854,8 +854,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_xframe->xf_globals; + *filename = f->f_xframe->xf_code->co_filename; Py_INCREF(*filename); *lineno = PyFrame_GetLineNumber(f); Py_DECREF(f); diff --git a/Python/ceval.c b/Python/ceval.c index 4f7edb84fc3696..01baeba6c3a8d5 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -29,7 +29,7 @@ #include "pycore_dict.h" #include "dictobject.h" #include "frameobject.h" -#include "pycore_frame.h" +#include "pycore_xframe.h" #include "opcode.h" #include "pydtrace.h" #include "setobject.h" @@ -62,27 +62,27 @@ static int lltrace; static int prtrace(PyThreadState *, PyObject *, const char *); #endif static int call_trace(Py_tracefunc, PyObject *, - PyThreadState *, InterpreterFrame *, + PyThreadState *, _PyExecFrame *, int, PyObject *); static int call_trace_protected(Py_tracefunc, PyObject *, - PyThreadState *, InterpreterFrame *, + PyThreadState *, _PyExecFrame *, int, PyObject *); static void call_exc_trace(Py_tracefunc, PyObject *, - PyThreadState *, InterpreterFrame *); + PyThreadState *, _PyExecFrame *); static int maybe_call_line_trace(Py_tracefunc, PyObject *, - PyThreadState *, InterpreterFrame *, int); -static void maybe_dtrace_line(InterpreterFrame *, PyTraceInfo *, int); -static void dtrace_function_entry(InterpreterFrame *); -static void dtrace_function_return(InterpreterFrame *); + PyThreadState *, _PyExecFrame *, int); +static void maybe_dtrace_line(_PyExecFrame *, PyTraceInfo *, int); +static void dtrace_function_entry(_PyExecFrame *); +static void dtrace_function_return(_PyExecFrame *); -static PyObject * import_name(PyThreadState *, InterpreterFrame *, +static PyObject * import_name(PyThreadState *, _PyExecFrame *, PyObject *, PyObject *, PyObject *); static PyObject * import_from(PyThreadState *, PyObject *, PyObject *); static int import_all_from(PyThreadState *, PyObject *, PyObject *); static void format_exc_check_arg(PyThreadState *, PyObject *, const char *, PyObject *); static void format_exc_unbound(PyThreadState *tstate, PyCodeObject *co, int oparg); static PyObject * unicode_concatenate(PyThreadState *, PyObject *, PyObject *, - InterpreterFrame *, const _Py_CODEUNIT *); + _PyExecFrame *, const _Py_CODEUNIT *); static int check_args_iterable(PyThreadState *, PyObject *func, PyObject *vararg); static void format_kwargs_error(PyThreadState *, PyObject *func, PyObject *kwargs); static void format_awaitable_error(PyThreadState *, PyTypeObject *, int, int); @@ -1065,14 +1065,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_xframe, 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_xframe, throwflag); } @@ -1231,7 +1231,7 @@ eval_frame_handle_pending(PyThreadState *tstate) if (cframe.use_tracing OR_DTRACE_LINE OR_LLTRACE) { \ goto tracing_dispatch; \ } \ - frame->f_lasti = INSTR_OFFSET(); \ + xframe->xf_lasti = INSTR_OFFSET(); \ NEXTOPARG(); \ DISPATCH_GOTO(); \ } @@ -1320,7 +1320,7 @@ eval_frame_handle_pending(PyThreadState *tstate) /* The stack can grow at most MAXINT deep, as co_nlocals and co_stacksize are ints. */ -#define STACK_LEVEL() ((int)(stack_pointer - frame->stack)) +#define STACK_LEVEL() ((int)(stack_pointer - xframe->xf_stack)) #define EMPTY() (STACK_LEVEL() == 0) #define TOP() (stack_pointer[-1]) #define SECOND() (stack_pointer[-2]) @@ -1388,12 +1388,12 @@ 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() xframe->xf_globals +#define BUILTINS() xframe->xf_builtins +#define LOCALS() xframe->xf_locals PyObject* _Py_HOT_FUNCTION -_PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int throwflag) +_PyEval_EvalFrameDefault(PyThreadState *tstate, _PyExecFrame *xframe, int throwflag) { _Py_EnsureTstateNotNULL(tstate); @@ -1437,9 +1437,9 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr cframe.previous = prev_cframe; tstate->cframe = &cframe; - /* push frame */ - tstate->frame = frame; - co = frame->f_code; + /* push execution frame */ + tstate->xframe = xframe; + co = xframe->xf_code; if (cframe.use_tracing) { if (tstate->c_tracefunc != NULL) { @@ -1458,7 +1458,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr whenever an exception is detected. */ if (call_trace_protected(tstate->c_tracefunc, tstate->c_traceobj, - tstate, frame, + tstate, xframe, PyTrace_CALL, Py_None)) { /* Trace function raised an error */ goto exit_eval_frame; @@ -1469,7 +1469,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr return itself and isn't called for "line" events */ if (call_trace_protected(tstate->c_profilefunc, tstate->c_profileobj, - tstate, frame, + tstate, xframe, PyTrace_CALL, Py_None)) { /* Profile function raised an error */ goto exit_eval_frame; @@ -1478,7 +1478,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr } if (PyDTrace_FUNCTION_ENTRY_ENABLED()) - dtrace_function_entry(frame); + dtrace_function_entry(xframe); /* Increment the warmup counter and quicken if warm enough * _Py_Quicken is idempotent so we don't worry about overflow */ @@ -1494,34 +1494,34 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr names = co->co_names; consts = co->co_consts; - localsplus = _PyFrame_GetLocalsArray(frame); + localsplus = _PyExecFrame_GetLocalsArray(xframe); first_instr = co->co_firstinstr; /* - frame->f_lasti refers to the index of the last instruction, + xframe->xf_lasti refers to the index of the last instruction, unless it's -1 in which case next_instr should be first_instr. - YIELD_FROM sets frame->f_lasti to itself, in order to repeatedly yield + YIELD_FROM sets xframe->xf_lasti to itself, in order to repeatedly yield multiple values. When the PREDICT() macros are enabled, some opcode pairs follow in - direct succession without updating frame->f_lasti. A successful + direct succession without updating xframe->xf_lasti. A successful prediction effectively links the two codes together as if they - were a single new opcode; accordingly,frame->f_lasti will point to + were a single new opcode; accordingly, xframe->xf_lasti will point to the first code in the pair (for instance, GET_ITER followed by - FOR_ITER is effectively a single opcode and frame->f_lasti will point + FOR_ITER is effectively a single opcode and xframe->xf_lasti will point to the beginning of the combined pair.) */ - assert(frame->f_lasti >= -1); - next_instr = first_instr + frame->f_lasti + 1; - stack_pointer = frame->stack + frame->stackdepth; + assert(xframe->xf_lasti >= -1); + next_instr = first_instr + xframe->xf_lasti + 1; + stack_pointer = xframe->xf_stack + xframe->xf_stackdepth; /* Set stackdepth to -1. * Update when returning or calling trace function. Having f_stackdepth <= 0 ensures that invalid values are not visible to the cycle GC. We choose -1 rather than 0 to assist debugging. */ - frame->stackdepth = -1; - frame->f_state = FRAME_EXECUTING; + xframe->xf_stackdepth = -1; + xframe->xf_state = FRAME_EXECUTING; #ifdef LLTRACE { @@ -1585,12 +1585,12 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr tracing_dispatch: { - int instr_prev = frame->f_lasti; - frame->f_lasti = INSTR_OFFSET(); + int instr_prev = xframe->xf_lasti; + xframe->xf_lasti = INSTR_OFFSET(); TRACING_NEXTOPARG(); if (PyDTrace_LINE_ENABLED()) - maybe_dtrace_line(frame, &tstate->trace_info, instr_prev); + maybe_dtrace_line(xframe, &tstate->trace_info, instr_prev); /* line-by-line tracing support */ @@ -1599,19 +1599,19 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr int err; /* see maybe_call_line_trace() for expository comments */ - frame->stackdepth = (int)(stack_pointer - frame->stack); + xframe->xf_stackdepth = (int)(stack_pointer - xframe->xf_stack); err = maybe_call_line_trace(tstate->c_tracefunc, tstate->c_traceobj, - tstate, frame, instr_prev); + tstate, xframe, instr_prev); if (err) { /* trace function raised an exception */ goto error; } /* Reload possibly changed frame fields */ - JUMPTO(frame->f_lasti); - stack_pointer = frame->stack+frame->stackdepth; - frame->stackdepth = -1; + JUMPTO(xframe->xf_lasti); + stack_pointer = xframe->xf_stack+xframe->xf_stackdepth; + xframe->xf_stackdepth = -1; TRACING_NEXTOPARG(); } } @@ -1622,11 +1622,11 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr if (lltrace) { if (HAS_ARG(opcode)) { printf("%d: %d, %d\n", - frame->f_lasti, opcode, oparg); + xframe->xf_lasti, opcode, oparg); } else { printf("%d: %d\n", - frame->f_lasti, opcode); + xframe->xf_lasti, opcode); } } #endif @@ -1875,7 +1875,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr speedup on microbenchmarks. */ if (PyUnicode_CheckExact(left) && PyUnicode_CheckExact(right)) { - sum = unicode_concatenate(tstate, left, right, frame, next_instr); + sum = unicode_concatenate(tstate, left, right, xframe, next_instr); /* unicode_concatenate consumed the ref to left */ } else { @@ -2162,7 +2162,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr PyObject *left = TOP(); PyObject *sum; if (PyUnicode_CheckExact(left) && PyUnicode_CheckExact(right)) { - sum = unicode_concatenate(tstate, left, right, frame, next_instr); + sum = unicode_concatenate(tstate, left, right, xframe, next_instr); /* unicode_concatenate consumed the ref to left */ } else { @@ -2322,8 +2322,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr case TARGET(RETURN_VALUE): { retval = POP(); assert(EMPTY()); - frame->f_state = FRAME_RETURNED; - frame->stackdepth = 0; + xframe->xf_state = FRAME_RETURNED; + xframe->xf_stackdepth = 0; goto exiting; } @@ -2480,7 +2480,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr if (retval == NULL) { if (tstate->c_tracefunc != NULL && _PyErr_ExceptionMatches(tstate, PyExc_StopIteration)) - call_exc_trace(tstate->c_tracefunc, tstate->c_traceobj, tstate, frame); + call_exc_trace(tstate->c_tracefunc, tstate->c_traceobj, tstate, xframe); if (_PyGen_FetchStopIterationValue(&retval) == 0) { gen_status = PYGEN_RETURN; } @@ -2508,10 +2508,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr assert (gen_status == PYGEN_NEXT); /* receiver remains on stack, retval is value to be yielded */ /* and repeat... */ - assert(frame->f_lasti > 0); - frame->f_lasti -= 1; - frame->f_state = FRAME_SUSPENDED; - frame->stackdepth = (int)(stack_pointer - frame->stack); + assert(xframe->xf_lasti > 0); + xframe->xf_lasti -= 1; + xframe->xf_state = FRAME_SUSPENDED; + xframe->xf_stackdepth = (int)(stack_pointer - xframe->xf_stack); goto exiting; } @@ -2527,8 +2527,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr } retval = w; } - frame->f_state = FRAME_SUSPENDED; - frame->stackdepth = (int)(stack_pointer - frame->stack); + xframe->xf_state = FRAME_SUSPENDED; + xframe->xf_stackdepth = (int)(stack_pointer - xframe->xf_stack); goto exiting; } @@ -2575,7 +2575,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr case TARGET(POP_EXCEPT_AND_RERAISE): { PyObject *lasti = PEEK(4); if (PyLong_Check(lasti)) { - frame->f_lasti = PyLong_AsLong(lasti); + xframe->xf_lasti = PyLong_AsLong(lasti); assert(!_PyErr_Occurred(tstate)); } else { @@ -2606,7 +2606,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr if (oparg) { PyObject *lasti = PEEK(oparg+3); if (PyLong_Check(lasti)) { - frame->f_lasti = PyLong_AsLong(lasti); + xframe->xf_lasti = PyLong_AsLong(lasti); assert(!_PyErr_Occurred(tstate)); } else { @@ -3581,7 +3581,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr PyObject *fromlist = POP(); PyObject *level = TOP(); PyObject *res; - res = import_name(tstate, frame, name, fromlist, level); + res = import_name(tstate, xframe, name, fromlist, level); Py_DECREF(level); Py_DECREF(fromlist); SET_TOP(res); @@ -3593,7 +3593,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr case TARGET(IMPORT_STAR): { PyObject *from = POP(), *locals; int err; - if (_PyFrame_FastToLocalsWithError(frame) < 0) { + if (_PyExecFrame_FastToLocalsWithError(xframe) < 0) { Py_DECREF(from); goto error; } @@ -3606,7 +3606,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr goto error; } err = import_all_from(tstate, locals, from); - _PyFrame_LocalsToFast(frame, 0); + _PyExecFrame_LocalsToFast(xframe, 0); Py_DECREF(from); if (err != 0) goto error; @@ -3920,7 +3920,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr goto error; } else if (tstate->c_tracefunc != NULL) { - call_exc_trace(tstate->c_tracefunc, tstate->c_traceobj, tstate, frame); + call_exc_trace(tstate->c_tracefunc, tstate->c_traceobj, tstate, xframe); } _PyErr_Clear(tstate); } @@ -4383,7 +4383,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr default: fprintf(stderr, "XXX lineno: %d, opcode: %d\n", - PyCode_Addr2Line(frame->f_code, frame->f_lasti*2), + PyCode_Addr2Line(xframe->xf_code, xframe->xf_lasti*2), opcode); _PyErr_SetString(tstate, PyExc_SystemError, "unknown opcode"); goto error; @@ -4452,22 +4452,22 @@ MISS_WITH_OPARG_COUNTER(BINARY_SUBSCR) #endif /* Log traceback info. */ - PyFrameObject *f = _PyFrame_GetFrameObject(frame); + PyFrameObject *f = _PyExecFrame_GetFrameObject(xframe); if (f != NULL) { PyTraceBack_Here(f); } if (tstate->c_tracefunc != NULL) { - /* Make sure state is set to FRAME_EXECUTING for tracing */ - assert(frame->f_state == FRAME_EXECUTING); - frame->f_state = FRAME_UNWINDING; + /* Make sure state is set to FRAME_UNWINDING for tracing */ + assert(xframe->xf_state == FRAME_EXECUTING); + xframe->xf_state = FRAME_UNWINDING; call_exc_trace(tstate->c_tracefunc, tstate->c_traceobj, - tstate, frame); + tstate, xframe); } exception_unwind: - frame->f_state = FRAME_UNWINDING; - /* We can't use frame->f_lasti here, as RERAISE may have set it */ + xframe->xf_state = FRAME_UNWINDING; + /* We can't use xframe->xf_lasti here, as RERAISE may have set it */ int offset = INSTR_OFFSET()-1; int level, handler, lasti; if (get_exception_handler(co, offset, &level, &handler, &lasti) == 0) { @@ -4482,7 +4482,7 @@ MISS_WITH_OPARG_COUNTER(BINARY_SUBSCR) } PyObject *exc, *val, *tb; if (lasti) { - PyObject *lasti = PyLong_FromLong(frame->f_lasti); + PyObject *lasti = PyLong_FromLong(xframe->xf_lasti); if (lasti == NULL) { goto exception_unwind; } @@ -4507,8 +4507,8 @@ MISS_WITH_OPARG_COUNTER(BINARY_SUBSCR) PUSH(exc); JUMPTO(handler); /* Resume normal execution */ - frame->f_state = FRAME_EXECUTING; - frame->f_lasti = handler; + xframe->xf_state = FRAME_EXECUTING; + xframe->xf_lasti = handler; NEXTOPARG(); goto dispatch_opcode; } /* main loop */ @@ -4521,19 +4521,19 @@ MISS_WITH_OPARG_COUNTER(BINARY_SUBSCR) PyObject *o = POP(); Py_XDECREF(o); } - frame->stackdepth = 0; - frame->f_state = FRAME_RAISED; + xframe->xf_stackdepth = 0; + xframe->xf_state = FRAME_RAISED; exiting: if (cframe.use_tracing) { if (tstate->c_tracefunc) { if (call_trace_protected(tstate->c_tracefunc, tstate->c_traceobj, - tstate, frame, PyTrace_RETURN, retval)) { + tstate, xframe, PyTrace_RETURN, retval)) { Py_CLEAR(retval); } } if (tstate->c_profilefunc) { if (call_trace_protected(tstate->c_profilefunc, tstate->c_profileobj, - tstate, frame, PyTrace_RETURN, retval)) { + tstate, xframe, PyTrace_RETURN, retval)) { Py_CLEAR(retval); } } @@ -4546,9 +4546,9 @@ MISS_WITH_OPARG_COUNTER(BINARY_SUBSCR) tstate->cframe->use_tracing = cframe.use_tracing; if (PyDTrace_FUNCTION_RETURN_ENABLED()) - dtrace_function_return(frame); + dtrace_function_return(xframe); _Py_LeaveRecursiveCall(tstate); - tstate->frame = frame->previous; + tstate->xframe = xframe->xf_previous; return _Py_CheckFunctionResult(tstate, NULL, retval, __func__); } @@ -5055,7 +5055,7 @@ initialize_locals(PyThreadState *tstate, PyFrameConstructor *con, } -static InterpreterFrame * +static _PyExecFrame * make_coro_frame(PyThreadState *tstate, PyFrameConstructor *con, PyObject *locals, PyObject *const *args, Py_ssize_t argcount, @@ -5073,14 +5073,14 @@ make_coro_frame(PyThreadState *tstate, for (Py_ssize_t i=0; i < code->co_nlocalsplus; i++) { localsarray[i] = NULL; } - InterpreterFrame *frame = (InterpreterFrame *)(localsarray + code->co_nlocalsplus); - _PyFrame_InitializeSpecials(frame, con, locals, code->co_nlocalsplus); - assert(frame->frame_obj == NULL); + _PyExecFrame *xframe = (_PyExecFrame *)(localsarray + code->co_nlocalsplus); + _PyExecFrame_InitializeSpecials(xframe, con, locals, code->co_nlocalsplus); + assert(xframe->xf_frame_obj == NULL); if (initialize_locals(tstate, con, localsarray, args, argcount, kwnames)) { - _PyFrame_Clear(frame, 1); + _PyExecFrame_Clear(xframe, 1); return NULL; } - return frame; + return xframe; } static PyObject * @@ -5090,11 +5090,11 @@ make_coro(PyThreadState *tstate, PyFrameConstructor *con, PyObject *kwnames) { assert (((PyCodeObject *)con->fc_code)->co_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR)); - InterpreterFrame *frame = make_coro_frame(tstate, con, locals, args, argcount, kwnames); - if (frame == NULL) { + _PyExecFrame *xframe = make_coro_frame(tstate, con, locals, args, argcount, kwnames); + if (xframe == NULL) { return NULL; } - PyObject *gen = _Py_MakeCoro(con, frame); + PyObject *gen = _Py_MakeCoro(con, xframe); if (gen == NULL) { return NULL; } @@ -5102,37 +5102,37 @@ make_coro(PyThreadState *tstate, PyFrameConstructor *con, return gen; } -static InterpreterFrame * +static _PyExecFrame * _PyEvalFramePushAndInit(PyThreadState *tstate, PyFrameConstructor *con, PyObject *locals, PyObject* const* args, size_t argcount, PyObject *kwnames) { - InterpreterFrame * frame = _PyThreadState_PushFrame(tstate, con, locals); - if (frame == NULL) { + _PyExecFrame * xframe = _PyThreadState_PushExecFrame(tstate, con, locals); + if (xframe == NULL) { return NULL; } - PyObject **localsarray = _PyFrame_GetLocalsArray(frame); + PyObject **localsarray = _PyExecFrame_GetLocalsArray(xframe); if (initialize_locals(tstate, con, localsarray, args, argcount, kwnames)) { - _PyFrame_Clear(frame, 0); + _PyExecFrame_Clear(xframe, 0); return NULL; } - frame->previous = tstate->frame; - tstate->frame = frame; - return frame; + xframe->xf_previous = tstate->xframe; + tstate->xframe = xframe; + return xframe; } static int -_PyEvalFrameClearAndPop(PyThreadState *tstate, InterpreterFrame * frame) +_PyEvalFrameClearAndPop(PyThreadState *tstate, _PyExecFrame * xframe) { ++tstate->recursion_depth; - assert(frame->frame_obj == NULL || frame->frame_obj->f_own_locals_memory == 0); - if (_PyFrame_Clear(frame, 0)) { + assert(xframe->xf_frame_obj == NULL || xframe->xf_frame_obj->f_own_locals_memory == 0); + if (_PyExecFrame_Clear(xframe, 0)) { return -1; } - assert(frame->frame_obj == NULL); + assert(xframe->xf_frame_obj == NULL); --tstate->recursion_depth; - tstate->frame = frame->previous; - _PyThreadState_PopFrame(tstate, frame); + tstate->xframe = xframe->xf_previous; + _PyThreadState_PopExecFrame(tstate, xframe); return 0; } @@ -5148,15 +5148,15 @@ _PyEval_Vector(PyThreadState *tstate, PyFrameConstructor *con, if (is_coro) { return make_coro(tstate, con, locals, args, argcount, kwnames); } - InterpreterFrame *frame = _PyEvalFramePushAndInit( + _PyExecFrame *xframe = _PyEvalFramePushAndInit( tstate, con, locals, args, argcount, kwnames); - if (frame == NULL) { + if (xframe == NULL) { return NULL; } assert (tstate->interp->eval_frame != NULL); - PyObject *retval = _PyEval_EvalFrame(tstate, frame, 0); - assert(frame->stackdepth == 0); - if (_PyEvalFrameClearAndPop(tstate, frame)) { + PyObject *retval = _PyEval_EvalFrame(tstate, xframe, 0); + assert(xframe->xf_stackdepth == 0); + if (_PyEvalFrameClearAndPop(tstate, xframe)) { retval = NULL; } return retval; @@ -5465,7 +5465,7 @@ prtrace(PyThreadState *tstate, PyObject *v, const char *str) static void call_exc_trace(Py_tracefunc func, PyObject *self, PyThreadState *tstate, - InterpreterFrame *f) + _PyExecFrame *xf) { PyObject *type, *value, *traceback, *orig_traceback, *arg; int err; @@ -5481,7 +5481,7 @@ call_exc_trace(Py_tracefunc func, PyObject *self, _PyErr_Restore(tstate, type, value, orig_traceback); return; } - err = call_trace(func, self, tstate, f, PyTrace_EXCEPTION, arg); + err = call_trace(func, self, tstate, xf, PyTrace_EXCEPTION, arg); Py_DECREF(arg); if (err == 0) { _PyErr_Restore(tstate, type, value, orig_traceback); @@ -5495,13 +5495,13 @@ call_exc_trace(Py_tracefunc func, PyObject *self, static int call_trace_protected(Py_tracefunc func, PyObject *obj, - PyThreadState *tstate, InterpreterFrame *frame, + PyThreadState *tstate, _PyExecFrame *xframe, int what, PyObject *arg) { PyObject *type, *value, *traceback; int err; _PyErr_Fetch(tstate, &type, &value, &traceback); - err = call_trace(func, obj, tstate, frame, what, arg); + err = call_trace(func, obj, tstate, xframe, what, arg); if (err == 0) { _PyErr_Restore(tstate, type, value, traceback); @@ -5516,9 +5516,9 @@ call_trace_protected(Py_tracefunc func, PyObject *obj, } static void -initialize_trace_info(PyTraceInfo *trace_info, InterpreterFrame *frame) +initialize_trace_info(PyTraceInfo *trace_info, _PyExecFrame *xframe) { - PyCodeObject *code = frame->f_code; + PyCodeObject *code = xframe->xf_code; if (trace_info->code != code) { trace_info->code = code; _PyCode_InitAddressRange(code, &trace_info->bounds); @@ -5527,7 +5527,7 @@ initialize_trace_info(PyTraceInfo *trace_info, InterpreterFrame *frame) static int call_trace(Py_tracefunc func, PyObject *obj, - PyThreadState *tstate, InterpreterFrame *frame, + PyThreadState *tstate, _PyExecFrame *xframe, int what, PyObject *arg) { int result; @@ -5535,16 +5535,16 @@ call_trace(Py_tracefunc func, PyObject *obj, return 0; tstate->tracing++; tstate->cframe->use_tracing = 0; - PyFrameObject *f = _PyFrame_GetFrameObject(frame); + PyFrameObject *f = _PyExecFrame_GetFrameObject(xframe); if (f == NULL) { return -1; } - if (frame->f_lasti < 0) { - f->f_lineno = frame->f_code->co_firstlineno; + if (xframe->xf_lasti < 0) { + f->f_lineno = xframe->xf_code->co_firstlineno; } else { - initialize_trace_info(&tstate->trace_info, frame); - f->f_lineno = _PyCode_CheckLineNumber(frame->f_lasti*2, &tstate->trace_info.bounds); + initialize_trace_info(&tstate->trace_info, xframe); + f->f_lineno = _PyCode_CheckLineNumber(xframe->xf_lasti*2, &tstate->trace_info.bounds); } result = func(obj, f, what, arg); f->f_lineno = 0; @@ -5574,7 +5574,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, InterpreterFrame *frame, int instr_prev) + PyThreadState *tstate, _PyExecFrame *xframe, int instr_prev) { int result = 0; @@ -5582,22 +5582,22 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj, represents a jump backwards, update the frame's line number and then call the trace function if we're tracing source lines. */ - initialize_trace_info(&tstate->trace_info, frame); + initialize_trace_info(&tstate->trace_info, xframe); int lastline = _PyCode_CheckLineNumber(instr_prev*2, &tstate->trace_info.bounds); - int line = _PyCode_CheckLineNumber(frame->f_lasti*2, &tstate->trace_info.bounds); - PyFrameObject *f = _PyFrame_GetFrameObject(frame); + int line = _PyCode_CheckLineNumber(xframe->xf_lasti*2, &tstate->trace_info.bounds); + PyFrameObject *f = _PyExecFrame_GetFrameObject(xframe); if (f == NULL) { return -1; } if (line != -1 && f->f_trace_lines) { /* Trace backward edges or if line number has changed */ - if (frame->f_lasti < instr_prev || line != lastline) { - result = call_trace(func, obj, tstate, frame, PyTrace_LINE, Py_None); + if (xframe->xf_lasti < instr_prev || line != lastline) { + result = call_trace(func, obj, tstate, xframe, PyTrace_LINE, Py_None); } } /* Always emit an opcode event if we're tracing all opcodes. */ if (f->f_trace_opcodes) { - result = call_trace(func, obj, tstate, frame, PyTrace_OPCODE, Py_None); + result = call_trace(func, obj, tstate, xframe, PyTrace_OPCODE, Py_None); } return result; } @@ -5743,21 +5743,21 @@ _PyEval_GetAsyncGenFinalizer(void) return tstate->async_gen_finalizer; } -InterpreterFrame * -_PyEval_GetFrame(void) +_PyExecFrame * +_PyEval_GetExecFrame(void) { PyThreadState *tstate = _PyThreadState_GET(); - return tstate->frame; + return tstate->xframe; } PyFrameObject * PyEval_GetFrame(void) { PyThreadState *tstate = _PyThreadState_GET(); - if (tstate->frame == NULL) { + if (tstate->xframe == NULL) { return NULL; } - PyFrameObject *f = _PyFrame_GetFrameObject(tstate->frame); + PyFrameObject *f = _PyExecFrame_GetFrameObject(tstate->xframe); if (f == NULL) { PyErr_Clear(); } @@ -5767,9 +5767,9 @@ PyEval_GetFrame(void) PyObject * _PyEval_GetBuiltins(PyThreadState *tstate) { - InterpreterFrame *frame = tstate->frame; - if (frame != NULL) { - return frame->f_builtins; + _PyExecFrame *xframe = tstate->xframe; + if (xframe != NULL) { + return xframe->xf_builtins; } return tstate->interp->builtins; } @@ -5800,17 +5800,17 @@ PyObject * PyEval_GetLocals(void) { PyThreadState *tstate = _PyThreadState_GET(); - InterpreterFrame *current_frame = tstate->frame; - if (current_frame == NULL) { + _PyExecFrame *xframe = tstate->xframe; + if (xframe == NULL) { _PyErr_SetString(tstate, PyExc_SystemError, "frame does not exist"); return NULL; } - if (_PyFrame_FastToLocalsWithError(current_frame) < 0) { + if (_PyExecFrame_FastToLocalsWithError(xframe) < 0) { return NULL; } - PyObject *locals = current_frame->f_locals; + PyObject *locals = xframe->xf_locals; assert(locals != NULL); return locals; } @@ -5819,22 +5819,22 @@ PyObject * PyEval_GetGlobals(void) { PyThreadState *tstate = _PyThreadState_GET(); - InterpreterFrame *current_frame = tstate->frame; - if (current_frame == NULL) { + _PyExecFrame *xframe = tstate->xframe; + if (xframe == NULL) { return NULL; } - return current_frame->f_globals; + return xframe->xf_globals; } int PyEval_MergeCompilerFlags(PyCompilerFlags *cf) { PyThreadState *tstate = _PyThreadState_GET(); - InterpreterFrame *current_frame = tstate->frame; + _PyExecFrame *xframe = tstate->xframe; int result = cf->cf_flags != 0; - if (current_frame != NULL) { - const int codeflags = current_frame->f_code->co_flags; + if (xframe != NULL) { + const int codeflags = xframe->xf_code->co_flags; const int compilerflags = codeflags & PyCF_MASK; if (compilerflags) { result = 1; @@ -5880,7 +5880,7 @@ PyEval_GetFuncDesc(PyObject *func) #define C_TRACE(x, call) \ if (use_tracing && tstate->c_profilefunc) { \ if (call_trace(tstate->c_profilefunc, tstate->c_profileobj, \ - tstate, tstate->frame, \ + tstate, tstate->xframe, \ PyTrace_C_CALL, func)) { \ x = NULL; \ } \ @@ -5890,13 +5890,13 @@ if (use_tracing && tstate->c_profilefunc) { \ if (x == NULL) { \ call_trace_protected(tstate->c_profilefunc, \ tstate->c_profileobj, \ - tstate, tstate->frame, \ + tstate, tstate->xframe, \ PyTrace_C_EXCEPTION, func); \ /* XXX should pass (type, value, tb) */ \ } else { \ if (call_trace(tstate->c_profilefunc, \ tstate->c_profileobj, \ - tstate, tstate->frame, \ + tstate, tstate->xframe, \ PyTrace_C_RETURN, func)) { \ Py_DECREF(x); \ x = NULL; \ @@ -6068,21 +6068,21 @@ _PyEval_SliceIndexNotNone(PyObject *v, Py_ssize_t *pi) } static PyObject * -import_name(PyThreadState *tstate, InterpreterFrame *frame, +import_name(PyThreadState *tstate, _PyExecFrame *xframe, PyObject *name, PyObject *fromlist, PyObject *level) { _Py_IDENTIFIER(__import__); PyObject *import_func, *res; PyObject* stack[5]; - import_func = _PyDict_GetItemIdWithError(frame->f_builtins, &PyId___import__); + import_func = _PyDict_GetItemIdWithError(xframe->xf_builtins, &PyId___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 = xframe->xf_locals; /* Fast path for not overloaded __import__. */ if (import_func == tstate->interp->import_func) { int ilevel = _PyLong_AsInt(level); @@ -6091,8 +6091,8 @@ import_name(PyThreadState *tstate, InterpreterFrame *frame, } res = PyImport_ImportModuleLevelObject( name, - frame->f_globals, - locals == NULL ? Py_None :locals, + xframe->xf_globals, + locals == NULL ? Py_None : locals, fromlist, ilevel); return res; @@ -6101,7 +6101,7 @@ import_name(PyThreadState *tstate, InterpreterFrame *frame, Py_INCREF(import_func); stack[0] = name; - stack[1] = frame->f_globals; + stack[1] = xframe->xf_globals; stack[2] = locals == NULL ? Py_None : locals; stack[3] = fromlist; stack[4] = level; @@ -6407,7 +6407,7 @@ format_awaitable_error(PyThreadState *tstate, PyTypeObject *type, int prevprevop static PyObject * unicode_concatenate(PyThreadState *tstate, PyObject *v, PyObject *w, - InterpreterFrame *frame, const _Py_CODEUNIT *next_instr) + _PyExecFrame *xframe, const _Py_CODEUNIT *next_instr) { PyObject *res; if (Py_REFCNT(v) == 2) { @@ -6422,14 +6422,14 @@ unicode_concatenate(PyThreadState *tstate, PyObject *v, PyObject *w, switch (opcode) { case STORE_FAST: { - PyObject **localsplus = _PyFrame_GetLocalsArray(frame); + PyObject **localsplus = _PyExecFrame_GetLocalsArray(xframe); if (GETLOCAL(oparg) == v) SETLOCAL(oparg, NULL); break; } case STORE_DEREF: { - PyObject *c = _PyFrame_GetLocalsArray(frame)[oparg]; + PyObject *c = _PyExecFrame_GetLocalsArray(xframe)[oparg]; if (PyCell_GET(c) == v) { PyCell_SET(c, NULL); Py_DECREF(v); @@ -6438,9 +6438,9 @@ unicode_concatenate(PyThreadState *tstate, PyObject *v, PyObject *w, } case STORE_NAME: { - PyObject *names = frame->f_code->co_names; + PyObject *names = xframe->xf_code->co_names; PyObject *name = GETITEM(names, oparg); - PyObject *locals = frame->f_locals; + PyObject *locals = xframe->xf_locals; if (locals && PyDict_CheckExact(locals)) { PyObject *w = PyDict_GetItemWithError(locals, name); if ((w == v && PyDict_DelItem(locals, name) != 0) || @@ -6518,38 +6518,38 @@ _PyEval_RequestCodeExtraIndex(freefunc free) } static void -dtrace_function_entry(InterpreterFrame *frame) +dtrace_function_entry(_PyExecFrame *xframe) { const char *filename; const char *funcname; int lineno; - PyCodeObject *code = frame->f_code; + PyCodeObject *code = xframe->xf_code; filename = PyUnicode_AsUTF8(code->co_filename); funcname = PyUnicode_AsUTF8(code->co_name); - lineno = PyCode_Addr2Line(frame->f_code, frame->f_lasti*2); + lineno = PyCode_Addr2Line(xframe->xf_code, xframe->xf_lasti*2); PyDTrace_FUNCTION_ENTRY(filename, funcname, lineno); } static void -dtrace_function_return(InterpreterFrame *frame) +dtrace_function_return(_PyExecFrame *xframe) { const char *filename; const char *funcname; int lineno; - PyCodeObject *code = frame->f_code; + PyCodeObject *code = xframe->xf_code; filename = PyUnicode_AsUTF8(code->co_filename); funcname = PyUnicode_AsUTF8(code->co_name); - lineno = PyCode_Addr2Line(frame->f_code, frame->f_lasti*2); + lineno = PyCode_Addr2Line(xframe->xf_code, xframe->xf_lasti*2); PyDTrace_FUNCTION_RETURN(filename, funcname, lineno); } /* DTrace equivalent of maybe_call_line_trace. */ static void -maybe_dtrace_line(InterpreterFrame *frame, +maybe_dtrace_line(_PyExecFrame *xframe, PyTraceInfo *trace_info, int instr_prev) { @@ -6558,19 +6558,19 @@ maybe_dtrace_line(InterpreterFrame *frame, /* If the last instruction executed isn't in the current instruction window, reset the window. */ - initialize_trace_info(trace_info, frame); + initialize_trace_info(trace_info, xframe); int lastline = _PyCode_CheckLineNumber(instr_prev*2, &trace_info->bounds); - int line = _PyCode_CheckLineNumber(frame->f_lasti*2, &trace_info->bounds); + int line = _PyCode_CheckLineNumber(xframe->xf_lasti*2, &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*2 == trace_info->bounds.ar_start)) + if (xframe->xf_lasti < instr_prev || + (line != lastline && xframe->xf_lasti*2 == trace_info->bounds.ar_start)) { - co_filename = PyUnicode_AsUTF8(frame->f_code->co_filename); + co_filename = PyUnicode_AsUTF8(xframe->xf_code->co_filename); if (!co_filename) { co_filename = "?"; } - co_name = PyUnicode_AsUTF8(frame->f_code->co_name); + co_name = PyUnicode_AsUTF8(xframe->xf_code->co_name); if (!co_name) { co_name = "?"; } diff --git a/Python/frame.c b/Python/frame.c index ae4284346ea12f..e941a160b09d60 100644 --- a/Python/frame.c +++ b/Python/frame.c @@ -1,36 +1,36 @@ #include "Python.h" #include "frameobject.h" -#include "pycore_frame.h" +#include "pycore_xframe.h" #include "pycore_object.h" // _PyObject_GC_UNTRACK() int -_PyFrame_Traverse(InterpreterFrame *frame, visitproc visit, void *arg) +_PyExecFrame_Traverse(_PyExecFrame *xframe, visitproc visit, void *arg) { - Py_VISIT(frame->frame_obj); - Py_VISIT(frame->f_globals); - Py_VISIT(frame->f_builtins); - Py_VISIT(frame->f_locals); - Py_VISIT(frame->f_code); + Py_VISIT(xframe->xf_frame_obj); + Py_VISIT(xframe->xf_globals); + Py_VISIT(xframe->xf_builtins); + Py_VISIT(xframe->xf_locals); + Py_VISIT(xframe->xf_code); /* locals */ - PyObject **locals = _PyFrame_GetLocalsArray(frame); - for (int i = 0; i < frame->nlocalsplus; i++) { + PyObject **locals = _PyExecFrame_GetLocalsArray(xframe); + for (int i = 0; i < xframe->xf_nlocalsplus; i++) { Py_VISIT(locals[i]); } /* stack */ - for (int i = 0; i <frame->stackdepth; i++) { - Py_VISIT(frame->stack[i]); + for (int i = 0; i <xframe->xf_stackdepth; i++) { + Py_VISIT(xframe->xf_stack[i]); } return 0; } PyFrameObject * -_PyFrame_MakeAndSetFrameObject(InterpreterFrame *frame) +_PyExecFrame_MakeAndSetFrameObject(_PyExecFrame *xframe) { - assert(frame->frame_obj == NULL); + assert(xframe->xf_frame_obj == NULL); PyObject *error_type, *error_value, *error_traceback; PyErr_Fetch(&error_type, &error_value, &error_traceback); - PyFrameObject *f = _PyFrame_New_NoTrack(frame, 0); + PyFrameObject *f = _PyFrame_New_NoTrack(xframe, 0); if (f == NULL) { Py_XDECREF(error_type); Py_XDECREF(error_value); @@ -39,50 +39,50 @@ _PyFrame_MakeAndSetFrameObject(InterpreterFrame *frame) else { PyErr_Restore(error_type, error_value, error_traceback); } - frame->frame_obj = f; + xframe->xf_frame_obj = f; return f; } -static InterpreterFrame * -copy_frame_to_heap(InterpreterFrame *frame) +static _PyExecFrame * +copy_frame_to_heap(_PyExecFrame *xframe) { - Py_ssize_t size = ((char*)&frame->stack[frame->stackdepth]) - (char *)_PyFrame_GetLocalsArray(frame); + PyObject **locals = _PyExecFrame_GetLocalsArray(xframe); + Py_ssize_t size = ((char*)&xframe->xf_stack[xframe->xf_stackdepth]) - (char *)locals; PyObject **copy = PyMem_Malloc(size); if (copy == NULL) { PyErr_NoMemory(); return NULL; } - PyObject **locals = _PyFrame_GetLocalsArray(frame); memcpy(copy, locals, size); - InterpreterFrame *res = (InterpreterFrame *)(copy + frame->nlocalsplus); + _PyExecFrame *res = (_PyExecFrame *)(copy + xframe->xf_nlocalsplus); return res; } static inline void -clear_specials(InterpreterFrame *frame) +clear_specials(_PyExecFrame *xframe) { - frame->generator = NULL; - Py_XDECREF(frame->frame_obj); - Py_XDECREF(frame->f_locals); - Py_DECREF(frame->f_globals); - Py_DECREF(frame->f_builtins); - Py_DECREF(frame->f_code); + xframe->xf_generator = NULL; + Py_XDECREF(xframe->xf_frame_obj); + Py_XDECREF(xframe->xf_locals); + Py_DECREF(xframe->xf_globals); + Py_DECREF(xframe->xf_builtins); + Py_DECREF(xframe->xf_code); } static void -take_ownership(PyFrameObject *f, InterpreterFrame *frame) +take_ownership(PyFrameObject *f, _PyExecFrame *xframe) { assert(f->f_own_locals_memory == 0); - assert(frame->frame_obj == NULL); + assert(xframe->xf_frame_obj == NULL); f->f_own_locals_memory = 1; - f->f_frame = frame; + f->f_xframe = xframe; assert(f->f_back == NULL); - if (frame->previous != NULL) { - /* Link PyFrameObjects.f_back and remove link through InterpreterFrame.previous */ - PyFrameObject *back = _PyFrame_GetFrameObject(frame->previous); + if (xframe->xf_previous != NULL) { + /* Link introspection frame's f_back and remove link through execution frame's xf_previous */ + PyFrameObject *back = _PyExecFrame_GetFrameObject(xframe->xf_previous); if (back == NULL) { /* Memory error here. */ assert(PyErr_ExceptionMatches(PyExc_MemoryError)); @@ -93,7 +93,7 @@ take_ownership(PyFrameObject *f, InterpreterFrame *frame) else { f->f_back = (PyFrameObject *)Py_NewRef(back); } - frame->previous = NULL; + xframe->xf_previous = NULL; } if (!_PyObject_GC_IS_TRACKED((PyObject *)f)) { _PyObject_GC_TRACK((PyObject *)f); @@ -101,35 +101,35 @@ take_ownership(PyFrameObject *f, InterpreterFrame *frame) } int -_PyFrame_Clear(InterpreterFrame * frame, int take) +_PyExecFrame_Clear(_PyExecFrame * xframe, int take) { - PyObject **localsarray = ((PyObject **)frame)-frame->nlocalsplus; - if (frame->frame_obj) { - PyFrameObject *f = frame->frame_obj; - frame->frame_obj = NULL; + PyObject **localsarray = ((PyObject **)xframe)-xframe->xf_nlocalsplus; + if (xframe->xf_frame_obj) { + PyFrameObject *f = xframe->xf_frame_obj; + xframe->xf_frame_obj = NULL; if (Py_REFCNT(f) > 1) { if (!take) { - frame = copy_frame_to_heap(frame); - if (frame == NULL) { + xframe = copy_frame_to_heap(xframe); + if (xframe == NULL) { return -1; } } - take_ownership(f, frame); + take_ownership(f, xframe); Py_DECREF(f); return 0; } Py_DECREF(f); } - for (int i = 0; i < frame->nlocalsplus; i++) { + for (int i = 0; i < xframe->xf_nlocalsplus; i++) { Py_XDECREF(localsarray[i]); } - assert(frame->stackdepth >= 0); - for (int i = 0; i < frame->stackdepth; i++) { - Py_DECREF(frame->stack[i]); + assert(xframe->xf_stackdepth >= 0); + for (int i = 0; i < xframe->xf_stackdepth; i++) { + Py_DECREF(xframe->xf_stack[i]); } - clear_specials(frame); + clear_specials(xframe); if (take) { - PyMem_Free(_PyFrame_GetLocalsArray(frame)); + PyMem_Free(_PyExecFrame_GetLocalsArray(xframe)); } return 0; } diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index d31a9c15fd1ec5..df6f16a3a0e6e0 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -2003,7 +2003,7 @@ Py_EndInterpreter(PyThreadState *tstate) if (tstate != _PyThreadState_GET()) { Py_FatalError("thread is not current"); } - if (tstate->frame != NULL) { + if (tstate->xframe != NULL) { Py_FatalError("thread still has a frame"); } interp->finalizing = 1; diff --git a/Python/pystate.c b/Python/pystate.c index 6a15b54d1dd84f..93aa4e7fb7b603 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -3,7 +3,7 @@ #include "Python.h" #include "pycore_ceval.h" -#include "pycore_frame.h" +#include "pycore_xframe.h" #include "pycore_initconfig.h" #include "pycore_object.h" // _PyType_InitCache() #include "pycore_pyerrors.h" @@ -636,7 +636,7 @@ new_threadstate(PyInterpreterState *interp, int init) tstate->interp = interp; - tstate->frame = NULL; + tstate->xframe = NULL; tstate->recursion_depth = 0; tstate->recursion_headroom = 0; tstate->stackcheck_counter = 0; @@ -686,7 +686,7 @@ new_threadstate(PyInterpreterState *interp, int init) PyMem_RawFree(tstate); return NULL; } - /* If top points to entry 0, then _PyThreadState_PopFrame will try to pop this chunk */ + /* If top points to entry 0, then _PyThreadState_PopExecFrame will try to pop this chunk */ tstate->datastack_top = &tstate->datastack_chunk->data[1]; tstate->datastack_limit = (PyObject **)(((char *)tstate->datastack_chunk) + DATA_STACK_CHUNK_SIZE); /* Mark trace_info as uninitialized */ @@ -861,11 +861,11 @@ PyThreadState_Clear(PyThreadState *tstate) { int verbose = _PyInterpreterState_GetConfig(tstate->interp)->verbose; - if (verbose && tstate->frame != NULL) { + if (verbose && tstate->xframe != NULL) { /* bpo-20526: After the main thread calls _PyRuntimeState_SetFinalizing() in Py_FinalizeEx(), threads must exit when trying to take the GIL. If a thread exit in the middle of - _PyEval_EvalFrameDefault(), tstate->frame is not reset to its + _PyEval_EvalFrameDefault(), tstate->xframe is not reset to its previous value. It is more likely with daemon threads, but it can happen with regular threads if threading._shutdown() fails (ex: interrupted by CTRL+C). */ @@ -1134,10 +1134,10 @@ PyFrameObject* PyThreadState_GetFrame(PyThreadState *tstate) { assert(tstate != NULL); - if (tstate->frame == NULL) { + if (tstate->xframe == NULL) { return NULL; } - PyFrameObject *frame = _PyFrame_GetFrameObject(tstate->frame); + PyFrameObject *frame = _PyExecFrame_GetFrameObject(tstate->xframe); if (frame == NULL) { PyErr_Clear(); } @@ -1261,15 +1261,15 @@ _PyThread_CurrentFrames(void) for (i = runtime->interpreters.head; i != NULL; i = i->next) { PyThreadState *t; for (t = i->tstate_head; t != NULL; t = t->next) { - InterpreterFrame *frame = t->frame; - if (frame == NULL) { + _PyExecFrame *xframe = t->xframe; + if (xframe == NULL) { continue; } PyObject *id = PyLong_FromUnsignedLong(t->thread_id); if (id == NULL) { goto fail; } - int stat = PyDict_SetItem(result, id, (PyObject *)_PyFrame_GetFrameObject(frame)); + int stat = PyDict_SetItem(result, id, (PyObject *)_PyExecFrame_GetFrameObject(xframe)); Py_DECREF(id); if (stat < 0) { goto fail; @@ -2037,8 +2037,8 @@ push_chunk(PyThreadState *tstate, int size) return res; } -InterpreterFrame * -_PyThreadState_PushFrame(PyThreadState *tstate, PyFrameConstructor *con, PyObject *locals) +_PyExecFrame * +_PyThreadState_PushExecFrame(PyThreadState *tstate, PyFrameConstructor *con, PyObject *locals) { PyCodeObject *code = (PyCodeObject *)con->fc_code; int nlocalsplus = code->co_nlocalsplus; @@ -2056,18 +2056,18 @@ _PyThreadState_PushFrame(PyThreadState *tstate, PyFrameConstructor *con, PyObjec else { tstate->datastack_top = top; } - InterpreterFrame * frame = (InterpreterFrame *)(localsarray + nlocalsplus); - _PyFrame_InitializeSpecials(frame, con, locals, nlocalsplus); + _PyExecFrame * xframe = (_PyExecFrame *)(localsarray + nlocalsplus); + _PyExecFrame_InitializeSpecials(xframe, con, locals, nlocalsplus); for (int i=0; i < nlocalsplus; i++) { localsarray[i] = NULL; } - return frame; + return xframe; } void -_PyThreadState_PopFrame(PyThreadState *tstate, InterpreterFrame * frame) +_PyThreadState_PopExecFrame(PyThreadState *tstate, _PyExecFrame * xframe) { - PyObject **locals = _PyFrame_GetLocalsArray(frame); + PyObject **locals = _PyExecFrame_GetLocalsArray(xframe); if (locals == &tstate->datastack_chunk->data[0]) { _PyStackChunk *chunk = tstate->datastack_chunk; _PyStackChunk *previous = chunk->previous; diff --git a/Python/suggestions.c b/Python/suggestions.c index 81976ff4f2eb41..01fca89c65074d 100644 --- a/Python/suggestions.c +++ b/Python/suggestions.c @@ -1,6 +1,6 @@ #include "Python.h" #include "frameobject.h" -#include "pycore_frame.h" +#include "pycore_xframe.h" #include "pycore_pyerrors.h" #include "pycore_code.h" // _PyCode_GetVarnames() @@ -232,7 +232,7 @@ offer_suggestions_for_name_error(PyNameErrorObject *exc) return suggestions; } - dir = PySequence_List(frame->f_frame->f_globals); + dir = PySequence_List(frame->f_xframe->xf_globals); if (dir == NULL) { return NULL; } @@ -242,7 +242,7 @@ offer_suggestions_for_name_error(PyNameErrorObject *exc) return suggestions; } - dir = PySequence_List(frame->f_frame->f_builtins); + dir = PySequence_List(frame->f_xframe->xf_builtins); if (dir == NULL) { return NULL; } diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 5dfa917e8ffb20..126cd5edfeb5d1 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -29,7 +29,7 @@ Data members: #include "code.h" #include "frameobject.h" // PyFrame_GetBack() -#include "pycore_frame.h" +#include "pycore_xframe.h" #include "pydtrace.h" #include "osdefs.h" // DELIM #include "stdlib_module_names.h" // _Py_stdlib_module_names @@ -1815,22 +1815,22 @@ sys__getframe_impl(PyObject *module, int depth) /*[clinic end generated code: output=d438776c04d59804 input=c1be8a6464b11ee5]*/ { PyThreadState *tstate = _PyThreadState_GET(); - InterpreterFrame *frame = tstate->frame; + _PyExecFrame *xframe = tstate->xframe; if (_PySys_Audit(tstate, "sys._getframe", NULL) < 0) { return NULL; } - while (depth > 0 && frame != NULL) { - frame = frame->previous; + while (depth > 0 && xframe != NULL) { + xframe = xframe->xf_previous; --depth; } - if (frame == NULL) { + if (xframe == NULL) { _PyErr_SetString(tstate, PyExc_ValueError, "call stack is not deep enough"); return NULL; } - return _Py_XNewRef((PyObject *)_PyFrame_GetFrameObject(frame)); + return _Py_XNewRef((PyObject *)_PyExecFrame_GetFrameObject(xframe)); } /*[clinic input] diff --git a/Python/traceback.c b/Python/traceback.c index 204121ba66d96e..073631acf96253 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -6,7 +6,7 @@ #include "code.h" // PyCode_Addr2Line etc #include "pycore_interp.h" // PyInterpreterState.gc #include "frameobject.h" // PyFrame_GetBack() -#include "pycore_frame.h" // _PyFrame_GetCode() +#include "pycore_xframe.h" // _PyExecFrame_GetCode() #include "pycore_pyarena.h" // _PyArena_Free() #include "pycore_ast.h" // asdl_seq_* #include "pycore_compile.h" // _PyAST_Optimize @@ -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*2, + return tb_create_raw((PyTracebackObject *)tb_next, frame, frame->f_xframe->xf_lasti*2, PyFrame_GetLineNumber(frame)); } @@ -710,7 +710,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_xframe->xf_code; int start_line; int end_line; @@ -1024,9 +1024,9 @@ _Py_DumpASCII(int fd, PyObject *text) This function is signal safe. */ static void -dump_frame(int fd, InterpreterFrame *frame) +dump_frame(int fd, _PyExecFrame *xframe) { - PyCodeObject *code = frame->f_code; + PyCodeObject *code = xframe->xf_code; PUTS(fd, " File "); if (code->co_filename != NULL && PyUnicode_Check(code->co_filename)) @@ -1038,7 +1038,7 @@ dump_frame(int fd, InterpreterFrame *frame) PUTS(fd, "???"); } - int lineno = PyCode_Addr2Line(code, frame->f_lasti*2); + int lineno = PyCode_Addr2Line(code, xframe->xf_lasti*2); PUTS(fd, ", line "); if (lineno >= 0) { _Py_DumpDecimal(fd, (size_t)lineno); @@ -1062,15 +1062,15 @@ dump_frame(int fd, InterpreterFrame *frame) static void dump_traceback(int fd, PyThreadState *tstate, int write_header) { - InterpreterFrame *frame; + _PyExecFrame *xframe; unsigned int depth; if (write_header) { PUTS(fd, "Stack (most recent call first):\n"); } - frame = tstate->frame; - if (frame == NULL) { + xframe = tstate->xframe; + if (xframe == NULL) { PUTS(fd, "<no Python frame>\n"); return; } @@ -1081,9 +1081,9 @@ dump_traceback(int fd, PyThreadState *tstate, int write_header) PUTS(fd, " ...\n"); break; } - dump_frame(fd, frame); - frame = frame->previous; - if (frame == NULL) { + dump_frame(fd, xframe); + xframe = xframe->xf_previous; + if (xframe == NULL) { break; } depth++; diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py index 8b09563c18c9b1..425869c5bec024 100755 --- a/Tools/gdb/libpython.py +++ b/Tools/gdb/libpython.py @@ -861,7 +861,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 = PyExecFramePtr(self.field('f_xframe')) def iter_locals(self): ''' @@ -932,17 +932,17 @@ def print_traceback(self): return return self._frame.print_traceback() -class PyFramePtr: +class PyExecFramePtr: def __init__(self, gdbval): self._gdbval = gdbval if not self.is_optimized_out(): - self.co = self._f_code() + self.co = self._xf_code() 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.xf_lasti = self._xf_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) @@ -960,7 +960,7 @@ def iter_locals(self): obj_ptr_ptr = gdb.lookup_type("PyObject").pointer().pointer() base = self._gdbval.cast(obj_ptr_ptr) - localsplus = base - self._f_nlocalsplus() + localsplus = base - self._xf_nlocalsplus() for i in safe_range(self.co_nlocals): pyop_value = PyObjectPtr.from_pyobject_ptr(localsplus[i]) if pyop_value.is_null(): @@ -968,23 +968,23 @@ def iter_locals(self): pyop_name = PyObjectPtr.from_pyobject_ptr(self.co_localsplusnames[i]) yield (pyop_name, pyop_value) - def _f_special(self, name, convert=PyObjectPtr.from_pyobject_ptr): + def _xf_special(self, name, convert=PyObjectPtr.from_pyobject_ptr): return convert(self._gdbval[name]) - def _f_globals(self): - return self._f_special("f_globals") + def _xf_globals(self): + return self._xf_special("xf_globals") - def _f_builtins(self): - return self._f_special("f_builtins") + def _xf_builtins(self): + return self._xf_special("xf_builtins") - def _f_code(self): - return self._f_special("f_code", PyCodeObjectPtr.from_pyobject_ptr) + def _xf_code(self): + return self._xf_special("xf_code", PyCodeObjectPtr.from_pyobject_ptr) - def _f_nlocalsplus(self): - return self._f_special("nlocalsplus", int_from_int) + def _xf_nlocalsplus(self): + return self._xf_special("xf_nlocalsplus", int_from_int) - def _f_lasti(self): - return self._f_special("f_lasti", int_from_int) + def _xf_lasti(self): + return self._xf_special("xf_lasti", int_from_int) def iter_globals(self): @@ -995,7 +995,7 @@ def iter_globals(self): if self.is_optimized_out(): return () - pyop_globals = self._f_globals() + pyop_globals = self._xf_globals() return pyop_globals.iteritems() def iter_builtins(self): @@ -1006,7 +1006,7 @@ def iter_builtins(self): if self.is_optimized_out(): return () - pyop_builtins = self._f_builtins() + pyop_builtins = self._xf_builtins() return pyop_builtins.iteritems() def get_var_by_name(self, name): @@ -1043,7 +1043,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.xf_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 @@ -1733,21 +1733,21 @@ def is_gc_collect(self): def get_pyop(self): try: - frame = self._gdbframe.read_var('frame') - frame = PyFramePtr(frame) - if not frame.is_optimized_out(): - return frame - # gdb is unable to get the "frame" argument of PyEval_EvalFrameEx() - # because it was "optimized out". Try to get "frame" from the frame + xframe = self._gdbframe.read_var('xframe') + xframe = PyExecFramePtr(xframe) + if not xframe.is_optimized_out(): + return xframe + # gdb is unable to get the "xframe" argument of PyEval_EvalFrameEx() + # because it was "optimized out". Try to get "xframe" from the frame # of the caller, _PyEval_Vector(). - orig_frame = frame + orig_xframe = xframe caller = self._gdbframe.older() if caller: - frame = caller.read_var('frame') - frame = PyFramePtr(frame) - if not frame.is_optimized_out(): - return frame - return orig_frame + xframe = caller.read_var('xframe') + xframe = PyExecFramePtr(xframe) + if not xframe.is_optimized_out(): + return xframe + return orig_xframe except ValueError: return None From d8858aa6517e821d172c96532118acbc4353604d Mon Sep 17 00:00:00 2001 From: Nick Coghlan <ncoghlan@gmail.com> Date: Sat, 14 Aug 2021 14:15:09 +1000 Subject: [PATCH 02/30] 'frame' and 'frame data' replaces introspection and execution frames --- Include/cpython/ceval.h | 2 +- Include/cpython/frameobject.h | 22 +- Include/cpython/pystate.h | 8 +- Include/genobject.h | 4 +- Include/internal/pycore_ceval.h | 8 +- Include/internal/pycore_framedata.h | 133 +++++++ Include/internal/pycore_xframe.h | 133 ------- Lib/test/test_socket.py | 4 +- .../2021-08-01-18-18-51.bpo-44800.TCsfH3.rst | 12 +- Misc/gdbinit | 16 +- Modules/_tracemalloc.c | 18 +- Modules/_xxsubinterpretersmodule.c | 8 +- Modules/signalmodule.c | 8 +- Objects/frameobject.c | 158 ++++---- Objects/genobject.c | 170 ++++----- Objects/typeobject.c | 10 +- Python/_warnings.c | 6 +- Python/ceval.c | 336 +++++++++--------- Python/frame.c | 96 ++--- Python/pylifecycle.c | 2 +- Python/pystate.c | 34 +- Python/suggestions.c | 6 +- Python/sysmodule.c | 12 +- Python/traceback.c | 24 +- Tools/gdb/libpython.py | 62 ++-- 25 files changed, 648 insertions(+), 644 deletions(-) create mode 100644 Include/internal/pycore_framedata.h delete mode 100644 Include/internal/pycore_xframe.h diff --git a/Include/cpython/ceval.h b/Include/cpython/ceval.h index d7b74ed0498c5f..def08ee81e4622 100644 --- a/Include/cpython/ceval.h +++ b/Include/cpython/ceval.h @@ -19,7 +19,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, _PyExecFrame *xf, int exc); +PyAPI_FUNC(PyObject *) _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int exc); PyAPI_FUNC(void) _PyEval_SetSwitchInterval(unsigned long microseconds); PyAPI_FUNC(unsigned long) _PyEval_GetSwitchInterval(void); diff --git a/Include/cpython/frameobject.h b/Include/cpython/frameobject.h index 75135e75af7666..f7df31bd779308 100644 --- a/Include/cpython/frameobject.h +++ b/Include/cpython/frameobject.h @@ -5,25 +5,25 @@ #endif /* Starting in CPython 3.11, CPython separates the frame state between the - * full "introspection frames" exposed by the Python and C runtime state - * introspection APIs, and internal lighter weight "execution frames", 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 - * introspection frame (if an instrospection API has been invoked and the - * introspection frame created). + * 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. + * over the previous approach of using full Python objects for both + * introspection and code execution. */ -// Declaration of _PyExecFrame is in cpython/pystate.h for use in PyThreadState +// Declaration of _Py_framedata is in cpython/pystate.h for use in PyThreadState struct _frame { PyObject_HEAD struct _frame *f_back; /* previous frame, or NULL */ - _PyExecFrame *f_xframe; /* points to the frame runtime data */ + _Py_framedata *f_fdata; /* points to the frame runtime 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? */ diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h index cb42333bda3e48..c0f3c779e40ef1 100644 --- a/Include/cpython/pystate.h +++ b/Include/cpython/pystate.h @@ -72,8 +72,8 @@ typedef struct _stack_chunk { // Declared here so the thread state can use it without creating an include loop // See cpython/frameobject.h for an explanation of the type -// See internal/pycore_xframe.h for the struct definition -typedef struct _Py_execution_frame _PyExecFrame; +// See internal/pycore_framedata.h for the struct definition +typedef struct _Py_execution_frame _Py_framedata; // The PyThreadState typedef is in Include/pystate.h. struct _ts { @@ -84,7 +84,7 @@ struct _ts { PyInterpreterState *interp; /* Borrowed reference to the current execution frame (it can be NULL) */ - _PyExecFrame *xframe; + _Py_framedata *fdata; int recursion_depth; int recursion_headroom; /* Allow 50 more calls to handle any errors. */ int stackcheck_counter; @@ -229,7 +229,7 @@ PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void); /* Frame evaluation API */ -typedef PyObject* (*_PyFrameEvalFunction)(PyThreadState *tstate, _PyExecFrame *, int); +typedef PyObject* (*_PyFrameEvalFunction)(PyThreadState *tstate, _Py_framedata *, int); PyAPI_FUNC(_PyFrameEvalFunction) _PyInterpreterState_GetEvalFrameFunc( PyInterpreterState *interp); diff --git a/Include/genobject.h b/Include/genobject.h index 65adc0d5ea623e..36ae755e8398d8 100644 --- a/Include/genobject.h +++ b/Include/genobject.h @@ -15,8 +15,8 @@ extern "C" { and coroutine objects. */ #define _PyGenObject_HEAD(prefix) \ PyObject_HEAD \ - /* Note: gi_xframe can be NULL if the generator is "finished" */ \ - _PyExecFrame *prefix##_xframe; \ + /* Note: gi_fdata can be NULL if the generator is "finished" */ \ + _Py_framedata *prefix##_fdata; \ /* The code object backing the generator */ \ PyCodeObject *prefix##_code; \ /* List of weak reference. */ \ diff --git a/Include/internal/pycore_ceval.h b/Include/internal/pycore_ceval.h index f87a37fbd53dad..ca1399cd5ae624 100644 --- a/Include/internal/pycore_ceval.h +++ b/Include/internal/pycore_ceval.h @@ -41,9 +41,9 @@ extern PyObject *_PyEval_BuiltinsFromGlobals( static inline PyObject* -_PyEval_EvalFrame(PyThreadState *tstate, _PyExecFrame *xframe, int throwflag) +_PyEval_EvalFrame(PyThreadState *tstate, _Py_framedata *fdata, int throwflag) { - return tstate->interp->eval_frame(tstate, xframe, throwflag); + return tstate->interp->eval_frame(tstate, fdata, throwflag); } extern PyObject * @@ -107,9 +107,9 @@ static inline void _Py_LeaveRecursiveCall_inline(void) { #define Py_LeaveRecursiveCall() _Py_LeaveRecursiveCall_inline() -_PyExecFrame *_PyEval_GetExecFrame(void); +_Py_framedata *_PyEval_GetFrameData(void); -PyObject *_Py_MakeCoro(PyFrameConstructor *, _PyExecFrame *); +PyObject *_Py_MakeCoro(PyFrameConstructor *, _Py_framedata *); #ifdef __cplusplus } diff --git a/Include/internal/pycore_framedata.h b/Include/internal/pycore_framedata.h new file mode 100644 index 00000000000000..1c49064ad0c2f2 --- /dev/null +++ b/Include/internal/pycore_framedata.h @@ -0,0 +1,133 @@ +#ifndef Py_INTERNAL_FRAMEDATA_H +#define Py_INTERNAL_FRAMEDATA_H +#ifdef __cplusplus +extern "C" { +#endif + +/* Internal-use-only frame object constructor */ +PyFrameObject* +_PyFrame_New_NoTrack(_Py_framedata *, int); + +/* These values are chosen so that the inline functions below all + * compare f_state to zero. + */ +enum _framestate { + FRAME_CREATED = -2, + FRAME_SUSPENDED = -1, + FRAME_EXECUTING = 0, + FRAME_RETURNED = 1, + FRAME_UNWINDING = 2, + FRAME_RAISED = 3, + FRAME_CLEARED = 4 +}; + +typedef signed char PyFrameState; + +// The _Py_framedata typedef is in Include/pyframeobject.h +struct _Py_execution_frame { + PyObject *globals; + PyObject *builtins; + PyObject *locals; + PyCodeObject *code; + PyFrameObject *frame_obj; // Full frame object (if created) + /* Borrowed reference to a generator, or NULL */ + PyObject *generator; + _Py_framedata *previous; + int lasti; /* Last instruction if called */ + int stackdepth; /* Depth of value stack */ + int nlocalsplus; + PyFrameState state; /* What state the frame is in */ + PyObject *stack[1]; +}; + +static inline int _Py_framedata_IsRunnable(_Py_framedata *fdata) { + return fdata->state < FRAME_EXECUTING; +} + +static inline int _Py_framedata_IsExecuting(_Py_framedata *fdata) { + return fdata->state == FRAME_EXECUTING; +} + +static inline int _Py_framedata_HasCompleted(_Py_framedata *fdata) { + return fdata->state > FRAME_EXECUTING; +} + +#define FRAME_SPECIALS_SIZE ((sizeof(_Py_framedata)-1)/sizeof(PyObject *)) + +_Py_framedata * +_Py_framedata_HeapAlloc(PyFrameConstructor *con, PyObject *locals); + +static inline void +_Py_framedata_InitializeSpecials( + _Py_framedata *fdata, PyFrameConstructor *con, + PyObject *locals, int nlocalsplus) +{ + fdata->code = (PyCodeObject *)Py_NewRef(con->fc_code); + fdata->builtins = Py_NewRef(con->fc_builtins); + fdata->globals = Py_NewRef(con->fc_globals); + fdata->locals = Py_XNewRef(locals); + fdata->nlocalsplus = nlocalsplus; + fdata->stackdepth = 0; + fdata->frame_obj = NULL; + fdata->generator = NULL; + fdata->lasti = -1; + fdata->state = FRAME_CREATED; +} + +/* Gets the pointer to the locals array + * that precedes this frame. + */ +static inline PyObject** +_Py_framedata_GetLocalsArray(_Py_framedata *fdata) +{ + return ((PyObject **)fdata) - fdata->nlocalsplus; +} + +/* For use by _Py_framedata_GetFrameObject + Do not call directly. */ +PyFrameObject * +_Py_framedata_MakeAndSetFrameObject(_Py_framedata *fdata); + +/* Gets the PyFrameObject for this frame, lazily + * creating it if necessary. + * Returns a borrowed referennce */ +static inline PyFrameObject * +_Py_framedata_GetFrameObject(_Py_framedata *fdata) +{ + PyFrameObject *res = fdata->frame_obj; + if (res != NULL) { + return res; + } + return _Py_framedata_MakeAndSetFrameObject(fdata); +} + +/* Clears all references in the frame. + * If take is non-zero, then the execution frame + * may be transfered to the frame object it references + * instead of being cleared. Either way + * the caller no longer owns the references + * in the frame. + * take should be set to 1 for heap allocated + * frames like the ones in generators and coroutines. + */ +int +_Py_framedata_Clear(_Py_framedata *fdata, int take); + +int +_Py_framedata_Traverse(_Py_framedata *fdata, visitproc visit, void *arg); + +int +_Py_framedata_FastToLocalsWithError(_Py_framedata *frame); + +void +_Py_framedata_LocalsToFast(_Py_framedata *frame, int clear); + +_Py_framedata *_PyThreadState_Push_framedata( + PyThreadState *tstate, PyFrameConstructor *con, PyObject *locals); + +void _PyThreadState_Pop_framedata(PyThreadState *tstate, _Py_framedata *frame); + +#ifdef __cplusplus +} +#endif +#endif /* !Py_INTERNAL_FRAMEDATA_H */ diff --git a/Include/internal/pycore_xframe.h b/Include/internal/pycore_xframe.h deleted file mode 100644 index 4550801f003220..00000000000000 --- a/Include/internal/pycore_xframe.h +++ /dev/null @@ -1,133 +0,0 @@ -#ifndef Py_INTERNAL_XFRAME_H -#define Py_INTERNAL_XFRAME_H -#ifdef __cplusplus -extern "C" { -#endif - -/* Internal-use-only introspection frame constructor */ -PyFrameObject* -_PyFrame_New_NoTrack(_PyExecFrame *, int); - -/* These values are chosen so that the inline functions below all - * compare f_state to zero. - */ -enum _framestate { - FRAME_CREATED = -2, - FRAME_SUSPENDED = -1, - FRAME_EXECUTING = 0, - FRAME_RETURNED = 1, - FRAME_UNWINDING = 2, - FRAME_RAISED = 3, - FRAME_CLEARED = 4 -}; - -typedef signed char PyFrameState; - -// The _PyExecFrame typedef is in Include/pyframeobject.h -struct _Py_execution_frame { - PyObject *xf_globals; - PyObject *xf_builtins; - PyObject *xf_locals; - PyCodeObject *xf_code; - PyFrameObject *xf_frame_obj; // Introspection frame (if created) - /* Borrowed reference to a generator, or NULL */ - PyObject *xf_generator; - _PyExecFrame *xf_previous; - int xf_lasti; /* Last instruction if called */ - int xf_stackdepth; /* Depth of value stack */ - int xf_nlocalsplus; - PyFrameState xf_state; /* What state the frame is in */ - PyObject *xf_stack[1]; -}; - -static inline int _PyExecFrame_IsRunnable(_PyExecFrame *xf) { - return xf->xf_state < FRAME_EXECUTING; -} - -static inline int _PyExecFrame_IsExecuting(_PyExecFrame *xf) { - return xf->xf_state == FRAME_EXECUTING; -} - -static inline int _PyExecFrame_HasCompleted(_PyExecFrame *xf) { - return xf->xf_state > FRAME_EXECUTING; -} - -#define FRAME_SPECIALS_SIZE ((sizeof(_PyExecFrame)-1)/sizeof(PyObject *)) - -_PyExecFrame * -_PyExecFrame_HeapAlloc(PyFrameConstructor *con, PyObject *locals); - -static inline void -_PyExecFrame_InitializeSpecials( - _PyExecFrame *xframe, PyFrameConstructor *con, - PyObject *locals, int nlocalsplus) -{ - xframe->xf_code = (PyCodeObject *)Py_NewRef(con->fc_code); - xframe->xf_builtins = Py_NewRef(con->fc_builtins); - xframe->xf_globals = Py_NewRef(con->fc_globals); - xframe->xf_locals = Py_XNewRef(locals); - xframe->xf_nlocalsplus = nlocalsplus; - xframe->xf_stackdepth = 0; - xframe->xf_frame_obj = NULL; - xframe->xf_generator = NULL; - xframe->xf_lasti = -1; - xframe->xf_state = FRAME_CREATED; -} - -/* Gets the pointer to the locals array - * that precedes this frame. - */ -static inline PyObject** -_PyExecFrame_GetLocalsArray(_PyExecFrame *xframe) -{ - return ((PyObject **)xframe) - xframe->xf_nlocalsplus; -} - -/* For use by _PyExecFrame_GetFrameObject - Do not call directly. */ -PyFrameObject * -_PyExecFrame_MakeAndSetFrameObject(_PyExecFrame *xframe); - -/* Gets the PyFrameObject for this frame, lazily - * creating it if necessary. - * Returns a borrowed referennce */ -static inline PyFrameObject * -_PyExecFrame_GetFrameObject(_PyExecFrame *xframe) -{ - PyFrameObject *res = xframe->xf_frame_obj; - if (res != NULL) { - return res; - } - return _PyExecFrame_MakeAndSetFrameObject(xframe); -} - -/* Clears all references in the frame. - * If take is non-zero, then the execution frame - * may be transfered to the frame object it references - * instead of being cleared. Either way - * the caller no longer owns the references - * in the frame. - * take should be set to 1 for heap allocated - * frames like the ones in generators and coroutines. - */ -int -_PyExecFrame_Clear(_PyExecFrame *xframe, int take); - -int -_PyExecFrame_Traverse(_PyExecFrame *xframe, visitproc visit, void *arg); - -int -_PyExecFrame_FastToLocalsWithError(_PyExecFrame *frame); - -void -_PyExecFrame_LocalsToFast(_PyExecFrame *frame, int clear); - -_PyExecFrame *_PyThreadState_PushExecFrame( - PyThreadState *tstate, PyFrameConstructor *con, PyObject *locals); - -void _PyThreadState_PopExecFrame(PyThreadState *tstate, _PyExecFrame *frame); - -#ifdef __cplusplus -} -#endif -#endif /* !Py_INTERNAL_XFRAME_H */ diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index c09f11e0f000fe..3b2d86c4ed19d0 100755 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -2090,11 +2090,11 @@ def _testSendFrame(self): self.cf = self.build_can_frame(0x00, b'\x01\x02\x03\x04\x05') self.cli.send(self.cf) - def testSendMaxFrame(self): + def testSendMafdata(self): cf, addr = self.s.recvfrom(self.bufsize) self.assertEqual(self.cf, cf) - def _testSendMaxFrame(self): + def _testSendMafdata(self): self.cf = self.build_can_frame(0x00, b'\x07' * 8) self.cli.send(self.cf) diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-08-01-18-18-51.bpo-44800.TCsfH3.rst b/Misc/NEWS.d/next/Core and Builtins/2021-08-01-18-18-51.bpo-44800.TCsfH3.rst index fbd49db71f6f6d..25f56ae4e11058 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2021-08-01-18-18-51.bpo-44800.TCsfH3.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2021-08-01-18-18-51.bpo-44800.TCsfH3.rst @@ -1,4 +1,8 @@ -Refactored internal APIs for the new lazy introspection frame creation to -consistently distinguish between the classic introspection frames (full -Python objects) and the new lighter weight internal execution frames (C -structs with no intrinsic instance lifecycle management) +Refactored internal APIs for the new lazy frame object creation to more +consistently distinguish between the full ``PyFrameObject`` Python object +implementation that is still used in the Python and C runtime state +introspection APIs (function prefix ``PyFrame``, field prefix ``f_``, typical +variable names ``frame`` and ``f``) and the new ``_Py_framedata`` internal +frame data storage (C structs with no intrinsic instance lifecycle management) +that is now used for code execution (function prefix ``_Py_framedata``, no +field prefix, typical variable name ``fdata``). diff --git a/Misc/gdbinit b/Misc/gdbinit index 06887c35d94093..fdd97a114948ee 100644 --- a/Misc/gdbinit +++ b/Misc/gdbinit @@ -37,12 +37,12 @@ end define pylocals set $_i = 0 - while $_i < f->f_xframe->xf_code->co_nlocals - if _PyExecFrame_GetLocalsArray(f->f_xframe) + $_i != 0 - set $_names = f->f_xframe->xf_code->co_varnames + while $_i < f->f_fdata->code->co_nlocals + if _Py_framedata_GetLocalsArray(f->f_fdata) + $_i != 0 + set $_names = f->f_fdata->code->co_varnames set $_name = PyUnicode_AsUTF8(PyTuple_GetItem($_names, $_i)) printf "%s:\n", $_name - pyo _PyExecFrame_GetLocalsArray(f->f_xframe)[$_i] + pyo _Py_framedata_GetLocalsArray(f->f_fdata)[$_i] end set $_i = $_i + 1 end @@ -55,8 +55,8 @@ end # command language define lineno set $__continue = 1 - set $__co = f->f_xframe->xf_code - set $__lasti = f->f_xframe->xf_lasti + set $__co = f->f_fdata->code + set $__lasti = f->f_fdata->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_xframe->xf_code->co_filename) - set $__n = PyUnicode_AsUTF8(f->f_xframe->xf_code->co_name) + set $__fn = PyUnicode_AsUTF8(f->f_fdata->code->co_filename) + set $__n = PyUnicode_AsUTF8(f->f_fdata->code->co_name) printf "%s (", $__fn lineno printf "): %s\n", $__n diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c index 769bb3d7aa8d9a..265f7f896dce30 100644 --- a/Modules/_tracemalloc.c +++ b/Modules/_tracemalloc.c @@ -3,7 +3,7 @@ #include "pycore_pymem.h" // _Py_tracemalloc_config #include "pycore_traceback.h" #include "pycore_hashtable.h" -#include <pycore_xframe.h> +#include <pycore_framedata.h> #include "clinic/_tracemalloc.c.h" /*[clinic input] @@ -299,16 +299,16 @@ hashtable_compare_traceback(const void *key1, const void *key2) static void -tracemalloc_get_frame(_PyExecFrame *xframe, frame_t *frame) +tracemalloc_get_frame(_Py_framedata *fdata, frame_t *frame) { frame->filename = unknown_filename; - int lineno = PyCode_Addr2Line(xframe->xf_code, xframe->xf_lasti*2); + int lineno = PyCode_Addr2Line(fdata->code, fdata->lasti*2); if (lineno < 0) { lineno = 0; } frame->lineno = (unsigned int)lineno; - PyObject *filename = xframe->xf_code->co_filename; + PyObject *filename = fdata->code->co_filename; if (filename == NULL) { #ifdef TRACE_DEBUG @@ -393,10 +393,10 @@ traceback_get_frames(traceback_t *traceback) return; } - _PyExecFrame *xframe = tstate->xframe; - for (; xframe != NULL;) { + _Py_framedata *fdata = tstate->fdata; + for (; fdata != NULL;) { if (traceback->nframe < _Py_tracemalloc_config.max_nframe) { - tracemalloc_get_frame(xframe, &traceback->frames[traceback->nframe]); + tracemalloc_get_frame(fdata, &traceback->frames[traceback->nframe]); assert(traceback->frames[traceback->nframe].filename != NULL); traceback->nframe++; } @@ -404,8 +404,8 @@ traceback_get_frames(traceback_t *traceback) traceback->total_nframe++; } - _PyExecFrame *back = xframe->xf_previous; - xframe = back; + _Py_framedata *back = fdata->previous; + fdata = back; } } diff --git a/Modules/_xxsubinterpretersmodule.c b/Modules/_xxsubinterpretersmodule.c index c6f986d654a639..886bba0ac4c216 100644 --- a/Modules/_xxsubinterpretersmodule.c +++ b/Modules/_xxsubinterpretersmodule.c @@ -4,7 +4,7 @@ #include "Python.h" #include "frameobject.h" -#include "pycore_xframe.h" +#include "pycore_framedata.h" #include "interpreteridobject.h" @@ -1835,12 +1835,12 @@ _is_running(PyInterpreterState *interp) } assert(!PyErr_Occurred()); - _PyExecFrame *xframe = tstate->xframe; - if (xframe == NULL) { + _Py_framedata *fdata = tstate->fdata; + if (fdata == NULL) { return 0; } - int executing = _PyExecFrame_IsExecuting(xframe); + int executing = _Py_framedata_IsExecuting(fdata); return executing; } diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c index 9834ee968f4ae3..f566d0cf20eab0 100644 --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -7,7 +7,7 @@ #include "pycore_atomic.h" // _Py_atomic_int #include "pycore_call.h" // _PyObject_Call() #include "pycore_ceval.h" // _PyEval_SignalReceived() -#include "pycore_xframe.h" +#include "pycore_framedata.h" #include "pycore_moduleobject.h" // _PyModule_GetState() #include "pycore_pyerrors.h" // _PyErr_SetString() #include "pycore_pylifecycle.h" // NSIG @@ -1787,7 +1787,7 @@ _PyErr_CheckSignalsTstate(PyThreadState *tstate) */ _Py_atomic_store(&is_tripped, 0); - _PyExecFrame *xframe = tstate->xframe; + _Py_framedata *fdata = tstate->fdata; signal_state_t *state = &signal_global_state; for (int i = 1; i < NSIG; i++) { if (!_Py_atomic_load_relaxed(&Handlers[i].tripped)) { @@ -1819,11 +1819,11 @@ _PyErr_CheckSignalsTstate(PyThreadState *tstate) continue; } PyObject *arglist = NULL; - if (xframe == NULL) { + if (fdata == NULL) { arglist = Py_BuildValue("(iO)", i, Py_None); } else { - PyFrameObject *f = _PyExecFrame_GetFrameObject(xframe); + PyFrameObject *f = _Py_framedata_GetFrameObject(fdata); if (f != NULL) { arglist = Py_BuildValue("(iO)", i, f); } diff --git a/Objects/frameobject.c b/Objects/frameobject.c index f16e4f87313331..edf2dbc9d1fe93 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -7,7 +7,7 @@ #include "pycore_code.h" // CO_FAST_LOCAL, etc. #include "frameobject.h" // PyFrameObject -#include "pycore_xframe.h" +#include "pycore_framedata.h" #include "opcode.h" // EXTENDED_ARG #include "structmember.h" // PyMemberDef @@ -32,7 +32,7 @@ frame_getlocals(PyFrameObject *f, void *closure) { if (PyFrame_FastToLocalsWithError(f) < 0) return NULL; - PyObject *locals = f->f_xframe->xf_locals; + PyObject *locals = f->f_fdata->locals; Py_INCREF(locals); return locals; } @@ -45,7 +45,7 @@ PyFrame_GetLineNumber(PyFrameObject *f) return f->f_lineno; } else { - return PyCode_Addr2Line(f->f_xframe->xf_code, f->f_xframe->xf_lasti*2); + return PyCode_Addr2Line(f->f_fdata->code, f->f_fdata->lasti*2); } } @@ -64,16 +64,16 @@ frame_getlineno(PyFrameObject *f, void *closure) static PyObject * frame_getlasti(PyFrameObject *f, void *closure) { - if (f->f_xframe->xf_lasti < 0) { + if (f->f_fdata->lasti < 0) { return PyLong_FromLong(-1); } - return PyLong_FromLong(f->f_xframe->xf_lasti*2); + return PyLong_FromLong(f->f_fdata->lasti*2); } static PyObject * frame_getglobals(PyFrameObject *f, void *closure) { - PyObject *globals = f->f_xframe->xf_globals; + PyObject *globals = f->f_fdata->globals; if (globals == NULL) { globals = Py_None; } @@ -84,7 +84,7 @@ frame_getglobals(PyFrameObject *f, void *closure) static PyObject * frame_getbuiltins(PyFrameObject *f, void *closure) { - PyObject *builtins = f->f_xframe->xf_builtins; + PyObject *builtins = f->f_fdata->builtins; if (builtins == NULL) { builtins = Py_None; } @@ -397,9 +397,9 @@ first_line_not_before(int *lines, int len, int line) static void frame_stack_pop(PyFrameObject *f) { - assert(f->f_xframe->xf_stackdepth > 0); - f->f_xframe->xf_stackdepth--; - PyObject *v = f->f_xframe->xf_stack[f->f_xframe->xf_stackdepth]; + assert(f->f_fdata->stackdepth > 0); + f->f_fdata->stackdepth--; + PyObject *v = f->f_fdata->stack[f->f_fdata->stackdepth]; Py_DECREF(v); } @@ -439,7 +439,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_xframe->xf_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"); @@ -481,7 +481,7 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno, void *Py_UNUSED(ignore } new_lineno = (int)l_new_lineno; - if (new_lineno < f->f_xframe->xf_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); @@ -490,8 +490,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_xframe->xf_code->co_code) / sizeof(_Py_CODEUNIT)); - int *lines = marklines(f->f_xframe->xf_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; } @@ -505,7 +505,7 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno, void *Py_UNUSED(ignore return -1; } - int64_t *stacks = mark_stacks(f->f_xframe->xf_code, len); + int64_t *stacks = mark_stacks(f->f_fdata->code, len); if (stacks == NULL) { PyMem_Free(lines); return -1; @@ -513,7 +513,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_xframe->xf_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++) { @@ -547,7 +547,7 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno, void *Py_UNUSED(ignore return -1; } /* Unwind block stack. */ - if (f->f_xframe->xf_state == FRAME_SUSPENDED) { + if (f->f_fdata->state == FRAME_SUSPENDED) { /* Account for value popped by yield */ start_stack = pop_value(start_stack); } @@ -557,7 +557,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_xframe->xf_lasti = best_addr; + f->f_fdata->lasti = best_addr; return 0; } @@ -625,20 +625,20 @@ frame_dealloc(PyFrameObject *f) /* Kill all local variables including specials, if we own them */ if (f->f_own_locals_memory) { f->f_own_locals_memory = 0; - _PyExecFrame *xframe = f->f_xframe; + _Py_framedata *fdata = f->f_fdata; /* Don't clear code object until the end */ - co = xframe->xf_code; - xframe->xf_code = NULL; - Py_CLEAR(xframe->xf_globals); - Py_CLEAR(xframe->xf_builtins); - Py_CLEAR(xframe->xf_locals); - PyObject **locals = _PyExecFrame_GetLocalsArray(xframe); + co = fdata->code; + fdata->code = NULL; + Py_CLEAR(fdata->globals); + Py_CLEAR(fdata->builtins); + Py_CLEAR(fdata->locals); + PyObject **locals = _Py_framedata_GetLocalsArray(fdata); for (int i = 0; i < co->co_nlocalsplus; i++) { Py_CLEAR(locals[i]); } /* stack */ - for (int i = 0; i < xframe->xf_stackdepth; i++) { - Py_CLEAR(xframe->xf_stack[i]); + for (int i = 0; i < fdata->stackdepth; i++) { + Py_CLEAR(fdata->stack[i]); } PyMem_Free(locals); } @@ -670,8 +670,8 @@ frame_traverse(PyFrameObject *f, visitproc visit, void *arg) if (f->f_own_locals_memory == 0) { return 0; } - assert(f->f_xframe->xf_frame_obj == NULL); - return _PyExecFrame_Traverse(f->f_xframe, visit, arg); + assert(f->f_fdata->frame_obj == NULL); + return _Py_framedata_Traverse(f->f_fdata, visit, arg); } static int @@ -682,35 +682,35 @@ 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_xframe->xf_state = FRAME_CLEARED; + f->f_fdata->state = FRAME_CLEARED; Py_CLEAR(f->f_trace); /* locals */ - PyObject **locals = _PyExecFrame_GetLocalsArray(f->f_xframe); - for (int i = 0; i < f->f_xframe->xf_nlocalsplus; i++) { + PyObject **locals = _Py_framedata_GetLocalsArray(f->f_fdata); + for (int i = 0; i < f->f_fdata->nlocalsplus; i++) { Py_CLEAR(locals[i]); } /* stack */ - for (int i = 0; i < f->f_xframe->xf_stackdepth; i++) { - Py_CLEAR(f->f_xframe->xf_stack[i]); + for (int i = 0; i < f->f_fdata->stackdepth; i++) { + Py_CLEAR(f->f_fdata->stack[i]); } - f->f_xframe->xf_stackdepth = 0; + f->f_fdata->stackdepth = 0; return 0; } static PyObject * frame_clear(PyFrameObject *f, PyObject *Py_UNUSED(ignored)) { - if (_PyExecFrame_IsExecuting(f->f_xframe)) { + if (_Py_framedata_IsExecuting(f->f_fdata)) { PyErr_SetString(PyExc_RuntimeError, "cannot clear an executing frame"); return NULL; } - if (f->f_xframe->xf_generator) { - _PyGen_Finalize(f->f_xframe->xf_generator); - assert(f->f_xframe->xf_generator == NULL); + if (f->f_fdata->generator) { + _PyGen_Finalize(f->f_fdata->generator); + assert(f->f_fdata->generator == NULL); } (void)frame_tp_clear(f); Py_RETURN_NONE; @@ -725,7 +725,7 @@ frame_sizeof(PyFrameObject *f, PyObject *Py_UNUSED(ignored)) Py_ssize_t res; res = sizeof(PyFrameObject); if (f->f_own_locals_memory) { - PyCodeObject *code = f->f_xframe->xf_code; + PyCodeObject *code = f->f_fdata->code; res += (code->co_nlocalsplus+code->co_stacksize) * sizeof(PyObject *); } return PyLong_FromSsize_t(res); @@ -738,7 +738,7 @@ static PyObject * frame_repr(PyFrameObject *f) { int lineno = PyFrame_GetLineNumber(f); - PyCodeObject *code = f->f_xframe->xf_code; + PyCodeObject *code = f->f_fdata->code; return PyUnicode_FromFormat( "<frame at %p, file %R, line %d, code %S>", f, code->co_filename, lineno, code->co_name); @@ -789,7 +789,7 @@ PyTypeObject PyFrame_Type = { _Py_IDENTIFIER(__builtins__); -static _PyExecFrame * +static _Py_framedata * allocate_heap_frame(PyFrameConstructor *con, PyObject *locals) { PyCodeObject *code = (PyCodeObject *)con->fc_code; @@ -802,13 +802,13 @@ allocate_heap_frame(PyFrameConstructor *con, PyObject *locals) for (Py_ssize_t i=0; i < code->co_nlocalsplus; i++) { localsarray[i] = NULL; } - _PyExecFrame *xframe = (_PyExecFrame *)(localsarray + code->co_nlocalsplus); - _PyExecFrame_InitializeSpecials(xframe, con, locals, code->co_nlocalsplus); - return xframe; + _Py_framedata *fdata = (_Py_framedata *)(localsarray + code->co_nlocalsplus); + _Py_framedata_InitializeSpecials(fdata, con, locals, code->co_nlocalsplus); + return fdata; } static inline PyFrameObject* -frame_alloc(_PyExecFrame *xframe, int owns) +frame_alloc(_Py_framedata *fdata, int owns) { PyFrameObject *f; struct _Py_frame_state *state = get_frame_state(); @@ -817,11 +817,11 @@ frame_alloc(_PyExecFrame *xframe, int owns) f = PyObject_GC_New(PyFrameObject, &PyFrame_Type); if (f == NULL) { if (owns) { - Py_XDECREF(xframe->xf_code); - Py_XDECREF(xframe->xf_builtins); - Py_XDECREF(xframe->xf_globals); - Py_XDECREF(xframe->xf_locals); - PyMem_Free(xframe); + Py_XDECREF(fdata->code); + Py_XDECREF(fdata->builtins); + Py_XDECREF(fdata->globals); + Py_XDECREF(fdata->locals); + PyMem_Free(fdata); } return NULL; } @@ -837,15 +837,15 @@ frame_alloc(_PyExecFrame *xframe, int owns) state->free_list = state->free_list->f_back; _Py_NewReference((PyObject *)f); } - f->f_xframe = xframe; + f->f_fdata = fdata; f->f_own_locals_memory = owns; return f; } PyFrameObject* _Py_HOT_FUNCTION -_PyFrame_New_NoTrack(_PyExecFrame *xframe, int owns) +_PyFrame_New_NoTrack(_Py_framedata *fdata, int owns) { - PyFrameObject *f = frame_alloc(xframe, owns); + PyFrameObject *f = frame_alloc(fdata, owns); if (f == NULL) { return NULL; } @@ -876,11 +876,11 @@ PyFrame_New(PyThreadState *tstate, PyCodeObject *code, .fc_kwdefaults = NULL, .fc_closure = NULL }; - _PyExecFrame *xframe = allocate_heap_frame(&desc, locals); - if (xframe == NULL) { + _Py_framedata *fdata = allocate_heap_frame(&desc, locals); + if (fdata == NULL) { return NULL; } - PyFrameObject *f = _PyFrame_New_NoTrack(xframe, 1); + PyFrameObject *f = _PyFrame_New_NoTrack(fdata, 1); if (f) { _PyObject_GC_TRACK(f); } @@ -888,11 +888,11 @@ PyFrame_New(PyThreadState *tstate, PyCodeObject *code, } static int -_PyExecFrame_OpAlreadyRan(_PyExecFrame *xframe, int opcode, int oparg) +_Py_framedata_OpAlreadyRan(_Py_framedata *fdata, int opcode, int oparg) { const _Py_CODEUNIT *code = - (const _Py_CODEUNIT *)PyBytes_AS_STRING(xframe->xf_code->co_code); - for (int i = 0; i < xframe->xf_lasti; i++) { + (const _Py_CODEUNIT *)PyBytes_AS_STRING(fdata->code->co_code); + for (int i = 0; i < fdata->lasti; i++) { if (_Py_OPCODE(code[i]) == opcode && _Py_OPARG(code[i]) == oparg) { return 1; } @@ -901,19 +901,19 @@ _PyExecFrame_OpAlreadyRan(_PyExecFrame *xframe, int opcode, int oparg) } int -_PyExecFrame_FastToLocalsWithError(_PyExecFrame *xframe) { - /* Merge fast locals into xframe->xf_locals */ +_Py_framedata_FastToLocalsWithError(_Py_framedata *fdata) { + /* Merge fast locals into fdata->locals */ PyObject *locals; PyObject **fast; PyCodeObject *co; - locals = xframe->xf_locals; + locals = fdata->locals; if (locals == NULL) { - locals = xframe->xf_locals = PyDict_New(); + locals = fdata->locals = PyDict_New(); if (locals == NULL) return -1; } - co = xframe->xf_code; - fast = _PyExecFrame_GetLocalsArray(xframe); + co = fdata->code; + fast = _Py_framedata_GetLocalsArray(fdata); for (int i = 0; i < co->co_nlocalsplus; i++) { _PyLocals_Kind kind = _PyLocals_GetKind(co->co_localspluskinds, i); @@ -931,7 +931,7 @@ _PyExecFrame_FastToLocalsWithError(_PyExecFrame *xframe) { PyObject *name = PyTuple_GET_ITEM(co->co_localsplusnames, i); PyObject *value = fast[i]; - if (xframe->xf_state != FRAME_CLEARED) { + if (fdata->state != FRAME_CLEARED) { if (kind & CO_FAST_FREE) { // The cell was set when the frame was created from // the function's closure. @@ -945,7 +945,7 @@ _PyExecFrame_FastToLocalsWithError(_PyExecFrame *xframe) { // run yet. if (value != NULL) { if (PyCell_Check(value) && - _PyExecFrame_OpAlreadyRan(xframe, MAKE_CELL, i)) { + _Py_framedata_OpAlreadyRan(fdata, MAKE_CELL, i)) { // (likely) MAKE_CELL must have executed already. value = PyCell_GET(value); } @@ -985,7 +985,7 @@ PyFrame_FastToLocalsWithError(PyFrameObject *f) PyErr_BadInternalCall(); return -1; } - return _PyExecFrame_FastToLocalsWithError(f->f_xframe); + return _Py_framedata_FastToLocalsWithError(f->f_fdata); } void @@ -1001,18 +1001,18 @@ PyFrame_FastToLocals(PyFrameObject *f) } void -_PyExecFrame_LocalsToFast(_PyExecFrame *xframe, int clear) +_Py_framedata_LocalsToFast(_Py_framedata *fdata, int clear) { /* Merge locals into fast locals */ PyObject *locals; PyObject **fast; PyObject *error_type, *error_value, *error_traceback; PyCodeObject *co; - locals = xframe->xf_locals; + locals = fdata->locals; if (locals == NULL) return; - fast = _PyExecFrame_GetLocalsArray(xframe); - co = xframe->xf_code; + fast = _Py_framedata_GetLocalsArray(fdata); + co = fdata->code; PyErr_Fetch(&error_type, &error_value, &error_traceback); for (int i = 0; i < co->co_nlocalsplus; i++) { @@ -1042,7 +1042,7 @@ _PyExecFrame_LocalsToFast(_PyExecFrame *xframe, int clear) else if (kind & CO_FAST_CELL && oldvalue != NULL) { /* Same test as in PyFrame_FastToLocals() above. */ if (PyCell_Check(oldvalue) && - _PyExecFrame_OpAlreadyRan(xframe, MAKE_CELL, i)) { + _Py_framedata_OpAlreadyRan(fdata, MAKE_CELL, i)) { // (likely) MAKE_CELL must have executed already. cell = oldvalue; } @@ -1069,10 +1069,10 @@ _PyExecFrame_LocalsToFast(_PyExecFrame *xframe, int clear) void PyFrame_LocalsToFast(PyFrameObject *f, int clear) { - if (f == NULL || f->f_xframe->xf_state == FRAME_CLEARED) { + if (f == NULL || f->f_fdata->state == FRAME_CLEARED) { return; } - _PyExecFrame_LocalsToFast(f->f_xframe, clear); + _Py_framedata_LocalsToFast(f->f_fdata, clear); } /* Clear out the free list */ @@ -1114,7 +1114,7 @@ PyCodeObject * PyFrame_GetCode(PyFrameObject *frame) { assert(frame != NULL); - PyCodeObject *code = frame->f_xframe->xf_code; + PyCodeObject *code = frame->f_fdata->code; assert(code != NULL); Py_INCREF(code); return code; @@ -1126,8 +1126,8 @@ PyFrame_GetBack(PyFrameObject *frame) { assert(frame != NULL); PyFrameObject *back = frame->f_back; - if (back == NULL && frame->f_xframe->xf_previous != NULL) { - back = _PyExecFrame_GetFrameObject(frame->f_xframe->xf_previous); + if (back == NULL && frame->f_fdata->previous != NULL) { + back = _Py_framedata_GetFrameObject(frame->f_fdata->previous); } Py_XINCREF(back); return back; diff --git a/Objects/genobject.c b/Objects/genobject.c index dbb4f4ffbeef21..a33ff4a60f1c76 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -6,7 +6,7 @@ #include "pycore_pyerrors.h" // _PyErr_ClearExcState() #include "pycore_pystate.h" // _PyThreadState_GET() #include "frameobject.h" -#include "pycore_xframe.h" +#include "pycore_framedata.h" #include "structmember.h" // PyMemberDef #include "opcode.h" @@ -35,10 +35,10 @@ gen_traverse(PyGenObject *gen, visitproc visit, void *arg) Py_VISIT(gen->gi_code); Py_VISIT(gen->gi_name); Py_VISIT(gen->gi_qualname); - _PyExecFrame *xframe = gen->gi_xframe; - if (xframe != NULL) { - assert(xframe->xf_frame_obj == NULL || xframe->xf_frame_obj->f_own_locals_memory == 0); - int err = _PyExecFrame_Traverse(xframe, visit, arg); + _Py_framedata *fdata = gen->gi_fdata; + if (fdata != NULL) { + assert(fdata->frame_obj == NULL || fdata->frame_obj->f_own_locals_memory == 0); + int err = _Py_framedata_Traverse(fdata, visit, arg); if (err) { return err; } @@ -55,7 +55,7 @@ _PyGen_Finalize(PyObject *self) PyObject *res = NULL; PyObject *error_type, *error_value, *error_traceback; - if (gen->gi_xframe == NULL || _PyExecFrame_HasCompleted(gen->gi_xframe)) { + if (gen->gi_fdata == NULL || _Py_framedata_HasCompleted(gen->gi_fdata)) { /* 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 && - gen->gi_xframe->xf_lasti == -1) + gen->gi_fdata->lasti == -1) { _PyErr_WarnUnawaitedCoroutine((PyObject *)gen); } @@ -130,11 +130,11 @@ gen_dealloc(PyGenObject *gen) and GC_Del. */ Py_CLEAR(((PyAsyncGenObject*)gen)->ag_finalizer); } - _PyExecFrame *xframe = gen->gi_xframe; - if (xframe != NULL) { - gen->gi_xframe = NULL; - xframe->xf_previous = NULL; - _PyExecFrame_Clear(xframe, 1); + _Py_framedata *fdata = gen->gi_fdata; + if (fdata != NULL) { + gen->gi_fdata = NULL; + fdata->previous = NULL; + _Py_framedata_Clear(fdata, 1); } if (((PyCodeObject *)gen->gi_code)->co_flags & CO_COROUTINE) { Py_CLEAR(((PyCoroObject *)gen)->cr_origin); @@ -151,11 +151,11 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult, int exc, int closing) { PyThreadState *tstate = _PyThreadState_GET(); - _PyExecFrame *xframe = gen->gi_xframe; + _Py_framedata *fdata = gen->gi_fdata; PyObject *result; *presult = NULL; - if (xframe != NULL && _PyExecFrame_IsExecuting(xframe)) { + if (fdata != NULL && _Py_framedata_IsExecuting(fdata)) { const char *msg = "generator already executing"; if (PyCoro_CheckExact(gen)) { msg = "coroutine already executing"; @@ -166,7 +166,7 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult, PyErr_SetString(PyExc_ValueError, msg); return PYGEN_ERROR; } - if (xframe == NULL || _PyExecFrame_HasCompleted(xframe)) { + if (fdata == NULL || _Py_framedata_HasCompleted(fdata)) { if (PyCoro_CheckExact(gen) && !closing) { /* `gen` is an exhausted coroutine: raise an error, except when called from gen_close(), which should @@ -185,15 +185,15 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult, return PYGEN_ERROR; } - assert(_PyExecFrame_IsRunnable(xframe)); - assert(xframe->xf_lasti >= 0 || ((unsigned char *)PyBytes_AS_STRING(gen->gi_code->co_code))[0] == GEN_START); + assert(_Py_framedata_IsRunnable(fdata)); + assert(fdata->lasti >= 0 || ((unsigned char *)PyBytes_AS_STRING(gen->gi_code->co_code))[0] == GEN_START); /* Push arg onto the frame's value stack */ result = arg ? arg : Py_None; Py_INCREF(result); - xframe->xf_stack[xframe->xf_stackdepth] = result; - xframe->xf_stackdepth++; + fdata->stack[fdata->stackdepth] = result; + fdata->stackdepth++; - xframe->xf_previous = tstate->xframe; + fdata->previous = tstate->fdata; gen->gi_exc_state.previous_item = tstate->exc_info; tstate->exc_info = &gen->gi_exc_state; @@ -203,20 +203,20 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult, _PyErr_ChainStackItem(NULL); } - result = _PyEval_EvalFrame(tstate, xframe, exc); + result = _PyEval_EvalFrame(tstate, fdata, exc); tstate->exc_info = gen->gi_exc_state.previous_item; gen->gi_exc_state.previous_item = NULL; - assert(tstate->xframe == xframe->xf_previous); + assert(tstate->fdata == fdata->previous); /* Don't keep the reference to previous any longer than necessary. It * may keep a chain of frames alive or it could create a reference * cycle. */ - xframe->xf_previous = NULL; + fdata->previous = NULL; /* If the generator just returned (as opposed to yielding), signal * that the generator is exhausted. */ if (result) { - if (!_PyExecFrame_HasCompleted(xframe)) { + if (!_Py_framedata_HasCompleted(fdata)) { *presult = result; return PYGEN_NEXT; } @@ -252,9 +252,9 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult, /* first clean reference cycle through stored exception traceback */ _PyErr_ClearExcState(&gen->gi_exc_state); - xframe->xf_generator = NULL; - gen->gi_xframe = NULL; - _PyExecFrame_Clear(xframe, 1); + fdata->generator = NULL; + gen->gi_fdata = NULL; + _Py_framedata_Clear(fdata, 1); *presult = result; return result ? PYGEN_RETURN : PYGEN_ERROR; } @@ -335,12 +335,12 @@ _PyGen_yf(PyGenObject *gen) { PyObject *yf = NULL; - if (gen->gi_xframe) { - _PyExecFrame *xframe = gen->gi_xframe; + if (gen->gi_fdata) { + _Py_framedata *fdata = gen->gi_fdata; PyObject *bytecode = gen->gi_code->co_code; unsigned char *code = (unsigned char *)PyBytes_AS_STRING(bytecode); - if (xframe->xf_lasti < 0) { + if (fdata->lasti < 0) { /* Return immediately if the frame didn't start yet. YIELD_FROM always come after LOAD_CONST: a code object should not start with YIELD_FROM */ @@ -348,10 +348,10 @@ _PyGen_yf(PyGenObject *gen) return NULL; } - if (code[(xframe->xf_lasti+1)*sizeof(_Py_CODEUNIT)] != YIELD_FROM) + if (code[(fdata->lasti+1)*sizeof(_Py_CODEUNIT)] != YIELD_FROM) return NULL; - assert(xframe->xf_stackdepth > 0); - yf = xframe->xf_stack[xframe->xf_stackdepth-1]; + assert(fdata->stackdepth > 0); + yf = fdata->stack[fdata->stackdepth-1]; Py_INCREF(yf); } @@ -366,10 +366,10 @@ gen_close(PyGenObject *gen, PyObject *args) int err = 0; if (yf) { - PyFrameState state = gen->gi_xframe->xf_state; - gen->gi_xframe->xf_state = FRAME_EXECUTING; + PyFrameState state = gen->gi_fdata->state; + gen->gi_fdata->state = FRAME_EXECUTING; err = gen_close_iter(yf); - gen->gi_xframe->xf_state = state; + gen->gi_fdata->state = state; Py_DECREF(yf); } if (err == 0) @@ -416,10 +416,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 = gen->gi_xframe->xf_state; - gen->gi_xframe->xf_state = FRAME_EXECUTING; + PyFrameState state = gen->gi_fdata->state; + gen->gi_fdata->state = FRAME_EXECUTING; err = gen_close_iter(yf); - gen->gi_xframe->xf_state = state; + gen->gi_fdata->state = state; Py_DECREF(yf); if (err < 0) return gen_send_ex(gen, Py_None, 1, 0); @@ -428,7 +428,7 @@ _gen_throw(PyGenObject *gen, int close_on_genexit, if (PyGen_CheckExact(yf) || PyCoro_CheckExact(yf)) { /* `yf` is a generator or a coroutine. */ PyThreadState *tstate = _PyThreadState_GET(); - _PyExecFrame *xframe = gen->gi_xframe; + _Py_framedata *fdata = gen->gi_fdata; /* Since we are fast-tracking things by skipping the eval loop, @@ -436,18 +436,18 @@ _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. */ - _PyExecFrame *prev = tstate->xframe; - xframe->xf_previous = prev; - tstate->xframe = xframe; + _Py_framedata *prev = tstate->fdata; + fdata->previous = prev; + tstate->fdata = fdata; /* Close the generator that we are currently iterating with 'yield from' or awaiting on with 'await'. */ - PyFrameState state = gen->gi_xframe->xf_state; - gen->gi_xframe->xf_state = FRAME_EXECUTING; + PyFrameState state = gen->gi_fdata->state; + gen->gi_fdata->state = FRAME_EXECUTING; ret = _gen_throw((PyGenObject *)yf, close_on_genexit, typ, val, tb); - gen->gi_xframe->xf_state = state; - tstate->xframe = prev; - xframe->xf_previous = NULL; + gen->gi_fdata->state = state; + tstate->fdata = prev; + fdata->previous = NULL; } else { /* `yf` is an iterator or a coroutine-like object. */ PyObject *meth; @@ -459,24 +459,24 @@ _gen_throw(PyGenObject *gen, int close_on_genexit, Py_DECREF(yf); goto throw_here; } - PyFrameState state = gen->gi_xframe->xf_state; - gen->gi_xframe->xf_state = FRAME_EXECUTING; + PyFrameState state = gen->gi_fdata->state; + gen->gi_fdata->state = FRAME_EXECUTING; ret = PyObject_CallFunctionObjArgs(meth, typ, val, tb, NULL); - gen->gi_xframe->xf_state = state; + gen->gi_fdata->state = state; Py_DECREF(meth); } Py_DECREF(yf); if (!ret) { PyObject *val; /* Pop subiterator from stack */ - assert(gen->gi_xframe->xf_stackdepth > 0); - gen->gi_xframe->xf_stackdepth--; - ret = gen->gi_xframe->xf_stack[gen->gi_xframe->xf_stackdepth]; + assert(gen->gi_fdata->stackdepth > 0); + gen->gi_fdata->stackdepth--; + ret = gen->gi_fdata->stack[gen->gi_fdata->stackdepth]; assert(ret == yf); Py_DECREF(ret); /* Termination repetition of YIELD_FROM */ - assert(gen->gi_xframe->xf_lasti >= 0); - gen->gi_xframe->xf_lasti += 1; + assert(gen->gi_fdata->lasti >= 0); + gen->gi_fdata->lasti += 1; if (_PyGen_FetchStopIterationValue(&val) == 0) { ret = gen_send(gen, val); Py_DECREF(val); @@ -733,10 +733,10 @@ gen_getyieldfrom(PyGenObject *gen, void *Py_UNUSED(ignored)) static PyObject * gen_getrunning(PyGenObject *gen, void *Py_UNUSED(ignored)) { - if (gen->gi_xframe == NULL) { + if (gen->gi_fdata == NULL) { Py_RETURN_FALSE; } - return PyBool_FromLong(_PyExecFrame_IsExecuting(gen->gi_xframe)); + return PyBool_FromLong(_Py_framedata_IsExecuting(gen->gi_fdata)); } static PyObject * @@ -745,10 +745,10 @@ _gen_getframe(PyGenObject *gen, const char *const name) if (PySys_Audit("object.__getattr__", "Os", gen, name) < 0) { return NULL; } - if (gen->gi_xframe == NULL) { + if (gen->gi_fdata == NULL) { Py_RETURN_NONE; } - return _Py_XNewRef((PyObject *)_PyExecFrame_GetFrameObject(gen->gi_xframe)); + return _Py_XNewRef((PyObject *)_Py_framedata_GetFrameObject(gen->gi_fdata)); } static PyObject * @@ -843,17 +843,17 @@ PyTypeObject PyGen_Type = { }; static PyObject * -make_gen(PyTypeObject *type, PyFrameConstructor *con, _PyExecFrame *xframe) +make_gen(PyTypeObject *type, PyFrameConstructor *con, _Py_framedata *fdata) { PyGenObject *gen = PyObject_GC_New(PyGenObject, type); if (gen == NULL) { - assert(xframe->xf_frame_obj == NULL); - _PyExecFrame_Clear(xframe, 1); + assert(fdata->frame_obj == NULL); + _Py_framedata_Clear(fdata, 1); return NULL; } - gen->gi_xframe = xframe; - xframe->xf_generator = (PyObject *)gen; - gen->gi_code = xframe->xf_code; + gen->gi_fdata = fdata; + fdata->generator = (PyObject *)gen; + gen->gi_code = fdata->code; Py_INCREF(gen->gi_code); gen->gi_weakreflist = NULL; gen->gi_exc_state.exc_type = NULL; @@ -878,17 +878,17 @@ static PyObject * compute_cr_origin(int origin_depth); PyObject * -_Py_MakeCoro(PyFrameConstructor *con, _PyExecFrame *xframe) +_Py_MakeCoro(PyFrameConstructor *con, _Py_framedata *fdata) { int coro_flags = ((PyCodeObject *)con->fc_code)->co_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR); assert(coro_flags); if (coro_flags == CO_GENERATOR) { - return make_gen(&PyGen_Type, con, xframe); + return make_gen(&PyGen_Type, con, fdata); } if (coro_flags == CO_ASYNC_GENERATOR) { PyAsyncGenObject *o; - o = (PyAsyncGenObject *)make_gen(&PyAsyncGen_Type, con, xframe); + o = (PyAsyncGenObject *)make_gen(&PyAsyncGen_Type, con, fdata); if (o == NULL) { return NULL; } @@ -899,7 +899,7 @@ _Py_MakeCoro(PyFrameConstructor *con, _PyExecFrame *xframe) return (PyObject*)o; } assert (coro_flags == CO_COROUTINE); - PyObject *coro = make_gen(&PyCoro_Type, con, xframe); + PyObject *coro = make_gen(&PyCoro_Type, con, fdata); if (!coro) { return NULL; } @@ -931,12 +931,12 @@ gen_new_with_qualname(PyTypeObject *type, PyFrameObject *f, } /* Take ownership of the frame */ - assert(f->f_xframe->xf_frame_obj == NULL); + assert(f->f_fdata->frame_obj == NULL); assert(f->f_own_locals_memory); - gen->gi_xframe = f->f_xframe; - gen->gi_xframe->xf_frame_obj = f; + gen->gi_fdata = f->f_fdata; + gen->gi_fdata->frame_obj = f; f->f_own_locals_memory = 0; - gen->gi_xframe->xf_generator = (PyObject *) gen; + gen->gi_fdata->generator = (PyObject *) gen; assert(PyObject_GC_IsTracked((PyObject *)f)); gen->gi_code = PyFrame_GetCode(f); @@ -1072,10 +1072,10 @@ coro_get_cr_await(PyCoroObject *coro, void *Py_UNUSED(ignored)) static PyObject * cr_getrunning(PyCoroObject *coro, void *Py_UNUSED(ignored)) { - if (coro->cr_xframe == NULL) { + if (coro->cr_fdata == NULL) { Py_RETURN_FALSE; } - return PyBool_FromLong(_PyExecFrame_IsExecuting(coro->cr_xframe)); + return PyBool_FromLong(_Py_framedata_IsExecuting(coro->cr_fdata)); } static PyObject * @@ -1271,11 +1271,11 @@ PyTypeObject _PyCoroWrapper_Type = { static PyObject * compute_cr_origin(int origin_depth) { - _PyExecFrame *xframe = _PyEval_GetExecFrame(); + _Py_framedata *fdata = _PyEval_GetFrameData(); /* First count how many frames we have */ int frame_count = 0; - for (; xframe && frame_count < origin_depth; ++frame_count) { - xframe = xframe->xf_previous; + for (; fdata && frame_count < origin_depth; ++frame_count) { + fdata = fdata->previous; } /* Now collect them */ @@ -1283,19 +1283,19 @@ compute_cr_origin(int origin_depth) if (cr_origin == NULL) { return NULL; } - xframe = _PyEval_GetExecFrame(); + fdata = _PyEval_GetFrameData(); for (int i = 0; i < frame_count; ++i) { - PyCodeObject *code = xframe->xf_code; + PyCodeObject *code = fdata->code; PyObject *frameinfo = Py_BuildValue("OiO", code->co_filename, - PyCode_Addr2Line(xframe->xf_code, xframe->xf_lasti*2), + PyCode_Addr2Line(fdata->code, fdata->lasti*2), code->co_name); if (!frameinfo) { Py_DECREF(cr_origin); return NULL; } PyTuple_SET_ITEM(cr_origin, i, frameinfo); - xframe = xframe->xf_previous; + fdata = fdata->previous; } return cr_origin; @@ -1990,7 +1990,7 @@ static PyObject * async_gen_athrow_send(PyAsyncGenAThrow *o, PyObject *arg) { PyGenObject *gen = (PyGenObject*)o->agt_gen; - _PyExecFrame *xframe = gen->gi_xframe; + _Py_framedata *fdata = gen->gi_fdata; PyObject *retval; if (o->agt_state == AWAITABLE_STATE_CLOSED) { @@ -2000,7 +2000,7 @@ async_gen_athrow_send(PyAsyncGenAThrow *o, PyObject *arg) return NULL; } - if (xframe == NULL || _PyExecFrame_HasCompleted(xframe)) { + if (fdata == NULL || _Py_framedata_HasCompleted(fdata)) { o->agt_state = AWAITABLE_STATE_CLOSED; PyErr_SetNone(PyExc_StopIteration); return NULL; diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 426f3ed850c659..6c004da0bca6c0 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -11,7 +11,7 @@ #include "pycore_pystate.h" // _PyThreadState_GET() #include "pycore_unionobject.h" // _Py_union_type_or #include "frameobject.h" -#include "pycore_xframe.h" +#include "pycore_framedata.h" #include "opcode.h" // MAKE_CELL #include "structmember.h" // PyMemberDef @@ -8874,13 +8874,13 @@ super_init_without_args(PyFrameObject *f, PyCodeObject *co, return -1; } - assert(f->f_xframe->xf_nlocalsplus > 0); - PyObject *firstarg = _PyExecFrame_GetLocalsArray(f->f_xframe)[0]; + assert(f->f_fdata->nlocalsplus > 0); + PyObject *firstarg = _Py_framedata_GetLocalsArray(f->f_fdata)[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 (f->f_xframe->xf_lasti >= 0) { + if (f->f_fdata->lasti >= 0) { assert(_Py_OPCODE(*co->co_firstinstr) == MAKE_CELL); assert(PyCell_Check(firstarg)); firstarg = PyCell_GET(firstarg); @@ -8900,7 +8900,7 @@ super_init_without_args(PyFrameObject *f, PyCodeObject *co, PyObject *name = PyTuple_GET_ITEM(co->co_localsplusnames, i); assert(PyUnicode_Check(name)); if (_PyUnicode_EqualToASCIIId(name, &PyId___class__)) { - PyObject *cell = _PyExecFrame_GetLocalsArray(f->f_xframe)[i]; + PyObject *cell = _Py_framedata_GetLocalsArray(f->f_fdata)[i]; if (cell == NULL || !PyCell_Check(cell)) { PyErr_SetString(PyExc_RuntimeError, "super(): bad __class__ cell"); diff --git a/Python/_warnings.c b/Python/_warnings.c index def70d6bf1c25c..0820280d92bdbf 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -5,7 +5,7 @@ #include "pycore_pyerrors.h" #include "pycore_pystate.h" // _PyThreadState_GET() #include "frameobject.h" // PyFrame_GetBack() -#include "pycore_xframe.h" +#include "pycore_framedata.h" #include "clinic/_warnings.c.h" #define MODULE_NAME "_warnings" @@ -854,8 +854,8 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno, *lineno = 1; } else { - globals = f->f_xframe->xf_globals; - *filename = f->f_xframe->xf_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 01baeba6c3a8d5..8e6511d6f4b1e0 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -29,7 +29,7 @@ #include "pycore_dict.h" #include "dictobject.h" #include "frameobject.h" -#include "pycore_xframe.h" +#include "pycore_framedata.h" #include "opcode.h" #include "pydtrace.h" #include "setobject.h" @@ -62,27 +62,27 @@ static int lltrace; static int prtrace(PyThreadState *, PyObject *, const char *); #endif static int call_trace(Py_tracefunc, PyObject *, - PyThreadState *, _PyExecFrame *, + PyThreadState *, _Py_framedata *, int, PyObject *); static int call_trace_protected(Py_tracefunc, PyObject *, - PyThreadState *, _PyExecFrame *, + PyThreadState *, _Py_framedata *, int, PyObject *); static void call_exc_trace(Py_tracefunc, PyObject *, - PyThreadState *, _PyExecFrame *); + PyThreadState *, _Py_framedata *); static int maybe_call_line_trace(Py_tracefunc, PyObject *, - PyThreadState *, _PyExecFrame *, int); -static void maybe_dtrace_line(_PyExecFrame *, PyTraceInfo *, int); -static void dtrace_function_entry(_PyExecFrame *); -static void dtrace_function_return(_PyExecFrame *); + PyThreadState *, _Py_framedata *, int); +static void maybe_dtrace_line(_Py_framedata *, PyTraceInfo *, int); +static void dtrace_function_entry(_Py_framedata *); +static void dtrace_function_return(_Py_framedata *); -static PyObject * import_name(PyThreadState *, _PyExecFrame *, +static PyObject * import_name(PyThreadState *, _Py_framedata *, PyObject *, PyObject *, PyObject *); static PyObject * import_from(PyThreadState *, PyObject *, PyObject *); static int import_all_from(PyThreadState *, PyObject *, PyObject *); static void format_exc_check_arg(PyThreadState *, PyObject *, const char *, PyObject *); static void format_exc_unbound(PyThreadState *tstate, PyCodeObject *co, int oparg); static PyObject * unicode_concatenate(PyThreadState *, PyObject *, PyObject *, - _PyExecFrame *, const _Py_CODEUNIT *); + _Py_framedata *, const _Py_CODEUNIT *); static int check_args_iterable(PyThreadState *, PyObject *func, PyObject *vararg); static void format_kwargs_error(PyThreadState *, PyObject *func, PyObject *kwargs); static void format_awaitable_error(PyThreadState *, PyTypeObject *, int, int); @@ -1065,14 +1065,14 @@ PyEval_EvalFrame(PyFrameObject *f) { /* Function kept for backward compatibility */ PyThreadState *tstate = _PyThreadState_GET(); - return _PyEval_EvalFrame(tstate, f->f_xframe, 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_xframe, throwflag); + return _PyEval_EvalFrame(tstate, f->f_fdata, throwflag); } @@ -1231,7 +1231,7 @@ eval_frame_handle_pending(PyThreadState *tstate) if (cframe.use_tracing OR_DTRACE_LINE OR_LLTRACE) { \ goto tracing_dispatch; \ } \ - xframe->xf_lasti = INSTR_OFFSET(); \ + fdata->lasti = INSTR_OFFSET(); \ NEXTOPARG(); \ DISPATCH_GOTO(); \ } @@ -1320,7 +1320,7 @@ eval_frame_handle_pending(PyThreadState *tstate) /* The stack can grow at most MAXINT deep, as co_nlocals and co_stacksize are ints. */ -#define STACK_LEVEL() ((int)(stack_pointer - xframe->xf_stack)) +#define STACK_LEVEL() ((int)(stack_pointer - fdata->stack)) #define EMPTY() (STACK_LEVEL() == 0) #define TOP() (stack_pointer[-1]) #define SECOND() (stack_pointer[-2]) @@ -1388,12 +1388,12 @@ eval_frame_handle_pending(PyThreadState *tstate) #define UPDATE_PREV_INSTR_OPARG(instr, oparg) ((uint8_t*)(instr))[-1] = (oparg) -#define GLOBALS() xframe->xf_globals -#define BUILTINS() xframe->xf_builtins -#define LOCALS() xframe->xf_locals +#define GLOBALS() fdata->globals +#define BUILTINS() fdata->builtins +#define LOCALS() fdata->locals PyObject* _Py_HOT_FUNCTION -_PyEval_EvalFrameDefault(PyThreadState *tstate, _PyExecFrame *xframe, int throwflag) +_PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwflag) { _Py_EnsureTstateNotNULL(tstate); @@ -1438,8 +1438,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyExecFrame *xframe, int throwf tstate->cframe = &cframe; /* push execution frame */ - tstate->xframe = xframe; - co = xframe->xf_code; + tstate->fdata = fdata; + co = fdata->code; if (cframe.use_tracing) { if (tstate->c_tracefunc != NULL) { @@ -1458,7 +1458,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyExecFrame *xframe, int throwf whenever an exception is detected. */ if (call_trace_protected(tstate->c_tracefunc, tstate->c_traceobj, - tstate, xframe, + tstate, fdata, PyTrace_CALL, Py_None)) { /* Trace function raised an error */ goto exit_eval_frame; @@ -1469,7 +1469,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyExecFrame *xframe, int throwf return itself and isn't called for "line" events */ if (call_trace_protected(tstate->c_profilefunc, tstate->c_profileobj, - tstate, xframe, + tstate, fdata, PyTrace_CALL, Py_None)) { /* Profile function raised an error */ goto exit_eval_frame; @@ -1478,7 +1478,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyExecFrame *xframe, int throwf } if (PyDTrace_FUNCTION_ENTRY_ENABLED()) - dtrace_function_entry(xframe); + dtrace_function_entry(fdata); /* Increment the warmup counter and quicken if warm enough * _Py_Quicken is idempotent so we don't worry about overflow */ @@ -1494,34 +1494,34 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyExecFrame *xframe, int throwf names = co->co_names; consts = co->co_consts; - localsplus = _PyExecFrame_GetLocalsArray(xframe); + localsplus = _Py_framedata_GetLocalsArray(fdata); first_instr = co->co_firstinstr; /* - xframe->xf_lasti refers to the index of the last instruction, + fdata->lasti refers to the index of the last instruction, unless it's -1 in which case next_instr should be first_instr. - YIELD_FROM sets xframe->xf_lasti to itself, in order to repeatedly yield + YIELD_FROM sets fdata->lasti to itself, in order to repeatedly yield multiple values. When the PREDICT() macros are enabled, some opcode pairs follow in - direct succession without updating xframe->xf_lasti. A successful + direct succession without updating fdata->lasti. A successful prediction effectively links the two codes together as if they - were a single new opcode; accordingly, xframe->xf_lasti will point to + were a single new opcode; accordingly, fdata->lasti will point to the first code in the pair (for instance, GET_ITER followed by - FOR_ITER is effectively a single opcode and xframe->xf_lasti will point + FOR_ITER is effectively a single opcode and fdata->lasti will point to the beginning of the combined pair.) */ - assert(xframe->xf_lasti >= -1); - next_instr = first_instr + xframe->xf_lasti + 1; - stack_pointer = xframe->xf_stack + xframe->xf_stackdepth; + assert(fdata->lasti >= -1); + next_instr = first_instr + fdata->lasti + 1; + stack_pointer = fdata->stack + fdata->stackdepth; /* Set stackdepth to -1. * Update when returning or calling trace function. Having f_stackdepth <= 0 ensures that invalid values are not visible to the cycle GC. We choose -1 rather than 0 to assist debugging. */ - xframe->xf_stackdepth = -1; - xframe->xf_state = FRAME_EXECUTING; + fdata->stackdepth = -1; + fdata->state = FRAME_EXECUTING; #ifdef LLTRACE { @@ -1585,12 +1585,12 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyExecFrame *xframe, int throwf tracing_dispatch: { - int instr_prev = xframe->xf_lasti; - xframe->xf_lasti = INSTR_OFFSET(); + int instr_prev = fdata->lasti; + fdata->lasti = INSTR_OFFSET(); TRACING_NEXTOPARG(); if (PyDTrace_LINE_ENABLED()) - maybe_dtrace_line(xframe, &tstate->trace_info, instr_prev); + maybe_dtrace_line(fdata, &tstate->trace_info, instr_prev); /* line-by-line tracing support */ @@ -1599,19 +1599,19 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyExecFrame *xframe, int throwf int err; /* see maybe_call_line_trace() for expository comments */ - xframe->xf_stackdepth = (int)(stack_pointer - xframe->xf_stack); + fdata->stackdepth = (int)(stack_pointer - fdata->stack); err = maybe_call_line_trace(tstate->c_tracefunc, tstate->c_traceobj, - tstate, xframe, instr_prev); + tstate, fdata, instr_prev); if (err) { /* trace function raised an exception */ goto error; } /* Reload possibly changed frame fields */ - JUMPTO(xframe->xf_lasti); - stack_pointer = xframe->xf_stack+xframe->xf_stackdepth; - xframe->xf_stackdepth = -1; + JUMPTO(fdata->lasti); + stack_pointer = fdata->stack+fdata->stackdepth; + fdata->stackdepth = -1; TRACING_NEXTOPARG(); } } @@ -1622,11 +1622,11 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyExecFrame *xframe, int throwf if (lltrace) { if (HAS_ARG(opcode)) { printf("%d: %d, %d\n", - xframe->xf_lasti, opcode, oparg); + fdata->lasti, opcode, oparg); } else { printf("%d: %d\n", - xframe->xf_lasti, opcode); + fdata->lasti, opcode); } } #endif @@ -1875,7 +1875,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyExecFrame *xframe, int throwf speedup on microbenchmarks. */ if (PyUnicode_CheckExact(left) && PyUnicode_CheckExact(right)) { - sum = unicode_concatenate(tstate, left, right, xframe, next_instr); + sum = unicode_concatenate(tstate, left, right, fdata, next_instr); /* unicode_concatenate consumed the ref to left */ } else { @@ -2162,7 +2162,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyExecFrame *xframe, int throwf PyObject *left = TOP(); PyObject *sum; if (PyUnicode_CheckExact(left) && PyUnicode_CheckExact(right)) { - sum = unicode_concatenate(tstate, left, right, xframe, next_instr); + sum = unicode_concatenate(tstate, left, right, fdata, next_instr); /* unicode_concatenate consumed the ref to left */ } else { @@ -2322,8 +2322,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyExecFrame *xframe, int throwf case TARGET(RETURN_VALUE): { retval = POP(); assert(EMPTY()); - xframe->xf_state = FRAME_RETURNED; - xframe->xf_stackdepth = 0; + fdata->state = FRAME_RETURNED; + fdata->stackdepth = 0; goto exiting; } @@ -2480,7 +2480,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyExecFrame *xframe, int throwf if (retval == NULL) { if (tstate->c_tracefunc != NULL && _PyErr_ExceptionMatches(tstate, PyExc_StopIteration)) - call_exc_trace(tstate->c_tracefunc, tstate->c_traceobj, tstate, xframe); + call_exc_trace(tstate->c_tracefunc, tstate->c_traceobj, tstate, fdata); if (_PyGen_FetchStopIterationValue(&retval) == 0) { gen_status = PYGEN_RETURN; } @@ -2508,10 +2508,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyExecFrame *xframe, int throwf assert (gen_status == PYGEN_NEXT); /* receiver remains on stack, retval is value to be yielded */ /* and repeat... */ - assert(xframe->xf_lasti > 0); - xframe->xf_lasti -= 1; - xframe->xf_state = FRAME_SUSPENDED; - xframe->xf_stackdepth = (int)(stack_pointer - xframe->xf_stack); + assert(fdata->lasti > 0); + fdata->lasti -= 1; + fdata->state = FRAME_SUSPENDED; + fdata->stackdepth = (int)(stack_pointer - fdata->stack); goto exiting; } @@ -2527,8 +2527,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyExecFrame *xframe, int throwf } retval = w; } - xframe->xf_state = FRAME_SUSPENDED; - xframe->xf_stackdepth = (int)(stack_pointer - xframe->xf_stack); + fdata->state = FRAME_SUSPENDED; + fdata->stackdepth = (int)(stack_pointer - fdata->stack); goto exiting; } @@ -2575,7 +2575,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyExecFrame *xframe, int throwf case TARGET(POP_EXCEPT_AND_RERAISE): { PyObject *lasti = PEEK(4); if (PyLong_Check(lasti)) { - xframe->xf_lasti = PyLong_AsLong(lasti); + fdata->lasti = PyLong_AsLong(lasti); assert(!_PyErr_Occurred(tstate)); } else { @@ -2606,7 +2606,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyExecFrame *xframe, int throwf if (oparg) { PyObject *lasti = PEEK(oparg+3); if (PyLong_Check(lasti)) { - xframe->xf_lasti = PyLong_AsLong(lasti); + fdata->lasti = PyLong_AsLong(lasti); assert(!_PyErr_Occurred(tstate)); } else { @@ -3581,7 +3581,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyExecFrame *xframe, int throwf PyObject *fromlist = POP(); PyObject *level = TOP(); PyObject *res; - res = import_name(tstate, xframe, name, fromlist, level); + res = import_name(tstate, fdata, name, fromlist, level); Py_DECREF(level); Py_DECREF(fromlist); SET_TOP(res); @@ -3593,7 +3593,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyExecFrame *xframe, int throwf case TARGET(IMPORT_STAR): { PyObject *from = POP(), *locals; int err; - if (_PyExecFrame_FastToLocalsWithError(xframe) < 0) { + if (_Py_framedata_FastToLocalsWithError(fdata) < 0) { Py_DECREF(from); goto error; } @@ -3606,7 +3606,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyExecFrame *xframe, int throwf goto error; } err = import_all_from(tstate, locals, from); - _PyExecFrame_LocalsToFast(xframe, 0); + _Py_framedata_LocalsToFast(fdata, 0); Py_DECREF(from); if (err != 0) goto error; @@ -3920,7 +3920,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyExecFrame *xframe, int throwf goto error; } else if (tstate->c_tracefunc != NULL) { - call_exc_trace(tstate->c_tracefunc, tstate->c_traceobj, tstate, xframe); + call_exc_trace(tstate->c_tracefunc, tstate->c_traceobj, tstate, fdata); } _PyErr_Clear(tstate); } @@ -4383,7 +4383,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyExecFrame *xframe, int throwf default: fprintf(stderr, "XXX lineno: %d, opcode: %d\n", - PyCode_Addr2Line(xframe->xf_code, xframe->xf_lasti*2), + PyCode_Addr2Line(fdata->code, fdata->lasti*2), opcode); _PyErr_SetString(tstate, PyExc_SystemError, "unknown opcode"); goto error; @@ -4452,22 +4452,22 @@ MISS_WITH_OPARG_COUNTER(BINARY_SUBSCR) #endif /* Log traceback info. */ - PyFrameObject *f = _PyExecFrame_GetFrameObject(xframe); + PyFrameObject *f = _Py_framedata_GetFrameObject(fdata); if (f != NULL) { PyTraceBack_Here(f); } if (tstate->c_tracefunc != NULL) { /* Make sure state is set to FRAME_UNWINDING for tracing */ - assert(xframe->xf_state == FRAME_EXECUTING); - xframe->xf_state = FRAME_UNWINDING; + assert(fdata->state == FRAME_EXECUTING); + fdata->state = FRAME_UNWINDING; call_exc_trace(tstate->c_tracefunc, tstate->c_traceobj, - tstate, xframe); + tstate, fdata); } exception_unwind: - xframe->xf_state = FRAME_UNWINDING; - /* We can't use xframe->xf_lasti here, as RERAISE may have set it */ + fdata->state = FRAME_UNWINDING; + /* We can't use fdata->lasti here, as RERAISE may have set it */ int offset = INSTR_OFFSET()-1; int level, handler, lasti; if (get_exception_handler(co, offset, &level, &handler, &lasti) == 0) { @@ -4482,7 +4482,7 @@ MISS_WITH_OPARG_COUNTER(BINARY_SUBSCR) } PyObject *exc, *val, *tb; if (lasti) { - PyObject *lasti = PyLong_FromLong(xframe->xf_lasti); + PyObject *lasti = PyLong_FromLong(fdata->lasti); if (lasti == NULL) { goto exception_unwind; } @@ -4507,8 +4507,8 @@ MISS_WITH_OPARG_COUNTER(BINARY_SUBSCR) PUSH(exc); JUMPTO(handler); /* Resume normal execution */ - xframe->xf_state = FRAME_EXECUTING; - xframe->xf_lasti = handler; + fdata->state = FRAME_EXECUTING; + fdata->lasti = handler; NEXTOPARG(); goto dispatch_opcode; } /* main loop */ @@ -4521,19 +4521,19 @@ MISS_WITH_OPARG_COUNTER(BINARY_SUBSCR) PyObject *o = POP(); Py_XDECREF(o); } - xframe->xf_stackdepth = 0; - xframe->xf_state = FRAME_RAISED; + fdata->stackdepth = 0; + fdata->state = FRAME_RAISED; exiting: if (cframe.use_tracing) { if (tstate->c_tracefunc) { if (call_trace_protected(tstate->c_tracefunc, tstate->c_traceobj, - tstate, xframe, PyTrace_RETURN, retval)) { + tstate, fdata, PyTrace_RETURN, retval)) { Py_CLEAR(retval); } } if (tstate->c_profilefunc) { if (call_trace_protected(tstate->c_profilefunc, tstate->c_profileobj, - tstate, xframe, PyTrace_RETURN, retval)) { + tstate, fdata, PyTrace_RETURN, retval)) { Py_CLEAR(retval); } } @@ -4546,9 +4546,9 @@ MISS_WITH_OPARG_COUNTER(BINARY_SUBSCR) tstate->cframe->use_tracing = cframe.use_tracing; if (PyDTrace_FUNCTION_RETURN_ENABLED()) - dtrace_function_return(xframe); + dtrace_function_return(fdata); _Py_LeaveRecursiveCall(tstate); - tstate->xframe = xframe->xf_previous; + tstate->fdata = fdata->previous; return _Py_CheckFunctionResult(tstate, NULL, retval, __func__); } @@ -5055,7 +5055,7 @@ initialize_locals(PyThreadState *tstate, PyFrameConstructor *con, } -static _PyExecFrame * +static _Py_framedata * make_coro_frame(PyThreadState *tstate, PyFrameConstructor *con, PyObject *locals, PyObject *const *args, Py_ssize_t argcount, @@ -5073,14 +5073,14 @@ make_coro_frame(PyThreadState *tstate, for (Py_ssize_t i=0; i < code->co_nlocalsplus; i++) { localsarray[i] = NULL; } - _PyExecFrame *xframe = (_PyExecFrame *)(localsarray + code->co_nlocalsplus); - _PyExecFrame_InitializeSpecials(xframe, con, locals, code->co_nlocalsplus); - assert(xframe->xf_frame_obj == NULL); + _Py_framedata *fdata = (_Py_framedata *)(localsarray + code->co_nlocalsplus); + _Py_framedata_InitializeSpecials(fdata, con, locals, code->co_nlocalsplus); + assert(fdata->frame_obj == NULL); if (initialize_locals(tstate, con, localsarray, args, argcount, kwnames)) { - _PyExecFrame_Clear(xframe, 1); + _Py_framedata_Clear(fdata, 1); return NULL; } - return xframe; + return fdata; } static PyObject * @@ -5090,11 +5090,11 @@ make_coro(PyThreadState *tstate, PyFrameConstructor *con, PyObject *kwnames) { assert (((PyCodeObject *)con->fc_code)->co_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR)); - _PyExecFrame *xframe = make_coro_frame(tstate, con, locals, args, argcount, kwnames); - if (xframe == NULL) { + _Py_framedata *fdata = make_coro_frame(tstate, con, locals, args, argcount, kwnames); + if (fdata == NULL) { return NULL; } - PyObject *gen = _Py_MakeCoro(con, xframe); + PyObject *gen = _Py_MakeCoro(con, fdata); if (gen == NULL) { return NULL; } @@ -5102,37 +5102,37 @@ make_coro(PyThreadState *tstate, PyFrameConstructor *con, return gen; } -static _PyExecFrame * +static _Py_framedata * _PyEvalFramePushAndInit(PyThreadState *tstate, PyFrameConstructor *con, PyObject *locals, PyObject* const* args, size_t argcount, PyObject *kwnames) { - _PyExecFrame * xframe = _PyThreadState_PushExecFrame(tstate, con, locals); - if (xframe == NULL) { + _Py_framedata * fdata = _PyThreadState_Push_framedata(tstate, con, locals); + if (fdata == NULL) { return NULL; } - PyObject **localsarray = _PyExecFrame_GetLocalsArray(xframe); + PyObject **localsarray = _Py_framedata_GetLocalsArray(fdata); if (initialize_locals(tstate, con, localsarray, args, argcount, kwnames)) { - _PyExecFrame_Clear(xframe, 0); + _Py_framedata_Clear(fdata, 0); return NULL; } - xframe->xf_previous = tstate->xframe; - tstate->xframe = xframe; - return xframe; + fdata->previous = tstate->fdata; + tstate->fdata = fdata; + return fdata; } static int -_PyEvalFrameClearAndPop(PyThreadState *tstate, _PyExecFrame * xframe) +_PyEvalFrameClearAndPop(PyThreadState *tstate, _Py_framedata * fdata) { ++tstate->recursion_depth; - assert(xframe->xf_frame_obj == NULL || xframe->xf_frame_obj->f_own_locals_memory == 0); - if (_PyExecFrame_Clear(xframe, 0)) { + assert(fdata->frame_obj == NULL || fdata->frame_obj->f_own_locals_memory == 0); + if (_Py_framedata_Clear(fdata, 0)) { return -1; } - assert(xframe->xf_frame_obj == NULL); + assert(fdata->frame_obj == NULL); --tstate->recursion_depth; - tstate->xframe = xframe->xf_previous; - _PyThreadState_PopExecFrame(tstate, xframe); + tstate->fdata = fdata->previous; + _PyThreadState_Pop_framedata(tstate, fdata); return 0; } @@ -5148,15 +5148,15 @@ _PyEval_Vector(PyThreadState *tstate, PyFrameConstructor *con, if (is_coro) { return make_coro(tstate, con, locals, args, argcount, kwnames); } - _PyExecFrame *xframe = _PyEvalFramePushAndInit( + _Py_framedata *fdata = _PyEvalFramePushAndInit( tstate, con, locals, args, argcount, kwnames); - if (xframe == NULL) { + if (fdata == NULL) { return NULL; } assert (tstate->interp->eval_frame != NULL); - PyObject *retval = _PyEval_EvalFrame(tstate, xframe, 0); - assert(xframe->xf_stackdepth == 0); - if (_PyEvalFrameClearAndPop(tstate, xframe)) { + PyObject *retval = _PyEval_EvalFrame(tstate, fdata, 0); + assert(fdata->stackdepth == 0); + if (_PyEvalFrameClearAndPop(tstate, fdata)) { retval = NULL; } return retval; @@ -5465,7 +5465,7 @@ prtrace(PyThreadState *tstate, PyObject *v, const char *str) static void call_exc_trace(Py_tracefunc func, PyObject *self, PyThreadState *tstate, - _PyExecFrame *xf) + _Py_framedata *fdata) { PyObject *type, *value, *traceback, *orig_traceback, *arg; int err; @@ -5481,7 +5481,7 @@ call_exc_trace(Py_tracefunc func, PyObject *self, _PyErr_Restore(tstate, type, value, orig_traceback); return; } - err = call_trace(func, self, tstate, xf, PyTrace_EXCEPTION, arg); + err = call_trace(func, self, tstate, fdata, PyTrace_EXCEPTION, arg); Py_DECREF(arg); if (err == 0) { _PyErr_Restore(tstate, type, value, orig_traceback); @@ -5495,13 +5495,13 @@ call_exc_trace(Py_tracefunc func, PyObject *self, static int call_trace_protected(Py_tracefunc func, PyObject *obj, - PyThreadState *tstate, _PyExecFrame *xframe, + PyThreadState *tstate, _Py_framedata *fdata, int what, PyObject *arg) { PyObject *type, *value, *traceback; int err; _PyErr_Fetch(tstate, &type, &value, &traceback); - err = call_trace(func, obj, tstate, xframe, what, arg); + err = call_trace(func, obj, tstate, fdata, what, arg); if (err == 0) { _PyErr_Restore(tstate, type, value, traceback); @@ -5516,9 +5516,9 @@ call_trace_protected(Py_tracefunc func, PyObject *obj, } static void -initialize_trace_info(PyTraceInfo *trace_info, _PyExecFrame *xframe) +initialize_trace_info(PyTraceInfo *trace_info, _Py_framedata *fdata) { - PyCodeObject *code = xframe->xf_code; + PyCodeObject *code = fdata->code; if (trace_info->code != code) { trace_info->code = code; _PyCode_InitAddressRange(code, &trace_info->bounds); @@ -5527,7 +5527,7 @@ initialize_trace_info(PyTraceInfo *trace_info, _PyExecFrame *xframe) static int call_trace(Py_tracefunc func, PyObject *obj, - PyThreadState *tstate, _PyExecFrame *xframe, + PyThreadState *tstate, _Py_framedata *fdata, int what, PyObject *arg) { int result; @@ -5535,16 +5535,16 @@ call_trace(Py_tracefunc func, PyObject *obj, return 0; tstate->tracing++; tstate->cframe->use_tracing = 0; - PyFrameObject *f = _PyExecFrame_GetFrameObject(xframe); + PyFrameObject *f = _Py_framedata_GetFrameObject(fdata); if (f == NULL) { return -1; } - if (xframe->xf_lasti < 0) { - f->f_lineno = xframe->xf_code->co_firstlineno; + if (fdata->lasti < 0) { + f->f_lineno = fdata->code->co_firstlineno; } else { - initialize_trace_info(&tstate->trace_info, xframe); - f->f_lineno = _PyCode_CheckLineNumber(xframe->xf_lasti*2, &tstate->trace_info.bounds); + initialize_trace_info(&tstate->trace_info, fdata); + f->f_lineno = _PyCode_CheckLineNumber(fdata->lasti*2, &tstate->trace_info.bounds); } result = func(obj, f, what, arg); f->f_lineno = 0; @@ -5574,7 +5574,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, _PyExecFrame *xframe, int instr_prev) + PyThreadState *tstate, _Py_framedata *fdata, int instr_prev) { int result = 0; @@ -5582,22 +5582,22 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj, represents a jump backwards, update the frame's line number and then call the trace function if we're tracing source lines. */ - initialize_trace_info(&tstate->trace_info, xframe); + initialize_trace_info(&tstate->trace_info, fdata); int lastline = _PyCode_CheckLineNumber(instr_prev*2, &tstate->trace_info.bounds); - int line = _PyCode_CheckLineNumber(xframe->xf_lasti*2, &tstate->trace_info.bounds); - PyFrameObject *f = _PyExecFrame_GetFrameObject(xframe); + int line = _PyCode_CheckLineNumber(fdata->lasti*2, &tstate->trace_info.bounds); + PyFrameObject *f = _Py_framedata_GetFrameObject(fdata); if (f == NULL) { return -1; } if (line != -1 && f->f_trace_lines) { /* Trace backward edges or if line number has changed */ - if (xframe->xf_lasti < instr_prev || line != lastline) { - result = call_trace(func, obj, tstate, xframe, PyTrace_LINE, Py_None); + if (fdata->lasti < instr_prev || line != lastline) { + result = call_trace(func, obj, tstate, fdata, PyTrace_LINE, Py_None); } } /* Always emit an opcode event if we're tracing all opcodes. */ if (f->f_trace_opcodes) { - result = call_trace(func, obj, tstate, xframe, PyTrace_OPCODE, Py_None); + result = call_trace(func, obj, tstate, fdata, PyTrace_OPCODE, Py_None); } return result; } @@ -5743,21 +5743,21 @@ _PyEval_GetAsyncGenFinalizer(void) return tstate->async_gen_finalizer; } -_PyExecFrame * -_PyEval_GetExecFrame(void) +_Py_framedata * +_PyEval_GetFrameData(void) { PyThreadState *tstate = _PyThreadState_GET(); - return tstate->xframe; + return tstate->fdata; } PyFrameObject * PyEval_GetFrame(void) { PyThreadState *tstate = _PyThreadState_GET(); - if (tstate->xframe == NULL) { + if (tstate->fdata == NULL) { return NULL; } - PyFrameObject *f = _PyExecFrame_GetFrameObject(tstate->xframe); + PyFrameObject *f = _Py_framedata_GetFrameObject(tstate->fdata); if (f == NULL) { PyErr_Clear(); } @@ -5767,9 +5767,9 @@ PyEval_GetFrame(void) PyObject * _PyEval_GetBuiltins(PyThreadState *tstate) { - _PyExecFrame *xframe = tstate->xframe; - if (xframe != NULL) { - return xframe->xf_builtins; + _Py_framedata *fdata = tstate->fdata; + if (fdata != NULL) { + return fdata->builtins; } return tstate->interp->builtins; } @@ -5800,17 +5800,17 @@ PyObject * PyEval_GetLocals(void) { PyThreadState *tstate = _PyThreadState_GET(); - _PyExecFrame *xframe = tstate->xframe; - if (xframe == NULL) { + _Py_framedata *fdata = tstate->fdata; + if (fdata == NULL) { _PyErr_SetString(tstate, PyExc_SystemError, "frame does not exist"); return NULL; } - if (_PyExecFrame_FastToLocalsWithError(xframe) < 0) { + if (_Py_framedata_FastToLocalsWithError(fdata) < 0) { return NULL; } - PyObject *locals = xframe->xf_locals; + PyObject *locals = fdata->locals; assert(locals != NULL); return locals; } @@ -5819,22 +5819,22 @@ PyObject * PyEval_GetGlobals(void) { PyThreadState *tstate = _PyThreadState_GET(); - _PyExecFrame *xframe = tstate->xframe; - if (xframe == NULL) { + _Py_framedata *fdata = tstate->fdata; + if (fdata == NULL) { return NULL; } - return xframe->xf_globals; + return fdata->globals; } int PyEval_MergeCompilerFlags(PyCompilerFlags *cf) { PyThreadState *tstate = _PyThreadState_GET(); - _PyExecFrame *xframe = tstate->xframe; + _Py_framedata *fdata = tstate->fdata; int result = cf->cf_flags != 0; - if (xframe != NULL) { - const int codeflags = xframe->xf_code->co_flags; + if (fdata != NULL) { + const int codeflags = fdata->code->co_flags; const int compilerflags = codeflags & PyCF_MASK; if (compilerflags) { result = 1; @@ -5880,7 +5880,7 @@ PyEval_GetFuncDesc(PyObject *func) #define C_TRACE(x, call) \ if (use_tracing && tstate->c_profilefunc) { \ if (call_trace(tstate->c_profilefunc, tstate->c_profileobj, \ - tstate, tstate->xframe, \ + tstate, tstate->fdata, \ PyTrace_C_CALL, func)) { \ x = NULL; \ } \ @@ -5890,13 +5890,13 @@ if (use_tracing && tstate->c_profilefunc) { \ if (x == NULL) { \ call_trace_protected(tstate->c_profilefunc, \ tstate->c_profileobj, \ - tstate, tstate->xframe, \ + tstate, tstate->fdata, \ PyTrace_C_EXCEPTION, func); \ /* XXX should pass (type, value, tb) */ \ } else { \ if (call_trace(tstate->c_profilefunc, \ tstate->c_profileobj, \ - tstate, tstate->xframe, \ + tstate, tstate->fdata, \ PyTrace_C_RETURN, func)) { \ Py_DECREF(x); \ x = NULL; \ @@ -6068,21 +6068,21 @@ _PyEval_SliceIndexNotNone(PyObject *v, Py_ssize_t *pi) } static PyObject * -import_name(PyThreadState *tstate, _PyExecFrame *xframe, +import_name(PyThreadState *tstate, _Py_framedata *fdata, PyObject *name, PyObject *fromlist, PyObject *level) { _Py_IDENTIFIER(__import__); PyObject *import_func, *res; PyObject* stack[5]; - import_func = _PyDict_GetItemIdWithError(xframe->xf_builtins, &PyId___import__); + import_func = _PyDict_GetItemIdWithError(fdata->builtins, &PyId___import__); if (import_func == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_SetString(tstate, PyExc_ImportError, "__import__ not found"); } return NULL; } - PyObject *locals = xframe->xf_locals; + PyObject *locals = fdata->locals; /* Fast path for not overloaded __import__. */ if (import_func == tstate->interp->import_func) { int ilevel = _PyLong_AsInt(level); @@ -6091,7 +6091,7 @@ import_name(PyThreadState *tstate, _PyExecFrame *xframe, } res = PyImport_ImportModuleLevelObject( name, - xframe->xf_globals, + fdata->globals, locals == NULL ? Py_None : locals, fromlist, ilevel); @@ -6101,7 +6101,7 @@ import_name(PyThreadState *tstate, _PyExecFrame *xframe, Py_INCREF(import_func); stack[0] = name; - stack[1] = xframe->xf_globals; + stack[1] = fdata->globals; stack[2] = locals == NULL ? Py_None : locals; stack[3] = fromlist; stack[4] = level; @@ -6407,7 +6407,7 @@ format_awaitable_error(PyThreadState *tstate, PyTypeObject *type, int prevprevop static PyObject * unicode_concatenate(PyThreadState *tstate, PyObject *v, PyObject *w, - _PyExecFrame *xframe, const _Py_CODEUNIT *next_instr) + _Py_framedata *fdata, const _Py_CODEUNIT *next_instr) { PyObject *res; if (Py_REFCNT(v) == 2) { @@ -6422,14 +6422,14 @@ unicode_concatenate(PyThreadState *tstate, PyObject *v, PyObject *w, switch (opcode) { case STORE_FAST: { - PyObject **localsplus = _PyExecFrame_GetLocalsArray(xframe); + PyObject **localsplus = _Py_framedata_GetLocalsArray(fdata); if (GETLOCAL(oparg) == v) SETLOCAL(oparg, NULL); break; } case STORE_DEREF: { - PyObject *c = _PyExecFrame_GetLocalsArray(xframe)[oparg]; + PyObject *c = _Py_framedata_GetLocalsArray(fdata)[oparg]; if (PyCell_GET(c) == v) { PyCell_SET(c, NULL); Py_DECREF(v); @@ -6438,9 +6438,9 @@ unicode_concatenate(PyThreadState *tstate, PyObject *v, PyObject *w, } case STORE_NAME: { - PyObject *names = xframe->xf_code->co_names; + PyObject *names = fdata->code->co_names; PyObject *name = GETITEM(names, oparg); - PyObject *locals = xframe->xf_locals; + PyObject *locals = fdata->locals; if (locals && PyDict_CheckExact(locals)) { PyObject *w = PyDict_GetItemWithError(locals, name); if ((w == v && PyDict_DelItem(locals, name) != 0) || @@ -6518,38 +6518,38 @@ _PyEval_RequestCodeExtraIndex(freefunc free) } static void -dtrace_function_entry(_PyExecFrame *xframe) +dtrace_function_entry(_Py_framedata *fdata) { const char *filename; const char *funcname; int lineno; - PyCodeObject *code = xframe->xf_code; + PyCodeObject *code = fdata->code; filename = PyUnicode_AsUTF8(code->co_filename); funcname = PyUnicode_AsUTF8(code->co_name); - lineno = PyCode_Addr2Line(xframe->xf_code, xframe->xf_lasti*2); + lineno = PyCode_Addr2Line(fdata->code, fdata->lasti*2); PyDTrace_FUNCTION_ENTRY(filename, funcname, lineno); } static void -dtrace_function_return(_PyExecFrame *xframe) +dtrace_function_return(_Py_framedata *fdata) { const char *filename; const char *funcname; int lineno; - PyCodeObject *code = xframe->xf_code; + PyCodeObject *code = fdata->code; filename = PyUnicode_AsUTF8(code->co_filename); funcname = PyUnicode_AsUTF8(code->co_name); - lineno = PyCode_Addr2Line(xframe->xf_code, xframe->xf_lasti*2); + lineno = PyCode_Addr2Line(fdata->code, fdata->lasti*2); PyDTrace_FUNCTION_RETURN(filename, funcname, lineno); } /* DTrace equivalent of maybe_call_line_trace. */ static void -maybe_dtrace_line(_PyExecFrame *xframe, +maybe_dtrace_line(_Py_framedata *fdata, PyTraceInfo *trace_info, int instr_prev) { @@ -6558,19 +6558,19 @@ maybe_dtrace_line(_PyExecFrame *xframe, /* If the last instruction executed isn't in the current instruction window, reset the window. */ - initialize_trace_info(trace_info, xframe); + initialize_trace_info(trace_info, fdata); int lastline = _PyCode_CheckLineNumber(instr_prev*2, &trace_info->bounds); - int line = _PyCode_CheckLineNumber(xframe->xf_lasti*2, &trace_info->bounds); + int line = _PyCode_CheckLineNumber(fdata->lasti*2, &trace_info->bounds); if (line != -1) { /* Trace backward edges or first instruction of a new line */ - if (xframe->xf_lasti < instr_prev || - (line != lastline && xframe->xf_lasti*2 == trace_info->bounds.ar_start)) + if (fdata->lasti < instr_prev || + (line != lastline && fdata->lasti*2 == trace_info->bounds.ar_start)) { - co_filename = PyUnicode_AsUTF8(xframe->xf_code->co_filename); + co_filename = PyUnicode_AsUTF8(fdata->code->co_filename); if (!co_filename) { co_filename = "?"; } - co_name = PyUnicode_AsUTF8(xframe->xf_code->co_name); + co_name = PyUnicode_AsUTF8(fdata->code->co_name); if (!co_name) { co_name = "?"; } diff --git a/Python/frame.c b/Python/frame.c index e941a160b09d60..f9497d627ab343 100644 --- a/Python/frame.c +++ b/Python/frame.c @@ -1,36 +1,36 @@ #include "Python.h" #include "frameobject.h" -#include "pycore_xframe.h" +#include "pycore_framedata.h" #include "pycore_object.h" // _PyObject_GC_UNTRACK() int -_PyExecFrame_Traverse(_PyExecFrame *xframe, visitproc visit, void *arg) +_Py_framedata_Traverse(_Py_framedata *fdata, visitproc visit, void *arg) { - Py_VISIT(xframe->xf_frame_obj); - Py_VISIT(xframe->xf_globals); - Py_VISIT(xframe->xf_builtins); - Py_VISIT(xframe->xf_locals); - Py_VISIT(xframe->xf_code); + Py_VISIT(fdata->frame_obj); + Py_VISIT(fdata->globals); + Py_VISIT(fdata->builtins); + Py_VISIT(fdata->locals); + Py_VISIT(fdata->code); /* locals */ - PyObject **locals = _PyExecFrame_GetLocalsArray(xframe); - for (int i = 0; i < xframe->xf_nlocalsplus; i++) { + PyObject **locals = _Py_framedata_GetLocalsArray(fdata); + for (int i = 0; i < fdata->nlocalsplus; i++) { Py_VISIT(locals[i]); } /* stack */ - for (int i = 0; i <xframe->xf_stackdepth; i++) { - Py_VISIT(xframe->xf_stack[i]); + for (int i = 0; i <fdata->stackdepth; i++) { + Py_VISIT(fdata->stack[i]); } return 0; } PyFrameObject * -_PyExecFrame_MakeAndSetFrameObject(_PyExecFrame *xframe) +_Py_framedata_MakeAndSetFrameObject(_Py_framedata *fdata) { - assert(xframe->xf_frame_obj == NULL); + assert(fdata->frame_obj == NULL); PyObject *error_type, *error_value, *error_traceback; PyErr_Fetch(&error_type, &error_value, &error_traceback); - PyFrameObject *f = _PyFrame_New_NoTrack(xframe, 0); + PyFrameObject *f = _PyFrame_New_NoTrack(fdata, 0); if (f == NULL) { Py_XDECREF(error_type); Py_XDECREF(error_value); @@ -39,50 +39,50 @@ _PyExecFrame_MakeAndSetFrameObject(_PyExecFrame *xframe) else { PyErr_Restore(error_type, error_value, error_traceback); } - xframe->xf_frame_obj = f; + fdata->frame_obj = f; return f; } -static _PyExecFrame * -copy_frame_to_heap(_PyExecFrame *xframe) +static _Py_framedata * +copy_frame_to_heap(_Py_framedata *fdata) { - PyObject **locals = _PyExecFrame_GetLocalsArray(xframe); - Py_ssize_t size = ((char*)&xframe->xf_stack[xframe->xf_stackdepth]) - (char *)locals; + PyObject **locals = _Py_framedata_GetLocalsArray(fdata); + Py_ssize_t size = ((char*)&fdata->stack[fdata->stackdepth]) - (char *)locals; PyObject **copy = PyMem_Malloc(size); if (copy == NULL) { PyErr_NoMemory(); return NULL; } memcpy(copy, locals, size); - _PyExecFrame *res = (_PyExecFrame *)(copy + xframe->xf_nlocalsplus); + _Py_framedata *res = (_Py_framedata *)(copy + fdata->nlocalsplus); return res; } static inline void -clear_specials(_PyExecFrame *xframe) +clear_specials(_Py_framedata *fdata) { - xframe->xf_generator = NULL; - Py_XDECREF(xframe->xf_frame_obj); - Py_XDECREF(xframe->xf_locals); - Py_DECREF(xframe->xf_globals); - Py_DECREF(xframe->xf_builtins); - Py_DECREF(xframe->xf_code); + fdata->generator = NULL; + Py_XDECREF(fdata->frame_obj); + Py_XDECREF(fdata->locals); + Py_DECREF(fdata->globals); + Py_DECREF(fdata->builtins); + Py_DECREF(fdata->code); } static void -take_ownership(PyFrameObject *f, _PyExecFrame *xframe) +take_ownership(PyFrameObject *f, _Py_framedata *fdata) { assert(f->f_own_locals_memory == 0); - assert(xframe->xf_frame_obj == NULL); + assert(fdata->frame_obj == NULL); f->f_own_locals_memory = 1; - f->f_xframe = xframe; + f->f_fdata = fdata; assert(f->f_back == NULL); - if (xframe->xf_previous != NULL) { - /* Link introspection frame's f_back and remove link through execution frame's xf_previous */ - PyFrameObject *back = _PyExecFrame_GetFrameObject(xframe->xf_previous); + if (fdata->previous != NULL) { + /* Link frame object's 'f_back' and remove link through frame data's 'previous' field */ + PyFrameObject *back = _Py_framedata_GetFrameObject(fdata->previous); if (back == NULL) { /* Memory error here. */ assert(PyErr_ExceptionMatches(PyExc_MemoryError)); @@ -93,7 +93,7 @@ take_ownership(PyFrameObject *f, _PyExecFrame *xframe) else { f->f_back = (PyFrameObject *)Py_NewRef(back); } - xframe->xf_previous = NULL; + fdata->previous = NULL; } if (!_PyObject_GC_IS_TRACKED((PyObject *)f)) { _PyObject_GC_TRACK((PyObject *)f); @@ -101,35 +101,35 @@ take_ownership(PyFrameObject *f, _PyExecFrame *xframe) } int -_PyExecFrame_Clear(_PyExecFrame * xframe, int take) +_Py_framedata_Clear(_Py_framedata * fdata, int take) { - PyObject **localsarray = ((PyObject **)xframe)-xframe->xf_nlocalsplus; - if (xframe->xf_frame_obj) { - PyFrameObject *f = xframe->xf_frame_obj; - xframe->xf_frame_obj = NULL; + PyObject **localsarray = ((PyObject **)fdata)-fdata->nlocalsplus; + if (fdata->frame_obj) { + PyFrameObject *f = fdata->frame_obj; + fdata->frame_obj = NULL; if (Py_REFCNT(f) > 1) { if (!take) { - xframe = copy_frame_to_heap(xframe); - if (xframe == NULL) { + fdata = copy_frame_to_heap(fdata); + if (fdata == NULL) { return -1; } } - take_ownership(f, xframe); + take_ownership(f, fdata); Py_DECREF(f); return 0; } Py_DECREF(f); } - for (int i = 0; i < xframe->xf_nlocalsplus; i++) { + for (int i = 0; i < fdata->nlocalsplus; i++) { Py_XDECREF(localsarray[i]); } - assert(xframe->xf_stackdepth >= 0); - for (int i = 0; i < xframe->xf_stackdepth; i++) { - Py_DECREF(xframe->xf_stack[i]); + assert(fdata->stackdepth >= 0); + for (int i = 0; i < fdata->stackdepth; i++) { + Py_DECREF(fdata->stack[i]); } - clear_specials(xframe); + clear_specials(fdata); if (take) { - PyMem_Free(_PyExecFrame_GetLocalsArray(xframe)); + PyMem_Free(_Py_framedata_GetLocalsArray(fdata)); } return 0; } diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index df6f16a3a0e6e0..7799af56581d9a 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -2003,7 +2003,7 @@ Py_EndInterpreter(PyThreadState *tstate) if (tstate != _PyThreadState_GET()) { Py_FatalError("thread is not current"); } - if (tstate->xframe != NULL) { + if (tstate->fdata != NULL) { Py_FatalError("thread still has a frame"); } interp->finalizing = 1; diff --git a/Python/pystate.c b/Python/pystate.c index 93aa4e7fb7b603..6e7e3d78925bcb 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -3,7 +3,7 @@ #include "Python.h" #include "pycore_ceval.h" -#include "pycore_xframe.h" +#include "pycore_framedata.h" #include "pycore_initconfig.h" #include "pycore_object.h" // _PyType_InitCache() #include "pycore_pyerrors.h" @@ -636,7 +636,7 @@ new_threadstate(PyInterpreterState *interp, int init) tstate->interp = interp; - tstate->xframe = NULL; + tstate->fdata = NULL; tstate->recursion_depth = 0; tstate->recursion_headroom = 0; tstate->stackcheck_counter = 0; @@ -686,7 +686,7 @@ new_threadstate(PyInterpreterState *interp, int init) PyMem_RawFree(tstate); return NULL; } - /* If top points to entry 0, then _PyThreadState_PopExecFrame will try to pop this chunk */ + /* If top points to entry 0, then _PyThreadState_Pop_framedata will try to pop this chunk */ tstate->datastack_top = &tstate->datastack_chunk->data[1]; tstate->datastack_limit = (PyObject **)(((char *)tstate->datastack_chunk) + DATA_STACK_CHUNK_SIZE); /* Mark trace_info as uninitialized */ @@ -861,11 +861,11 @@ PyThreadState_Clear(PyThreadState *tstate) { int verbose = _PyInterpreterState_GetConfig(tstate->interp)->verbose; - if (verbose && tstate->xframe != NULL) { + if (verbose && tstate->fdata != NULL) { /* bpo-20526: After the main thread calls _PyRuntimeState_SetFinalizing() in Py_FinalizeEx(), threads must exit when trying to take the GIL. If a thread exit in the middle of - _PyEval_EvalFrameDefault(), tstate->xframe is not reset to its + _PyEval_EvalFrameDefault(), tstate->fdata is not reset to its previous value. It is more likely with daemon threads, but it can happen with regular threads if threading._shutdown() fails (ex: interrupted by CTRL+C). */ @@ -1134,10 +1134,10 @@ PyFrameObject* PyThreadState_GetFrame(PyThreadState *tstate) { assert(tstate != NULL); - if (tstate->xframe == NULL) { + if (tstate->fdata == NULL) { return NULL; } - PyFrameObject *frame = _PyExecFrame_GetFrameObject(tstate->xframe); + PyFrameObject *frame = _Py_framedata_GetFrameObject(tstate->fdata); if (frame == NULL) { PyErr_Clear(); } @@ -1261,15 +1261,15 @@ _PyThread_CurrentFrames(void) for (i = runtime->interpreters.head; i != NULL; i = i->next) { PyThreadState *t; for (t = i->tstate_head; t != NULL; t = t->next) { - _PyExecFrame *xframe = t->xframe; - if (xframe == NULL) { + _Py_framedata *fdata = t->fdata; + if (fdata == NULL) { continue; } PyObject *id = PyLong_FromUnsignedLong(t->thread_id); if (id == NULL) { goto fail; } - int stat = PyDict_SetItem(result, id, (PyObject *)_PyExecFrame_GetFrameObject(xframe)); + int stat = PyDict_SetItem(result, id, (PyObject *)_Py_framedata_GetFrameObject(fdata)); Py_DECREF(id); if (stat < 0) { goto fail; @@ -2037,8 +2037,8 @@ push_chunk(PyThreadState *tstate, int size) return res; } -_PyExecFrame * -_PyThreadState_PushExecFrame(PyThreadState *tstate, PyFrameConstructor *con, PyObject *locals) +_Py_framedata * +_PyThreadState_Push_framedata(PyThreadState *tstate, PyFrameConstructor *con, PyObject *locals) { PyCodeObject *code = (PyCodeObject *)con->fc_code; int nlocalsplus = code->co_nlocalsplus; @@ -2056,18 +2056,18 @@ _PyThreadState_PushExecFrame(PyThreadState *tstate, PyFrameConstructor *con, PyO else { tstate->datastack_top = top; } - _PyExecFrame * xframe = (_PyExecFrame *)(localsarray + nlocalsplus); - _PyExecFrame_InitializeSpecials(xframe, con, locals, nlocalsplus); + _Py_framedata * fdata = (_Py_framedata *)(localsarray + nlocalsplus); + _Py_framedata_InitializeSpecials(fdata, con, locals, nlocalsplus); for (int i=0; i < nlocalsplus; i++) { localsarray[i] = NULL; } - return xframe; + return fdata; } void -_PyThreadState_PopExecFrame(PyThreadState *tstate, _PyExecFrame * xframe) +_PyThreadState_Pop_framedata(PyThreadState *tstate, _Py_framedata * fdata) { - PyObject **locals = _PyExecFrame_GetLocalsArray(xframe); + PyObject **locals = _Py_framedata_GetLocalsArray(fdata); if (locals == &tstate->datastack_chunk->data[0]) { _PyStackChunk *chunk = tstate->datastack_chunk; _PyStackChunk *previous = chunk->previous; diff --git a/Python/suggestions.c b/Python/suggestions.c index 01fca89c65074d..4d9f5dddd80c42 100644 --- a/Python/suggestions.c +++ b/Python/suggestions.c @@ -1,6 +1,6 @@ #include "Python.h" #include "frameobject.h" -#include "pycore_xframe.h" +#include "pycore_framedata.h" #include "pycore_pyerrors.h" #include "pycore_code.h" // _PyCode_GetVarnames() @@ -232,7 +232,7 @@ offer_suggestions_for_name_error(PyNameErrorObject *exc) return suggestions; } - dir = PySequence_List(frame->f_xframe->xf_globals); + dir = PySequence_List(frame->f_fdata->globals); if (dir == NULL) { return NULL; } @@ -242,7 +242,7 @@ offer_suggestions_for_name_error(PyNameErrorObject *exc) return suggestions; } - dir = PySequence_List(frame->f_xframe->xf_builtins); + dir = PySequence_List(frame->f_fdata->builtins); if (dir == NULL) { return NULL; } diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 126cd5edfeb5d1..873e40ea1757a4 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -29,7 +29,7 @@ Data members: #include "code.h" #include "frameobject.h" // PyFrame_GetBack() -#include "pycore_xframe.h" +#include "pycore_framedata.h" #include "pydtrace.h" #include "osdefs.h" // DELIM #include "stdlib_module_names.h" // _Py_stdlib_module_names @@ -1815,22 +1815,22 @@ sys__getframe_impl(PyObject *module, int depth) /*[clinic end generated code: output=d438776c04d59804 input=c1be8a6464b11ee5]*/ { PyThreadState *tstate = _PyThreadState_GET(); - _PyExecFrame *xframe = tstate->xframe; + _Py_framedata *fdata = tstate->fdata; if (_PySys_Audit(tstate, "sys._getframe", NULL) < 0) { return NULL; } - while (depth > 0 && xframe != NULL) { - xframe = xframe->xf_previous; + while (depth > 0 && fdata != NULL) { + fdata = fdata->previous; --depth; } - if (xframe == NULL) { + if (fdata == NULL) { _PyErr_SetString(tstate, PyExc_ValueError, "call stack is not deep enough"); return NULL; } - return _Py_XNewRef((PyObject *)_PyExecFrame_GetFrameObject(xframe)); + return _Py_XNewRef((PyObject *)_Py_framedata_GetFrameObject(fdata)); } /*[clinic input] diff --git a/Python/traceback.c b/Python/traceback.c index 073631acf96253..1493406ffbb7c8 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -6,7 +6,7 @@ #include "code.h" // PyCode_Addr2Line etc #include "pycore_interp.h" // PyInterpreterState.gc #include "frameobject.h" // PyFrame_GetBack() -#include "pycore_xframe.h" // _PyExecFrame_GetCode() +#include "pycore_framedata.h" // _Py_framedata_GetCode() #include "pycore_pyarena.h" // _PyArena_Free() #include "pycore_ast.h" // asdl_seq_* #include "pycore_compile.h" // _PyAST_Optimize @@ -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_xframe->xf_lasti*2, + return tb_create_raw((PyTracebackObject *)tb_next, frame, frame->f_fdata->lasti*2, PyFrame_GetLineNumber(frame)); } @@ -710,7 +710,7 @@ tb_displayline(PyTracebackObject* tb, PyObject *f, PyObject *filename, int linen } int code_offset = tb->tb_lasti; - PyCodeObject* code = frame->f_xframe->xf_code; + PyCodeObject* code = frame->f_fdata->code; int start_line; int end_line; @@ -1024,9 +1024,9 @@ _Py_DumpASCII(int fd, PyObject *text) This function is signal safe. */ static void -dump_frame(int fd, _PyExecFrame *xframe) +dump_frame(int fd, _Py_framedata *fdata) { - PyCodeObject *code = xframe->xf_code; + PyCodeObject *code = fdata->code; PUTS(fd, " File "); if (code->co_filename != NULL && PyUnicode_Check(code->co_filename)) @@ -1038,7 +1038,7 @@ dump_frame(int fd, _PyExecFrame *xframe) PUTS(fd, "???"); } - int lineno = PyCode_Addr2Line(code, xframe->xf_lasti*2); + int lineno = PyCode_Addr2Line(code, fdata->lasti*2); PUTS(fd, ", line "); if (lineno >= 0) { _Py_DumpDecimal(fd, (size_t)lineno); @@ -1062,15 +1062,15 @@ dump_frame(int fd, _PyExecFrame *xframe) static void dump_traceback(int fd, PyThreadState *tstate, int write_header) { - _PyExecFrame *xframe; + _Py_framedata *fdata; unsigned int depth; if (write_header) { PUTS(fd, "Stack (most recent call first):\n"); } - xframe = tstate->xframe; - if (xframe == NULL) { + fdata = tstate->fdata; + if (fdata == NULL) { PUTS(fd, "<no Python frame>\n"); return; } @@ -1081,9 +1081,9 @@ dump_traceback(int fd, PyThreadState *tstate, int write_header) PUTS(fd, " ...\n"); break; } - dump_frame(fd, xframe); - xframe = xframe->xf_previous; - if (xframe == NULL) { + dump_frame(fd, fdata); + fdata = fdata->previous; + if (fdata == NULL) { break; } depth++; diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py index 425869c5bec024..086229444402bb 100755 --- a/Tools/gdb/libpython.py +++ b/Tools/gdb/libpython.py @@ -861,7 +861,7 @@ def __init__(self, gdbval, cast_to=None): PyObjectPtr.__init__(self, gdbval, cast_to) if not self.is_optimized_out(): - self._frame = PyExecFramePtr(self.field('f_xframe')) + self._frame = Py_framedataPtr(self.field('f_fdata')) def iter_locals(self): ''' @@ -932,17 +932,17 @@ def print_traceback(self): return return self._frame.print_traceback() -class PyExecFramePtr: +class Py_framedataPtr: def __init__(self, gdbval): self._gdbval = gdbval if not self.is_optimized_out(): - self.co = self._xf_code() + self.co = self._code() self.co_name = self.co.pyop_field('co_name') self.co_filename = self.co.pyop_field('co_filename') - self.xf_lasti = self._xf_lasti() + self.lasti = self._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) @@ -960,7 +960,7 @@ def iter_locals(self): obj_ptr_ptr = gdb.lookup_type("PyObject").pointer().pointer() base = self._gdbval.cast(obj_ptr_ptr) - localsplus = base - self._xf_nlocalsplus() + localsplus = base - self._nlocalsplus() for i in safe_range(self.co_nlocals): pyop_value = PyObjectPtr.from_pyobject_ptr(localsplus[i]) if pyop_value.is_null(): @@ -968,23 +968,23 @@ def iter_locals(self): pyop_name = PyObjectPtr.from_pyobject_ptr(self.co_localsplusnames[i]) yield (pyop_name, pyop_value) - def _xf_special(self, name, convert=PyObjectPtr.from_pyobject_ptr): + def _special(self, name, convert=PyObjectPtr.from_pyobject_ptr): return convert(self._gdbval[name]) - def _xf_globals(self): - return self._xf_special("xf_globals") + def _globals(self): + return self._special("globals") - def _xf_builtins(self): - return self._xf_special("xf_builtins") + def _builtins(self): + return self._special("builtins") - def _xf_code(self): - return self._xf_special("xf_code", PyCodeObjectPtr.from_pyobject_ptr) + def _code(self): + return self._special("code", PyCodeObjectPtr.from_pyobject_ptr) - def _xf_nlocalsplus(self): - return self._xf_special("xf_nlocalsplus", int_from_int) + def _nlocalsplus(self): + return self._special("nlocalsplus", int_from_int) - def _xf_lasti(self): - return self._xf_special("xf_lasti", int_from_int) + def _lasti(self): + return self._special("lasti", int_from_int) def iter_globals(self): @@ -995,7 +995,7 @@ def iter_globals(self): if self.is_optimized_out(): return () - pyop_globals = self._xf_globals() + pyop_globals = self._globals() return pyop_globals.iteritems() def iter_builtins(self): @@ -1006,7 +1006,7 @@ def iter_builtins(self): if self.is_optimized_out(): return () - pyop_builtins = self._xf_builtins() + pyop_builtins = self._builtins() return pyop_builtins.iteritems() def get_var_by_name(self, name): @@ -1043,7 +1043,7 @@ def current_line_num(self): if self.is_optimized_out(): return None try: - return self.co.addr2line(self.xf_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 @@ -1733,21 +1733,21 @@ def is_gc_collect(self): def get_pyop(self): try: - xframe = self._gdbframe.read_var('xframe') - xframe = PyExecFramePtr(xframe) - if not xframe.is_optimized_out(): - return xframe - # gdb is unable to get the "xframe" argument of PyEval_EvalFrameEx() - # because it was "optimized out". Try to get "xframe" from the frame + fdata = self._gdbframe.read_var('fdata') + fdata = Py_framedataPtr(fdata) + if not fdata.is_optimized_out(): + return fdata + # gdb is unable to get the "fdata" argument of PyEval_EvalFrameEx() + # because it was "optimized out". Try to get "fdata" from the frame # of the caller, _PyEval_Vector(). - orig_xframe = xframe + orig_fdata = fdata caller = self._gdbframe.older() if caller: - xframe = caller.read_var('xframe') - xframe = PyExecFramePtr(xframe) - if not xframe.is_optimized_out(): - return xframe - return orig_xframe + fdata = caller.read_var('fdata') + fdata = Py_framedataPtr(fdata) + if not fdata.is_optimized_out(): + return fdata + return orig_fdata except ValueError: return None From ccf953b83f01b82208c1c1609f6b19d69cbee88f Mon Sep 17 00:00:00 2001 From: Nick Coghlan <ncoghlan@gmail.com> Date: Sat, 14 Aug 2021 14:32:49 +1000 Subject: [PATCH 03/30] Tweak some comments --- Include/cpython/pystate.h | 2 +- Include/internal/pycore_framedata.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h index c0f3c779e40ef1..f874e2fd29bd8c 100644 --- a/Include/cpython/pystate.h +++ b/Include/cpython/pystate.h @@ -83,7 +83,7 @@ struct _ts { struct _ts *next; PyInterpreterState *interp; - /* Borrowed reference to the current execution frame (it can be NULL) */ + /* Borrowed reference to the current execution frame's data (it can be NULL) */ _Py_framedata *fdata; int recursion_depth; int recursion_headroom; /* Allow 50 more calls to handle any errors. */ diff --git a/Include/internal/pycore_framedata.h b/Include/internal/pycore_framedata.h index 1c49064ad0c2f2..ff2e417671fc38 100644 --- a/Include/internal/pycore_framedata.h +++ b/Include/internal/pycore_framedata.h @@ -102,12 +102,12 @@ _Py_framedata_GetFrameObject(_Py_framedata *fdata) } /* Clears all references in the frame. - * If take is non-zero, then the execution frame + * If take is non-zero, then the frame data * may be transfered to the frame object it references * instead of being cleared. Either way * the caller no longer owns the references * in the frame. - * take should be set to 1 for heap allocated + * take should be set to 1 for heap allocated * frames like the ones in generators and coroutines. */ int From 4a097bdf68bd6947dbd18956239b9290670eaa76 Mon Sep 17 00:00:00 2001 From: Nick Coghlan <ncoghlan@gmail.com> Date: Sat, 14 Aug 2021 14:48:58 +1000 Subject: [PATCH 04/30] Another comment fix --- Include/internal/pycore_framedata.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Include/internal/pycore_framedata.h b/Include/internal/pycore_framedata.h index ff2e417671fc38..58c2e709ba0289 100644 --- a/Include/internal/pycore_framedata.h +++ b/Include/internal/pycore_framedata.h @@ -9,7 +9,7 @@ PyFrameObject* _PyFrame_New_NoTrack(_Py_framedata *, int); /* These values are chosen so that the inline functions below all - * compare f_state to zero. + * compare fdata->state to zero. */ enum _framestate { FRAME_CREATED = -2, From bd004900b20c1d3d673c04d49538233611f6b3e0 Mon Sep 17 00:00:00 2001 From: Nick Coghlan <ncoghlan@gmail.com> Date: Sat, 14 Aug 2021 14:49:14 +1000 Subject: [PATCH 05/30] Fix LLTRACE macro compile error --- Python/ceval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/ceval.c b/Python/ceval.c index 03f683309c046f..52c9eb689d5c81 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -1201,7 +1201,7 @@ eval_frame_handle_pending(PyThreadState *tstate) * the CFG. */ #ifdef LLTRACE -#define LLTRACE_INSTR() if (lltrace) { lltrace_instruction(frame, opcode, oparg); } +#define LLTRACE_INSTR() if (lltrace) { lltrace_instruction(fdata, opcode, oparg); } #else #define LLTRACE_INSTR() ((void)0) #endif From 04aa7e88510086112352bbc59febe3121da60c6c Mon Sep 17 00:00:00 2001 From: Nick Coghlan <ncoghlan@gmail.com> Date: Sat, 14 Aug 2021 14:51:58 +1000 Subject: [PATCH 06/30] Revert unintended function name changes --- Include/internal/pycore_framedata.h | 4 ++-- Python/ceval.c | 4 ++-- Python/pystate.c | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Include/internal/pycore_framedata.h b/Include/internal/pycore_framedata.h index 58c2e709ba0289..83c676024b015c 100644 --- a/Include/internal/pycore_framedata.h +++ b/Include/internal/pycore_framedata.h @@ -122,10 +122,10 @@ _Py_framedata_FastToLocalsWithError(_Py_framedata *frame); void _Py_framedata_LocalsToFast(_Py_framedata *frame, int clear); -_Py_framedata *_PyThreadState_Push_framedata( +_Py_framedata *_PyThreadState_PushFrame( PyThreadState *tstate, PyFrameConstructor *con, PyObject *locals); -void _PyThreadState_Pop_framedata(PyThreadState *tstate, _Py_framedata *frame); +void _PyThreadState_PopFrame(PyThreadState *tstate, _Py_framedata *frame); #ifdef __cplusplus } diff --git a/Python/ceval.c b/Python/ceval.c index 52c9eb689d5c81..806865c219d498 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -5259,7 +5259,7 @@ _PyEvalFramePushAndInit(PyThreadState *tstate, PyFrameConstructor *con, PyObject *locals, PyObject* const* args, size_t argcount, PyObject *kwnames) { - _Py_framedata * fdata = _PyThreadState_Push_framedata(tstate, con, locals); + _Py_framedata * fdata = _PyThreadState_PushFrame(tstate, con, locals); if (fdata == NULL) { return NULL; } @@ -5284,7 +5284,7 @@ _PyEvalFrameClearAndPop(PyThreadState *tstate, _Py_framedata * fdata) assert(fdata->frame_obj == NULL); --tstate->recursion_depth; tstate->fdata = fdata->previous; - _PyThreadState_Pop_framedata(tstate, fdata); + _PyThreadState_PopFrame(tstate, fdata); return 0; } diff --git a/Python/pystate.c b/Python/pystate.c index 6e7e3d78925bcb..76cb9dafe09825 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -686,7 +686,7 @@ new_threadstate(PyInterpreterState *interp, int init) PyMem_RawFree(tstate); return NULL; } - /* If top points to entry 0, then _PyThreadState_Pop_framedata will try to pop this chunk */ + /* If top points to entry 0, then _PyThreadState_PopFrame will try to pop this chunk */ tstate->datastack_top = &tstate->datastack_chunk->data[1]; tstate->datastack_limit = (PyObject **)(((char *)tstate->datastack_chunk) + DATA_STACK_CHUNK_SIZE); /* Mark trace_info as uninitialized */ @@ -2038,7 +2038,7 @@ push_chunk(PyThreadState *tstate, int size) } _Py_framedata * -_PyThreadState_Push_framedata(PyThreadState *tstate, PyFrameConstructor *con, PyObject *locals) +_PyThreadState_PushFrame(PyThreadState *tstate, PyFrameConstructor *con, PyObject *locals) { PyCodeObject *code = (PyCodeObject *)con->fc_code; int nlocalsplus = code->co_nlocalsplus; @@ -2065,7 +2065,7 @@ _PyThreadState_Push_framedata(PyThreadState *tstate, PyFrameConstructor *con, Py } void -_PyThreadState_Pop_framedata(PyThreadState *tstate, _Py_framedata * fdata) +_PyThreadState_PopFrame(PyThreadState *tstate, _Py_framedata * fdata) { PyObject **locals = _Py_framedata_GetLocalsArray(fdata); if (locals == &tstate->datastack_chunk->data[0]) { From e9018e7d839b23681e276678254483492acb4f7d Mon Sep 17 00:00:00 2001 From: Nick Coghlan <ncoghlan@gmail.com> Date: Sat, 14 Aug 2021 14:53:01 +1000 Subject: [PATCH 07/30] Fix comment alignment --- Python/traceback.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/traceback.c b/Python/traceback.c index 1493406ffbb7c8..2cd8525ed865da 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -6,7 +6,7 @@ #include "code.h" // PyCode_Addr2Line etc #include "pycore_interp.h" // PyInterpreterState.gc #include "frameobject.h" // PyFrame_GetBack() -#include "pycore_framedata.h" // _Py_framedata_GetCode() +#include "pycore_framedata.h" // _Py_framedata_GetCode() #include "pycore_pyarena.h" // _PyArena_Free() #include "pycore_ast.h" // asdl_seq_* #include "pycore_compile.h" // _PyAST_Optimize From 0ce41c8d7e704575559cae7104a00fa8f2992a3f Mon Sep 17 00:00:00 2001 From: Nick Coghlan <ncoghlan@gmail.com> Date: Sat, 14 Aug 2021 14:57:18 +1000 Subject: [PATCH 08/30] Follow proposed new naming conventions in gdb hooks --- Tools/gdb/libpython.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py index 086229444402bb..f0b11e67eb25f4 100755 --- a/Tools/gdb/libpython.py +++ b/Tools/gdb/libpython.py @@ -861,7 +861,7 @@ def __init__(self, gdbval, cast_to=None): PyObjectPtr.__init__(self, gdbval, cast_to) if not self.is_optimized_out(): - self._frame = Py_framedataPtr(self.field('f_fdata')) + self._fdata = _Py_framedataPtr(self.field('f_fdata')) def iter_locals(self): ''' @@ -870,7 +870,7 @@ def iter_locals(self): ''' if self.is_optimized_out(): return - return self._frame.iter_locals() + return self._fdata.iter_locals() def iter_globals(self): ''' @@ -879,7 +879,7 @@ def iter_globals(self): ''' if self.is_optimized_out(): return () - return self._frame.iter_globals() + return self._fdata.iter_globals() def iter_builtins(self): ''' @@ -888,19 +888,19 @@ def iter_builtins(self): ''' if self.is_optimized_out(): return () - return self._frame.iter_builtins() + return self._fdata.iter_builtins() def get_var_by_name(self, name): if self.is_optimized_out(): return None, None - return self._frame.get_var_by_name(name) + return self._fdata.get_var_by_name(name) def filename(self): '''Get the path of the current Python source file, as a string''' if self.is_optimized_out(): return FRAME_INFO_OPTIMIZED_OUT - return self._frame.filename() + return self._fdata.filename() def current_line_num(self): '''Get current line number as an integer (1-based) @@ -911,28 +911,28 @@ def current_line_num(self): ''' if self.is_optimized_out(): return None - return self._frame.current_line_num() + return self._fdata.current_line_num() def current_line(self): '''Get the text of the current source line as a string, with a trailing newline character''' if self.is_optimized_out(): return FRAME_INFO_OPTIMIZED_OUT - return self._frame.current_line() + return self._fdata.current_line() def write_repr(self, out, visited): if self.is_optimized_out(): out.write(FRAME_INFO_OPTIMIZED_OUT) return - return self._frame.write_repr(out, visited) + return self._fdata.write_repr(out, visited) def print_traceback(self): if self.is_optimized_out(): sys.stdout.write(' %s\n' % FRAME_INFO_OPTIMIZED_OUT) return - return self._frame.print_traceback() + return self._fdata.print_traceback() -class Py_framedataPtr: +class _Py_framedataPtr: def __init__(self, gdbval): self._gdbval = gdbval @@ -1734,7 +1734,7 @@ def is_gc_collect(self): def get_pyop(self): try: fdata = self._gdbframe.read_var('fdata') - fdata = Py_framedataPtr(fdata) + fdata = _Py_framedataPtr(fdata) if not fdata.is_optimized_out(): return fdata # gdb is unable to get the "fdata" argument of PyEval_EvalFrameEx() @@ -1744,7 +1744,7 @@ def get_pyop(self): caller = self._gdbframe.older() if caller: fdata = caller.read_var('fdata') - fdata = Py_framedataPtr(fdata) + fdata = _Py_framedataPtr(fdata) if not fdata.is_optimized_out(): return fdata return orig_fdata From 4eeff9a9a99e6bb635e82a82186fc799103d7e21 Mon Sep 17 00:00:00 2001 From: Nick Coghlan <ncoghlan@gmail.com> Date: Sun, 6 Mar 2022 11:39:33 +1000 Subject: [PATCH 09/30] Reduce conflicts for main branch merge --- Include/cpython/ceval.h | 2 +- Include/cpython/frameobject.h | 4 +- Include/cpython/pystate.h | 8 +- Include/genobject.h | 2 +- Include/internal/pycore_ceval.h | 6 +- .../{pycore_framedata.h => pycore_frame.h} | 44 ++++---- .../2021-08-01-18-18-51.bpo-44800.TCsfH3.rst | 4 +- Misc/gdbinit | 4 +- Modules/_tracemalloc.c | 8 +- Modules/_xxsubinterpretersmodule.c | 6 +- Modules/signalmodule.c | 6 +- Objects/frameobject.c | 44 ++++---- Objects/genobject.c | 48 ++++----- Objects/typeobject.c | 6 +- Python/_warnings.c | 2 +- Python/ceval.c | 100 +++++++++--------- Python/frame.c | 26 ++--- Python/pystate.c | 18 ++-- Python/suggestions.c | 2 +- Python/sysmodule.c | 6 +- Python/traceback.c | 6 +- Tools/gdb/libpython.py | 8 +- 22 files changed, 180 insertions(+), 180 deletions(-) rename Include/internal/{pycore_framedata.h => pycore_frame.h} (63%) diff --git a/Include/cpython/ceval.h b/Include/cpython/ceval.h index def08ee81e4622..cbee144ad94a4f 100644 --- a/Include/cpython/ceval.h +++ b/Include/cpython/ceval.h @@ -19,7 +19,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, _Py_framedata *fdata, int exc); +PyAPI_FUNC(PyObject *) _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_InterpreterFrame *fdata, int exc); PyAPI_FUNC(void) _PyEval_SetSwitchInterval(unsigned long microseconds); PyAPI_FUNC(unsigned long) _PyEval_GetSwitchInterval(void); diff --git a/Include/cpython/frameobject.h b/Include/cpython/frameobject.h index f7df31bd779308..c58189bd8adb18 100644 --- a/Include/cpython/frameobject.h +++ b/Include/cpython/frameobject.h @@ -18,12 +18,12 @@ * over the previous approach of using full Python objects for both * introspection and code execution. */ -// Declaration of _Py_framedata is in cpython/pystate.h for use in PyThreadState +// Declaration of _Py_InterpreterFrame is in cpython/pystate.h for use in PyThreadState struct _frame { PyObject_HEAD struct _frame *f_back; /* previous frame, or NULL */ - _Py_framedata *f_fdata; /* points to the frame runtime data */ + _Py_InterpreterFrame *f_fdata; /* points to the frame runtime 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? */ diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h index f874e2fd29bd8c..72ec5e37be6e13 100644 --- a/Include/cpython/pystate.h +++ b/Include/cpython/pystate.h @@ -72,8 +72,8 @@ typedef struct _stack_chunk { // Declared here so the thread state can use it without creating an include loop // See cpython/frameobject.h for an explanation of the type -// See internal/pycore_framedata.h for the struct definition -typedef struct _Py_execution_frame _Py_framedata; +// See internal/pycore_frame.h for the struct definition +typedef struct _Py_execution_frame _Py_InterpreterFrame; // The PyThreadState typedef is in Include/pystate.h. struct _ts { @@ -84,7 +84,7 @@ struct _ts { PyInterpreterState *interp; /* Borrowed reference to the current execution frame's data (it can be NULL) */ - _Py_framedata *fdata; + _Py_InterpreterFrame *fdata; int recursion_depth; int recursion_headroom; /* Allow 50 more calls to handle any errors. */ int stackcheck_counter; @@ -229,7 +229,7 @@ PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void); /* Frame evaluation API */ -typedef PyObject* (*_PyFrameEvalFunction)(PyThreadState *tstate, _Py_framedata *, int); +typedef PyObject* (*_PyFrameEvalFunction)(PyThreadState *tstate, _Py_InterpreterFrame *, int); PyAPI_FUNC(_PyFrameEvalFunction) _PyInterpreterState_GetEvalFrameFunc( PyInterpreterState *interp); diff --git a/Include/genobject.h b/Include/genobject.h index 36ae755e8398d8..c78d45599746fa 100644 --- a/Include/genobject.h +++ b/Include/genobject.h @@ -16,7 +16,7 @@ extern "C" { #define _PyGenObject_HEAD(prefix) \ PyObject_HEAD \ /* Note: gi_fdata can be NULL if the generator is "finished" */ \ - _Py_framedata *prefix##_fdata; \ + _Py_InterpreterFrame *prefix##_fdata; \ /* The code object backing the generator */ \ PyCodeObject *prefix##_code; \ /* List of weak reference. */ \ diff --git a/Include/internal/pycore_ceval.h b/Include/internal/pycore_ceval.h index ca1399cd5ae624..583f1628b05201 100644 --- a/Include/internal/pycore_ceval.h +++ b/Include/internal/pycore_ceval.h @@ -41,7 +41,7 @@ extern PyObject *_PyEval_BuiltinsFromGlobals( static inline PyObject* -_PyEval_EvalFrame(PyThreadState *tstate, _Py_framedata *fdata, int throwflag) +_PyEval_EvalFrame(PyThreadState *tstate, _Py_InterpreterFrame *fdata, int throwflag) { return tstate->interp->eval_frame(tstate, fdata, throwflag); } @@ -107,9 +107,9 @@ static inline void _Py_LeaveRecursiveCall_inline(void) { #define Py_LeaveRecursiveCall() _Py_LeaveRecursiveCall_inline() -_Py_framedata *_PyEval_GetFrameData(void); +_Py_InterpreterFrame *_PyEval_GetFrameData(void); -PyObject *_Py_MakeCoro(PyFrameConstructor *, _Py_framedata *); +PyObject *_Py_MakeCoro(PyFrameConstructor *, _Py_InterpreterFrame *); #ifdef __cplusplus } diff --git a/Include/internal/pycore_framedata.h b/Include/internal/pycore_frame.h similarity index 63% rename from Include/internal/pycore_framedata.h rename to Include/internal/pycore_frame.h index 83c676024b015c..c309bbeb69b83c 100644 --- a/Include/internal/pycore_framedata.h +++ b/Include/internal/pycore_frame.h @@ -6,7 +6,7 @@ extern "C" { /* Internal-use-only frame object constructor */ PyFrameObject* -_PyFrame_New_NoTrack(_Py_framedata *, int); +_PyFrame_New_NoTrack(_Py_InterpreterFrame *, int); /* These values are chosen so that the inline functions below all * compare fdata->state to zero. @@ -23,7 +23,7 @@ enum _framestate { typedef signed char PyFrameState; -// The _Py_framedata typedef is in Include/pyframeobject.h +// The _Py_InterpreterFrame typedef is in Include/pyframeobject.h struct _Py_execution_frame { PyObject *globals; PyObject *builtins; @@ -32,7 +32,7 @@ struct _Py_execution_frame { PyFrameObject *frame_obj; // Full frame object (if created) /* Borrowed reference to a generator, or NULL */ PyObject *generator; - _Py_framedata *previous; + _Py_InterpreterFrame *previous; int lasti; /* Last instruction if called */ int stackdepth; /* Depth of value stack */ int nlocalsplus; @@ -40,26 +40,26 @@ struct _Py_execution_frame { PyObject *stack[1]; }; -static inline int _Py_framedata_IsRunnable(_Py_framedata *fdata) { +static inline int _Py_InterpreterFrame_IsRunnable(_Py_InterpreterFrame *fdata) { return fdata->state < FRAME_EXECUTING; } -static inline int _Py_framedata_IsExecuting(_Py_framedata *fdata) { +static inline int _Py_InterpreterFrame_IsExecuting(_Py_InterpreterFrame *fdata) { return fdata->state == FRAME_EXECUTING; } -static inline int _Py_framedata_HasCompleted(_Py_framedata *fdata) { +static inline int _Py_InterpreterFrame_HasCompleted(_Py_InterpreterFrame *fdata) { return fdata->state > FRAME_EXECUTING; } -#define FRAME_SPECIALS_SIZE ((sizeof(_Py_framedata)-1)/sizeof(PyObject *)) +#define FRAME_SPECIALS_SIZE ((sizeof(_Py_InterpreterFrame)-1)/sizeof(PyObject *)) -_Py_framedata * -_Py_framedata_HeapAlloc(PyFrameConstructor *con, PyObject *locals); +_Py_InterpreterFrame * +_Py_InterpreterFrame_HeapAlloc(PyFrameConstructor *con, PyObject *locals); static inline void -_Py_framedata_InitializeSpecials( - _Py_framedata *fdata, PyFrameConstructor *con, +_Py_InterpreterFrame_InitializeSpecials( + _Py_InterpreterFrame *fdata, PyFrameConstructor *con, PyObject *locals, int nlocalsplus) { fdata->code = (PyCodeObject *)Py_NewRef(con->fc_code); @@ -78,27 +78,27 @@ _Py_framedata_InitializeSpecials( * that precedes this frame. */ static inline PyObject** -_Py_framedata_GetLocalsArray(_Py_framedata *fdata) +_Py_InterpreterFrame_GetLocalsArray(_Py_InterpreterFrame *fdata) { return ((PyObject **)fdata) - fdata->nlocalsplus; } -/* For use by _Py_framedata_GetFrameObject +/* For use by _Py_InterpreterFrame_GetFrameObject Do not call directly. */ PyFrameObject * -_Py_framedata_MakeAndSetFrameObject(_Py_framedata *fdata); +_Py_InterpreterFrame_MakeAndSetFrameObject(_Py_InterpreterFrame *fdata); /* Gets the PyFrameObject for this frame, lazily * creating it if necessary. * Returns a borrowed referennce */ static inline PyFrameObject * -_Py_framedata_GetFrameObject(_Py_framedata *fdata) +_Py_InterpreterFrame_GetFrameObject(_Py_InterpreterFrame *fdata) { PyFrameObject *res = fdata->frame_obj; if (res != NULL) { return res; } - return _Py_framedata_MakeAndSetFrameObject(fdata); + return _Py_InterpreterFrame_MakeAndSetFrameObject(fdata); } /* Clears all references in the frame. @@ -111,21 +111,21 @@ _Py_framedata_GetFrameObject(_Py_framedata *fdata) * frames like the ones in generators and coroutines. */ int -_Py_framedata_Clear(_Py_framedata *fdata, int take); +_Py_InterpreterFrame_Clear(_Py_InterpreterFrame *fdata, int take); int -_Py_framedata_Traverse(_Py_framedata *fdata, visitproc visit, void *arg); +_Py_InterpreterFrame_Traverse(_Py_InterpreterFrame *fdata, visitproc visit, void *arg); int -_Py_framedata_FastToLocalsWithError(_Py_framedata *frame); +_Py_InterpreterFrame_FastToLocalsWithError(_Py_InterpreterFrame *frame); void -_Py_framedata_LocalsToFast(_Py_framedata *frame, int clear); +_Py_InterpreterFrame_LocalsToFast(_Py_InterpreterFrame *frame, int clear); -_Py_framedata *_PyThreadState_PushFrame( +_Py_InterpreterFrame *_PyThreadState_PushFrame( PyThreadState *tstate, PyFrameConstructor *con, PyObject *locals); -void _PyThreadState_PopFrame(PyThreadState *tstate, _Py_framedata *frame); +void _PyThreadState_PopFrame(PyThreadState *tstate, _Py_InterpreterFrame *frame); #ifdef __cplusplus } diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-08-01-18-18-51.bpo-44800.TCsfH3.rst b/Misc/NEWS.d/next/Core and Builtins/2021-08-01-18-18-51.bpo-44800.TCsfH3.rst index 25f56ae4e11058..e45eb4bc5adb3e 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2021-08-01-18-18-51.bpo-44800.TCsfH3.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2021-08-01-18-18-51.bpo-44800.TCsfH3.rst @@ -2,7 +2,7 @@ Refactored internal APIs for the new lazy frame object creation to more consistently distinguish between the full ``PyFrameObject`` Python object implementation that is still used in the Python and C runtime state introspection APIs (function prefix ``PyFrame``, field prefix ``f_``, typical -variable names ``frame`` and ``f``) and the new ``_Py_framedata`` internal +variable names ``frame`` and ``f``) and the new ``_Py_InterpreterFrame`` internal frame data storage (C structs with no intrinsic instance lifecycle management) -that is now used for code execution (function prefix ``_Py_framedata``, no +that is now used for code execution (function prefix ``_Py_InterpreterFrame``, no field prefix, typical variable name ``fdata``). diff --git a/Misc/gdbinit b/Misc/gdbinit index fdd97a114948ee..017202a098cf4e 100644 --- a/Misc/gdbinit +++ b/Misc/gdbinit @@ -38,11 +38,11 @@ end define pylocals set $_i = 0 while $_i < f->f_fdata->code->co_nlocals - if _Py_framedata_GetLocalsArray(f->f_fdata) + $_i != 0 + if _Py_InterpreterFrame_GetLocalsArray(f->f_fdata) + $_i != 0 set $_names = f->f_fdata->code->co_varnames set $_name = PyUnicode_AsUTF8(PyTuple_GetItem($_names, $_i)) printf "%s:\n", $_name - pyo _Py_framedata_GetLocalsArray(f->f_fdata)[$_i] + pyo _Py_InterpreterFrame_GetLocalsArray(f->f_fdata)[$_i] end set $_i = $_i + 1 end diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c index 265f7f896dce30..d123e2b8df7a64 100644 --- a/Modules/_tracemalloc.c +++ b/Modules/_tracemalloc.c @@ -3,7 +3,7 @@ #include "pycore_pymem.h" // _Py_tracemalloc_config #include "pycore_traceback.h" #include "pycore_hashtable.h" -#include <pycore_framedata.h> +#include <pycore_frame.h> #include "clinic/_tracemalloc.c.h" /*[clinic input] @@ -299,7 +299,7 @@ hashtable_compare_traceback(const void *key1, const void *key2) static void -tracemalloc_get_frame(_Py_framedata *fdata, frame_t *frame) +tracemalloc_get_frame(_Py_InterpreterFrame *fdata, frame_t *frame) { frame->filename = unknown_filename; int lineno = PyCode_Addr2Line(fdata->code, fdata->lasti*2); @@ -393,7 +393,7 @@ traceback_get_frames(traceback_t *traceback) return; } - _Py_framedata *fdata = tstate->fdata; + _Py_InterpreterFrame *fdata = tstate->fdata; for (; fdata != NULL;) { if (traceback->nframe < _Py_tracemalloc_config.max_nframe) { tracemalloc_get_frame(fdata, &traceback->frames[traceback->nframe]); @@ -404,7 +404,7 @@ traceback_get_frames(traceback_t *traceback) traceback->total_nframe++; } - _Py_framedata *back = fdata->previous; + _Py_InterpreterFrame *back = fdata->previous; fdata = back; } } diff --git a/Modules/_xxsubinterpretersmodule.c b/Modules/_xxsubinterpretersmodule.c index 886bba0ac4c216..b1229aea5f1f0d 100644 --- a/Modules/_xxsubinterpretersmodule.c +++ b/Modules/_xxsubinterpretersmodule.c @@ -4,7 +4,7 @@ #include "Python.h" #include "frameobject.h" -#include "pycore_framedata.h" +#include "pycore_frame.h" #include "interpreteridobject.h" @@ -1835,12 +1835,12 @@ _is_running(PyInterpreterState *interp) } assert(!PyErr_Occurred()); - _Py_framedata *fdata = tstate->fdata; + _Py_InterpreterFrame *fdata = tstate->fdata; if (fdata == NULL) { return 0; } - int executing = _Py_framedata_IsExecuting(fdata); + int executing = _Py_InterpreterFrame_IsExecuting(fdata); return executing; } diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c index f566d0cf20eab0..d6ba65f3412af0 100644 --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -7,7 +7,7 @@ #include "pycore_atomic.h" // _Py_atomic_int #include "pycore_call.h" // _PyObject_Call() #include "pycore_ceval.h" // _PyEval_SignalReceived() -#include "pycore_framedata.h" +#include "pycore_frame.h" #include "pycore_moduleobject.h" // _PyModule_GetState() #include "pycore_pyerrors.h" // _PyErr_SetString() #include "pycore_pylifecycle.h" // NSIG @@ -1787,7 +1787,7 @@ _PyErr_CheckSignalsTstate(PyThreadState *tstate) */ _Py_atomic_store(&is_tripped, 0); - _Py_framedata *fdata = tstate->fdata; + _Py_InterpreterFrame *fdata = tstate->fdata; signal_state_t *state = &signal_global_state; for (int i = 1; i < NSIG; i++) { if (!_Py_atomic_load_relaxed(&Handlers[i].tripped)) { @@ -1823,7 +1823,7 @@ _PyErr_CheckSignalsTstate(PyThreadState *tstate) arglist = Py_BuildValue("(iO)", i, Py_None); } else { - PyFrameObject *f = _Py_framedata_GetFrameObject(fdata); + PyFrameObject *f = _Py_InterpreterFrame_GetFrameObject(fdata); if (f != NULL) { arglist = Py_BuildValue("(iO)", i, f); } diff --git a/Objects/frameobject.c b/Objects/frameobject.c index 1f5229589e0bf0..fb6374c1ae43d1 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -7,7 +7,7 @@ #include "pycore_code.h" // CO_FAST_LOCAL, etc. #include "frameobject.h" // PyFrameObject -#include "pycore_framedata.h" +#include "pycore_frame.h" #include "opcode.h" // EXTENDED_ARG #include "structmember.h" // PyMemberDef @@ -625,14 +625,14 @@ frame_dealloc(PyFrameObject *f) /* Kill all local variables including specials, if we own them */ if (f->f_own_locals_memory) { f->f_own_locals_memory = 0; - _Py_framedata *fdata = f->f_fdata; + _Py_InterpreterFrame *fdata = f->f_fdata; /* Don't clear code object until the end */ co = fdata->code; fdata->code = NULL; Py_CLEAR(fdata->globals); Py_CLEAR(fdata->builtins); Py_CLEAR(fdata->locals); - PyObject **locals = _Py_framedata_GetLocalsArray(fdata); + PyObject **locals = _Py_InterpreterFrame_GetLocalsArray(fdata); for (int i = 0; i < co->co_nlocalsplus; i++) { Py_CLEAR(locals[i]); } @@ -671,7 +671,7 @@ frame_traverse(PyFrameObject *f, visitproc visit, void *arg) return 0; } assert(f->f_fdata->frame_obj == NULL); - return _Py_framedata_Traverse(f->f_fdata, visit, arg); + return _Py_InterpreterFrame_Traverse(f->f_fdata, visit, arg); } static int @@ -687,7 +687,7 @@ frame_tp_clear(PyFrameObject *f) Py_CLEAR(f->f_trace); /* locals */ - PyObject **locals = _Py_framedata_GetLocalsArray(f->f_fdata); + PyObject **locals = _Py_InterpreterFrame_GetLocalsArray(f->f_fdata); for (int i = 0; i < f->f_fdata->nlocalsplus; i++) { Py_CLEAR(locals[i]); } @@ -703,7 +703,7 @@ frame_tp_clear(PyFrameObject *f) static PyObject * frame_clear(PyFrameObject *f, PyObject *Py_UNUSED(ignored)) { - if (_Py_framedata_IsExecuting(f->f_fdata)) { + if (_Py_InterpreterFrame_IsExecuting(f->f_fdata)) { PyErr_SetString(PyExc_RuntimeError, "cannot clear an executing frame"); return NULL; @@ -789,7 +789,7 @@ PyTypeObject PyFrame_Type = { _Py_IDENTIFIER(__builtins__); -static _Py_framedata * +static _Py_InterpreterFrame * allocate_heap_frame(PyFrameConstructor *con, PyObject *locals) { PyCodeObject *code = (PyCodeObject *)con->fc_code; @@ -802,13 +802,13 @@ allocate_heap_frame(PyFrameConstructor *con, PyObject *locals) for (Py_ssize_t i=0; i < code->co_nlocalsplus; i++) { localsarray[i] = NULL; } - _Py_framedata *fdata = (_Py_framedata *)(localsarray + code->co_nlocalsplus); - _Py_framedata_InitializeSpecials(fdata, con, locals, code->co_nlocalsplus); + _Py_InterpreterFrame *fdata = (_Py_InterpreterFrame *)(localsarray + code->co_nlocalsplus); + _Py_InterpreterFrame_InitializeSpecials(fdata, con, locals, code->co_nlocalsplus); return fdata; } static inline PyFrameObject* -frame_alloc(_Py_framedata *fdata, int owns) +frame_alloc(_Py_InterpreterFrame *fdata, int owns) { PyFrameObject *f; struct _Py_frame_state *state = get_frame_state(); @@ -843,7 +843,7 @@ frame_alloc(_Py_framedata *fdata, int owns) } PyFrameObject* _Py_HOT_FUNCTION -_PyFrame_New_NoTrack(_Py_framedata *fdata, int owns) +_PyFrame_New_NoTrack(_Py_InterpreterFrame *fdata, int owns) { PyFrameObject *f = frame_alloc(fdata, owns); if (f == NULL) { @@ -876,7 +876,7 @@ PyFrame_New(PyThreadState *tstate, PyCodeObject *code, .fc_kwdefaults = NULL, .fc_closure = NULL }; - _Py_framedata *fdata = allocate_heap_frame(&desc, locals); + _Py_InterpreterFrame *fdata = allocate_heap_frame(&desc, locals); if (fdata == NULL) { return NULL; } @@ -888,7 +888,7 @@ PyFrame_New(PyThreadState *tstate, PyCodeObject *code, } static int -_Py_framedata_OpAlreadyRan(_Py_framedata *fdata, int opcode, int oparg) +_Py_InterpreterFrame_OpAlreadyRan(_Py_InterpreterFrame *fdata, int opcode, int oparg) { const _Py_CODEUNIT *code = (const _Py_CODEUNIT *)PyBytes_AS_STRING(fdata->code->co_code); @@ -901,7 +901,7 @@ _Py_framedata_OpAlreadyRan(_Py_framedata *fdata, int opcode, int oparg) } int -_Py_framedata_FastToLocalsWithError(_Py_framedata *fdata) { +_Py_InterpreterFrame_FastToLocalsWithError(_Py_InterpreterFrame *fdata) { /* Merge fast locals into fdata->locals */ PyObject *locals; PyObject **fast; @@ -913,7 +913,7 @@ _Py_framedata_FastToLocalsWithError(_Py_framedata *fdata) { return -1; } co = fdata->code; - fast = _Py_framedata_GetLocalsArray(fdata); + fast = _Py_InterpreterFrame_GetLocalsArray(fdata); for (int i = 0; i < co->co_nlocalsplus; i++) { _PyLocals_Kind kind = _PyLocals_GetKind(co->co_localspluskinds, i); @@ -945,7 +945,7 @@ _Py_framedata_FastToLocalsWithError(_Py_framedata *fdata) { // run yet. if (value != NULL) { if (PyCell_Check(value) && - _Py_framedata_OpAlreadyRan(fdata, MAKE_CELL, i)) { + _Py_InterpreterFrame_OpAlreadyRan(fdata, MAKE_CELL, i)) { // (likely) MAKE_CELL must have executed already. value = PyCell_GET(value); } @@ -985,7 +985,7 @@ PyFrame_FastToLocalsWithError(PyFrameObject *f) PyErr_BadInternalCall(); return -1; } - return _Py_framedata_FastToLocalsWithError(f->f_fdata); + return _Py_InterpreterFrame_FastToLocalsWithError(f->f_fdata); } void @@ -1001,7 +1001,7 @@ PyFrame_FastToLocals(PyFrameObject *f) } void -_Py_framedata_LocalsToFast(_Py_framedata *fdata, int clear) +_Py_InterpreterFrame_LocalsToFast(_Py_InterpreterFrame *fdata, int clear) { /* Merge locals into fast locals */ PyObject *locals; @@ -1011,7 +1011,7 @@ _Py_framedata_LocalsToFast(_Py_framedata *fdata, int clear) locals = fdata->locals; if (locals == NULL) return; - fast = _Py_framedata_GetLocalsArray(fdata); + fast = _Py_InterpreterFrame_GetLocalsArray(fdata); co = fdata->code; PyErr_Fetch(&error_type, &error_value, &error_traceback); @@ -1042,7 +1042,7 @@ _Py_framedata_LocalsToFast(_Py_framedata *fdata, int clear) else if (kind & CO_FAST_CELL && oldvalue != NULL) { /* Same test as in PyFrame_FastToLocals() above. */ if (PyCell_Check(oldvalue) && - _Py_framedata_OpAlreadyRan(fdata, MAKE_CELL, i)) { + _Py_InterpreterFrame_OpAlreadyRan(fdata, MAKE_CELL, i)) { // (likely) MAKE_CELL must have executed already. cell = oldvalue; } @@ -1072,7 +1072,7 @@ PyFrame_LocalsToFast(PyFrameObject *f, int clear) if (f == NULL || f->f_fdata->state == FRAME_CLEARED) { return; } - _Py_framedata_LocalsToFast(f->f_fdata, clear); + _Py_InterpreterFrame_LocalsToFast(f->f_fdata, clear); } /* Clear out the free list */ @@ -1127,7 +1127,7 @@ PyFrame_GetBack(PyFrameObject *frame) assert(frame != NULL); PyFrameObject *back = frame->f_back; if (back == NULL && frame->f_fdata->previous != NULL) { - back = _Py_framedata_GetFrameObject(frame->f_fdata->previous); + back = _Py_InterpreterFrame_GetFrameObject(frame->f_fdata->previous); } Py_XINCREF(back); return back; diff --git a/Objects/genobject.c b/Objects/genobject.c index a33ff4a60f1c76..2b80671400f360 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -6,7 +6,7 @@ #include "pycore_pyerrors.h" // _PyErr_ClearExcState() #include "pycore_pystate.h" // _PyThreadState_GET() #include "frameobject.h" -#include "pycore_framedata.h" +#include "pycore_frame.h" #include "structmember.h" // PyMemberDef #include "opcode.h" @@ -35,10 +35,10 @@ gen_traverse(PyGenObject *gen, visitproc visit, void *arg) Py_VISIT(gen->gi_code); Py_VISIT(gen->gi_name); Py_VISIT(gen->gi_qualname); - _Py_framedata *fdata = gen->gi_fdata; + _Py_InterpreterFrame *fdata = gen->gi_fdata; if (fdata != NULL) { assert(fdata->frame_obj == NULL || fdata->frame_obj->f_own_locals_memory == 0); - int err = _Py_framedata_Traverse(fdata, visit, arg); + int err = _Py_InterpreterFrame_Traverse(fdata, visit, arg); if (err) { return err; } @@ -55,7 +55,7 @@ _PyGen_Finalize(PyObject *self) PyObject *res = NULL; PyObject *error_type, *error_value, *error_traceback; - if (gen->gi_fdata == NULL || _Py_framedata_HasCompleted(gen->gi_fdata)) { + if (gen->gi_fdata == NULL || _Py_InterpreterFrame_HasCompleted(gen->gi_fdata)) { /* Generator isn't paused, so no need to close */ return; } @@ -130,11 +130,11 @@ gen_dealloc(PyGenObject *gen) and GC_Del. */ Py_CLEAR(((PyAsyncGenObject*)gen)->ag_finalizer); } - _Py_framedata *fdata = gen->gi_fdata; + _Py_InterpreterFrame *fdata = gen->gi_fdata; if (fdata != NULL) { gen->gi_fdata = NULL; fdata->previous = NULL; - _Py_framedata_Clear(fdata, 1); + _Py_InterpreterFrame_Clear(fdata, 1); } if (((PyCodeObject *)gen->gi_code)->co_flags & CO_COROUTINE) { Py_CLEAR(((PyCoroObject *)gen)->cr_origin); @@ -151,11 +151,11 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult, int exc, int closing) { PyThreadState *tstate = _PyThreadState_GET(); - _Py_framedata *fdata = gen->gi_fdata; + _Py_InterpreterFrame *fdata = gen->gi_fdata; PyObject *result; *presult = NULL; - if (fdata != NULL && _Py_framedata_IsExecuting(fdata)) { + if (fdata != NULL && _Py_InterpreterFrame_IsExecuting(fdata)) { const char *msg = "generator already executing"; if (PyCoro_CheckExact(gen)) { msg = "coroutine already executing"; @@ -166,7 +166,7 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult, PyErr_SetString(PyExc_ValueError, msg); return PYGEN_ERROR; } - if (fdata == NULL || _Py_framedata_HasCompleted(fdata)) { + if (fdata == NULL || _Py_InterpreterFrame_HasCompleted(fdata)) { if (PyCoro_CheckExact(gen) && !closing) { /* `gen` is an exhausted coroutine: raise an error, except when called from gen_close(), which should @@ -185,7 +185,7 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult, return PYGEN_ERROR; } - assert(_Py_framedata_IsRunnable(fdata)); + assert(_Py_InterpreterFrame_IsRunnable(fdata)); assert(fdata->lasti >= 0 || ((unsigned char *)PyBytes_AS_STRING(gen->gi_code->co_code))[0] == GEN_START); /* Push arg onto the frame's value stack */ result = arg ? arg : Py_None; @@ -216,7 +216,7 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult, /* If the generator just returned (as opposed to yielding), signal * that the generator is exhausted. */ if (result) { - if (!_Py_framedata_HasCompleted(fdata)) { + if (!_Py_InterpreterFrame_HasCompleted(fdata)) { *presult = result; return PYGEN_NEXT; } @@ -254,7 +254,7 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult, fdata->generator = NULL; gen->gi_fdata = NULL; - _Py_framedata_Clear(fdata, 1); + _Py_InterpreterFrame_Clear(fdata, 1); *presult = result; return result ? PYGEN_RETURN : PYGEN_ERROR; } @@ -336,7 +336,7 @@ _PyGen_yf(PyGenObject *gen) PyObject *yf = NULL; if (gen->gi_fdata) { - _Py_framedata *fdata = gen->gi_fdata; + _Py_InterpreterFrame *fdata = gen->gi_fdata; PyObject *bytecode = gen->gi_code->co_code; unsigned char *code = (unsigned char *)PyBytes_AS_STRING(bytecode); @@ -428,7 +428,7 @@ _gen_throw(PyGenObject *gen, int close_on_genexit, if (PyGen_CheckExact(yf) || PyCoro_CheckExact(yf)) { /* `yf` is a generator or a coroutine. */ PyThreadState *tstate = _PyThreadState_GET(); - _Py_framedata *fdata = gen->gi_fdata; + _Py_InterpreterFrame *fdata = gen->gi_fdata; /* Since we are fast-tracking things by skipping the eval loop, @@ -436,7 +436,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. */ - _Py_framedata *prev = tstate->fdata; + _Py_InterpreterFrame *prev = tstate->fdata; fdata->previous = prev; tstate->fdata = fdata; /* Close the generator that we are currently iterating with @@ -736,7 +736,7 @@ gen_getrunning(PyGenObject *gen, void *Py_UNUSED(ignored)) if (gen->gi_fdata == NULL) { Py_RETURN_FALSE; } - return PyBool_FromLong(_Py_framedata_IsExecuting(gen->gi_fdata)); + return PyBool_FromLong(_Py_InterpreterFrame_IsExecuting(gen->gi_fdata)); } static PyObject * @@ -748,7 +748,7 @@ _gen_getframe(PyGenObject *gen, const char *const name) if (gen->gi_fdata == NULL) { Py_RETURN_NONE; } - return _Py_XNewRef((PyObject *)_Py_framedata_GetFrameObject(gen->gi_fdata)); + return _Py_XNewRef((PyObject *)_Py_InterpreterFrame_GetFrameObject(gen->gi_fdata)); } static PyObject * @@ -843,12 +843,12 @@ PyTypeObject PyGen_Type = { }; static PyObject * -make_gen(PyTypeObject *type, PyFrameConstructor *con, _Py_framedata *fdata) +make_gen(PyTypeObject *type, PyFrameConstructor *con, _Py_InterpreterFrame *fdata) { PyGenObject *gen = PyObject_GC_New(PyGenObject, type); if (gen == NULL) { assert(fdata->frame_obj == NULL); - _Py_framedata_Clear(fdata, 1); + _Py_InterpreterFrame_Clear(fdata, 1); return NULL; } gen->gi_fdata = fdata; @@ -878,7 +878,7 @@ static PyObject * compute_cr_origin(int origin_depth); PyObject * -_Py_MakeCoro(PyFrameConstructor *con, _Py_framedata *fdata) +_Py_MakeCoro(PyFrameConstructor *con, _Py_InterpreterFrame *fdata) { int coro_flags = ((PyCodeObject *)con->fc_code)->co_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR); @@ -1075,7 +1075,7 @@ cr_getrunning(PyCoroObject *coro, void *Py_UNUSED(ignored)) if (coro->cr_fdata == NULL) { Py_RETURN_FALSE; } - return PyBool_FromLong(_Py_framedata_IsExecuting(coro->cr_fdata)); + return PyBool_FromLong(_Py_InterpreterFrame_IsExecuting(coro->cr_fdata)); } static PyObject * @@ -1271,7 +1271,7 @@ PyTypeObject _PyCoroWrapper_Type = { static PyObject * compute_cr_origin(int origin_depth) { - _Py_framedata *fdata = _PyEval_GetFrameData(); + _Py_InterpreterFrame *fdata = _PyEval_GetFrameData(); /* First count how many frames we have */ int frame_count = 0; for (; fdata && frame_count < origin_depth; ++frame_count) { @@ -1990,7 +1990,7 @@ static PyObject * async_gen_athrow_send(PyAsyncGenAThrow *o, PyObject *arg) { PyGenObject *gen = (PyGenObject*)o->agt_gen; - _Py_framedata *fdata = gen->gi_fdata; + _Py_InterpreterFrame *fdata = gen->gi_fdata; PyObject *retval; if (o->agt_state == AWAITABLE_STATE_CLOSED) { @@ -2000,7 +2000,7 @@ async_gen_athrow_send(PyAsyncGenAThrow *o, PyObject *arg) return NULL; } - if (fdata == NULL || _Py_framedata_HasCompleted(fdata)) { + if (fdata == NULL || _Py_InterpreterFrame_HasCompleted(fdata)) { o->agt_state = AWAITABLE_STATE_CLOSED; PyErr_SetNone(PyExc_StopIteration); return NULL; diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 7dba0059659821..939c8aef1ee3fa 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -11,7 +11,7 @@ #include "pycore_pystate.h" // _PyThreadState_GET() #include "pycore_unionobject.h" // _Py_union_type_or #include "frameobject.h" -#include "pycore_framedata.h" +#include "pycore_frame.h" #include "opcode.h" // MAKE_CELL #include "structmember.h" // PyMemberDef @@ -8875,7 +8875,7 @@ super_init_without_args(PyFrameObject *f, PyCodeObject *co, } assert(f->f_fdata->nlocalsplus > 0); - PyObject *firstarg = _Py_framedata_GetLocalsArray(f->f_fdata)[0]; + PyObject *firstarg = _Py_InterpreterFrame_GetLocalsArray(f->f_fdata)[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() @@ -8900,7 +8900,7 @@ super_init_without_args(PyFrameObject *f, PyCodeObject *co, PyObject *name = PyTuple_GET_ITEM(co->co_localsplusnames, i); assert(PyUnicode_Check(name)); if (_PyUnicode_EqualToASCIIId(name, &PyId___class__)) { - PyObject *cell = _Py_framedata_GetLocalsArray(f->f_fdata)[i]; + PyObject *cell = _Py_InterpreterFrame_GetLocalsArray(f->f_fdata)[i]; if (cell == NULL || !PyCell_Check(cell)) { PyErr_SetString(PyExc_RuntimeError, "super(): bad __class__ cell"); diff --git a/Python/_warnings.c b/Python/_warnings.c index 0820280d92bdbf..9d9434d7afb643 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -5,7 +5,7 @@ #include "pycore_pyerrors.h" #include "pycore_pystate.h" // _PyThreadState_GET() #include "frameobject.h" // PyFrame_GetBack() -#include "pycore_framedata.h" +#include "pycore_frame.h" #include "clinic/_warnings.c.h" #define MODULE_NAME "_warnings" diff --git a/Python/ceval.c b/Python/ceval.c index 58d9bc8ca6ce27..98606b51f59934 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -29,7 +29,7 @@ #include "pycore_dict.h" #include "dictobject.h" #include "frameobject.h" -#include "pycore_framedata.h" +#include "pycore_frame.h" #include "opcode.h" #include "pydtrace.h" #include "setobject.h" @@ -60,7 +60,7 @@ static PyObject * do_call_core( #ifdef LLTRACE static int lltrace; static int prtrace(PyThreadState *, PyObject *, const char *); -static void lltrace_instruction(_Py_framedata *fdata, int opcode, int oparg) +static void lltrace_instruction(_Py_InterpreterFrame *fdata, int opcode, int oparg) { if (HAS_ARG(opcode)) { printf("%d: %d, %d\n", @@ -73,27 +73,27 @@ static void lltrace_instruction(_Py_framedata *fdata, int opcode, int oparg) } #endif static int call_trace(Py_tracefunc, PyObject *, - PyThreadState *, _Py_framedata *, + PyThreadState *, _Py_InterpreterFrame *, int, PyObject *); static int call_trace_protected(Py_tracefunc, PyObject *, - PyThreadState *, _Py_framedata *, + PyThreadState *, _Py_InterpreterFrame *, int, PyObject *); static void call_exc_trace(Py_tracefunc, PyObject *, - PyThreadState *, _Py_framedata *); + PyThreadState *, _Py_InterpreterFrame *); static int maybe_call_line_trace(Py_tracefunc, PyObject *, - PyThreadState *, _Py_framedata *, int); -static void maybe_dtrace_line(_Py_framedata *, PyTraceInfo *, int); -static void dtrace_function_entry(_Py_framedata *); -static void dtrace_function_return(_Py_framedata *); + PyThreadState *, _Py_InterpreterFrame *, int); +static void maybe_dtrace_line(_Py_InterpreterFrame *, PyTraceInfo *, int); +static void dtrace_function_entry(_Py_InterpreterFrame *); +static void dtrace_function_return(_Py_InterpreterFrame *); -static PyObject * import_name(PyThreadState *, _Py_framedata *, +static PyObject * import_name(PyThreadState *, _Py_InterpreterFrame *, PyObject *, PyObject *, PyObject *); static PyObject * import_from(PyThreadState *, PyObject *, PyObject *); static int import_all_from(PyThreadState *, PyObject *, PyObject *); static void format_exc_check_arg(PyThreadState *, PyObject *, const char *, PyObject *); static void format_exc_unbound(PyThreadState *tstate, PyCodeObject *co, int oparg); static PyObject * unicode_concatenate(PyThreadState *, PyObject *, PyObject *, - _Py_framedata *, const _Py_CODEUNIT *); + _Py_InterpreterFrame *, const _Py_CODEUNIT *); static int check_args_iterable(PyThreadState *, PyObject *func, PyObject *vararg); static void format_kwargs_error(PyThreadState *, PyObject *func, PyObject *kwargs); static void format_awaitable_error(PyThreadState *, PyTypeObject *, int, int); @@ -1461,7 +1461,7 @@ eval_frame_handle_pending(PyThreadState *tstate) Py_INCREF(res); static int -trace_function_entry(PyThreadState *tstate, _Py_framedata *fdata) +trace_function_entry(PyThreadState *tstate, _Py_InterpreterFrame *fdata) { if (tstate->c_tracefunc != NULL) { /* tstate->c_tracefunc, if defined, is a @@ -1500,7 +1500,7 @@ trace_function_entry(PyThreadState *tstate, _Py_framedata *fdata) } PyObject* _Py_HOT_FUNCTION -_PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwflag) +_PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_InterpreterFrame *fdata, int throwflag) { _Py_EnsureTstateNotNULL(tstate); @@ -1559,7 +1559,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf PyObject *names = co->co_names; PyObject *consts = co->co_consts; - PyObject **localsplus = _Py_framedata_GetLocalsArray(fdata); + PyObject **localsplus = _Py_InterpreterFrame_GetLocalsArray(fdata); _Py_CODEUNIT *first_instr = co->co_firstinstr; /* fdata->lasti refers to the index of the last instruction, @@ -3814,7 +3814,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf TARGET(IMPORT_STAR): { PyObject *from = POP(), *locals; int err; - if (_Py_framedata_FastToLocalsWithError(fdata) < 0) { + if (_Py_InterpreterFrame_FastToLocalsWithError(fdata) < 0) { Py_DECREF(from); goto error; } @@ -3827,7 +3827,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf goto error; } err = import_all_from(tstate, locals, from); - _Py_framedata_LocalsToFast(fdata, 0); + _Py_InterpreterFrame_LocalsToFast(fdata, 0); Py_DECREF(from); if (err != 0) goto error; @@ -4793,7 +4793,7 @@ MISS_WITH_OPARG_COUNTER(BINARY_SUBSCR) #endif /* Log traceback info. */ - PyFrameObject *f = _Py_framedata_GetFrameObject(fdata); + PyFrameObject *f = _Py_InterpreterFrame_GetFrameObject(fdata); if (f != NULL) { PyTraceBack_Here(f); } @@ -5396,7 +5396,7 @@ initialize_locals(PyThreadState *tstate, PyFrameConstructor *con, } -static _Py_framedata * +static _Py_InterpreterFrame * make_coro_frame(PyThreadState *tstate, PyFrameConstructor *con, PyObject *locals, PyObject *const *args, Py_ssize_t argcount, @@ -5414,11 +5414,11 @@ make_coro_frame(PyThreadState *tstate, for (Py_ssize_t i=0; i < code->co_nlocalsplus; i++) { localsarray[i] = NULL; } - _Py_framedata *fdata = (_Py_framedata *)(localsarray + code->co_nlocalsplus); - _Py_framedata_InitializeSpecials(fdata, con, locals, code->co_nlocalsplus); + _Py_InterpreterFrame *fdata = (_Py_InterpreterFrame *)(localsarray + code->co_nlocalsplus); + _Py_InterpreterFrame_InitializeSpecials(fdata, con, locals, code->co_nlocalsplus); assert(fdata->frame_obj == NULL); if (initialize_locals(tstate, con, localsarray, args, argcount, kwnames)) { - _Py_framedata_Clear(fdata, 1); + _Py_InterpreterFrame_Clear(fdata, 1); return NULL; } return fdata; @@ -5431,7 +5431,7 @@ make_coro(PyThreadState *tstate, PyFrameConstructor *con, PyObject *kwnames) { assert (((PyCodeObject *)con->fc_code)->co_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR)); - _Py_framedata *fdata = make_coro_frame(tstate, con, locals, args, argcount, kwnames); + _Py_InterpreterFrame *fdata = make_coro_frame(tstate, con, locals, args, argcount, kwnames); if (fdata == NULL) { return NULL; } @@ -5443,18 +5443,18 @@ make_coro(PyThreadState *tstate, PyFrameConstructor *con, return gen; } -static _Py_framedata * +static _Py_InterpreterFrame * _PyEvalFramePushAndInit(PyThreadState *tstate, PyFrameConstructor *con, PyObject *locals, PyObject* const* args, size_t argcount, PyObject *kwnames) { - _Py_framedata * fdata = _PyThreadState_PushFrame(tstate, con, locals); + _Py_InterpreterFrame * fdata = _PyThreadState_PushFrame(tstate, con, locals); if (fdata == NULL) { return NULL; } - PyObject **localsarray = _Py_framedata_GetLocalsArray(fdata); + PyObject **localsarray = _Py_InterpreterFrame_GetLocalsArray(fdata); if (initialize_locals(tstate, con, localsarray, args, argcount, kwnames)) { - _Py_framedata_Clear(fdata, 0); + _Py_InterpreterFrame_Clear(fdata, 0); return NULL; } fdata->previous = tstate->fdata; @@ -5463,11 +5463,11 @@ _PyEvalFramePushAndInit(PyThreadState *tstate, PyFrameConstructor *con, } static int -_PyEvalFrameClearAndPop(PyThreadState *tstate, _Py_framedata * fdata) +_PyEvalFrameClearAndPop(PyThreadState *tstate, _Py_InterpreterFrame * fdata) { ++tstate->recursion_depth; assert(fdata->frame_obj == NULL || fdata->frame_obj->f_own_locals_memory == 0); - if (_Py_framedata_Clear(fdata, 0)) { + if (_Py_InterpreterFrame_Clear(fdata, 0)) { return -1; } assert(fdata->frame_obj == NULL); @@ -5489,7 +5489,7 @@ _PyEval_Vector(PyThreadState *tstate, PyFrameConstructor *con, if (is_coro) { return make_coro(tstate, con, locals, args, argcount, kwnames); } - _Py_framedata *fdata = _PyEvalFramePushAndInit( + _Py_InterpreterFrame *fdata = _PyEvalFramePushAndInit( tstate, con, locals, args, argcount, kwnames); if (fdata == NULL) { return NULL; @@ -5806,7 +5806,7 @@ prtrace(PyThreadState *tstate, PyObject *v, const char *str) static void call_exc_trace(Py_tracefunc func, PyObject *self, PyThreadState *tstate, - _Py_framedata *fdata) + _Py_InterpreterFrame *fdata) { PyObject *type, *value, *traceback, *orig_traceback, *arg; int err; @@ -5836,7 +5836,7 @@ call_exc_trace(Py_tracefunc func, PyObject *self, static int call_trace_protected(Py_tracefunc func, PyObject *obj, - PyThreadState *tstate, _Py_framedata *fdata, + PyThreadState *tstate, _Py_InterpreterFrame *fdata, int what, PyObject *arg) { PyObject *type, *value, *traceback; @@ -5857,7 +5857,7 @@ call_trace_protected(Py_tracefunc func, PyObject *obj, } static void -initialize_trace_info(PyTraceInfo *trace_info, _Py_framedata *fdata) +initialize_trace_info(PyTraceInfo *trace_info, _Py_InterpreterFrame *fdata) { PyCodeObject *code = fdata->code; if (trace_info->code != code) { @@ -5868,7 +5868,7 @@ initialize_trace_info(PyTraceInfo *trace_info, _Py_framedata *fdata) static int call_trace(Py_tracefunc func, PyObject *obj, - PyThreadState *tstate, _Py_framedata *fdata, + PyThreadState *tstate, _Py_InterpreterFrame *fdata, int what, PyObject *arg) { int result; @@ -5876,7 +5876,7 @@ call_trace(Py_tracefunc func, PyObject *obj, return 0; tstate->tracing++; tstate->cframe->use_tracing = 0; - PyFrameObject *f = _Py_framedata_GetFrameObject(fdata); + PyFrameObject *f = _Py_InterpreterFrame_GetFrameObject(fdata); if (f == NULL) { return -1; } @@ -5915,7 +5915,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, _Py_framedata *fdata, int instr_prev) + PyThreadState *tstate, _Py_InterpreterFrame *fdata, int instr_prev) { int result = 0; @@ -5926,7 +5926,7 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj, initialize_trace_info(&tstate->trace_info, fdata); int lastline = _PyCode_CheckLineNumber(instr_prev*2, &tstate->trace_info.bounds); int line = _PyCode_CheckLineNumber(fdata->lasti*2, &tstate->trace_info.bounds); - PyFrameObject *f = _Py_framedata_GetFrameObject(fdata); + PyFrameObject *f = _Py_InterpreterFrame_GetFrameObject(fdata); if (f == NULL) { return -1; } @@ -6084,7 +6084,7 @@ _PyEval_GetAsyncGenFinalizer(void) return tstate->async_gen_finalizer; } -_Py_framedata * +_Py_InterpreterFrame * _PyEval_GetFrameData(void) { PyThreadState *tstate = _PyThreadState_GET(); @@ -6098,7 +6098,7 @@ PyEval_GetFrame(void) if (tstate->fdata == NULL) { return NULL; } - PyFrameObject *f = _Py_framedata_GetFrameObject(tstate->fdata); + PyFrameObject *f = _Py_InterpreterFrame_GetFrameObject(tstate->fdata); if (f == NULL) { PyErr_Clear(); } @@ -6108,7 +6108,7 @@ PyEval_GetFrame(void) PyObject * _PyEval_GetBuiltins(PyThreadState *tstate) { - _Py_framedata *fdata = tstate->fdata; + _Py_InterpreterFrame *fdata = tstate->fdata; if (fdata != NULL) { return fdata->builtins; } @@ -6141,13 +6141,13 @@ PyObject * PyEval_GetLocals(void) { PyThreadState *tstate = _PyThreadState_GET(); - _Py_framedata *fdata = tstate->fdata; + _Py_InterpreterFrame *fdata = tstate->fdata; if (fdata == NULL) { _PyErr_SetString(tstate, PyExc_SystemError, "frame does not exist"); return NULL; } - if (_Py_framedata_FastToLocalsWithError(fdata) < 0) { + if (_Py_InterpreterFrame_FastToLocalsWithError(fdata) < 0) { return NULL; } @@ -6160,7 +6160,7 @@ PyObject * PyEval_GetGlobals(void) { PyThreadState *tstate = _PyThreadState_GET(); - _Py_framedata *fdata = tstate->fdata; + _Py_InterpreterFrame *fdata = tstate->fdata; if (fdata == NULL) { return NULL; } @@ -6171,7 +6171,7 @@ int PyEval_MergeCompilerFlags(PyCompilerFlags *cf) { PyThreadState *tstate = _PyThreadState_GET(); - _Py_framedata *fdata = tstate->fdata; + _Py_InterpreterFrame *fdata = tstate->fdata; int result = cf->cf_flags != 0; if (fdata != NULL) { @@ -6409,7 +6409,7 @@ _PyEval_SliceIndexNotNone(PyObject *v, Py_ssize_t *pi) } static PyObject * -import_name(PyThreadState *tstate, _Py_framedata *fdata, +import_name(PyThreadState *tstate, _Py_InterpreterFrame *fdata, PyObject *name, PyObject *fromlist, PyObject *level) { _Py_IDENTIFIER(__import__); @@ -6748,7 +6748,7 @@ format_awaitable_error(PyThreadState *tstate, PyTypeObject *type, int prevprevop static PyObject * unicode_concatenate(PyThreadState *tstate, PyObject *v, PyObject *w, - _Py_framedata *fdata, const _Py_CODEUNIT *next_instr) + _Py_InterpreterFrame *fdata, const _Py_CODEUNIT *next_instr) { PyObject *res; if (Py_REFCNT(v) == 2) { @@ -6763,14 +6763,14 @@ unicode_concatenate(PyThreadState *tstate, PyObject *v, PyObject *w, switch (opcode) { case STORE_FAST: { - PyObject **localsplus = _Py_framedata_GetLocalsArray(fdata); + PyObject **localsplus = _Py_InterpreterFrame_GetLocalsArray(fdata); if (GETLOCAL(oparg) == v) SETLOCAL(oparg, NULL); break; } case STORE_DEREF: { - PyObject *c = _Py_framedata_GetLocalsArray(fdata)[oparg]; + PyObject *c = _Py_InterpreterFrame_GetLocalsArray(fdata)[oparg]; if (PyCell_GET(c) == v) { PyCell_SET(c, NULL); Py_DECREF(v); @@ -6859,7 +6859,7 @@ _PyEval_RequestCodeExtraIndex(freefunc free) } static void -dtrace_function_entry(_Py_framedata *fdata) +dtrace_function_entry(_Py_InterpreterFrame *fdata) { const char *filename; const char *funcname; @@ -6874,7 +6874,7 @@ dtrace_function_entry(_Py_framedata *fdata) } static void -dtrace_function_return(_Py_framedata *fdata) +dtrace_function_return(_Py_InterpreterFrame *fdata) { const char *filename; const char *funcname; @@ -6890,7 +6890,7 @@ dtrace_function_return(_Py_framedata *fdata) /* DTrace equivalent of maybe_call_line_trace. */ static void -maybe_dtrace_line(_Py_framedata *fdata, +maybe_dtrace_line(_Py_InterpreterFrame *fdata, PyTraceInfo *trace_info, int instr_prev) { diff --git a/Python/frame.c b/Python/frame.c index f9497d627ab343..85855ef28e4c32 100644 --- a/Python/frame.c +++ b/Python/frame.c @@ -1,11 +1,11 @@ #include "Python.h" #include "frameobject.h" -#include "pycore_framedata.h" +#include "pycore_frame.h" #include "pycore_object.h" // _PyObject_GC_UNTRACK() int -_Py_framedata_Traverse(_Py_framedata *fdata, visitproc visit, void *arg) +_Py_InterpreterFrame_Traverse(_Py_InterpreterFrame *fdata, visitproc visit, void *arg) { Py_VISIT(fdata->frame_obj); Py_VISIT(fdata->globals); @@ -13,7 +13,7 @@ _Py_framedata_Traverse(_Py_framedata *fdata, visitproc visit, void *arg) Py_VISIT(fdata->locals); Py_VISIT(fdata->code); /* locals */ - PyObject **locals = _Py_framedata_GetLocalsArray(fdata); + PyObject **locals = _Py_InterpreterFrame_GetLocalsArray(fdata); for (int i = 0; i < fdata->nlocalsplus; i++) { Py_VISIT(locals[i]); } @@ -25,7 +25,7 @@ _Py_framedata_Traverse(_Py_framedata *fdata, visitproc visit, void *arg) } PyFrameObject * -_Py_framedata_MakeAndSetFrameObject(_Py_framedata *fdata) +_Py_InterpreterFrame_MakeAndSetFrameObject(_Py_InterpreterFrame *fdata) { assert(fdata->frame_obj == NULL); PyObject *error_type, *error_value, *error_traceback; @@ -44,11 +44,11 @@ _Py_framedata_MakeAndSetFrameObject(_Py_framedata *fdata) } -static _Py_framedata * -copy_frame_to_heap(_Py_framedata *fdata) +static _Py_InterpreterFrame * +copy_frame_to_heap(_Py_InterpreterFrame *fdata) { - PyObject **locals = _Py_framedata_GetLocalsArray(fdata); + PyObject **locals = _Py_InterpreterFrame_GetLocalsArray(fdata); Py_ssize_t size = ((char*)&fdata->stack[fdata->stackdepth]) - (char *)locals; PyObject **copy = PyMem_Malloc(size); if (copy == NULL) { @@ -56,12 +56,12 @@ copy_frame_to_heap(_Py_framedata *fdata) return NULL; } memcpy(copy, locals, size); - _Py_framedata *res = (_Py_framedata *)(copy + fdata->nlocalsplus); + _Py_InterpreterFrame *res = (_Py_InterpreterFrame *)(copy + fdata->nlocalsplus); return res; } static inline void -clear_specials(_Py_framedata *fdata) +clear_specials(_Py_InterpreterFrame *fdata) { fdata->generator = NULL; Py_XDECREF(fdata->frame_obj); @@ -72,7 +72,7 @@ clear_specials(_Py_framedata *fdata) } static void -take_ownership(PyFrameObject *f, _Py_framedata *fdata) +take_ownership(PyFrameObject *f, _Py_InterpreterFrame *fdata) { assert(f->f_own_locals_memory == 0); assert(fdata->frame_obj == NULL); @@ -82,7 +82,7 @@ take_ownership(PyFrameObject *f, _Py_framedata *fdata) assert(f->f_back == NULL); if (fdata->previous != NULL) { /* Link frame object's 'f_back' and remove link through frame data's 'previous' field */ - PyFrameObject *back = _Py_framedata_GetFrameObject(fdata->previous); + PyFrameObject *back = _Py_InterpreterFrame_GetFrameObject(fdata->previous); if (back == NULL) { /* Memory error here. */ assert(PyErr_ExceptionMatches(PyExc_MemoryError)); @@ -101,7 +101,7 @@ take_ownership(PyFrameObject *f, _Py_framedata *fdata) } int -_Py_framedata_Clear(_Py_framedata * fdata, int take) +_Py_InterpreterFrame_Clear(_Py_InterpreterFrame * fdata, int take) { PyObject **localsarray = ((PyObject **)fdata)-fdata->nlocalsplus; if (fdata->frame_obj) { @@ -129,7 +129,7 @@ _Py_framedata_Clear(_Py_framedata * fdata, int take) } clear_specials(fdata); if (take) { - PyMem_Free(_Py_framedata_GetLocalsArray(fdata)); + PyMem_Free(_Py_InterpreterFrame_GetLocalsArray(fdata)); } return 0; } diff --git a/Python/pystate.c b/Python/pystate.c index 76cb9dafe09825..9a1e38d8ca1706 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -3,7 +3,7 @@ #include "Python.h" #include "pycore_ceval.h" -#include "pycore_framedata.h" +#include "pycore_frame.h" #include "pycore_initconfig.h" #include "pycore_object.h" // _PyType_InitCache() #include "pycore_pyerrors.h" @@ -1137,7 +1137,7 @@ PyThreadState_GetFrame(PyThreadState *tstate) if (tstate->fdata == NULL) { return NULL; } - PyFrameObject *frame = _Py_framedata_GetFrameObject(tstate->fdata); + PyFrameObject *frame = _Py_InterpreterFrame_GetFrameObject(tstate->fdata); if (frame == NULL) { PyErr_Clear(); } @@ -1261,7 +1261,7 @@ _PyThread_CurrentFrames(void) for (i = runtime->interpreters.head; i != NULL; i = i->next) { PyThreadState *t; for (t = i->tstate_head; t != NULL; t = t->next) { - _Py_framedata *fdata = t->fdata; + _Py_InterpreterFrame *fdata = t->fdata; if (fdata == NULL) { continue; } @@ -1269,7 +1269,7 @@ _PyThread_CurrentFrames(void) if (id == NULL) { goto fail; } - int stat = PyDict_SetItem(result, id, (PyObject *)_Py_framedata_GetFrameObject(fdata)); + int stat = PyDict_SetItem(result, id, (PyObject *)_Py_InterpreterFrame_GetFrameObject(fdata)); Py_DECREF(id); if (stat < 0) { goto fail; @@ -2037,7 +2037,7 @@ push_chunk(PyThreadState *tstate, int size) return res; } -_Py_framedata * +_Py_InterpreterFrame * _PyThreadState_PushFrame(PyThreadState *tstate, PyFrameConstructor *con, PyObject *locals) { PyCodeObject *code = (PyCodeObject *)con->fc_code; @@ -2056,8 +2056,8 @@ _PyThreadState_PushFrame(PyThreadState *tstate, PyFrameConstructor *con, PyObjec else { tstate->datastack_top = top; } - _Py_framedata * fdata = (_Py_framedata *)(localsarray + nlocalsplus); - _Py_framedata_InitializeSpecials(fdata, con, locals, nlocalsplus); + _Py_InterpreterFrame * fdata = (_Py_InterpreterFrame *)(localsarray + nlocalsplus); + _Py_InterpreterFrame_InitializeSpecials(fdata, con, locals, nlocalsplus); for (int i=0; i < nlocalsplus; i++) { localsarray[i] = NULL; } @@ -2065,9 +2065,9 @@ _PyThreadState_PushFrame(PyThreadState *tstate, PyFrameConstructor *con, PyObjec } void -_PyThreadState_PopFrame(PyThreadState *tstate, _Py_framedata * fdata) +_PyThreadState_PopFrame(PyThreadState *tstate, _Py_InterpreterFrame * fdata) { - PyObject **locals = _Py_framedata_GetLocalsArray(fdata); + PyObject **locals = _Py_InterpreterFrame_GetLocalsArray(fdata); if (locals == &tstate->datastack_chunk->data[0]) { _PyStackChunk *chunk = tstate->datastack_chunk; _PyStackChunk *previous = chunk->previous; diff --git a/Python/suggestions.c b/Python/suggestions.c index 4d9f5dddd80c42..250437c3f302dd 100644 --- a/Python/suggestions.c +++ b/Python/suggestions.c @@ -1,6 +1,6 @@ #include "Python.h" #include "frameobject.h" -#include "pycore_framedata.h" +#include "pycore_frame.h" #include "pycore_pyerrors.h" #include "pycore_code.h" // _PyCode_GetVarnames() diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 873e40ea1757a4..b35404eec262c8 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -29,7 +29,7 @@ Data members: #include "code.h" #include "frameobject.h" // PyFrame_GetBack() -#include "pycore_framedata.h" +#include "pycore_frame.h" #include "pydtrace.h" #include "osdefs.h" // DELIM #include "stdlib_module_names.h" // _Py_stdlib_module_names @@ -1815,7 +1815,7 @@ sys__getframe_impl(PyObject *module, int depth) /*[clinic end generated code: output=d438776c04d59804 input=c1be8a6464b11ee5]*/ { PyThreadState *tstate = _PyThreadState_GET(); - _Py_framedata *fdata = tstate->fdata; + _Py_InterpreterFrame *fdata = tstate->fdata; if (_PySys_Audit(tstate, "sys._getframe", NULL) < 0) { return NULL; @@ -1830,7 +1830,7 @@ sys__getframe_impl(PyObject *module, int depth) "call stack is not deep enough"); return NULL; } - return _Py_XNewRef((PyObject *)_Py_framedata_GetFrameObject(fdata)); + return _Py_XNewRef((PyObject *)_Py_InterpreterFrame_GetFrameObject(fdata)); } /*[clinic input] diff --git a/Python/traceback.c b/Python/traceback.c index 2cd8525ed865da..0a7cf4d5a352d6 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -6,7 +6,7 @@ #include "code.h" // PyCode_Addr2Line etc #include "pycore_interp.h" // PyInterpreterState.gc #include "frameobject.h" // PyFrame_GetBack() -#include "pycore_framedata.h" // _Py_framedata_GetCode() +#include "pycore_frame.h" // _Py_InterpreterFrame_GetCode() #include "pycore_pyarena.h" // _PyArena_Free() #include "pycore_ast.h" // asdl_seq_* #include "pycore_compile.h" // _PyAST_Optimize @@ -1024,7 +1024,7 @@ _Py_DumpASCII(int fd, PyObject *text) This function is signal safe. */ static void -dump_frame(int fd, _Py_framedata *fdata) +dump_frame(int fd, _Py_InterpreterFrame *fdata) { PyCodeObject *code = fdata->code; PUTS(fd, " File "); @@ -1062,7 +1062,7 @@ dump_frame(int fd, _Py_framedata *fdata) static void dump_traceback(int fd, PyThreadState *tstate, int write_header) { - _Py_framedata *fdata; + _Py_InterpreterFrame *fdata; unsigned int depth; if (write_header) { diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py index f0b11e67eb25f4..690d2ee1d0f08b 100755 --- a/Tools/gdb/libpython.py +++ b/Tools/gdb/libpython.py @@ -861,7 +861,7 @@ def __init__(self, gdbval, cast_to=None): PyObjectPtr.__init__(self, gdbval, cast_to) if not self.is_optimized_out(): - self._fdata = _Py_framedataPtr(self.field('f_fdata')) + self._fdata = _Py_InterpreterFramePtr(self.field('f_fdata')) def iter_locals(self): ''' @@ -932,7 +932,7 @@ def print_traceback(self): return return self._fdata.print_traceback() -class _Py_framedataPtr: +class _Py_InterpreterFramePtr: def __init__(self, gdbval): self._gdbval = gdbval @@ -1734,7 +1734,7 @@ def is_gc_collect(self): def get_pyop(self): try: fdata = self._gdbframe.read_var('fdata') - fdata = _Py_framedataPtr(fdata) + fdata = _Py_InterpreterFramePtr(fdata) if not fdata.is_optimized_out(): return fdata # gdb is unable to get the "fdata" argument of PyEval_EvalFrameEx() @@ -1744,7 +1744,7 @@ def get_pyop(self): caller = self._gdbframe.older() if caller: fdata = caller.read_var('fdata') - fdata = _Py_framedataPtr(fdata) + fdata = _Py_InterpreterFramePtr(fdata) if not fdata.is_optimized_out(): return fdata return orig_fdata From 6fa0f5332d70ab46fc3cdaa1c82baa280215ce48 Mon Sep 17 00:00:00 2001 From: Nick Coghlan <ncoghlan@gmail.com> Date: Sun, 6 Mar 2022 11:44:03 +1000 Subject: [PATCH 10/30] Fix bad search & replace --- Lib/test/test_socket.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 3b2d86c4ed19d0..c09f11e0f000fe 100755 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -2090,11 +2090,11 @@ def _testSendFrame(self): self.cf = self.build_can_frame(0x00, b'\x01\x02\x03\x04\x05') self.cli.send(self.cf) - def testSendMafdata(self): + def testSendMaxFrame(self): cf, addr = self.s.recvfrom(self.bufsize) self.assertEqual(self.cf, cf) - def _testSendMafdata(self): + def _testSendMaxFrame(self): self.cf = self.build_can_frame(0x00, b'\x07' * 8) self.cli.send(self.cf) From 776ca80b19e04d1d8ded5a589c0634c2234223e8 Mon Sep 17 00:00:00 2001 From: Nick Coghlan <ncoghlan@gmail.com> Date: Sun, 6 Mar 2022 11:47:03 +1000 Subject: [PATCH 11/30] main branch has no underscore --- Include/cpython/ceval.h | 2 +- Include/cpython/frameobject.h | 4 +- Include/cpython/pystate.h | 6 +- Include/genobject.h | 2 +- Include/internal/pycore_ceval.h | 6 +- Include/internal/pycore_frame.h | 44 ++++----- .../2021-08-01-18-18-51.bpo-44800.TCsfH3.rst | 4 +- Misc/gdbinit | 4 +- Modules/_tracemalloc.c | 6 +- Modules/_xxsubinterpretersmodule.c | 4 +- Modules/signalmodule.c | 4 +- Objects/frameobject.c | 42 ++++---- Objects/genobject.c | 46 ++++----- Objects/typeobject.c | 4 +- Python/ceval.c | 98 +++++++++---------- Python/frame.c | 24 ++--- Python/pystate.c | 16 +-- Python/sysmodule.c | 4 +- Python/traceback.c | 6 +- Tools/gdb/libpython.py | 8 +- 20 files changed, 167 insertions(+), 167 deletions(-) diff --git a/Include/cpython/ceval.h b/Include/cpython/ceval.h index cbee144ad94a4f..102eb2d3c16302 100644 --- a/Include/cpython/ceval.h +++ b/Include/cpython/ceval.h @@ -19,7 +19,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, _Py_InterpreterFrame *fdata, int exc); +PyAPI_FUNC(PyObject *) _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *fdata, int exc); PyAPI_FUNC(void) _PyEval_SetSwitchInterval(unsigned long microseconds); PyAPI_FUNC(unsigned long) _PyEval_GetSwitchInterval(void); diff --git a/Include/cpython/frameobject.h b/Include/cpython/frameobject.h index c58189bd8adb18..2a5ebce6aea804 100644 --- a/Include/cpython/frameobject.h +++ b/Include/cpython/frameobject.h @@ -18,12 +18,12 @@ * over the previous approach of using full Python objects for both * introspection and code execution. */ -// Declaration of _Py_InterpreterFrame is in cpython/pystate.h for use in PyThreadState +// Declaration of _PyInterpreterFrame is in cpython/pystate.h for use in PyThreadState struct _frame { PyObject_HEAD struct _frame *f_back; /* previous frame, or NULL */ - _Py_InterpreterFrame *f_fdata; /* points to the frame runtime data */ + _PyInterpreterFrame *f_fdata; /* points to the frame runtime 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? */ diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h index 72ec5e37be6e13..869a4df8491e97 100644 --- a/Include/cpython/pystate.h +++ b/Include/cpython/pystate.h @@ -73,7 +73,7 @@ typedef struct _stack_chunk { // Declared here so the thread state can use it without creating an include loop // See cpython/frameobject.h for an explanation of the type // See internal/pycore_frame.h for the struct definition -typedef struct _Py_execution_frame _Py_InterpreterFrame; +typedef struct _Py_execution_frame _PyInterpreterFrame; // The PyThreadState typedef is in Include/pystate.h. struct _ts { @@ -84,7 +84,7 @@ struct _ts { PyInterpreterState *interp; /* Borrowed reference to the current execution frame's data (it can be NULL) */ - _Py_InterpreterFrame *fdata; + _PyInterpreterFrame *fdata; int recursion_depth; int recursion_headroom; /* Allow 50 more calls to handle any errors. */ int stackcheck_counter; @@ -229,7 +229,7 @@ PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void); /* Frame evaluation API */ -typedef PyObject* (*_PyFrameEvalFunction)(PyThreadState *tstate, _Py_InterpreterFrame *, int); +typedef PyObject* (*_PyFrameEvalFunction)(PyThreadState *tstate, _PyInterpreterFrame *, int); PyAPI_FUNC(_PyFrameEvalFunction) _PyInterpreterState_GetEvalFrameFunc( PyInterpreterState *interp); diff --git a/Include/genobject.h b/Include/genobject.h index c78d45599746fa..0b1bb52b8ae7bb 100644 --- a/Include/genobject.h +++ b/Include/genobject.h @@ -16,7 +16,7 @@ extern "C" { #define _PyGenObject_HEAD(prefix) \ PyObject_HEAD \ /* Note: gi_fdata can be NULL if the generator is "finished" */ \ - _Py_InterpreterFrame *prefix##_fdata; \ + _PyInterpreterFrame *prefix##_fdata; \ /* The code object backing the generator */ \ PyCodeObject *prefix##_code; \ /* List of weak reference. */ \ diff --git a/Include/internal/pycore_ceval.h b/Include/internal/pycore_ceval.h index 583f1628b05201..f06d813d42e76d 100644 --- a/Include/internal/pycore_ceval.h +++ b/Include/internal/pycore_ceval.h @@ -41,7 +41,7 @@ extern PyObject *_PyEval_BuiltinsFromGlobals( static inline PyObject* -_PyEval_EvalFrame(PyThreadState *tstate, _Py_InterpreterFrame *fdata, int throwflag) +_PyEval_EvalFrame(PyThreadState *tstate, _PyInterpreterFrame *fdata, int throwflag) { return tstate->interp->eval_frame(tstate, fdata, throwflag); } @@ -107,9 +107,9 @@ static inline void _Py_LeaveRecursiveCall_inline(void) { #define Py_LeaveRecursiveCall() _Py_LeaveRecursiveCall_inline() -_Py_InterpreterFrame *_PyEval_GetFrameData(void); +_PyInterpreterFrame *_PyEval_GetFrameData(void); -PyObject *_Py_MakeCoro(PyFrameConstructor *, _Py_InterpreterFrame *); +PyObject *_Py_MakeCoro(PyFrameConstructor *, _PyInterpreterFrame *); #ifdef __cplusplus } diff --git a/Include/internal/pycore_frame.h b/Include/internal/pycore_frame.h index c309bbeb69b83c..aac3730762bbce 100644 --- a/Include/internal/pycore_frame.h +++ b/Include/internal/pycore_frame.h @@ -6,7 +6,7 @@ extern "C" { /* Internal-use-only frame object constructor */ PyFrameObject* -_PyFrame_New_NoTrack(_Py_InterpreterFrame *, int); +_PyFrame_New_NoTrack(_PyInterpreterFrame *, int); /* These values are chosen so that the inline functions below all * compare fdata->state to zero. @@ -23,7 +23,7 @@ enum _framestate { typedef signed char PyFrameState; -// The _Py_InterpreterFrame typedef is in Include/pyframeobject.h +// The _PyInterpreterFrame typedef is in Include/pyframeobject.h struct _Py_execution_frame { PyObject *globals; PyObject *builtins; @@ -32,7 +32,7 @@ struct _Py_execution_frame { PyFrameObject *frame_obj; // Full frame object (if created) /* Borrowed reference to a generator, or NULL */ PyObject *generator; - _Py_InterpreterFrame *previous; + _PyInterpreterFrame *previous; int lasti; /* Last instruction if called */ int stackdepth; /* Depth of value stack */ int nlocalsplus; @@ -40,26 +40,26 @@ struct _Py_execution_frame { PyObject *stack[1]; }; -static inline int _Py_InterpreterFrame_IsRunnable(_Py_InterpreterFrame *fdata) { +static inline int _PyInterpreterFrame_IsRunnable(_PyInterpreterFrame *fdata) { return fdata->state < FRAME_EXECUTING; } -static inline int _Py_InterpreterFrame_IsExecuting(_Py_InterpreterFrame *fdata) { +static inline int _PyInterpreterFrame_IsExecuting(_PyInterpreterFrame *fdata) { return fdata->state == FRAME_EXECUTING; } -static inline int _Py_InterpreterFrame_HasCompleted(_Py_InterpreterFrame *fdata) { +static inline int _PyInterpreterFrame_HasCompleted(_PyInterpreterFrame *fdata) { return fdata->state > FRAME_EXECUTING; } -#define FRAME_SPECIALS_SIZE ((sizeof(_Py_InterpreterFrame)-1)/sizeof(PyObject *)) +#define FRAME_SPECIALS_SIZE ((sizeof(_PyInterpreterFrame)-1)/sizeof(PyObject *)) -_Py_InterpreterFrame * -_Py_InterpreterFrame_HeapAlloc(PyFrameConstructor *con, PyObject *locals); +_PyInterpreterFrame * +_PyInterpreterFrame_HeapAlloc(PyFrameConstructor *con, PyObject *locals); static inline void -_Py_InterpreterFrame_InitializeSpecials( - _Py_InterpreterFrame *fdata, PyFrameConstructor *con, +_PyInterpreterFrame_InitializeSpecials( + _PyInterpreterFrame *fdata, PyFrameConstructor *con, PyObject *locals, int nlocalsplus) { fdata->code = (PyCodeObject *)Py_NewRef(con->fc_code); @@ -78,27 +78,27 @@ _Py_InterpreterFrame_InitializeSpecials( * that precedes this frame. */ static inline PyObject** -_Py_InterpreterFrame_GetLocalsArray(_Py_InterpreterFrame *fdata) +_PyInterpreterFrame_GetLocalsArray(_PyInterpreterFrame *fdata) { return ((PyObject **)fdata) - fdata->nlocalsplus; } -/* For use by _Py_InterpreterFrame_GetFrameObject +/* For use by _PyInterpreterFrame_GetFrameObject Do not call directly. */ PyFrameObject * -_Py_InterpreterFrame_MakeAndSetFrameObject(_Py_InterpreterFrame *fdata); +_PyInterpreterFrame_MakeAndSetFrameObject(_PyInterpreterFrame *fdata); /* Gets the PyFrameObject for this frame, lazily * creating it if necessary. * Returns a borrowed referennce */ static inline PyFrameObject * -_Py_InterpreterFrame_GetFrameObject(_Py_InterpreterFrame *fdata) +_PyInterpreterFrame_GetFrameObject(_PyInterpreterFrame *fdata) { PyFrameObject *res = fdata->frame_obj; if (res != NULL) { return res; } - return _Py_InterpreterFrame_MakeAndSetFrameObject(fdata); + return _PyInterpreterFrame_MakeAndSetFrameObject(fdata); } /* Clears all references in the frame. @@ -111,21 +111,21 @@ _Py_InterpreterFrame_GetFrameObject(_Py_InterpreterFrame *fdata) * frames like the ones in generators and coroutines. */ int -_Py_InterpreterFrame_Clear(_Py_InterpreterFrame *fdata, int take); +_PyInterpreterFrame_Clear(_PyInterpreterFrame *fdata, int take); int -_Py_InterpreterFrame_Traverse(_Py_InterpreterFrame *fdata, visitproc visit, void *arg); +_PyInterpreterFrame_Traverse(_PyInterpreterFrame *fdata, visitproc visit, void *arg); int -_Py_InterpreterFrame_FastToLocalsWithError(_Py_InterpreterFrame *frame); +_PyInterpreterFrame_FastToLocalsWithError(_PyInterpreterFrame *frame); void -_Py_InterpreterFrame_LocalsToFast(_Py_InterpreterFrame *frame, int clear); +_PyInterpreterFrame_LocalsToFast(_PyInterpreterFrame *frame, int clear); -_Py_InterpreterFrame *_PyThreadState_PushFrame( +_PyInterpreterFrame *_PyThreadState_PushFrame( PyThreadState *tstate, PyFrameConstructor *con, PyObject *locals); -void _PyThreadState_PopFrame(PyThreadState *tstate, _Py_InterpreterFrame *frame); +void _PyThreadState_PopFrame(PyThreadState *tstate, _PyInterpreterFrame *frame); #ifdef __cplusplus } diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-08-01-18-18-51.bpo-44800.TCsfH3.rst b/Misc/NEWS.d/next/Core and Builtins/2021-08-01-18-18-51.bpo-44800.TCsfH3.rst index e45eb4bc5adb3e..7af529e5966dd5 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2021-08-01-18-18-51.bpo-44800.TCsfH3.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2021-08-01-18-18-51.bpo-44800.TCsfH3.rst @@ -2,7 +2,7 @@ Refactored internal APIs for the new lazy frame object creation to more consistently distinguish between the full ``PyFrameObject`` Python object implementation that is still used in the Python and C runtime state introspection APIs (function prefix ``PyFrame``, field prefix ``f_``, typical -variable names ``frame`` and ``f``) and the new ``_Py_InterpreterFrame`` internal +variable names ``frame`` and ``f``) and the new ``_PyInterpreterFrame`` internal frame data storage (C structs with no intrinsic instance lifecycle management) -that is now used for code execution (function prefix ``_Py_InterpreterFrame``, no +that is now used for code execution (function prefix ``_PyInterpreterFrame``, no field prefix, typical variable name ``fdata``). diff --git a/Misc/gdbinit b/Misc/gdbinit index 017202a098cf4e..289cf9dcb92df8 100644 --- a/Misc/gdbinit +++ b/Misc/gdbinit @@ -38,11 +38,11 @@ end define pylocals set $_i = 0 while $_i < f->f_fdata->code->co_nlocals - if _Py_InterpreterFrame_GetLocalsArray(f->f_fdata) + $_i != 0 + if _PyInterpreterFrame_GetLocalsArray(f->f_fdata) + $_i != 0 set $_names = f->f_fdata->code->co_varnames set $_name = PyUnicode_AsUTF8(PyTuple_GetItem($_names, $_i)) printf "%s:\n", $_name - pyo _Py_InterpreterFrame_GetLocalsArray(f->f_fdata)[$_i] + pyo _PyInterpreterFrame_GetLocalsArray(f->f_fdata)[$_i] end set $_i = $_i + 1 end diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c index d123e2b8df7a64..8d231b733bcb5a 100644 --- a/Modules/_tracemalloc.c +++ b/Modules/_tracemalloc.c @@ -299,7 +299,7 @@ hashtable_compare_traceback(const void *key1, const void *key2) static void -tracemalloc_get_frame(_Py_InterpreterFrame *fdata, frame_t *frame) +tracemalloc_get_frame(_PyInterpreterFrame *fdata, frame_t *frame) { frame->filename = unknown_filename; int lineno = PyCode_Addr2Line(fdata->code, fdata->lasti*2); @@ -393,7 +393,7 @@ traceback_get_frames(traceback_t *traceback) return; } - _Py_InterpreterFrame *fdata = tstate->fdata; + _PyInterpreterFrame *fdata = tstate->fdata; for (; fdata != NULL;) { if (traceback->nframe < _Py_tracemalloc_config.max_nframe) { tracemalloc_get_frame(fdata, &traceback->frames[traceback->nframe]); @@ -404,7 +404,7 @@ traceback_get_frames(traceback_t *traceback) traceback->total_nframe++; } - _Py_InterpreterFrame *back = fdata->previous; + _PyInterpreterFrame *back = fdata->previous; fdata = back; } } diff --git a/Modules/_xxsubinterpretersmodule.c b/Modules/_xxsubinterpretersmodule.c index b1229aea5f1f0d..530e9edd7d171b 100644 --- a/Modules/_xxsubinterpretersmodule.c +++ b/Modules/_xxsubinterpretersmodule.c @@ -1835,12 +1835,12 @@ _is_running(PyInterpreterState *interp) } assert(!PyErr_Occurred()); - _Py_InterpreterFrame *fdata = tstate->fdata; + _PyInterpreterFrame *fdata = tstate->fdata; if (fdata == NULL) { return 0; } - int executing = _Py_InterpreterFrame_IsExecuting(fdata); + int executing = _PyInterpreterFrame_IsExecuting(fdata); return executing; } diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c index d6ba65f3412af0..80e6c2728df0ed 100644 --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -1787,7 +1787,7 @@ _PyErr_CheckSignalsTstate(PyThreadState *tstate) */ _Py_atomic_store(&is_tripped, 0); - _Py_InterpreterFrame *fdata = tstate->fdata; + _PyInterpreterFrame *fdata = tstate->fdata; signal_state_t *state = &signal_global_state; for (int i = 1; i < NSIG; i++) { if (!_Py_atomic_load_relaxed(&Handlers[i].tripped)) { @@ -1823,7 +1823,7 @@ _PyErr_CheckSignalsTstate(PyThreadState *tstate) arglist = Py_BuildValue("(iO)", i, Py_None); } else { - PyFrameObject *f = _Py_InterpreterFrame_GetFrameObject(fdata); + PyFrameObject *f = _PyInterpreterFrame_GetFrameObject(fdata); if (f != NULL) { arglist = Py_BuildValue("(iO)", i, f); } diff --git a/Objects/frameobject.c b/Objects/frameobject.c index fb6374c1ae43d1..05dafd07226e86 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -625,14 +625,14 @@ frame_dealloc(PyFrameObject *f) /* Kill all local variables including specials, if we own them */ if (f->f_own_locals_memory) { f->f_own_locals_memory = 0; - _Py_InterpreterFrame *fdata = f->f_fdata; + _PyInterpreterFrame *fdata = f->f_fdata; /* Don't clear code object until the end */ co = fdata->code; fdata->code = NULL; Py_CLEAR(fdata->globals); Py_CLEAR(fdata->builtins); Py_CLEAR(fdata->locals); - PyObject **locals = _Py_InterpreterFrame_GetLocalsArray(fdata); + PyObject **locals = _PyInterpreterFrame_GetLocalsArray(fdata); for (int i = 0; i < co->co_nlocalsplus; i++) { Py_CLEAR(locals[i]); } @@ -671,7 +671,7 @@ frame_traverse(PyFrameObject *f, visitproc visit, void *arg) return 0; } assert(f->f_fdata->frame_obj == NULL); - return _Py_InterpreterFrame_Traverse(f->f_fdata, visit, arg); + return _PyInterpreterFrame_Traverse(f->f_fdata, visit, arg); } static int @@ -687,7 +687,7 @@ frame_tp_clear(PyFrameObject *f) Py_CLEAR(f->f_trace); /* locals */ - PyObject **locals = _Py_InterpreterFrame_GetLocalsArray(f->f_fdata); + PyObject **locals = _PyInterpreterFrame_GetLocalsArray(f->f_fdata); for (int i = 0; i < f->f_fdata->nlocalsplus; i++) { Py_CLEAR(locals[i]); } @@ -703,7 +703,7 @@ frame_tp_clear(PyFrameObject *f) static PyObject * frame_clear(PyFrameObject *f, PyObject *Py_UNUSED(ignored)) { - if (_Py_InterpreterFrame_IsExecuting(f->f_fdata)) { + if (_PyInterpreterFrame_IsExecuting(f->f_fdata)) { PyErr_SetString(PyExc_RuntimeError, "cannot clear an executing frame"); return NULL; @@ -789,7 +789,7 @@ PyTypeObject PyFrame_Type = { _Py_IDENTIFIER(__builtins__); -static _Py_InterpreterFrame * +static _PyInterpreterFrame * allocate_heap_frame(PyFrameConstructor *con, PyObject *locals) { PyCodeObject *code = (PyCodeObject *)con->fc_code; @@ -802,13 +802,13 @@ allocate_heap_frame(PyFrameConstructor *con, PyObject *locals) for (Py_ssize_t i=0; i < code->co_nlocalsplus; i++) { localsarray[i] = NULL; } - _Py_InterpreterFrame *fdata = (_Py_InterpreterFrame *)(localsarray + code->co_nlocalsplus); - _Py_InterpreterFrame_InitializeSpecials(fdata, con, locals, code->co_nlocalsplus); + _PyInterpreterFrame *fdata = (_PyInterpreterFrame *)(localsarray + code->co_nlocalsplus); + _PyInterpreterFrame_InitializeSpecials(fdata, con, locals, code->co_nlocalsplus); return fdata; } static inline PyFrameObject* -frame_alloc(_Py_InterpreterFrame *fdata, int owns) +frame_alloc(_PyInterpreterFrame *fdata, int owns) { PyFrameObject *f; struct _Py_frame_state *state = get_frame_state(); @@ -843,7 +843,7 @@ frame_alloc(_Py_InterpreterFrame *fdata, int owns) } PyFrameObject* _Py_HOT_FUNCTION -_PyFrame_New_NoTrack(_Py_InterpreterFrame *fdata, int owns) +_PyFrame_New_NoTrack(_PyInterpreterFrame *fdata, int owns) { PyFrameObject *f = frame_alloc(fdata, owns); if (f == NULL) { @@ -876,7 +876,7 @@ PyFrame_New(PyThreadState *tstate, PyCodeObject *code, .fc_kwdefaults = NULL, .fc_closure = NULL }; - _Py_InterpreterFrame *fdata = allocate_heap_frame(&desc, locals); + _PyInterpreterFrame *fdata = allocate_heap_frame(&desc, locals); if (fdata == NULL) { return NULL; } @@ -888,7 +888,7 @@ PyFrame_New(PyThreadState *tstate, PyCodeObject *code, } static int -_Py_InterpreterFrame_OpAlreadyRan(_Py_InterpreterFrame *fdata, int opcode, int oparg) +_PyInterpreterFrame_OpAlreadyRan(_PyInterpreterFrame *fdata, int opcode, int oparg) { const _Py_CODEUNIT *code = (const _Py_CODEUNIT *)PyBytes_AS_STRING(fdata->code->co_code); @@ -901,7 +901,7 @@ _Py_InterpreterFrame_OpAlreadyRan(_Py_InterpreterFrame *fdata, int opcode, int o } int -_Py_InterpreterFrame_FastToLocalsWithError(_Py_InterpreterFrame *fdata) { +_PyInterpreterFrame_FastToLocalsWithError(_PyInterpreterFrame *fdata) { /* Merge fast locals into fdata->locals */ PyObject *locals; PyObject **fast; @@ -913,7 +913,7 @@ _Py_InterpreterFrame_FastToLocalsWithError(_Py_InterpreterFrame *fdata) { return -1; } co = fdata->code; - fast = _Py_InterpreterFrame_GetLocalsArray(fdata); + fast = _PyInterpreterFrame_GetLocalsArray(fdata); for (int i = 0; i < co->co_nlocalsplus; i++) { _PyLocals_Kind kind = _PyLocals_GetKind(co->co_localspluskinds, i); @@ -945,7 +945,7 @@ _Py_InterpreterFrame_FastToLocalsWithError(_Py_InterpreterFrame *fdata) { // run yet. if (value != NULL) { if (PyCell_Check(value) && - _Py_InterpreterFrame_OpAlreadyRan(fdata, MAKE_CELL, i)) { + _PyInterpreterFrame_OpAlreadyRan(fdata, MAKE_CELL, i)) { // (likely) MAKE_CELL must have executed already. value = PyCell_GET(value); } @@ -985,7 +985,7 @@ PyFrame_FastToLocalsWithError(PyFrameObject *f) PyErr_BadInternalCall(); return -1; } - return _Py_InterpreterFrame_FastToLocalsWithError(f->f_fdata); + return _PyInterpreterFrame_FastToLocalsWithError(f->f_fdata); } void @@ -1001,7 +1001,7 @@ PyFrame_FastToLocals(PyFrameObject *f) } void -_Py_InterpreterFrame_LocalsToFast(_Py_InterpreterFrame *fdata, int clear) +_PyInterpreterFrame_LocalsToFast(_PyInterpreterFrame *fdata, int clear) { /* Merge locals into fast locals */ PyObject *locals; @@ -1011,7 +1011,7 @@ _Py_InterpreterFrame_LocalsToFast(_Py_InterpreterFrame *fdata, int clear) locals = fdata->locals; if (locals == NULL) return; - fast = _Py_InterpreterFrame_GetLocalsArray(fdata); + fast = _PyInterpreterFrame_GetLocalsArray(fdata); co = fdata->code; PyErr_Fetch(&error_type, &error_value, &error_traceback); @@ -1042,7 +1042,7 @@ _Py_InterpreterFrame_LocalsToFast(_Py_InterpreterFrame *fdata, int clear) else if (kind & CO_FAST_CELL && oldvalue != NULL) { /* Same test as in PyFrame_FastToLocals() above. */ if (PyCell_Check(oldvalue) && - _Py_InterpreterFrame_OpAlreadyRan(fdata, MAKE_CELL, i)) { + _PyInterpreterFrame_OpAlreadyRan(fdata, MAKE_CELL, i)) { // (likely) MAKE_CELL must have executed already. cell = oldvalue; } @@ -1072,7 +1072,7 @@ PyFrame_LocalsToFast(PyFrameObject *f, int clear) if (f == NULL || f->f_fdata->state == FRAME_CLEARED) { return; } - _Py_InterpreterFrame_LocalsToFast(f->f_fdata, clear); + _PyInterpreterFrame_LocalsToFast(f->f_fdata, clear); } /* Clear out the free list */ @@ -1127,7 +1127,7 @@ PyFrame_GetBack(PyFrameObject *frame) assert(frame != NULL); PyFrameObject *back = frame->f_back; if (back == NULL && frame->f_fdata->previous != NULL) { - back = _Py_InterpreterFrame_GetFrameObject(frame->f_fdata->previous); + back = _PyInterpreterFrame_GetFrameObject(frame->f_fdata->previous); } Py_XINCREF(back); return back; diff --git a/Objects/genobject.c b/Objects/genobject.c index 2b80671400f360..c1fb045a28822d 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -35,10 +35,10 @@ gen_traverse(PyGenObject *gen, visitproc visit, void *arg) Py_VISIT(gen->gi_code); Py_VISIT(gen->gi_name); Py_VISIT(gen->gi_qualname); - _Py_InterpreterFrame *fdata = gen->gi_fdata; + _PyInterpreterFrame *fdata = gen->gi_fdata; if (fdata != NULL) { assert(fdata->frame_obj == NULL || fdata->frame_obj->f_own_locals_memory == 0); - int err = _Py_InterpreterFrame_Traverse(fdata, visit, arg); + int err = _PyInterpreterFrame_Traverse(fdata, visit, arg); if (err) { return err; } @@ -55,7 +55,7 @@ _PyGen_Finalize(PyObject *self) PyObject *res = NULL; PyObject *error_type, *error_value, *error_traceback; - if (gen->gi_fdata == NULL || _Py_InterpreterFrame_HasCompleted(gen->gi_fdata)) { + if (gen->gi_fdata == NULL || _PyInterpreterFrame_HasCompleted(gen->gi_fdata)) { /* Generator isn't paused, so no need to close */ return; } @@ -130,11 +130,11 @@ gen_dealloc(PyGenObject *gen) and GC_Del. */ Py_CLEAR(((PyAsyncGenObject*)gen)->ag_finalizer); } - _Py_InterpreterFrame *fdata = gen->gi_fdata; + _PyInterpreterFrame *fdata = gen->gi_fdata; if (fdata != NULL) { gen->gi_fdata = NULL; fdata->previous = NULL; - _Py_InterpreterFrame_Clear(fdata, 1); + _PyInterpreterFrame_Clear(fdata, 1); } if (((PyCodeObject *)gen->gi_code)->co_flags & CO_COROUTINE) { Py_CLEAR(((PyCoroObject *)gen)->cr_origin); @@ -151,11 +151,11 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult, int exc, int closing) { PyThreadState *tstate = _PyThreadState_GET(); - _Py_InterpreterFrame *fdata = gen->gi_fdata; + _PyInterpreterFrame *fdata = gen->gi_fdata; PyObject *result; *presult = NULL; - if (fdata != NULL && _Py_InterpreterFrame_IsExecuting(fdata)) { + if (fdata != NULL && _PyInterpreterFrame_IsExecuting(fdata)) { const char *msg = "generator already executing"; if (PyCoro_CheckExact(gen)) { msg = "coroutine already executing"; @@ -166,7 +166,7 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult, PyErr_SetString(PyExc_ValueError, msg); return PYGEN_ERROR; } - if (fdata == NULL || _Py_InterpreterFrame_HasCompleted(fdata)) { + if (fdata == NULL || _PyInterpreterFrame_HasCompleted(fdata)) { if (PyCoro_CheckExact(gen) && !closing) { /* `gen` is an exhausted coroutine: raise an error, except when called from gen_close(), which should @@ -185,7 +185,7 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult, return PYGEN_ERROR; } - assert(_Py_InterpreterFrame_IsRunnable(fdata)); + assert(_PyInterpreterFrame_IsRunnable(fdata)); assert(fdata->lasti >= 0 || ((unsigned char *)PyBytes_AS_STRING(gen->gi_code->co_code))[0] == GEN_START); /* Push arg onto the frame's value stack */ result = arg ? arg : Py_None; @@ -216,7 +216,7 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult, /* If the generator just returned (as opposed to yielding), signal * that the generator is exhausted. */ if (result) { - if (!_Py_InterpreterFrame_HasCompleted(fdata)) { + if (!_PyInterpreterFrame_HasCompleted(fdata)) { *presult = result; return PYGEN_NEXT; } @@ -254,7 +254,7 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult, fdata->generator = NULL; gen->gi_fdata = NULL; - _Py_InterpreterFrame_Clear(fdata, 1); + _PyInterpreterFrame_Clear(fdata, 1); *presult = result; return result ? PYGEN_RETURN : PYGEN_ERROR; } @@ -336,7 +336,7 @@ _PyGen_yf(PyGenObject *gen) PyObject *yf = NULL; if (gen->gi_fdata) { - _Py_InterpreterFrame *fdata = gen->gi_fdata; + _PyInterpreterFrame *fdata = gen->gi_fdata; PyObject *bytecode = gen->gi_code->co_code; unsigned char *code = (unsigned char *)PyBytes_AS_STRING(bytecode); @@ -428,7 +428,7 @@ _gen_throw(PyGenObject *gen, int close_on_genexit, if (PyGen_CheckExact(yf) || PyCoro_CheckExact(yf)) { /* `yf` is a generator or a coroutine. */ PyThreadState *tstate = _PyThreadState_GET(); - _Py_InterpreterFrame *fdata = gen->gi_fdata; + _PyInterpreterFrame *fdata = gen->gi_fdata; /* Since we are fast-tracking things by skipping the eval loop, @@ -436,7 +436,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. */ - _Py_InterpreterFrame *prev = tstate->fdata; + _PyInterpreterFrame *prev = tstate->fdata; fdata->previous = prev; tstate->fdata = fdata; /* Close the generator that we are currently iterating with @@ -736,7 +736,7 @@ gen_getrunning(PyGenObject *gen, void *Py_UNUSED(ignored)) if (gen->gi_fdata == NULL) { Py_RETURN_FALSE; } - return PyBool_FromLong(_Py_InterpreterFrame_IsExecuting(gen->gi_fdata)); + return PyBool_FromLong(_PyInterpreterFrame_IsExecuting(gen->gi_fdata)); } static PyObject * @@ -748,7 +748,7 @@ _gen_getframe(PyGenObject *gen, const char *const name) if (gen->gi_fdata == NULL) { Py_RETURN_NONE; } - return _Py_XNewRef((PyObject *)_Py_InterpreterFrame_GetFrameObject(gen->gi_fdata)); + return _Py_XNewRef((PyObject *)_PyInterpreterFrame_GetFrameObject(gen->gi_fdata)); } static PyObject * @@ -843,12 +843,12 @@ PyTypeObject PyGen_Type = { }; static PyObject * -make_gen(PyTypeObject *type, PyFrameConstructor *con, _Py_InterpreterFrame *fdata) +make_gen(PyTypeObject *type, PyFrameConstructor *con, _PyInterpreterFrame *fdata) { PyGenObject *gen = PyObject_GC_New(PyGenObject, type); if (gen == NULL) { assert(fdata->frame_obj == NULL); - _Py_InterpreterFrame_Clear(fdata, 1); + _PyInterpreterFrame_Clear(fdata, 1); return NULL; } gen->gi_fdata = fdata; @@ -878,7 +878,7 @@ static PyObject * compute_cr_origin(int origin_depth); PyObject * -_Py_MakeCoro(PyFrameConstructor *con, _Py_InterpreterFrame *fdata) +_Py_MakeCoro(PyFrameConstructor *con, _PyInterpreterFrame *fdata) { int coro_flags = ((PyCodeObject *)con->fc_code)->co_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR); @@ -1075,7 +1075,7 @@ cr_getrunning(PyCoroObject *coro, void *Py_UNUSED(ignored)) if (coro->cr_fdata == NULL) { Py_RETURN_FALSE; } - return PyBool_FromLong(_Py_InterpreterFrame_IsExecuting(coro->cr_fdata)); + return PyBool_FromLong(_PyInterpreterFrame_IsExecuting(coro->cr_fdata)); } static PyObject * @@ -1271,7 +1271,7 @@ PyTypeObject _PyCoroWrapper_Type = { static PyObject * compute_cr_origin(int origin_depth) { - _Py_InterpreterFrame *fdata = _PyEval_GetFrameData(); + _PyInterpreterFrame *fdata = _PyEval_GetFrameData(); /* First count how many frames we have */ int frame_count = 0; for (; fdata && frame_count < origin_depth; ++frame_count) { @@ -1990,7 +1990,7 @@ static PyObject * async_gen_athrow_send(PyAsyncGenAThrow *o, PyObject *arg) { PyGenObject *gen = (PyGenObject*)o->agt_gen; - _Py_InterpreterFrame *fdata = gen->gi_fdata; + _PyInterpreterFrame *fdata = gen->gi_fdata; PyObject *retval; if (o->agt_state == AWAITABLE_STATE_CLOSED) { @@ -2000,7 +2000,7 @@ async_gen_athrow_send(PyAsyncGenAThrow *o, PyObject *arg) return NULL; } - if (fdata == NULL || _Py_InterpreterFrame_HasCompleted(fdata)) { + if (fdata == NULL || _PyInterpreterFrame_HasCompleted(fdata)) { o->agt_state = AWAITABLE_STATE_CLOSED; PyErr_SetNone(PyExc_StopIteration); return NULL; diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 939c8aef1ee3fa..abe73c6acfb199 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -8875,7 +8875,7 @@ super_init_without_args(PyFrameObject *f, PyCodeObject *co, } assert(f->f_fdata->nlocalsplus > 0); - PyObject *firstarg = _Py_InterpreterFrame_GetLocalsArray(f->f_fdata)[0]; + PyObject *firstarg = _PyInterpreterFrame_GetLocalsArray(f->f_fdata)[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() @@ -8900,7 +8900,7 @@ super_init_without_args(PyFrameObject *f, PyCodeObject *co, PyObject *name = PyTuple_GET_ITEM(co->co_localsplusnames, i); assert(PyUnicode_Check(name)); if (_PyUnicode_EqualToASCIIId(name, &PyId___class__)) { - PyObject *cell = _Py_InterpreterFrame_GetLocalsArray(f->f_fdata)[i]; + PyObject *cell = _PyInterpreterFrame_GetLocalsArray(f->f_fdata)[i]; if (cell == NULL || !PyCell_Check(cell)) { PyErr_SetString(PyExc_RuntimeError, "super(): bad __class__ cell"); diff --git a/Python/ceval.c b/Python/ceval.c index 98606b51f59934..773d6da533c01c 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -60,7 +60,7 @@ static PyObject * do_call_core( #ifdef LLTRACE static int lltrace; static int prtrace(PyThreadState *, PyObject *, const char *); -static void lltrace_instruction(_Py_InterpreterFrame *fdata, int opcode, int oparg) +static void lltrace_instruction(_PyInterpreterFrame *fdata, int opcode, int oparg) { if (HAS_ARG(opcode)) { printf("%d: %d, %d\n", @@ -73,27 +73,27 @@ static void lltrace_instruction(_Py_InterpreterFrame *fdata, int opcode, int opa } #endif static int call_trace(Py_tracefunc, PyObject *, - PyThreadState *, _Py_InterpreterFrame *, + PyThreadState *, _PyInterpreterFrame *, int, PyObject *); static int call_trace_protected(Py_tracefunc, PyObject *, - PyThreadState *, _Py_InterpreterFrame *, + PyThreadState *, _PyInterpreterFrame *, int, PyObject *); static void call_exc_trace(Py_tracefunc, PyObject *, - PyThreadState *, _Py_InterpreterFrame *); + PyThreadState *, _PyInterpreterFrame *); static int maybe_call_line_trace(Py_tracefunc, PyObject *, - PyThreadState *, _Py_InterpreterFrame *, int); -static void maybe_dtrace_line(_Py_InterpreterFrame *, PyTraceInfo *, int); -static void dtrace_function_entry(_Py_InterpreterFrame *); -static void dtrace_function_return(_Py_InterpreterFrame *); + PyThreadState *, _PyInterpreterFrame *, int); +static void maybe_dtrace_line(_PyInterpreterFrame *, PyTraceInfo *, int); +static void dtrace_function_entry(_PyInterpreterFrame *); +static void dtrace_function_return(_PyInterpreterFrame *); -static PyObject * import_name(PyThreadState *, _Py_InterpreterFrame *, +static PyObject * import_name(PyThreadState *, _PyInterpreterFrame *, PyObject *, PyObject *, PyObject *); static PyObject * import_from(PyThreadState *, PyObject *, PyObject *); static int import_all_from(PyThreadState *, PyObject *, PyObject *); static void format_exc_check_arg(PyThreadState *, PyObject *, const char *, PyObject *); static void format_exc_unbound(PyThreadState *tstate, PyCodeObject *co, int oparg); static PyObject * unicode_concatenate(PyThreadState *, PyObject *, PyObject *, - _Py_InterpreterFrame *, const _Py_CODEUNIT *); + _PyInterpreterFrame *, const _Py_CODEUNIT *); static int check_args_iterable(PyThreadState *, PyObject *func, PyObject *vararg); static void format_kwargs_error(PyThreadState *, PyObject *func, PyObject *kwargs); static void format_awaitable_error(PyThreadState *, PyTypeObject *, int, int); @@ -1461,7 +1461,7 @@ eval_frame_handle_pending(PyThreadState *tstate) Py_INCREF(res); static int -trace_function_entry(PyThreadState *tstate, _Py_InterpreterFrame *fdata) +trace_function_entry(PyThreadState *tstate, _PyInterpreterFrame *fdata) { if (tstate->c_tracefunc != NULL) { /* tstate->c_tracefunc, if defined, is a @@ -1500,7 +1500,7 @@ trace_function_entry(PyThreadState *tstate, _Py_InterpreterFrame *fdata) } PyObject* _Py_HOT_FUNCTION -_PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_InterpreterFrame *fdata, int throwflag) +_PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *fdata, int throwflag) { _Py_EnsureTstateNotNULL(tstate); @@ -1559,7 +1559,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_InterpreterFrame *fdata, int PyObject *names = co->co_names; PyObject *consts = co->co_consts; - PyObject **localsplus = _Py_InterpreterFrame_GetLocalsArray(fdata); + PyObject **localsplus = _PyInterpreterFrame_GetLocalsArray(fdata); _Py_CODEUNIT *first_instr = co->co_firstinstr; /* fdata->lasti refers to the index of the last instruction, @@ -3814,7 +3814,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_InterpreterFrame *fdata, int TARGET(IMPORT_STAR): { PyObject *from = POP(), *locals; int err; - if (_Py_InterpreterFrame_FastToLocalsWithError(fdata) < 0) { + if (_PyInterpreterFrame_FastToLocalsWithError(fdata) < 0) { Py_DECREF(from); goto error; } @@ -3827,7 +3827,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_InterpreterFrame *fdata, int goto error; } err = import_all_from(tstate, locals, from); - _Py_InterpreterFrame_LocalsToFast(fdata, 0); + _PyInterpreterFrame_LocalsToFast(fdata, 0); Py_DECREF(from); if (err != 0) goto error; @@ -4793,7 +4793,7 @@ MISS_WITH_OPARG_COUNTER(BINARY_SUBSCR) #endif /* Log traceback info. */ - PyFrameObject *f = _Py_InterpreterFrame_GetFrameObject(fdata); + PyFrameObject *f = _PyInterpreterFrame_GetFrameObject(fdata); if (f != NULL) { PyTraceBack_Here(f); } @@ -5396,7 +5396,7 @@ initialize_locals(PyThreadState *tstate, PyFrameConstructor *con, } -static _Py_InterpreterFrame * +static _PyInterpreterFrame * make_coro_frame(PyThreadState *tstate, PyFrameConstructor *con, PyObject *locals, PyObject *const *args, Py_ssize_t argcount, @@ -5414,11 +5414,11 @@ make_coro_frame(PyThreadState *tstate, for (Py_ssize_t i=0; i < code->co_nlocalsplus; i++) { localsarray[i] = NULL; } - _Py_InterpreterFrame *fdata = (_Py_InterpreterFrame *)(localsarray + code->co_nlocalsplus); - _Py_InterpreterFrame_InitializeSpecials(fdata, con, locals, code->co_nlocalsplus); + _PyInterpreterFrame *fdata = (_PyInterpreterFrame *)(localsarray + code->co_nlocalsplus); + _PyInterpreterFrame_InitializeSpecials(fdata, con, locals, code->co_nlocalsplus); assert(fdata->frame_obj == NULL); if (initialize_locals(tstate, con, localsarray, args, argcount, kwnames)) { - _Py_InterpreterFrame_Clear(fdata, 1); + _PyInterpreterFrame_Clear(fdata, 1); return NULL; } return fdata; @@ -5431,7 +5431,7 @@ make_coro(PyThreadState *tstate, PyFrameConstructor *con, PyObject *kwnames) { assert (((PyCodeObject *)con->fc_code)->co_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR)); - _Py_InterpreterFrame *fdata = make_coro_frame(tstate, con, locals, args, argcount, kwnames); + _PyInterpreterFrame *fdata = make_coro_frame(tstate, con, locals, args, argcount, kwnames); if (fdata == NULL) { return NULL; } @@ -5443,18 +5443,18 @@ make_coro(PyThreadState *tstate, PyFrameConstructor *con, return gen; } -static _Py_InterpreterFrame * +static _PyInterpreterFrame * _PyEvalFramePushAndInit(PyThreadState *tstate, PyFrameConstructor *con, PyObject *locals, PyObject* const* args, size_t argcount, PyObject *kwnames) { - _Py_InterpreterFrame * fdata = _PyThreadState_PushFrame(tstate, con, locals); + _PyInterpreterFrame * fdata = _PyThreadState_PushFrame(tstate, con, locals); if (fdata == NULL) { return NULL; } - PyObject **localsarray = _Py_InterpreterFrame_GetLocalsArray(fdata); + PyObject **localsarray = _PyInterpreterFrame_GetLocalsArray(fdata); if (initialize_locals(tstate, con, localsarray, args, argcount, kwnames)) { - _Py_InterpreterFrame_Clear(fdata, 0); + _PyInterpreterFrame_Clear(fdata, 0); return NULL; } fdata->previous = tstate->fdata; @@ -5463,11 +5463,11 @@ _PyEvalFramePushAndInit(PyThreadState *tstate, PyFrameConstructor *con, } static int -_PyEvalFrameClearAndPop(PyThreadState *tstate, _Py_InterpreterFrame * fdata) +_PyEvalFrameClearAndPop(PyThreadState *tstate, _PyInterpreterFrame * fdata) { ++tstate->recursion_depth; assert(fdata->frame_obj == NULL || fdata->frame_obj->f_own_locals_memory == 0); - if (_Py_InterpreterFrame_Clear(fdata, 0)) { + if (_PyInterpreterFrame_Clear(fdata, 0)) { return -1; } assert(fdata->frame_obj == NULL); @@ -5489,7 +5489,7 @@ _PyEval_Vector(PyThreadState *tstate, PyFrameConstructor *con, if (is_coro) { return make_coro(tstate, con, locals, args, argcount, kwnames); } - _Py_InterpreterFrame *fdata = _PyEvalFramePushAndInit( + _PyInterpreterFrame *fdata = _PyEvalFramePushAndInit( tstate, con, locals, args, argcount, kwnames); if (fdata == NULL) { return NULL; @@ -5806,7 +5806,7 @@ prtrace(PyThreadState *tstate, PyObject *v, const char *str) static void call_exc_trace(Py_tracefunc func, PyObject *self, PyThreadState *tstate, - _Py_InterpreterFrame *fdata) + _PyInterpreterFrame *fdata) { PyObject *type, *value, *traceback, *orig_traceback, *arg; int err; @@ -5836,7 +5836,7 @@ call_exc_trace(Py_tracefunc func, PyObject *self, static int call_trace_protected(Py_tracefunc func, PyObject *obj, - PyThreadState *tstate, _Py_InterpreterFrame *fdata, + PyThreadState *tstate, _PyInterpreterFrame *fdata, int what, PyObject *arg) { PyObject *type, *value, *traceback; @@ -5857,7 +5857,7 @@ call_trace_protected(Py_tracefunc func, PyObject *obj, } static void -initialize_trace_info(PyTraceInfo *trace_info, _Py_InterpreterFrame *fdata) +initialize_trace_info(PyTraceInfo *trace_info, _PyInterpreterFrame *fdata) { PyCodeObject *code = fdata->code; if (trace_info->code != code) { @@ -5868,7 +5868,7 @@ initialize_trace_info(PyTraceInfo *trace_info, _Py_InterpreterFrame *fdata) static int call_trace(Py_tracefunc func, PyObject *obj, - PyThreadState *tstate, _Py_InterpreterFrame *fdata, + PyThreadState *tstate, _PyInterpreterFrame *fdata, int what, PyObject *arg) { int result; @@ -5876,7 +5876,7 @@ call_trace(Py_tracefunc func, PyObject *obj, return 0; tstate->tracing++; tstate->cframe->use_tracing = 0; - PyFrameObject *f = _Py_InterpreterFrame_GetFrameObject(fdata); + PyFrameObject *f = _PyInterpreterFrame_GetFrameObject(fdata); if (f == NULL) { return -1; } @@ -5915,7 +5915,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, _Py_InterpreterFrame *fdata, int instr_prev) + PyThreadState *tstate, _PyInterpreterFrame *fdata, int instr_prev) { int result = 0; @@ -5926,7 +5926,7 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj, initialize_trace_info(&tstate->trace_info, fdata); int lastline = _PyCode_CheckLineNumber(instr_prev*2, &tstate->trace_info.bounds); int line = _PyCode_CheckLineNumber(fdata->lasti*2, &tstate->trace_info.bounds); - PyFrameObject *f = _Py_InterpreterFrame_GetFrameObject(fdata); + PyFrameObject *f = _PyInterpreterFrame_GetFrameObject(fdata); if (f == NULL) { return -1; } @@ -6084,7 +6084,7 @@ _PyEval_GetAsyncGenFinalizer(void) return tstate->async_gen_finalizer; } -_Py_InterpreterFrame * +_PyInterpreterFrame * _PyEval_GetFrameData(void) { PyThreadState *tstate = _PyThreadState_GET(); @@ -6098,7 +6098,7 @@ PyEval_GetFrame(void) if (tstate->fdata == NULL) { return NULL; } - PyFrameObject *f = _Py_InterpreterFrame_GetFrameObject(tstate->fdata); + PyFrameObject *f = _PyInterpreterFrame_GetFrameObject(tstate->fdata); if (f == NULL) { PyErr_Clear(); } @@ -6108,7 +6108,7 @@ PyEval_GetFrame(void) PyObject * _PyEval_GetBuiltins(PyThreadState *tstate) { - _Py_InterpreterFrame *fdata = tstate->fdata; + _PyInterpreterFrame *fdata = tstate->fdata; if (fdata != NULL) { return fdata->builtins; } @@ -6141,13 +6141,13 @@ PyObject * PyEval_GetLocals(void) { PyThreadState *tstate = _PyThreadState_GET(); - _Py_InterpreterFrame *fdata = tstate->fdata; + _PyInterpreterFrame *fdata = tstate->fdata; if (fdata == NULL) { _PyErr_SetString(tstate, PyExc_SystemError, "frame does not exist"); return NULL; } - if (_Py_InterpreterFrame_FastToLocalsWithError(fdata) < 0) { + if (_PyInterpreterFrame_FastToLocalsWithError(fdata) < 0) { return NULL; } @@ -6160,7 +6160,7 @@ PyObject * PyEval_GetGlobals(void) { PyThreadState *tstate = _PyThreadState_GET(); - _Py_InterpreterFrame *fdata = tstate->fdata; + _PyInterpreterFrame *fdata = tstate->fdata; if (fdata == NULL) { return NULL; } @@ -6171,7 +6171,7 @@ int PyEval_MergeCompilerFlags(PyCompilerFlags *cf) { PyThreadState *tstate = _PyThreadState_GET(); - _Py_InterpreterFrame *fdata = tstate->fdata; + _PyInterpreterFrame *fdata = tstate->fdata; int result = cf->cf_flags != 0; if (fdata != NULL) { @@ -6409,7 +6409,7 @@ _PyEval_SliceIndexNotNone(PyObject *v, Py_ssize_t *pi) } static PyObject * -import_name(PyThreadState *tstate, _Py_InterpreterFrame *fdata, +import_name(PyThreadState *tstate, _PyInterpreterFrame *fdata, PyObject *name, PyObject *fromlist, PyObject *level) { _Py_IDENTIFIER(__import__); @@ -6748,7 +6748,7 @@ format_awaitable_error(PyThreadState *tstate, PyTypeObject *type, int prevprevop static PyObject * unicode_concatenate(PyThreadState *tstate, PyObject *v, PyObject *w, - _Py_InterpreterFrame *fdata, const _Py_CODEUNIT *next_instr) + _PyInterpreterFrame *fdata, const _Py_CODEUNIT *next_instr) { PyObject *res; if (Py_REFCNT(v) == 2) { @@ -6763,14 +6763,14 @@ unicode_concatenate(PyThreadState *tstate, PyObject *v, PyObject *w, switch (opcode) { case STORE_FAST: { - PyObject **localsplus = _Py_InterpreterFrame_GetLocalsArray(fdata); + PyObject **localsplus = _PyInterpreterFrame_GetLocalsArray(fdata); if (GETLOCAL(oparg) == v) SETLOCAL(oparg, NULL); break; } case STORE_DEREF: { - PyObject *c = _Py_InterpreterFrame_GetLocalsArray(fdata)[oparg]; + PyObject *c = _PyInterpreterFrame_GetLocalsArray(fdata)[oparg]; if (PyCell_GET(c) == v) { PyCell_SET(c, NULL); Py_DECREF(v); @@ -6859,7 +6859,7 @@ _PyEval_RequestCodeExtraIndex(freefunc free) } static void -dtrace_function_entry(_Py_InterpreterFrame *fdata) +dtrace_function_entry(_PyInterpreterFrame *fdata) { const char *filename; const char *funcname; @@ -6874,7 +6874,7 @@ dtrace_function_entry(_Py_InterpreterFrame *fdata) } static void -dtrace_function_return(_Py_InterpreterFrame *fdata) +dtrace_function_return(_PyInterpreterFrame *fdata) { const char *filename; const char *funcname; @@ -6890,7 +6890,7 @@ dtrace_function_return(_Py_InterpreterFrame *fdata) /* DTrace equivalent of maybe_call_line_trace. */ static void -maybe_dtrace_line(_Py_InterpreterFrame *fdata, +maybe_dtrace_line(_PyInterpreterFrame *fdata, PyTraceInfo *trace_info, int instr_prev) { diff --git a/Python/frame.c b/Python/frame.c index 85855ef28e4c32..9135b9bb40171b 100644 --- a/Python/frame.c +++ b/Python/frame.c @@ -5,7 +5,7 @@ #include "pycore_object.h" // _PyObject_GC_UNTRACK() int -_Py_InterpreterFrame_Traverse(_Py_InterpreterFrame *fdata, visitproc visit, void *arg) +_PyInterpreterFrame_Traverse(_PyInterpreterFrame *fdata, visitproc visit, void *arg) { Py_VISIT(fdata->frame_obj); Py_VISIT(fdata->globals); @@ -13,7 +13,7 @@ _Py_InterpreterFrame_Traverse(_Py_InterpreterFrame *fdata, visitproc visit, void Py_VISIT(fdata->locals); Py_VISIT(fdata->code); /* locals */ - PyObject **locals = _Py_InterpreterFrame_GetLocalsArray(fdata); + PyObject **locals = _PyInterpreterFrame_GetLocalsArray(fdata); for (int i = 0; i < fdata->nlocalsplus; i++) { Py_VISIT(locals[i]); } @@ -25,7 +25,7 @@ _Py_InterpreterFrame_Traverse(_Py_InterpreterFrame *fdata, visitproc visit, void } PyFrameObject * -_Py_InterpreterFrame_MakeAndSetFrameObject(_Py_InterpreterFrame *fdata) +_PyInterpreterFrame_MakeAndSetFrameObject(_PyInterpreterFrame *fdata) { assert(fdata->frame_obj == NULL); PyObject *error_type, *error_value, *error_traceback; @@ -44,11 +44,11 @@ _Py_InterpreterFrame_MakeAndSetFrameObject(_Py_InterpreterFrame *fdata) } -static _Py_InterpreterFrame * -copy_frame_to_heap(_Py_InterpreterFrame *fdata) +static _PyInterpreterFrame * +copy_frame_to_heap(_PyInterpreterFrame *fdata) { - PyObject **locals = _Py_InterpreterFrame_GetLocalsArray(fdata); + PyObject **locals = _PyInterpreterFrame_GetLocalsArray(fdata); Py_ssize_t size = ((char*)&fdata->stack[fdata->stackdepth]) - (char *)locals; PyObject **copy = PyMem_Malloc(size); if (copy == NULL) { @@ -56,12 +56,12 @@ copy_frame_to_heap(_Py_InterpreterFrame *fdata) return NULL; } memcpy(copy, locals, size); - _Py_InterpreterFrame *res = (_Py_InterpreterFrame *)(copy + fdata->nlocalsplus); + _PyInterpreterFrame *res = (_PyInterpreterFrame *)(copy + fdata->nlocalsplus); return res; } static inline void -clear_specials(_Py_InterpreterFrame *fdata) +clear_specials(_PyInterpreterFrame *fdata) { fdata->generator = NULL; Py_XDECREF(fdata->frame_obj); @@ -72,7 +72,7 @@ clear_specials(_Py_InterpreterFrame *fdata) } static void -take_ownership(PyFrameObject *f, _Py_InterpreterFrame *fdata) +take_ownership(PyFrameObject *f, _PyInterpreterFrame *fdata) { assert(f->f_own_locals_memory == 0); assert(fdata->frame_obj == NULL); @@ -82,7 +82,7 @@ take_ownership(PyFrameObject *f, _Py_InterpreterFrame *fdata) assert(f->f_back == NULL); if (fdata->previous != NULL) { /* Link frame object's 'f_back' and remove link through frame data's 'previous' field */ - PyFrameObject *back = _Py_InterpreterFrame_GetFrameObject(fdata->previous); + PyFrameObject *back = _PyInterpreterFrame_GetFrameObject(fdata->previous); if (back == NULL) { /* Memory error here. */ assert(PyErr_ExceptionMatches(PyExc_MemoryError)); @@ -101,7 +101,7 @@ take_ownership(PyFrameObject *f, _Py_InterpreterFrame *fdata) } int -_Py_InterpreterFrame_Clear(_Py_InterpreterFrame * fdata, int take) +_PyInterpreterFrame_Clear(_PyInterpreterFrame * fdata, int take) { PyObject **localsarray = ((PyObject **)fdata)-fdata->nlocalsplus; if (fdata->frame_obj) { @@ -129,7 +129,7 @@ _Py_InterpreterFrame_Clear(_Py_InterpreterFrame * fdata, int take) } clear_specials(fdata); if (take) { - PyMem_Free(_Py_InterpreterFrame_GetLocalsArray(fdata)); + PyMem_Free(_PyInterpreterFrame_GetLocalsArray(fdata)); } return 0; } diff --git a/Python/pystate.c b/Python/pystate.c index 9a1e38d8ca1706..c943d95ae852e6 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -1137,7 +1137,7 @@ PyThreadState_GetFrame(PyThreadState *tstate) if (tstate->fdata == NULL) { return NULL; } - PyFrameObject *frame = _Py_InterpreterFrame_GetFrameObject(tstate->fdata); + PyFrameObject *frame = _PyInterpreterFrame_GetFrameObject(tstate->fdata); if (frame == NULL) { PyErr_Clear(); } @@ -1261,7 +1261,7 @@ _PyThread_CurrentFrames(void) for (i = runtime->interpreters.head; i != NULL; i = i->next) { PyThreadState *t; for (t = i->tstate_head; t != NULL; t = t->next) { - _Py_InterpreterFrame *fdata = t->fdata; + _PyInterpreterFrame *fdata = t->fdata; if (fdata == NULL) { continue; } @@ -1269,7 +1269,7 @@ _PyThread_CurrentFrames(void) if (id == NULL) { goto fail; } - int stat = PyDict_SetItem(result, id, (PyObject *)_Py_InterpreterFrame_GetFrameObject(fdata)); + int stat = PyDict_SetItem(result, id, (PyObject *)_PyInterpreterFrame_GetFrameObject(fdata)); Py_DECREF(id); if (stat < 0) { goto fail; @@ -2037,7 +2037,7 @@ push_chunk(PyThreadState *tstate, int size) return res; } -_Py_InterpreterFrame * +_PyInterpreterFrame * _PyThreadState_PushFrame(PyThreadState *tstate, PyFrameConstructor *con, PyObject *locals) { PyCodeObject *code = (PyCodeObject *)con->fc_code; @@ -2056,8 +2056,8 @@ _PyThreadState_PushFrame(PyThreadState *tstate, PyFrameConstructor *con, PyObjec else { tstate->datastack_top = top; } - _Py_InterpreterFrame * fdata = (_Py_InterpreterFrame *)(localsarray + nlocalsplus); - _Py_InterpreterFrame_InitializeSpecials(fdata, con, locals, nlocalsplus); + _PyInterpreterFrame * fdata = (_PyInterpreterFrame *)(localsarray + nlocalsplus); + _PyInterpreterFrame_InitializeSpecials(fdata, con, locals, nlocalsplus); for (int i=0; i < nlocalsplus; i++) { localsarray[i] = NULL; } @@ -2065,9 +2065,9 @@ _PyThreadState_PushFrame(PyThreadState *tstate, PyFrameConstructor *con, PyObjec } void -_PyThreadState_PopFrame(PyThreadState *tstate, _Py_InterpreterFrame * fdata) +_PyThreadState_PopFrame(PyThreadState *tstate, _PyInterpreterFrame * fdata) { - PyObject **locals = _Py_InterpreterFrame_GetLocalsArray(fdata); + PyObject **locals = _PyInterpreterFrame_GetLocalsArray(fdata); if (locals == &tstate->datastack_chunk->data[0]) { _PyStackChunk *chunk = tstate->datastack_chunk; _PyStackChunk *previous = chunk->previous; diff --git a/Python/sysmodule.c b/Python/sysmodule.c index b35404eec262c8..3e363808258ce7 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1815,7 +1815,7 @@ sys__getframe_impl(PyObject *module, int depth) /*[clinic end generated code: output=d438776c04d59804 input=c1be8a6464b11ee5]*/ { PyThreadState *tstate = _PyThreadState_GET(); - _Py_InterpreterFrame *fdata = tstate->fdata; + _PyInterpreterFrame *fdata = tstate->fdata; if (_PySys_Audit(tstate, "sys._getframe", NULL) < 0) { return NULL; @@ -1830,7 +1830,7 @@ sys__getframe_impl(PyObject *module, int depth) "call stack is not deep enough"); return NULL; } - return _Py_XNewRef((PyObject *)_Py_InterpreterFrame_GetFrameObject(fdata)); + return _Py_XNewRef((PyObject *)_PyInterpreterFrame_GetFrameObject(fdata)); } /*[clinic input] diff --git a/Python/traceback.c b/Python/traceback.c index 0a7cf4d5a352d6..51a1054ed346a6 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -6,7 +6,7 @@ #include "code.h" // PyCode_Addr2Line etc #include "pycore_interp.h" // PyInterpreterState.gc #include "frameobject.h" // PyFrame_GetBack() -#include "pycore_frame.h" // _Py_InterpreterFrame_GetCode() +#include "pycore_frame.h" // _PyInterpreterFrame_GetCode() #include "pycore_pyarena.h" // _PyArena_Free() #include "pycore_ast.h" // asdl_seq_* #include "pycore_compile.h" // _PyAST_Optimize @@ -1024,7 +1024,7 @@ _Py_DumpASCII(int fd, PyObject *text) This function is signal safe. */ static void -dump_frame(int fd, _Py_InterpreterFrame *fdata) +dump_frame(int fd, _PyInterpreterFrame *fdata) { PyCodeObject *code = fdata->code; PUTS(fd, " File "); @@ -1062,7 +1062,7 @@ dump_frame(int fd, _Py_InterpreterFrame *fdata) static void dump_traceback(int fd, PyThreadState *tstate, int write_header) { - _Py_InterpreterFrame *fdata; + _PyInterpreterFrame *fdata; unsigned int depth; if (write_header) { diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py index 690d2ee1d0f08b..c50a9797f50a13 100755 --- a/Tools/gdb/libpython.py +++ b/Tools/gdb/libpython.py @@ -861,7 +861,7 @@ def __init__(self, gdbval, cast_to=None): PyObjectPtr.__init__(self, gdbval, cast_to) if not self.is_optimized_out(): - self._fdata = _Py_InterpreterFramePtr(self.field('f_fdata')) + self._fdata = _PyInterpreterFramePtr(self.field('f_fdata')) def iter_locals(self): ''' @@ -932,7 +932,7 @@ def print_traceback(self): return return self._fdata.print_traceback() -class _Py_InterpreterFramePtr: +class _PyInterpreterFramePtr: def __init__(self, gdbval): self._gdbval = gdbval @@ -1734,7 +1734,7 @@ def is_gc_collect(self): def get_pyop(self): try: fdata = self._gdbframe.read_var('fdata') - fdata = _Py_InterpreterFramePtr(fdata) + fdata = _PyInterpreterFramePtr(fdata) if not fdata.is_optimized_out(): return fdata # gdb is unable to get the "fdata" argument of PyEval_EvalFrameEx() @@ -1744,7 +1744,7 @@ def get_pyop(self): caller = self._gdbframe.older() if caller: fdata = caller.read_var('fdata') - fdata = _Py_InterpreterFramePtr(fdata) + fdata = _PyInterpreterFramePtr(fdata) if not fdata.is_optimized_out(): return fdata return orig_fdata From 682af2392da01b1cf93155a764c7510a8147dbd2 Mon Sep 17 00:00:00 2001 From: Nick Coghlan <ncoghlan@gmail.com> Date: Sun, 6 Mar 2022 11:48:44 +1000 Subject: [PATCH 12/30] Reduce function header conflicts --- Include/cpython/ceval.h | 2 +- Include/internal/pycore_ceval.h | 2 +- Include/internal/pycore_frame.h | 6 +++--- Modules/_tracemalloc.c | 2 +- Objects/frameobject.c | 8 ++++---- Python/ceval.c | 16 ++++++++-------- Python/frame.c | 2 +- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Include/cpython/ceval.h b/Include/cpython/ceval.h index 102eb2d3c16302..bb2acf2ac2889f 100644 --- a/Include/cpython/ceval.h +++ b/Include/cpython/ceval.h @@ -19,7 +19,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, _PyInterpreterFrame *fdata, int exc); +PyAPI_FUNC(PyObject *) _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *f, int exc); PyAPI_FUNC(void) _PyEval_SetSwitchInterval(unsigned long microseconds); PyAPI_FUNC(unsigned long) _PyEval_GetSwitchInterval(void); diff --git a/Include/internal/pycore_ceval.h b/Include/internal/pycore_ceval.h index f06d813d42e76d..67ec1740738cec 100644 --- a/Include/internal/pycore_ceval.h +++ b/Include/internal/pycore_ceval.h @@ -41,7 +41,7 @@ extern PyObject *_PyEval_BuiltinsFromGlobals( static inline PyObject* -_PyEval_EvalFrame(PyThreadState *tstate, _PyInterpreterFrame *fdata, int throwflag) +_PyEval_EvalFrame(PyThreadState *tstate, _PyInterpreterFrame *f, int throwflag) { return tstate->interp->eval_frame(tstate, fdata, throwflag); } diff --git a/Include/internal/pycore_frame.h b/Include/internal/pycore_frame.h index aac3730762bbce..4b5eda4e8daeb1 100644 --- a/Include/internal/pycore_frame.h +++ b/Include/internal/pycore_frame.h @@ -59,7 +59,7 @@ _PyInterpreterFrame_HeapAlloc(PyFrameConstructor *con, PyObject *locals); static inline void _PyInterpreterFrame_InitializeSpecials( - _PyInterpreterFrame *fdata, PyFrameConstructor *con, + _PyInterpreterFrame *f, PyFrameConstructor *con, PyObject *locals, int nlocalsplus) { fdata->code = (PyCodeObject *)Py_NewRef(con->fc_code); @@ -111,10 +111,10 @@ _PyInterpreterFrame_GetFrameObject(_PyInterpreterFrame *fdata) * frames like the ones in generators and coroutines. */ int -_PyInterpreterFrame_Clear(_PyInterpreterFrame *fdata, int take); +_PyInterpreterFrame_Clear(_PyInterpreterFrame *f, int take); int -_PyInterpreterFrame_Traverse(_PyInterpreterFrame *fdata, visitproc visit, void *arg); +_PyInterpreterFrame_Traverse(_PyInterpreterFrame *f, visitproc visit, void *arg); int _PyInterpreterFrame_FastToLocalsWithError(_PyInterpreterFrame *frame); diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c index 8d231b733bcb5a..9455fa41ef1853 100644 --- a/Modules/_tracemalloc.c +++ b/Modules/_tracemalloc.c @@ -299,7 +299,7 @@ hashtable_compare_traceback(const void *key1, const void *key2) static void -tracemalloc_get_frame(_PyInterpreterFrame *fdata, frame_t *frame) +tracemalloc_get_frame(_PyInterpreterFrame *f, frame_t *frame) { frame->filename = unknown_filename; int lineno = PyCode_Addr2Line(fdata->code, fdata->lasti*2); diff --git a/Objects/frameobject.c b/Objects/frameobject.c index 05dafd07226e86..365984e48745d5 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -808,7 +808,7 @@ allocate_heap_frame(PyFrameConstructor *con, PyObject *locals) } static inline PyFrameObject* -frame_alloc(_PyInterpreterFrame *fdata, int owns) +frame_alloc(_PyInterpreterFrame *f, int owns) { PyFrameObject *f; struct _Py_frame_state *state = get_frame_state(); @@ -843,7 +843,7 @@ frame_alloc(_PyInterpreterFrame *fdata, int owns) } PyFrameObject* _Py_HOT_FUNCTION -_PyFrame_New_NoTrack(_PyInterpreterFrame *fdata, int owns) +_PyFrame_New_NoTrack(_PyInterpreterFrame *f, int owns) { PyFrameObject *f = frame_alloc(fdata, owns); if (f == NULL) { @@ -888,7 +888,7 @@ PyFrame_New(PyThreadState *tstate, PyCodeObject *code, } static int -_PyInterpreterFrame_OpAlreadyRan(_PyInterpreterFrame *fdata, int opcode, int oparg) +_PyInterpreterFrame_OpAlreadyRan(_PyInterpreterFrame *f, int opcode, int oparg) { const _Py_CODEUNIT *code = (const _Py_CODEUNIT *)PyBytes_AS_STRING(fdata->code->co_code); @@ -1001,7 +1001,7 @@ PyFrame_FastToLocals(PyFrameObject *f) } void -_PyInterpreterFrame_LocalsToFast(_PyInterpreterFrame *fdata, int clear) +_PyInterpreterFrame_LocalsToFast(_PyInterpreterFrame *f, int clear) { /* Merge locals into fast locals */ PyObject *locals; diff --git a/Python/ceval.c b/Python/ceval.c index 773d6da533c01c..f2ce3b6cee3aa4 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -60,7 +60,7 @@ static PyObject * do_call_core( #ifdef LLTRACE static int lltrace; static int prtrace(PyThreadState *, PyObject *, const char *); -static void lltrace_instruction(_PyInterpreterFrame *fdata, int opcode, int oparg) +static void lltrace_instruction(_PyInterpreterFrame *f, int opcode, int oparg) { if (HAS_ARG(opcode)) { printf("%d: %d, %d\n", @@ -1500,7 +1500,7 @@ trace_function_entry(PyThreadState *tstate, _PyInterpreterFrame *fdata) } PyObject* _Py_HOT_FUNCTION -_PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *fdata, int throwflag) +_PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *f, int throwflag) { _Py_EnsureTstateNotNULL(tstate); @@ -5836,7 +5836,7 @@ call_exc_trace(Py_tracefunc func, PyObject *self, static int call_trace_protected(Py_tracefunc func, PyObject *obj, - PyThreadState *tstate, _PyInterpreterFrame *fdata, + PyThreadState *tstate, _PyInterpreterFrame *f, int what, PyObject *arg) { PyObject *type, *value, *traceback; @@ -5868,7 +5868,7 @@ initialize_trace_info(PyTraceInfo *trace_info, _PyInterpreterFrame *fdata) static int call_trace(Py_tracefunc func, PyObject *obj, - PyThreadState *tstate, _PyInterpreterFrame *fdata, + PyThreadState *tstate, _PyInterpreterFrame *f, int what, PyObject *arg) { int result; @@ -5915,7 +5915,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 *fdata, int instr_prev) + PyThreadState *tstate, _PyInterpreterFrame *f, int instr_prev) { int result = 0; @@ -6409,7 +6409,7 @@ _PyEval_SliceIndexNotNone(PyObject *v, Py_ssize_t *pi) } static PyObject * -import_name(PyThreadState *tstate, _PyInterpreterFrame *fdata, +import_name(PyThreadState *tstate, _PyInterpreterFrame *f, PyObject *name, PyObject *fromlist, PyObject *level) { _Py_IDENTIFIER(__import__); @@ -6748,7 +6748,7 @@ format_awaitable_error(PyThreadState *tstate, PyTypeObject *type, int prevprevop static PyObject * unicode_concatenate(PyThreadState *tstate, PyObject *v, PyObject *w, - _PyInterpreterFrame *fdata, const _Py_CODEUNIT *next_instr) + _PyInterpreterFrame *f, const _Py_CODEUNIT *next_instr) { PyObject *res; if (Py_REFCNT(v) == 2) { @@ -6890,7 +6890,7 @@ dtrace_function_return(_PyInterpreterFrame *fdata) /* DTrace equivalent of maybe_call_line_trace. */ static void -maybe_dtrace_line(_PyInterpreterFrame *fdata, +maybe_dtrace_line(_PyInterpreterFrame *f, PyTraceInfo *trace_info, int instr_prev) { diff --git a/Python/frame.c b/Python/frame.c index 9135b9bb40171b..619a40ae8cc15e 100644 --- a/Python/frame.c +++ b/Python/frame.c @@ -5,7 +5,7 @@ #include "pycore_object.h" // _PyObject_GC_UNTRACK() int -_PyInterpreterFrame_Traverse(_PyInterpreterFrame *fdata, visitproc visit, void *arg) +_PyInterpreterFrame_Traverse(_PyInterpreterFrame *f, visitproc visit, void *arg) { Py_VISIT(fdata->frame_obj); Py_VISIT(fdata->globals); From c76e63b1630c28be95e06dbe23eb7e4cf0206976 Mon Sep 17 00:00:00 2001 From: Nick Coghlan <ncoghlan@gmail.com> Date: Sun, 6 Mar 2022 11:53:19 +1000 Subject: [PATCH 13/30] Yet more merge conflict reduction --- Include/cpython/ceval.h | 2 +- Include/cpython/pystate.h | 2 +- Include/internal/pycore_ceval.h | 4 ++-- Include/internal/pycore_frame.h | 2 +- Objects/genobject.c | 4 ++-- Python/ceval.c | 26 +++++++++++++------------- Python/frame.c | 2 +- Python/pystate.c | 2 +- Python/traceback.c | 2 +- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Include/cpython/ceval.h b/Include/cpython/ceval.h index bb2acf2ac2889f..c5a2a4315e0a67 100644 --- a/Include/cpython/ceval.h +++ b/Include/cpython/ceval.h @@ -19,7 +19,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, _PyInterpreterFrame *f, int exc); +PyAPI_FUNC(PyObject *) _PyEval_EvalFrameDefault(PyThreadState *tstate, struct _PyInterpreterFrame *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 869a4df8491e97..da42bfc4e5b913 100644 --- a/Include/cpython/pystate.h +++ b/Include/cpython/pystate.h @@ -229,7 +229,7 @@ PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void); /* Frame evaluation API */ -typedef PyObject* (*_PyFrameEvalFunction)(PyThreadState *tstate, _PyInterpreterFrame *, int); +typedef PyObject* (*_PyFrameEvalFunction)(PyThreadState *tstate, struct _PyInterpreterFrame *, int); PyAPI_FUNC(_PyFrameEvalFunction) _PyInterpreterState_GetEvalFrameFunc( PyInterpreterState *interp); diff --git a/Include/internal/pycore_ceval.h b/Include/internal/pycore_ceval.h index 67ec1740738cec..3b0a54a48133a7 100644 --- a/Include/internal/pycore_ceval.h +++ b/Include/internal/pycore_ceval.h @@ -41,7 +41,7 @@ extern PyObject *_PyEval_BuiltinsFromGlobals( static inline PyObject* -_PyEval_EvalFrame(PyThreadState *tstate, _PyInterpreterFrame *f, int throwflag) +_PyEval_EvalFrame(PyThreadState *tstate, struct _PyInterpreterFrame *f, int throwflag) { return tstate->interp->eval_frame(tstate, fdata, throwflag); } @@ -109,7 +109,7 @@ static inline void _Py_LeaveRecursiveCall_inline(void) { _PyInterpreterFrame *_PyEval_GetFrameData(void); -PyObject *_Py_MakeCoro(PyFrameConstructor *, _PyInterpreterFrame *); +PyObject *_Py_MakeCoro(PyFrameConstructor *, struct _PyInterpreterFrame *); #ifdef __cplusplus } diff --git a/Include/internal/pycore_frame.h b/Include/internal/pycore_frame.h index 4b5eda4e8daeb1..5dc27f5f17d266 100644 --- a/Include/internal/pycore_frame.h +++ b/Include/internal/pycore_frame.h @@ -125,7 +125,7 @@ _PyInterpreterFrame_LocalsToFast(_PyInterpreterFrame *frame, int clear); _PyInterpreterFrame *_PyThreadState_PushFrame( PyThreadState *tstate, PyFrameConstructor *con, PyObject *locals); -void _PyThreadState_PopFrame(PyThreadState *tstate, _PyInterpreterFrame *frame); +void _PyThreadState_PopFrame(PyThreadState *tstate, struct _PyInterpreterFrame *frame); #ifdef __cplusplus } diff --git a/Objects/genobject.c b/Objects/genobject.c index c1fb045a28822d..f3a367a13a7840 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -843,7 +843,7 @@ PyTypeObject PyGen_Type = { }; static PyObject * -make_gen(PyTypeObject *type, PyFrameConstructor *con, _PyInterpreterFrame *fdata) +make_gen(PyTypeObject *type, PyFrameConstructor *con, struct _PyInterpreterFrame *fdata) { PyGenObject *gen = PyObject_GC_New(PyGenObject, type); if (gen == NULL) { @@ -878,7 +878,7 @@ static PyObject * compute_cr_origin(int origin_depth); PyObject * -_Py_MakeCoro(PyFrameConstructor *con, _PyInterpreterFrame *fdata) +_Py_MakeCoro(PyFrameConstructor *con, struct _PyInterpreterFrame *fdata) { int coro_flags = ((PyCodeObject *)con->fc_code)->co_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR); diff --git a/Python/ceval.c b/Python/ceval.c index f2ce3b6cee3aa4..950ae7178c472c 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -73,20 +73,20 @@ static void lltrace_instruction(_PyInterpreterFrame *f, int opcode, int oparg) } #endif static int call_trace(Py_tracefunc, PyObject *, - PyThreadState *, _PyInterpreterFrame *, + PyThreadState *, struct _PyInterpreterFrame *, int, PyObject *); static int call_trace_protected(Py_tracefunc, PyObject *, - PyThreadState *, _PyInterpreterFrame *, + PyThreadState *, struct _PyInterpreterFrame *, int, PyObject *); static void call_exc_trace(Py_tracefunc, PyObject *, - PyThreadState *, _PyInterpreterFrame *); + PyThreadState *, struct _PyInterpreterFrame *); static int maybe_call_line_trace(Py_tracefunc, PyObject *, - PyThreadState *, _PyInterpreterFrame *, int); + PyThreadState *, struct _PyInterpreterFrame *, int); static void maybe_dtrace_line(_PyInterpreterFrame *, PyTraceInfo *, int); static void dtrace_function_entry(_PyInterpreterFrame *); static void dtrace_function_return(_PyInterpreterFrame *); -static PyObject * import_name(PyThreadState *, _PyInterpreterFrame *, +static PyObject * import_name(PyThreadState *, struct _PyInterpreterFrame *, PyObject *, PyObject *, PyObject *); static PyObject * import_from(PyThreadState *, PyObject *, PyObject *); static int import_all_from(PyThreadState *, PyObject *, PyObject *); @@ -1461,7 +1461,7 @@ eval_frame_handle_pending(PyThreadState *tstate) Py_INCREF(res); static int -trace_function_entry(PyThreadState *tstate, _PyInterpreterFrame *fdata) +trace_function_entry(PyThreadState *tstate, struct _PyInterpreterFrame *fdata) { if (tstate->c_tracefunc != NULL) { /* tstate->c_tracefunc, if defined, is a @@ -1500,7 +1500,7 @@ trace_function_entry(PyThreadState *tstate, _PyInterpreterFrame *fdata) } PyObject* _Py_HOT_FUNCTION -_PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *f, int throwflag) +_PyEval_EvalFrameDefault(PyThreadState *tstate, struct _PyInterpreterFrame *f, int throwflag) { _Py_EnsureTstateNotNULL(tstate); @@ -5463,7 +5463,7 @@ _PyEvalFramePushAndInit(PyThreadState *tstate, PyFrameConstructor *con, } static int -_PyEvalFrameClearAndPop(PyThreadState *tstate, _PyInterpreterFrame * fdata) +_PyEvalFrameClearAndPop(PyThreadState *tstate, struct _PyInterpreterFrame * fdata) { ++tstate->recursion_depth; assert(fdata->frame_obj == NULL || fdata->frame_obj->f_own_locals_memory == 0); @@ -5836,7 +5836,7 @@ call_exc_trace(Py_tracefunc func, PyObject *self, static int call_trace_protected(Py_tracefunc func, PyObject *obj, - PyThreadState *tstate, _PyInterpreterFrame *f, + PyThreadState *tstate, struct _PyInterpreterFrame *f, int what, PyObject *arg) { PyObject *type, *value, *traceback; @@ -5857,7 +5857,7 @@ call_trace_protected(Py_tracefunc func, PyObject *obj, } static void -initialize_trace_info(PyTraceInfo *trace_info, _PyInterpreterFrame *fdata) +initialize_trace_info(PyTraceInfo *trace_info, struct _PyInterpreterFrame *fdata) { PyCodeObject *code = fdata->code; if (trace_info->code != code) { @@ -5868,7 +5868,7 @@ initialize_trace_info(PyTraceInfo *trace_info, _PyInterpreterFrame *fdata) static int call_trace(Py_tracefunc func, PyObject *obj, - PyThreadState *tstate, _PyInterpreterFrame *f, + PyThreadState *tstate, struct _PyInterpreterFrame *f, int what, PyObject *arg) { int result; @@ -5915,7 +5915,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 *f, int instr_prev) + PyThreadState *tstate, struct _PyInterpreterFrame *f, int instr_prev) { int result = 0; @@ -6409,7 +6409,7 @@ _PyEval_SliceIndexNotNone(PyObject *v, Py_ssize_t *pi) } static PyObject * -import_name(PyThreadState *tstate, _PyInterpreterFrame *f, +import_name(PyThreadState *tstate, struct _PyInterpreterFrame *f, PyObject *name, PyObject *fromlist, PyObject *level) { _Py_IDENTIFIER(__import__); diff --git a/Python/frame.c b/Python/frame.c index 619a40ae8cc15e..48ca9038180f0e 100644 --- a/Python/frame.c +++ b/Python/frame.c @@ -72,7 +72,7 @@ clear_specials(_PyInterpreterFrame *fdata) } static void -take_ownership(PyFrameObject *f, _PyInterpreterFrame *fdata) +take_ownership(PyFrameObject *f, struct _PyInterpreterFrame *fdata) { assert(f->f_own_locals_memory == 0); assert(fdata->frame_obj == NULL); diff --git a/Python/pystate.c b/Python/pystate.c index c943d95ae852e6..70cc6bec0907d4 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -2065,7 +2065,7 @@ _PyThreadState_PushFrame(PyThreadState *tstate, PyFrameConstructor *con, PyObjec } void -_PyThreadState_PopFrame(PyThreadState *tstate, _PyInterpreterFrame * fdata) +_PyThreadState_PopFrame(PyThreadState *tstate, struct _PyInterpreterFrame * fdata) { PyObject **locals = _PyInterpreterFrame_GetLocalsArray(fdata); if (locals == &tstate->datastack_chunk->data[0]) { diff --git a/Python/traceback.c b/Python/traceback.c index 51a1054ed346a6..5844ace1a628f1 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -1024,7 +1024,7 @@ _Py_DumpASCII(int fd, PyObject *text) This function is signal safe. */ static void -dump_frame(int fd, _PyInterpreterFrame *fdata) +dump_frame(int fd, struct _PyInterpreterFrame *fdata) { PyCodeObject *code = fdata->code; PUTS(fd, " File "); From cae935d25ef7ed175cfcf489e1fde1d753739fef Mon Sep 17 00:00:00 2001 From: Nick Coghlan <ncoghlan@gmail.com> Date: Sun, 6 Mar 2022 13:00:51 +1000 Subject: [PATCH 14/30] Reinstate _Py_framedata struct rename --- Include/cpython/ceval.h | 2 +- Include/cpython/pystate.h | 4 +- Include/internal/pycore_ceval.h | 4 +- Include/internal/pycore_frame.h | 58 ++++++------- .../2021-08-01-18-18-51.bpo-44800.TCsfH3.rst | 4 +- Modules/_tracemalloc.c | 6 +- Modules/_xxsubinterpretersmodule.c | 2 +- Modules/signalmodule.c | 4 +- Objects/frameobject.c | 20 ++--- Objects/genobject.c | 52 ++++++------ Objects/typeobject.c | 6 +- Python/ceval.c | 82 +++++++++---------- Python/frame.c | 20 ++--- Python/pystate.c | 8 +- Python/sysmodule.c | 4 +- Python/traceback.c | 4 +- Tools/gdb/libpython.py | 2 +- 17 files changed, 141 insertions(+), 141 deletions(-) diff --git a/Include/cpython/ceval.h b/Include/cpython/ceval.h index 5a904bd3f08e90..f811879f896d17 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_framedata *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..5edff06d63282d 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_framedata *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_framedata *, int); PyAPI_FUNC(_PyFrameEvalFunction) _PyInterpreterState_GetEvalFrameFunc( PyInterpreterState *interp); diff --git a/Include/internal/pycore_ceval.h b/Include/internal/pycore_ceval.h index 70178e38650cf5..e0f66fdb906cb0 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_framedata *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_framedata *_PyEval_GetFrame(void); PyObject *_Py_MakeCoro(PyFunctionObject *func); diff --git a/Include/internal/pycore_frame.h b/Include/internal/pycore_frame.h index 80f75f1159f25f..8da7f8130ddda5 100644 --- a/Include/internal/pycore_frame.h +++ b/Include/internal/pycore_frame.h @@ -20,13 +20,13 @@ extern "C" { * over the previous approach of using full Python objects for both * introspection and code execution. */ -// Declaration of _PyInterpreterFrame is in cpython/pystate.h for use in PyThreadState +// Declaration of _Py_framedata is in cpython/pystate.h for use in PyThreadState struct _frame { PyObject_HEAD PyFrameObject *f_back; /* previous frame, or NULL */ - struct _PyInterpreterFrame *f_fdata; /* points to the frame data */ + struct _Py_framedata *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? */ @@ -65,63 +65,63 @@ typedef signed char PyFrameState; unless it's -1 in which case next_instr should be first_instr. */ -typedef struct _PyInterpreterFrame { +typedef struct _Py_framedata { 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; + struct _Py_framedata *previous; int lasti; /* Last instruction if called */ int stacktop; /* Offset of TOS from localsplus */ 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; +} _Py_framedata; -static inline int _PyFrame_IsRunnable(_PyInterpreterFrame *f) { +static inline int _PyFrame_IsRunnable(_Py_framedata *f) { return f->state < FRAME_EXECUTING; } -static inline int _PyFrame_IsExecuting(_PyInterpreterFrame *f) { +static inline int _PyFrame_IsExecuting(_Py_framedata *f) { return f->state == FRAME_EXECUTING; } -static inline int _PyFrameHasCompleted(_PyInterpreterFrame *f) { +static inline int _PyFrameHasCompleted(_Py_framedata *f) { return f->state > FRAME_EXECUTING; } -static inline PyObject **_PyFrame_Stackbase(_PyInterpreterFrame *f) { +static inline PyObject **_PyFrame_Stackbase(_Py_framedata *f) { return f->localsplus + f->code->co_nlocalsplus; } -static inline PyObject *_PyFrame_StackPeek(_PyInterpreterFrame *f) { +static inline PyObject *_PyFrame_StackPeek(_Py_framedata *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) { +static inline PyObject *_PyFrame_StackPop(_Py_framedata *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_framedata *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_framedata)-1)/sizeof(PyObject *)) -void _PyFrame_Copy(_PyInterpreterFrame *src, _PyInterpreterFrame *dest); +void _PyFrame_Copy(_Py_framedata *src, _Py_framedata *dest); /* Consumes reference to func */ static inline void _PyFrame_InitializeSpecials( - _PyInterpreterFrame *frame, PyFunctionObject *func, + _Py_framedata *frame, PyFunctionObject *func, PyObject *locals, int nlocalsplus) { frame->func = func; @@ -141,19 +141,19 @@ _PyFrame_InitializeSpecials( * that precedes this frame. */ static inline PyObject** -_PyFrame_GetLocalsArray(_PyInterpreterFrame *frame) +_PyFrame_GetLocalsArray(_Py_framedata *frame) { return frame->localsplus; } static inline PyObject** -_PyFrame_GetStackPointer(_PyInterpreterFrame *frame) +_PyFrame_GetStackPointer(_Py_framedata *frame) { return frame->localsplus+frame->stacktop; } static inline void -_PyFrame_SetStackPointer(_PyInterpreterFrame *frame, PyObject **stack_pointer) +_PyFrame_SetStackPointer(_Py_framedata *frame, PyObject **stack_pointer) { frame->stacktop = (int)(stack_pointer - frame->localsplus); } @@ -161,13 +161,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_framedata *frame); /* Gets the PyFrameObject for this frame, lazily * creating it if necessary. * Returns a borrowed referennce */ static inline PyFrameObject * -_PyFrame_GetFrameObject(_PyInterpreterFrame *fdata) +_PyFrame_GetFrameObject(_Py_framedata *fdata) { PyFrameObject *res = fdata->frame_obj; if (res != NULL) { @@ -186,21 +186,21 @@ _PyFrame_GetFrameObject(_PyInterpreterFrame *fdata) * frames like the ones in generators and coroutines. */ void -_PyFrame_Clear(_PyInterpreterFrame * frame); +_PyFrame_Clear(_Py_framedata * frame); int -_PyFrame_Traverse(_PyInterpreterFrame *frame, visitproc visit, void *arg); +_PyFrame_Traverse(_Py_framedata *frame, visitproc visit, void *arg); int -_PyFrame_FastToLocalsWithError(_PyInterpreterFrame *frame); +_PyFrame_FastToLocalsWithError(_Py_framedata *frame); void -_PyFrame_LocalsToFast(_PyInterpreterFrame *frame, int clear); +_PyFrame_LocalsToFast(_Py_framedata *frame, int clear); -extern _PyInterpreterFrame * +extern _Py_framedata * _PyThreadState_BumpFramePointerSlow(PyThreadState *tstate, size_t size); -static inline _PyInterpreterFrame * +static inline _Py_framedata * _PyThreadState_BumpFramePointer(PyThreadState *tstate, size_t size) { PyObject **base = tstate->datastack_top; @@ -209,16 +209,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_framedata *)base; } } return _PyThreadState_BumpFramePointerSlow(tstate, size); } -void _PyThreadState_PopFrame(PyThreadState *tstate, _PyInterpreterFrame *frame); +void _PyThreadState_PopFrame(PyThreadState *tstate, _Py_framedata *frame); /* Consume reference to func */ -_PyInterpreterFrame * +_Py_framedata * _PyFrame_Push(PyThreadState *tstate, PyFunctionObject *func); #ifdef __cplusplus diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-08-01-18-18-51.bpo-44800.TCsfH3.rst b/Misc/NEWS.d/next/Core and Builtins/2021-08-01-18-18-51.bpo-44800.TCsfH3.rst index 7af529e5966dd5..25f56ae4e11058 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2021-08-01-18-18-51.bpo-44800.TCsfH3.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2021-08-01-18-18-51.bpo-44800.TCsfH3.rst @@ -2,7 +2,7 @@ Refactored internal APIs for the new lazy frame object creation to more consistently distinguish between the full ``PyFrameObject`` Python object implementation that is still used in the Python and C runtime state introspection APIs (function prefix ``PyFrame``, field prefix ``f_``, typical -variable names ``frame`` and ``f``) and the new ``_PyInterpreterFrame`` internal +variable names ``frame`` and ``f``) and the new ``_Py_framedata`` internal frame data storage (C structs with no intrinsic instance lifecycle management) -that is now used for code execution (function prefix ``_PyInterpreterFrame``, no +that is now used for code execution (function prefix ``_Py_framedata``, no field prefix, typical variable name ``fdata``). diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c index 945bdc5857aebc..a22bee4a7e407e 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_framedata *pyframe, frame_t *frame) { frame->filename = &_Py_STR(anon_unknown); int lineno = PyCode_Addr2Line(pyframe->code, pyframe->lasti*sizeof(_Py_CODEUNIT)); @@ -399,7 +399,7 @@ traceback_get_frames(traceback_t *traceback) return; } - _PyInterpreterFrame *pyframe = tstate->cframe->current_frame; + _Py_framedata *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_framedata *back = pyframe->previous; pyframe = back; } } diff --git a/Modules/_xxsubinterpretersmodule.c b/Modules/_xxsubinterpretersmodule.c index 9579af38c3b80c..1bc45b0aaf21d4 100644 --- a/Modules/_xxsubinterpretersmodule.c +++ b/Modules/_xxsubinterpretersmodule.c @@ -1839,7 +1839,7 @@ _is_running(PyInterpreterState *interp) } assert(!PyErr_Occurred()); - _PyInterpreterFrame *fdata = tstate->cframe->current_frame; + _Py_framedata *fdata = tstate->cframe->current_frame; if (fdata == NULL) { return 0; } diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c index 8208936c0703d0..b5e943d60aff1f 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_framedata #include "pycore_moduleobject.h" // _PyModule_GetState() #include "pycore_pyerrors.h" // _PyErr_SetString() #include "pycore_pylifecycle.h" // NSIG @@ -1809,7 +1809,7 @@ _PyErr_CheckSignalsTstate(PyThreadState *tstate) */ _Py_atomic_store(&is_tripped, 0); - _PyInterpreterFrame *fdata = tstate->cframe->current_frame; + _Py_framedata *fdata = 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 7c415f8b562ebc..a19f166f043308 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -629,8 +629,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_fdata == (_PyInterpreterFrame *)f->_f_frame_data); - _PyInterpreterFrame *frame = (_PyInterpreterFrame *)f->_f_frame_data; + assert(f->f_fdata == (_Py_framedata *)f->_f_frame_data); + _Py_framedata *frame = (_Py_framedata *)f->_f_frame_data; /* Don't clear code object until the end */ co = frame->code; frame->code = NULL; @@ -707,7 +707,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_framedata, localsplus); PyCodeObject *code = f->f_fdata->code; res += (code->co_nlocalsplus+code->co_stacksize) * sizeof(PyObject *); return PyLong_FromSsize_t(res); @@ -738,7 +738,7 @@ PyTypeObject PyFrame_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "frame", offsetof(PyFrameObject, _f_frame_data) + - offsetof(_PyInterpreterFrame, localsplus), + offsetof(_Py_framedata, localsplus), sizeof(PyObject *), (destructor)frame_dealloc, /* tp_dealloc */ 0, /* tp_vectorcall_offset */ @@ -771,7 +771,7 @@ PyTypeObject PyFrame_Type = { }; static void -init_frame(_PyInterpreterFrame *frame, PyFunctionObject *func, PyObject *locals) +init_frame(_Py_framedata *frame, PyFunctionObject *func, PyObject *locals) { /* _PyFrame_InitializeSpecials consumes reference to func */ Py_INCREF(func); @@ -827,8 +827,8 @@ PyFrame_New(PyThreadState *tstate, PyCodeObject *code, Py_DECREF(func); return NULL; } - init_frame((_PyInterpreterFrame *)f->_f_frame_data, func, locals); - f->f_fdata = (_PyInterpreterFrame *)f->_f_frame_data; + init_frame((_Py_framedata *)f->_f_frame_data, func, locals); + f->f_fdata = (_Py_framedata *)f->_f_frame_data; f->f_owns_frame = 1; Py_DECREF(func); _PyObject_GC_TRACK(f); @@ -836,7 +836,7 @@ PyFrame_New(PyThreadState *tstate, PyCodeObject *code, } static int -_PyFrame_OpAlreadyRan(_PyInterpreterFrame *fdata, int opcode, int oparg) +_PyFrame_OpAlreadyRan(_Py_framedata *fdata, int opcode, int oparg) { const _Py_CODEUNIT *code = (const _Py_CODEUNIT *)PyBytes_AS_STRING(fdata->code->co_code); @@ -849,7 +849,7 @@ _PyFrame_OpAlreadyRan(_PyInterpreterFrame *fdata, int opcode, int oparg) } int -_PyFrame_FastToLocalsWithError(_PyInterpreterFrame *frame) { +_PyFrame_FastToLocalsWithError(_Py_framedata *frame) { /* Merge fast locals into f->locals */ PyObject *locals; PyObject **fast; @@ -960,7 +960,7 @@ PyFrame_FastToLocals(PyFrameObject *f) } void -_PyFrame_LocalsToFast(_PyInterpreterFrame *frame, int clear) +_PyFrame_LocalsToFast(_Py_framedata *frame, int clear) { /* Merge locals into fast locals */ PyObject *locals; diff --git a/Objects/genobject.c b/Objects/genobject.c index fec2243f604ad8..40845bac9c0718 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_framedata #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_framedata *frame = (_Py_framedata *)(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_framedata *)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)->state == FRAME_CREATED) + ((_Py_framedata *)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_framedata *frame = (_Py_framedata *)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_framedata *frame = (_Py_framedata *)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_framedata *frame = (_Py_framedata *)gen->gi_iframe; PyObject *bytecode = gen->gi_code->co_code; unsigned char *code = (unsigned char *)PyBytes_AS_STRING(bytecode); @@ -377,7 +377,7 @@ gen_close(PyGenObject *gen, PyObject *args) int err = 0; if (yf) { - _PyInterpreterFrame *frame = (_PyInterpreterFrame *)gen->gi_iframe; + _Py_framedata *frame = (_Py_framedata *)gen->gi_iframe; PyFrameState state = frame->state; frame->state = FRAME_EXECUTING; err = gen_close_iter(yf); @@ -418,7 +418,7 @@ _gen_throw(PyGenObject *gen, int close_on_genexit, PyObject *yf = _PyGen_yf(gen); if (yf) { - _PyInterpreterFrame *frame = (_PyInterpreterFrame *)gen->gi_iframe; + _Py_framedata *frame = (_Py_framedata *)gen->gi_iframe; PyObject *ret; int err; if (PyErr_GivenExceptionMatches(typ, PyExc_GeneratorExit) && @@ -445,7 +445,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_framedata *prev = tstate->cframe->current_frame; frame->previous = prev; tstate->cframe->current_frame = frame; /* Close the generator that we are currently iterating with @@ -479,7 +479,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_framedata *)gen->gi_iframe); assert(ret == yf); Py_DECREF(ret); /* Termination repetition of SEND loop */ @@ -750,7 +750,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_framedata *)gen->gi_iframe)); } static PyObject * @@ -759,7 +759,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)->state == FRAME_SUSPENDED); + return PyBool_FromLong(((_Py_framedata *)gen->gi_iframe)->state == FRAME_SUSPENDED); } static PyObject * @@ -771,7 +771,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_framedata *)gen->gi_iframe)); } static PyObject * @@ -802,7 +802,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_framedata, localsplus); PyCodeObject *code = gen->gi_code; res += (code->co_nlocalsplus+code->co_stacksize) * sizeof(PyObject *); return PyLong_FromSsize_t(res); @@ -831,7 +831,7 @@ PyTypeObject PyGen_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "generator", /* tp_name */ offsetof(PyGenObject, gi_iframe) + - offsetof(_PyInterpreterFrame, localsplus), /* tp_basicsize */ + offsetof(_Py_framedata, localsplus), /* tp_basicsize */ sizeof(PyObject *), /* tp_itemsize */ /* methods */ (destructor)gen_dealloc, /* tp_dealloc */ @@ -905,7 +905,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_framedata *current_frame); PyObject * _Py_MakeCoro(PyFunctionObject *func) @@ -964,8 +964,8 @@ gen_new_with_qualname(PyTypeObject *type, PyFrameObject *f, /* Copy the frame */ 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_framedata *frame = (_Py_framedata *)gen->gi_iframe; + _PyFrame_Copy((_Py_framedata *)f->_f_frame_data, frame); gen->gi_frame_valid = 1; assert(frame->frame_obj == f); f->f_owns_frame = 0; @@ -1108,7 +1108,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)->state == FRAME_SUSPENDED); + return PyBool_FromLong(((_Py_framedata *)coro->cr_iframe)->state == FRAME_SUSPENDED); } static PyObject * @@ -1117,7 +1117,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_framedata *)coro->cr_iframe)); } static PyObject * @@ -1176,7 +1176,7 @@ PyTypeObject PyCoro_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "coroutine", /* tp_name */ offsetof(PyCoroObject, cr_iframe) + - offsetof(_PyInterpreterFrame, localsplus), /* tp_basicsize */ + offsetof(_Py_framedata, localsplus), /* tp_basicsize */ sizeof(PyObject *), /* tp_itemsize */ /* methods */ (destructor)gen_dealloc, /* tp_dealloc */ @@ -1314,9 +1314,9 @@ PyTypeObject _PyCoroWrapper_Type = { }; static PyObject * -compute_cr_origin(int origin_depth, _PyInterpreterFrame *current_frame) +compute_cr_origin(int origin_depth, _Py_framedata *current_frame) { - _PyInterpreterFrame *frame = current_frame; + _Py_framedata *frame = current_frame; /* First count how many frames we have */ int frame_count = 0; for (; frame && frame_count < origin_depth; ++frame_count) { @@ -1567,7 +1567,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_framedata, localsplus), /* tp_basicsize */ sizeof(PyObject *), /* tp_itemsize */ /* methods */ (destructor)gen_dealloc, /* tp_dealloc */ @@ -2053,7 +2053,7 @@ static PyObject * async_gen_athrow_send(PyAsyncGenAThrow *o, PyObject *arg) { PyGenObject *gen = (PyGenObject*)o->agt_gen; - _PyInterpreterFrame *frame = (_PyInterpreterFrame *)gen->gi_iframe; + _Py_framedata *frame = (_Py_framedata *)gen->gi_iframe; PyObject *retval; if (o->agt_state == AWAITABLE_STATE_CLOSED) { diff --git a/Objects/typeobject.c b/Objects/typeobject.c index c78a21561cbe9b..29748d2fb11a99 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_framedata #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_framedata *cframe, PyCodeObject *co, PyTypeObject **type_p, PyObject **obj_p) { if (co->co_argcount == 0) { @@ -9017,7 +9017,7 @@ super_init(PyObject *self, PyObject *args, PyObject *kwds) /* 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; + _Py_framedata *cframe = tstate->cframe->current_frame; if (cframe == NULL) { PyErr_SetString(PyExc_RuntimeError, "super(): no current frame"); diff --git a/Python/ceval.c b/Python/ceval.c index a44b7d1ad60b73..7418b860def8a7 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_framedata *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_framedata *, int, PyObject *); static int call_trace_protected(Py_tracefunc, PyObject *, - PyThreadState *, _PyInterpreterFrame *, + PyThreadState *, _Py_framedata *, int, PyObject *); static void call_exc_trace(Py_tracefunc, PyObject *, - PyThreadState *, _PyInterpreterFrame *); + PyThreadState *, _Py_framedata *); 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_framedata *, int); +static void maybe_dtrace_line(_Py_framedata *, PyTraceInfo *, int); +static void dtrace_function_entry(_Py_framedata *); +static void dtrace_function_return(_Py_framedata *); -static PyObject * import_name(PyThreadState *, _PyInterpreterFrame *, +static PyObject * import_name(PyThreadState *, _Py_framedata *, 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_framedata * _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_framedata *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 *fdata) +trace_function_entry(PyThreadState *tstate, _Py_framedata *fdata) { if (tstate->c_tracefunc != NULL) { /* tstate->c_tracefunc, if defined, is a @@ -1547,7 +1547,7 @@ trace_function_entry(PyThreadState *tstate, _PyInterpreterFrame *fdata) } static int -trace_function_exit(PyThreadState *tstate, _PyInterpreterFrame *frame, PyObject *retval) +trace_function_exit(PyThreadState *tstate, _Py_framedata *frame, PyObject *retval) { if (tstate->c_tracefunc) { if (call_trace_protected(tstate->c_tracefunc, tstate->c_traceobj, @@ -1574,10 +1574,10 @@ skip_backwards_over_extended_args(PyCodeObject *code, int offset) return offset; } -static _PyInterpreterFrame * -pop_frame(PyThreadState *tstate, _PyInterpreterFrame *frame) +static _Py_framedata * +pop_frame(PyThreadState *tstate, _Py_framedata *frame) { - _PyInterpreterFrame *prev_frame = frame->previous; + _Py_framedata *prev_frame = frame->previous; _PyEvalFrameClearAndPop(tstate, frame); return prev_frame; } @@ -1598,7 +1598,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_framedata *frame, int throwflag) { _Py_EnsureTstateNotNULL(tstate); CALL_STAT_INC(pyeval_calls); @@ -2208,7 +2208,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_framedata *new_frame = _PyThreadState_BumpFramePointer(tstate, size); if (new_frame == NULL) { goto error; } @@ -4637,7 +4637,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_framedata *new_frame = _PyEvalFramePushAndInit( tstate, (PyFunctionObject *)function, locals, stack_pointer, positional_args, call_shape.kwnames ); @@ -4746,7 +4746,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_framedata *new_frame = _PyFrame_Push(tstate, func); if (new_frame == NULL) { goto error; } @@ -4781,7 +4781,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int int minargs = cache1->min_args; DEOPT_IF(argcount < minargs, CALL); STAT_INC(CALL, hit); - _PyInterpreterFrame *new_frame = _PyFrame_Push(tstate, func); + _Py_framedata *new_frame = _PyFrame_Push(tstate, func); if (new_frame == NULL) { goto error; } @@ -5299,7 +5299,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int } assert(EMPTY()); _PyFrame_SetStackPointer(frame, stack_pointer); - _PyInterpreterFrame *gen_frame = (_PyInterpreterFrame *)gen->gi_iframe; + _Py_framedata *gen_frame = (_Py_framedata *)gen->gi_iframe; _PyFrame_Copy(frame, gen_frame); assert(frame->frame_obj == NULL); gen->gi_frame_valid = 1; @@ -5307,7 +5307,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int gen_frame->state = FRAME_CREATED; _Py_LeaveRecursiveCall(tstate); if (!frame->is_entry) { - _PyInterpreterFrame *prev = frame->previous; + _Py_framedata *prev = frame->previous; _PyThreadState_PopFrame(tstate, frame); frame = cframe.current_frame = prev; _PyFrame_StackPush(frame, (PyObject *)gen); @@ -6239,7 +6239,7 @@ initialize_locals(PyThreadState *tstate, PyFunctionObject *func, } /* Consumes references to func and all the args */ -static _PyInterpreterFrame * +static _Py_framedata * _PyEvalFramePushAndInit(PyThreadState *tstate, PyFunctionObject *func, PyObject *locals, PyObject* const* args, size_t argcount, PyObject *kwnames) @@ -6247,7 +6247,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_framedata *frame = _PyThreadState_BumpFramePointer(tstate, size); if (frame == NULL) { goto fail; } @@ -6277,7 +6277,7 @@ _PyEvalFramePushAndInit(PyThreadState *tstate, PyFunctionObject *func, } static void -_PyEvalFrameClearAndPop(PyThreadState *tstate, _PyInterpreterFrame * frame) +_PyEvalFrameClearAndPop(PyThreadState *tstate, _Py_framedata * frame) { tstate->recursion_remaining--; assert(frame->frame_obj == NULL || frame->frame_obj->f_owns_frame == 0); @@ -6304,7 +6304,7 @@ _PyEval_Vector(PyThreadState *tstate, PyFunctionObject *func, Py_INCREF(args[i+argcount]); } } - _PyInterpreterFrame *frame = _PyEvalFramePushAndInit( + _Py_framedata *frame = _PyEvalFramePushAndInit( tstate, func, locals, args, argcount, kwnames); if (frame == NULL) { return NULL; @@ -6673,7 +6673,7 @@ prtrace(PyThreadState *tstate, PyObject *v, const char *str) static void call_exc_trace(Py_tracefunc func, PyObject *self, PyThreadState *tstate, - _PyInterpreterFrame *fdata) + _Py_framedata *fdata) { PyObject *type, *value, *traceback, *orig_traceback, *arg; int err; @@ -6703,7 +6703,7 @@ call_exc_trace(Py_tracefunc func, PyObject *self, static int call_trace_protected(Py_tracefunc func, PyObject *obj, - PyThreadState *tstate, _PyInterpreterFrame *fdata, + PyThreadState *tstate, _Py_framedata *fdata, int what, PyObject *arg) { PyObject *type, *value, *traceback; @@ -6724,7 +6724,7 @@ call_trace_protected(Py_tracefunc func, PyObject *obj, } static void -initialize_trace_info(PyTraceInfo *trace_info, _PyInterpreterFrame *fdata) +initialize_trace_info(PyTraceInfo *trace_info, _Py_framedata *fdata) { PyCodeObject *code = fdata->code; if (trace_info->code != code) { @@ -6735,7 +6735,7 @@ initialize_trace_info(PyTraceInfo *trace_info, _PyInterpreterFrame *fdata) static int call_trace(Py_tracefunc func, PyObject *obj, - PyThreadState *tstate, _PyInterpreterFrame *frame, + PyThreadState *tstate, _Py_framedata *frame, int what, PyObject *arg) { int result; @@ -6776,7 +6776,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_framedata *frame, int instr_prev) { int result = 0; @@ -6954,7 +6954,7 @@ _PyEval_GetAsyncGenFinalizer(void) return tstate->async_gen_finalizer; } -_PyInterpreterFrame * +_Py_framedata * _PyEval_GetFrame(void) { PyThreadState *tstate = _PyThreadState_GET(); @@ -6978,7 +6978,7 @@ PyEval_GetFrame(void) PyObject * _PyEval_GetBuiltins(PyThreadState *tstate) { - _PyInterpreterFrame *frame = tstate->cframe->current_frame; + _Py_framedata *frame = tstate->cframe->current_frame; if (frame != NULL) { return frame->builtins; } @@ -7017,7 +7017,7 @@ PyObject * PyEval_GetLocals(void) { PyThreadState *tstate = _PyThreadState_GET(); - _PyInterpreterFrame *fdata = tstate->cframe->current_frame; + _Py_framedata *fdata = tstate->cframe->current_frame; if (fdata == NULL) { _PyErr_SetString(tstate, PyExc_SystemError, "frame data does not exist"); return NULL; @@ -7036,7 +7036,7 @@ PyObject * PyEval_GetGlobals(void) { PyThreadState *tstate = _PyThreadState_GET(); - _PyInterpreterFrame *fdata = tstate->cframe->current_frame; + _Py_framedata *fdata = tstate->cframe->current_frame; if (fdata == NULL) { _PyErr_SetString(tstate, PyExc_SystemError, "frame data does not exist"); return NULL; @@ -7048,7 +7048,7 @@ int PyEval_MergeCompilerFlags(PyCompilerFlags *cf) { PyThreadState *tstate = _PyThreadState_GET(); - _PyInterpreterFrame *fdata = tstate->cframe->current_frame; + _Py_framedata *fdata = tstate->cframe->current_frame; int result = cf->cf_flags != 0; if (fdata != NULL) { @@ -7252,7 +7252,7 @@ _PyEval_SliceIndexNotNone(PyObject *v, Py_ssize_t *pi) } static PyObject * -import_name(PyThreadState *tstate, _PyInterpreterFrame *fdata, +import_name(PyThreadState *tstate, _Py_framedata *fdata, PyObject *name, PyObject *fromlist, PyObject *level) { PyObject *import_func, *res; @@ -7723,7 +7723,7 @@ _PyEval_RequestCodeExtraIndex(freefunc free) } static void -dtrace_function_entry(_PyInterpreterFrame *fdata) +dtrace_function_entry(_Py_framedata *fdata) { const char *filename; const char *funcname; @@ -7738,7 +7738,7 @@ dtrace_function_entry(_PyInterpreterFrame *fdata) } static void -dtrace_function_return(_PyInterpreterFrame *fdata) +dtrace_function_return(_Py_framedata *fdata) { const char *filename; const char *funcname; @@ -7754,7 +7754,7 @@ dtrace_function_return(_PyInterpreterFrame *fdata) /* DTrace equivalent of maybe_call_line_trace. */ static void -maybe_dtrace_line(_PyInterpreterFrame *fdata, +maybe_dtrace_line(_Py_framedata *fdata, PyTraceInfo *trace_info, int instr_prev) { diff --git a/Python/frame.c b/Python/frame.c index 022fb328c9ecc0..36890863845980 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_framedata *frame, visitproc visit, void *arg) { Py_VISIT(frame->frame_obj); Py_VISIT(frame->locals); @@ -24,7 +24,7 @@ _PyFrame_Traverse(_PyInterpreterFrame *frame, visitproc visit, void *arg) } PyFrameObject * -_PyFrame_MakeAndSetFrameObject(_PyInterpreterFrame *frame) +_PyFrame_MakeAndSetFrameObject(_Py_framedata *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_framedata *src, _Py_framedata *dest) { assert(src->stacktop >= src->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_framedata *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_framedata *)f->_f_frame_data, frame, size); + frame = (_Py_framedata *)f->_f_frame_data; f->f_owns_frame = 1; 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_framedata.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_framedata *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_framedata * _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_framedata *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 070948b9d5acd3..182406f6de2d53 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -1410,7 +1410,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_framedata *frame = t->cframe->current_frame; if (frame == NULL) { continue; } @@ -2197,7 +2197,7 @@ push_chunk(PyThreadState *tstate, int size) return res; } -_PyInterpreterFrame * +_Py_framedata * _PyThreadState_BumpFramePointerSlow(PyThreadState *tstate, size_t size) { assert(size < INT_MAX/sizeof(PyObject *)); @@ -2209,11 +2209,11 @@ _PyThreadState_BumpFramePointerSlow(PyThreadState *tstate, size_t size) else { tstate->datastack_top = top; } - return (_PyInterpreterFrame *)base; + return (_Py_framedata *)base; } void -_PyThreadState_PopFrame(PyThreadState *tstate, _PyInterpreterFrame * frame) +_PyThreadState_PopFrame(PyThreadState *tstate, _Py_framedata * frame) { assert(tstate->datastack_chunk); PyObject **base = (PyObject **)frame; diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 7e96fcca57d7a8..826e6967dc160b 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_framedata #include "pycore_initconfig.h" // _PyStatus_EXCEPTION() #include "pycore_namespace.h" // _PyNamespace_New() #include "pycore_object.h" // _PyObject_IS_GC() @@ -1807,7 +1807,7 @@ sys__getframe_impl(PyObject *module, int depth) /*[clinic end generated code: output=d438776c04d59804 input=c1be8a6464b11ee5]*/ { PyThreadState *tstate = _PyThreadState_GET(); - _PyInterpreterFrame *fdata = tstate->cframe->current_frame; + _Py_framedata *fdata = 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 2a204b45b6a46f..14a90dc0188d11 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 *fdata) +dump_frame(int fd, _Py_framedata *fdata) { PyCodeObject *code = fdata->code; PUTS(fd, " File "); @@ -1205,7 +1205,7 @@ dump_frame(int fd, _PyInterpreterFrame *fdata) static void dump_traceback(int fd, PyThreadState *tstate, int write_header) { - _PyInterpreterFrame *fdata; + _Py_framedata *fdata; unsigned int depth = 0; if (write_header) { diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py index 84e1e7d6c55df1..246771d0501cef 100755 --- a/Tools/gdb/libpython.py +++ b/Tools/gdb/libpython.py @@ -914,7 +914,7 @@ def __init__(self, gdbval, cast_to=None): PyObjectPtr.__init__(self, gdbval, cast_to) if not self.is_optimized_out(): - self._fdata = _PyInterpreterFramePtr(self.field('f_fdata')) + self._fdata = _Py_framedataPtr(self.field('f_fdata')) def iter_locals(self): ''' From 2866bfa82153be037213bf1a01539811e23515a4 Mon Sep 17 00:00:00 2001 From: Nick Coghlan <ncoghlan@gmail.com> Date: Sun, 6 Mar 2022 13:09:25 +1000 Subject: [PATCH 15/30] Fix type declaration for gen/coro frame data --- Include/cpython/genobject.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Include/cpython/genobject.h b/Include/cpython/genobject.h index b485ac6183e2ee..74096c77dc38a9 100644 --- a/Include/cpython/genobject.h +++ b/Include/cpython/genobject.h @@ -28,7 +28,7 @@ extern "C" { char prefix##_running_async; \ /* The frame */ \ char prefix##_frame_valid; \ - PyObject *prefix##_iframe[1]; + void *prefix##_iframe[1]; typedef struct { /* The gi_ prefix is intended to remind of generator-iterator. */ From 239a62fa8e0dd9d93505f0ed4fee60e7db4c16f0 Mon Sep 17 00:00:00 2001 From: Nick Coghlan <ncoghlan@gmail.com> Date: Sun, 6 Mar 2022 13:10:03 +1000 Subject: [PATCH 16/30] Document frame related naming conventions --- Include/internal/pycore_frame.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Include/internal/pycore_frame.h b/Include/internal/pycore_frame.h index 8da7f8130ddda5..bf5d7bcf51f209 100644 --- a/Include/internal/pycore_frame.h +++ b/Include/internal/pycore_frame.h @@ -19,8 +19,22 @@ extern "C" { * 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 + * + * Variable naming conventions: + * + * * "frame" and "f" are used for full frame objects + * * "fdata" is used for frame data structs + * + * Function/macro naming conventions: + * + * * "PyFrame_*"" and "_PyFrame_*" functions accept a full frame object + * * "_Py_framedata_*" functions accept a frame data struct */ -// Declaration of _Py_framedata is in cpython/pystate.h for use in PyThreadState struct _frame { From 2680f35d44e501928423676de82f360e15c0105a Mon Sep 17 00:00:00 2001 From: Nick Coghlan <ncoghlan@gmail.com> Date: Sun, 6 Mar 2022 13:13:46 +1000 Subject: [PATCH 17/30] Migrate gen/coro iframe field to fdata naming convention --- Include/cpython/genobject.h | 2 +- Objects/frameobject.c | 2 +- Objects/genobject.c | 40 ++++++++++++++++++------------------- Python/ceval.c | 2 +- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Include/cpython/genobject.h b/Include/cpython/genobject.h index 74096c77dc38a9..a206d3be62c09a 100644 --- a/Include/cpython/genobject.h +++ b/Include/cpython/genobject.h @@ -28,7 +28,7 @@ extern "C" { char prefix##_running_async; \ /* The frame */ \ char prefix##_frame_valid; \ - void *prefix##_iframe[1]; + void *prefix##_fdata[1]; typedef struct { /* The gi_ prefix is intended to remind of generator-iterator. */ diff --git a/Objects/frameobject.c b/Objects/frameobject.c index a19f166f043308..9554162039ec29 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -692,7 +692,7 @@ frame_clear(PyFrameObject *f, PyObject *Py_UNUSED(ignored)) } if (f->f_fdata->is_generator) { assert(!f->f_owns_frame); - size_t offset_in_gen = offsetof(PyGenObject, gi_iframe); + size_t offset_in_gen = offsetof(PyGenObject, gi_fdata); PyObject *gen = (PyObject *)(((char *)f->f_fdata) - offset_in_gen); _PyGen_Finalize(gen); } diff --git a/Objects/genobject.c b/Objects/genobject.c index 40845bac9c0718..cd8f9933bb7075 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -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) { - _Py_framedata *frame = (_Py_framedata *)(gen->gi_iframe); + _Py_framedata *frame = (_Py_framedata *)(gen->gi_fdata); 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((_Py_framedata *)gen->gi_iframe)) { + if (gen->gi_frame_valid == 0 || _PyFrameHasCompleted((_Py_framedata *)gen->gi_fdata)) { /* 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 && - ((_Py_framedata *)gen->gi_iframe)->state == FRAME_CREATED) + ((_Py_framedata *)gen->gi_fdata)->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) { - _Py_framedata *frame = (_Py_framedata *)gen->gi_iframe; + _Py_framedata *frame = (_Py_framedata *)gen->gi_fdata; 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(); - _Py_framedata *frame = (_Py_framedata *)gen->gi_iframe; + _Py_framedata *frame = (_Py_framedata *)gen->gi_fdata; PyObject *result; *presult = NULL; @@ -348,7 +348,7 @@ _PyGen_yf(PyGenObject *gen) PyObject *yf = NULL; if (gen->gi_frame_valid) { - _Py_framedata *frame = (_Py_framedata *)gen->gi_iframe; + _Py_framedata *frame = (_Py_framedata *)gen->gi_fdata; PyObject *bytecode = gen->gi_code->co_code; unsigned char *code = (unsigned char *)PyBytes_AS_STRING(bytecode); @@ -377,7 +377,7 @@ gen_close(PyGenObject *gen, PyObject *args) int err = 0; if (yf) { - _Py_framedata *frame = (_Py_framedata *)gen->gi_iframe; + _Py_framedata *frame = (_Py_framedata *)gen->gi_fdata; PyFrameState state = frame->state; frame->state = FRAME_EXECUTING; err = gen_close_iter(yf); @@ -418,7 +418,7 @@ _gen_throw(PyGenObject *gen, int close_on_genexit, PyObject *yf = _PyGen_yf(gen); if (yf) { - _Py_framedata *frame = (_Py_framedata *)gen->gi_iframe; + _Py_framedata *frame = (_Py_framedata *)gen->gi_fdata; PyObject *ret; int err; if (PyErr_GivenExceptionMatches(typ, PyExc_GeneratorExit) && @@ -479,7 +479,7 @@ _gen_throw(PyGenObject *gen, int close_on_genexit, PyObject *val; /* Pop subiterator from stack */ assert(gen->gi_frame_valid); - ret = _PyFrame_StackPop((_Py_framedata *)gen->gi_iframe); + ret = _PyFrame_StackPop((_Py_framedata *)gen->gi_fdata); assert(ret == yf); Py_DECREF(ret); /* Termination repetition of SEND loop */ @@ -750,7 +750,7 @@ gen_getrunning(PyGenObject *gen, void *Py_UNUSED(ignored)) if (gen->gi_frame_valid == 0) { Py_RETURN_FALSE; } - return PyBool_FromLong(_PyFrame_IsExecuting((_Py_framedata *)gen->gi_iframe)); + return PyBool_FromLong(_PyFrame_IsExecuting((_Py_framedata *)gen->gi_fdata)); } static PyObject * @@ -759,7 +759,7 @@ gen_getsuspended(PyGenObject *gen, void *Py_UNUSED(ignored)) if (gen->gi_frame_valid == 0) { Py_RETURN_FALSE; } - return PyBool_FromLong(((_Py_framedata *)gen->gi_iframe)->state == FRAME_SUSPENDED); + return PyBool_FromLong(((_Py_framedata *)gen->gi_fdata)->state == FRAME_SUSPENDED); } static PyObject * @@ -771,7 +771,7 @@ _gen_getframe(PyGenObject *gen, const char *const name) if (gen->gi_frame_valid == 0) { Py_RETURN_NONE; } - return _Py_XNewRef((PyObject *)_PyFrame_GetFrameObject((_Py_framedata *)gen->gi_iframe)); + return _Py_XNewRef((PyObject *)_PyFrame_GetFrameObject((_Py_framedata *)gen->gi_fdata)); } static PyObject * @@ -802,7 +802,7 @@ static PyObject * gen_sizeof(PyGenObject *gen, PyObject *Py_UNUSED(ignored)) { Py_ssize_t res; - res = offsetof(PyGenObject, gi_iframe) + offsetof(_Py_framedata, localsplus); + res = offsetof(PyGenObject, gi_fdata) + offsetof(_Py_framedata, localsplus); PyCodeObject *code = gen->gi_code; res += (code->co_nlocalsplus+code->co_stacksize) * sizeof(PyObject *); return PyLong_FromSsize_t(res); @@ -830,7 +830,7 @@ static PyAsyncMethods gen_as_async = { PyTypeObject PyGen_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "generator", /* tp_name */ - offsetof(PyGenObject, gi_iframe) + + offsetof(PyGenObject, gi_fdata) + offsetof(_Py_framedata, localsplus), /* tp_basicsize */ sizeof(PyObject *), /* tp_itemsize */ /* methods */ @@ -964,7 +964,7 @@ gen_new_with_qualname(PyTypeObject *type, PyFrameObject *f, /* Copy the frame */ assert(f->f_fdata->frame_obj == NULL); assert(f->f_owns_frame); - _Py_framedata *frame = (_Py_framedata *)gen->gi_iframe; + _Py_framedata *frame = (_Py_framedata *)gen->gi_fdata; _PyFrame_Copy((_Py_framedata *)f->_f_frame_data, frame); gen->gi_frame_valid = 1; assert(frame->frame_obj == f); @@ -1108,7 +1108,7 @@ cr_getsuspended(PyCoroObject *coro, void *Py_UNUSED(ignored)) if (coro->cr_frame_valid == 0) { Py_RETURN_FALSE; } - return PyBool_FromLong(((_Py_framedata *)coro->cr_iframe)->state == FRAME_SUSPENDED); + return PyBool_FromLong(((_Py_framedata *)coro->cr_fdata)->state == FRAME_SUSPENDED); } static PyObject * @@ -1117,7 +1117,7 @@ cr_getrunning(PyCoroObject *coro, void *Py_UNUSED(ignored)) if (coro->cr_frame_valid == 0) { Py_RETURN_FALSE; } - return PyBool_FromLong(_PyFrame_IsExecuting((_Py_framedata *)coro->cr_iframe)); + return PyBool_FromLong(_PyFrame_IsExecuting((_Py_framedata *)coro->cr_fdata)); } static PyObject * @@ -1175,7 +1175,7 @@ static PyAsyncMethods coro_as_async = { PyTypeObject PyCoro_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "coroutine", /* tp_name */ - offsetof(PyCoroObject, cr_iframe) + + offsetof(PyCoroObject, cr_fdata) + offsetof(_Py_framedata, localsplus), /* tp_basicsize */ sizeof(PyObject *), /* tp_itemsize */ /* methods */ @@ -1566,7 +1566,7 @@ static PyAsyncMethods async_gen_as_async = { PyTypeObject PyAsyncGen_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "async_generator", /* tp_name */ - offsetof(PyAsyncGenObject, ag_iframe) + + offsetof(PyAsyncGenObject, ag_fdata) + offsetof(_Py_framedata, localsplus), /* tp_basicsize */ sizeof(PyObject *), /* tp_itemsize */ /* methods */ @@ -2053,7 +2053,7 @@ static PyObject * async_gen_athrow_send(PyAsyncGenAThrow *o, PyObject *arg) { PyGenObject *gen = (PyGenObject*)o->agt_gen; - _Py_framedata *frame = (_Py_framedata *)gen->gi_iframe; + _Py_framedata *frame = (_Py_framedata *)gen->gi_fdata; PyObject *retval; if (o->agt_state == AWAITABLE_STATE_CLOSED) { diff --git a/Python/ceval.c b/Python/ceval.c index 7418b860def8a7..a8648159ef22a4 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -5299,7 +5299,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *frame, int throwf } assert(EMPTY()); _PyFrame_SetStackPointer(frame, stack_pointer); - _Py_framedata *gen_frame = (_Py_framedata *)gen->gi_iframe; + _Py_framedata *gen_frame = (_Py_framedata *)gen->gi_fdata; _PyFrame_Copy(frame, gen_frame); assert(frame->frame_obj == NULL); gen->gi_frame_valid = 1; From ebda1d308426d09109360a7895e035d6bcd1352f Mon Sep 17 00:00:00 2001 From: Nick Coghlan <ncoghlan@gmail.com> Date: Sat, 12 Mar 2022 17:17:25 +1000 Subject: [PATCH 18/30] Use fdata for frame data locals and parameters --- Include/cpython/ceval.h | 2 +- Include/internal/pycore_ceval.h | 6 +- Include/internal/pycore_frame.h | 54 +++++++-------- Objects/frameobject.c | 54 +++++++-------- Objects/genobject.c | 116 ++++++++++++++++---------------- Python/ceval.c | 76 ++++++++++----------- Python/frame.c | 66 +++++++++--------- Python/pystate.c | 6 +- 8 files changed, 190 insertions(+), 190 deletions(-) diff --git a/Include/cpython/ceval.h b/Include/cpython/ceval.h index f811879f896d17..eb30bfaa923eba 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 _Py_framedata *f, int exc); +PyAPI_FUNC(PyObject *) _PyEval_EvalFrameDefault(PyThreadState *tstate, struct _Py_framedata *fdata, int exc); PyAPI_FUNC(void) _PyEval_SetSwitchInterval(unsigned long microseconds); PyAPI_FUNC(unsigned long) _PyEval_GetSwitchInterval(void); diff --git a/Include/internal/pycore_ceval.h b/Include/internal/pycore_ceval.h index e0f66fdb906cb0..d65056f07d325c 100644 --- a/Include/internal/pycore_ceval.h +++ b/Include/internal/pycore_ceval.h @@ -47,12 +47,12 @@ extern PyObject *_PyEval_BuiltinsFromGlobals( static inline PyObject* -_PyEval_EvalFrame(PyThreadState *tstate, struct _Py_framedata *frame, int throwflag) +_PyEval_EvalFrame(PyThreadState *tstate, struct _Py_framedata *fdata, int throwflag) { if (tstate->interp->eval_frame == NULL) { - return _PyEval_EvalFrameDefault(tstate, frame, throwflag); + return _PyEval_EvalFrameDefault(tstate, fdata, throwflag); } - return tstate->interp->eval_frame(tstate, frame, throwflag); + return tstate->interp->eval_frame(tstate, fdata, throwflag); } extern PyObject * diff --git a/Include/internal/pycore_frame.h b/Include/internal/pycore_frame.h index bf5d7bcf51f209..2705884063428a 100644 --- a/Include/internal/pycore_frame.h +++ b/Include/internal/pycore_frame.h @@ -123,9 +123,9 @@ static inline PyObject *_PyFrame_StackPop(_Py_framedata *f) { return f->localsplus[f->stacktop]; } -static inline void _PyFrame_StackPush(_Py_framedata *f, PyObject *value) { - f->localsplus[f->stacktop] = value; - f->stacktop++; +static inline void _PyFrame_StackPush(_Py_framedata *fdata, PyObject *value) { + fdata->localsplus[fdata->stacktop] = value; + fdata->stacktop++; } #define FRAME_SPECIALS_SIZE ((sizeof(_Py_framedata)-1)/sizeof(PyObject *)) @@ -135,47 +135,47 @@ void _PyFrame_Copy(_Py_framedata *src, _Py_framedata *dest); /* Consumes reference to func */ static inline void _PyFrame_InitializeSpecials( - _Py_framedata *frame, PyFunctionObject *func, + _Py_framedata *fdata, PyFunctionObject *func, PyObject *locals, int nlocalsplus) { - 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->lasti = -1; - frame->state = FRAME_CREATED; - frame->is_entry = false; - frame->is_generator = false; + fdata->func = func; + fdata->code = (PyCodeObject *)Py_NewRef(func->func_code); + fdata->builtins = func->func_builtins; + fdata->globals = func->func_globals; + fdata->locals = Py_XNewRef(locals); + fdata->stacktop = nlocalsplus; + fdata->frame_obj = NULL; + fdata->lasti = -1; + fdata->state = FRAME_CREATED; + fdata->is_entry = false; + fdata->is_generator = false; } /* Gets the pointer to the locals array * that precedes this frame. */ static inline PyObject** -_PyFrame_GetLocalsArray(_Py_framedata *frame) +_PyFrame_GetLocalsArray(_Py_framedata *fdata) { - return frame->localsplus; + return fdata->localsplus; } static inline PyObject** -_PyFrame_GetStackPointer(_Py_framedata *frame) +_PyFrame_GetStackPointer(_Py_framedata *fdata) { - return frame->localsplus+frame->stacktop; + return fdata->localsplus+fdata->stacktop; } static inline void -_PyFrame_SetStackPointer(_Py_framedata *frame, PyObject **stack_pointer) +_PyFrame_SetStackPointer(_Py_framedata *fdata, PyObject **stack_pointer) { - frame->stacktop = (int)(stack_pointer - frame->localsplus); + fdata->stacktop = (int)(stack_pointer - fdata->localsplus); } /* For use by _PyFrame_GetFrameObject Do not call directly. */ PyFrameObject * -_PyFrame_MakeAndSetFrameObject(_Py_framedata *frame); +_PyFrame_MakeAndSetFrameObject(_Py_framedata *fdata); /* Gets the PyFrameObject for this frame, lazily * creating it if necessary. @@ -200,16 +200,16 @@ _PyFrame_GetFrameObject(_Py_framedata *fdata) * frames like the ones in generators and coroutines. */ void -_PyFrame_Clear(_Py_framedata * frame); +_PyFrame_Clear(_Py_framedata * fdata); int -_PyFrame_Traverse(_Py_framedata *frame, visitproc visit, void *arg); +_PyFrame_Traverse(_Py_framedata *fdata, visitproc visit, void *arg); int -_PyFrame_FastToLocalsWithError(_Py_framedata *frame); +_PyFrame_FastToLocalsWithError(_Py_framedata *fdata); void -_PyFrame_LocalsToFast(_Py_framedata *frame, int clear); +_PyFrame_LocalsToFast(_Py_framedata *fdata, int clear); extern _Py_framedata * _PyThreadState_BumpFramePointerSlow(PyThreadState *tstate, size_t size); @@ -229,7 +229,7 @@ _PyThreadState_BumpFramePointer(PyThreadState *tstate, size_t size) return _PyThreadState_BumpFramePointerSlow(tstate, size); } -void _PyThreadState_PopFrame(PyThreadState *tstate, _Py_framedata *frame); +void _PyThreadState_PopFrame(PyThreadState *tstate, _Py_framedata *fdata); /* Consume reference to func */ _Py_framedata * diff --git a/Objects/frameobject.c b/Objects/frameobject.c index 9554162039ec29..7b1bc93f698b6d 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -630,14 +630,14 @@ frame_dealloc(PyFrameObject *f) if (f->f_owns_frame) { f->f_owns_frame = 0; assert(f->f_fdata == (_Py_framedata *)f->_f_frame_data); - _Py_framedata *frame = (_Py_framedata *)f->_f_frame_data; + _Py_framedata *fdata = (_Py_framedata *)f->_f_frame_data; /* Don't clear code object until the end */ - 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++) { + co = fdata->code; + fdata->code = NULL; + Py_CLEAR(fdata->func); + Py_CLEAR(fdata->locals); + PyObject **locals = _PyFrame_GetLocalsArray(fdata); + for (int i = 0; i < fdata->stacktop; i++) { Py_CLEAR(locals[i]); } } @@ -771,14 +771,14 @@ PyTypeObject PyFrame_Type = { }; static void -init_frame(_Py_framedata *frame, PyFunctionObject *func, PyObject *locals) +init_frame(_Py_framedata *fdata, PyFunctionObject *func, PyObject *locals) { /* _PyFrame_InitializeSpecials consumes reference to func */ Py_INCREF(func); PyCodeObject *code = (PyCodeObject *)func->func_code; - _PyFrame_InitializeSpecials(frame, func, locals, code->co_nlocalsplus); + _PyFrame_InitializeSpecials(fdata, func, locals, code->co_nlocalsplus); for (Py_ssize_t i = 0; i < code->co_nlocalsplus; i++) { - frame->localsplus[i] = NULL; + fdata->localsplus[i] = NULL; } } @@ -849,30 +849,30 @@ _PyFrame_OpAlreadyRan(_Py_framedata *fdata, int opcode, int oparg) } int -_PyFrame_FastToLocalsWithError(_Py_framedata *frame) { +_PyFrame_FastToLocalsWithError(_Py_framedata *fdata) { /* Merge fast locals into f->locals */ PyObject *locals; PyObject **fast; PyCodeObject *co; - locals = frame->locals; + locals = fdata->locals; if (locals == NULL) { - locals = frame->locals = PyDict_New(); + locals = fdata->locals = PyDict_New(); if (locals == NULL) return -1; } - co = frame->code; - fast = _PyFrame_GetLocalsArray(frame); - if (frame->lasti < 0 && _Py_OPCODE(co->co_firstinstr[0]) == COPY_FREE_VARS) { + co = fdata->code; + fast = _PyFrame_GetLocalsArray(fdata); + if (fdata->lasti < 0 && _Py_OPCODE(co->co_firstinstr[0]) == COPY_FREE_VARS) { /* Free vars have not been initialized -- Do that */ - PyCodeObject *co = frame->code; - PyObject *closure = frame->func->func_closure; + PyCodeObject *co = fdata->code; + PyObject *closure = fdata->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; + fdata->localsplus[offset + i] = o; } - frame->lasti = 0; + fdata->lasti = 0; } for (int i = 0; i < co->co_nlocalsplus; i++) { _PyLocals_Kind kind = _PyLocals_GetKind(co->co_localspluskinds, i); @@ -891,7 +891,7 @@ _PyFrame_FastToLocalsWithError(_Py_framedata *frame) { PyObject *name = PyTuple_GET_ITEM(co->co_localsplusnames, i); PyObject *value = fast[i]; - if (frame->state != FRAME_CLEARED) { + if (fdata->state != FRAME_CLEARED) { if (kind & CO_FAST_FREE) { // The cell was set by COPY_FREE_VARS. assert(value != NULL && PyCell_Check(value)); @@ -904,7 +904,7 @@ _PyFrame_FastToLocalsWithError(_Py_framedata *frame) { // run yet. if (value != NULL) { if (PyCell_Check(value) && - _PyFrame_OpAlreadyRan(frame, MAKE_CELL, i)) { + _PyFrame_OpAlreadyRan(fdata, MAKE_CELL, i)) { // (likely) MAKE_CELL must have executed already. value = PyCell_GET(value); } @@ -960,18 +960,18 @@ PyFrame_FastToLocals(PyFrameObject *f) } void -_PyFrame_LocalsToFast(_Py_framedata *frame, int clear) +_PyFrame_LocalsToFast(_Py_framedata *fdata, int clear) { /* Merge locals into fast locals */ PyObject *locals; PyObject **fast; PyObject *error_type, *error_value, *error_traceback; PyCodeObject *co; - locals = frame->locals; + locals = fdata->locals; if (locals == NULL) return; - fast = _PyFrame_GetLocalsArray(frame); - co = frame->code; + fast = _PyFrame_GetLocalsArray(fdata); + co = fdata->code; PyErr_Fetch(&error_type, &error_value, &error_traceback); for (int i = 0; i < co->co_nlocalsplus; i++) { @@ -1001,7 +1001,7 @@ _PyFrame_LocalsToFast(_Py_framedata *frame, int clear) else if (kind & CO_FAST_CELL && oldvalue != NULL) { /* Same test as in PyFrame_FastToLocals() above. */ if (PyCell_Check(oldvalue) && - _PyFrame_OpAlreadyRan(frame, MAKE_CELL, i)) { + _PyFrame_OpAlreadyRan(fdata, MAKE_CELL, i)) { // (likely) MAKE_CELL must have executed already. cell = oldvalue; } diff --git a/Objects/genobject.c b/Objects/genobject.c index cd8f9933bb7075..f008cfbef2c1a6 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -36,9 +36,9 @@ gen_traverse(PyGenObject *gen, visitproc visit, void *arg) Py_VISIT(gen->gi_name); Py_VISIT(gen->gi_qualname); if (gen->gi_frame_valid) { - _Py_framedata *frame = (_Py_framedata *)(gen->gi_fdata); - assert(frame->frame_obj == NULL || frame->frame_obj->f_owns_frame == 0); - int err = _PyFrame_Traverse(frame, visit, arg); + _Py_framedata *fdata = (_Py_framedata *)(gen->gi_fdata); + assert(fdata->frame_obj == NULL || fdata->frame_obj->f_owns_frame == 0); + int err = _PyFrame_Traverse(fdata, visit, arg); if (err) { return err; } @@ -131,11 +131,11 @@ gen_dealloc(PyGenObject *gen) Py_CLEAR(((PyAsyncGenObject*)gen)->ag_origin_or_finalizer); } if (gen->gi_frame_valid) { - _Py_framedata *frame = (_Py_framedata *)gen->gi_fdata; + _Py_framedata *fdata = (_Py_framedata *)gen->gi_fdata; gen->gi_frame_valid = 0; - frame->is_generator = false; - frame->previous = NULL; - _PyFrame_Clear(frame); + fdata->is_generator = false; + fdata->previous = NULL; + _PyFrame_Clear(fdata); } if (((PyCodeObject *)gen->gi_code)->co_flags & CO_COROUTINE) { Py_CLEAR(((PyCoroObject *)gen)->cr_origin_or_finalizer); @@ -152,11 +152,11 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult, int exc, int closing) { PyThreadState *tstate = _PyThreadState_GET(); - _Py_framedata *frame = (_Py_framedata *)gen->gi_fdata; + _Py_framedata *fdata = (_Py_framedata *)gen->gi_fdata; PyObject *result; *presult = NULL; - if (frame->state == FRAME_CREATED && arg && arg != Py_None) { + if (fdata->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)) { @@ -169,7 +169,7 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult, PyErr_SetString(PyExc_TypeError, msg); return PYGEN_ERROR; } - if (gen->gi_frame_valid && _PyFrame_IsExecuting(frame)) { + if (gen->gi_frame_valid && _PyFrame_IsExecuting(fdata)) { const char *msg = "generator already executing"; if (PyCoro_CheckExact(gen)) { msg = "coroutine already executing"; @@ -180,7 +180,7 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult, PyErr_SetString(PyExc_ValueError, msg); return PYGEN_ERROR; } - if (gen->gi_frame_valid == 0 || _PyFrameHasCompleted(frame)) { + if (gen->gi_frame_valid == 0 || _PyFrameHasCompleted(fdata)) { if (PyCoro_CheckExact(gen) && !closing) { /* `gen` is an exhausted coroutine: raise an error, except when called from gen_close(), which should @@ -200,13 +200,13 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult, } assert(gen->gi_frame_valid); - assert(_PyFrame_IsRunnable(frame)); + assert(_PyFrame_IsRunnable(fdata)); /* Push arg onto the frame's value stack */ result = arg ? arg : Py_None; Py_INCREF(result); - _PyFrame_StackPush(frame, result); + _PyFrame_StackPush(fdata, result); - frame->previous = tstate->cframe->current_frame; + fdata->previous = tstate->cframe->current_frame; gen->gi_exc_state.previous_item = tstate->exc_info; tstate->exc_info = &gen->gi_exc_state; @@ -216,20 +216,20 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult, _PyErr_ChainStackItem(NULL); } - result = _PyEval_EvalFrame(tstate, frame, exc); + result = _PyEval_EvalFrame(tstate, fdata, exc); tstate->exc_info = gen->gi_exc_state.previous_item; gen->gi_exc_state.previous_item = NULL; - assert(tstate->cframe->current_frame == frame->previous); + assert(tstate->cframe->current_frame == fdata->previous); /* Don't keep the reference to previous any longer than necessary. It * may keep a chain of frames alive or it could create a reference * cycle. */ - frame->previous = NULL; + fdata->previous = NULL; /* If the generator just returned (as opposed to yielding), signal * that the generator is exhausted. */ if (result) { - if (!_PyFrameHasCompleted(frame)) { + if (!_PyFrameHasCompleted(fdata)) { *presult = result; return PYGEN_NEXT; } @@ -265,9 +265,9 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult, /* first clean reference cycle through stored exception traceback */ _PyErr_ClearExcState(&gen->gi_exc_state); - frame->is_generator = false; + fdata->is_generator = false; gen->gi_frame_valid = 0; - _PyFrame_Clear(frame); + _PyFrame_Clear(fdata); *presult = result; return result ? PYGEN_RETURN : PYGEN_ERROR; } @@ -348,11 +348,11 @@ _PyGen_yf(PyGenObject *gen) PyObject *yf = NULL; if (gen->gi_frame_valid) { - _Py_framedata *frame = (_Py_framedata *)gen->gi_fdata; + _Py_framedata *fdata = (_Py_framedata *)gen->gi_fdata; PyObject *bytecode = gen->gi_code->co_code; unsigned char *code = (unsigned char *)PyBytes_AS_STRING(bytecode); - if (frame->lasti < 1) { + if (fdata->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 */ @@ -360,9 +360,9 @@ _PyGen_yf(PyGenObject *gen) return NULL; } - if (code[(frame->lasti-1)*sizeof(_Py_CODEUNIT)] != SEND || frame->stacktop < 0) + if (code[(fdata->lasti-1)*sizeof(_Py_CODEUNIT)] != SEND || fdata->stacktop < 0) return NULL; - yf = _PyFrame_StackPeek(frame); + yf = _PyFrame_StackPeek(fdata); Py_INCREF(yf); } @@ -377,11 +377,11 @@ gen_close(PyGenObject *gen, PyObject *args) int err = 0; if (yf) { - _Py_framedata *frame = (_Py_framedata *)gen->gi_fdata; - PyFrameState state = frame->state; - frame->state = FRAME_EXECUTING; + _Py_framedata *fdata = (_Py_framedata *)gen->gi_fdata; + PyFrameState state = fdata->state; + fdata->state = FRAME_EXECUTING; err = gen_close_iter(yf); - frame->state = state; + fdata->state = state; Py_DECREF(yf); } if (err == 0) @@ -418,7 +418,7 @@ _gen_throw(PyGenObject *gen, int close_on_genexit, PyObject *yf = _PyGen_yf(gen); if (yf) { - _Py_framedata *frame = (_Py_framedata *)gen->gi_fdata; + _Py_framedata *fdata = (_Py_framedata *)gen->gi_fdata; PyObject *ret; int err; if (PyErr_GivenExceptionMatches(typ, PyExc_GeneratorExit) && @@ -428,8 +428,8 @@ _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->state; - frame->state = FRAME_EXECUTING; + PyFrameState state = fdata->state; + fdata->state = FRAME_EXECUTING; err = gen_close_iter(yf); frame->state = state; Py_DECREF(yf); @@ -446,15 +446,15 @@ _gen_throw(PyGenObject *gen, int close_on_genexit, /* XXX We should probably be updating the current frame somewhere in ceval.c. */ _Py_framedata *prev = tstate->cframe->current_frame; - frame->previous = prev; - tstate->cframe->current_frame = frame; + fdata->previous = prev; + tstate->cframe->current_frame = fdata; /* Close the generator that we are currently iterating with 'yield from' or awaiting on with 'await'. */ - PyFrameState state = frame->state; - frame->state = FRAME_EXECUTING; + PyFrameState state = fdata->state; + fdata->state = FRAME_EXECUTING; ret = _gen_throw((PyGenObject *)yf, close_on_genexit, typ, val, tb); - frame->state = state; + fdata->state = state; tstate->cframe->current_frame = prev; frame->previous = NULL; } else { @@ -468,10 +468,10 @@ _gen_throw(PyGenObject *gen, int close_on_genexit, Py_DECREF(yf); goto throw_here; } - PyFrameState state = frame->state; - frame->state = FRAME_EXECUTING; + PyFrameState state = fdata->state; + fdata->state = FRAME_EXECUTING; ret = PyObject_CallFunctionObjArgs(meth, typ, val, tb, NULL); - frame->state = state; + fdata->state = state; Py_DECREF(meth); } Py_DECREF(yf); @@ -483,14 +483,14 @@ _gen_throw(PyGenObject *gen, int close_on_genexit, assert(ret == yf); Py_DECREF(ret); /* Termination repetition of SEND loop */ - assert(frame->lasti >= 0); + assert(fdata->lasti >= 0); PyObject *bytecode = gen->gi_code->co_code; unsigned char *code = (unsigned char *)PyBytes_AS_STRING(bytecode); /* Backup to SEND */ - frame->lasti--; - assert(code[frame->lasti*sizeof(_Py_CODEUNIT)] == SEND); - int jump = code[frame->lasti*sizeof(_Py_CODEUNIT)+1]; - frame->lasti += jump; + fdata->lasti--; + assert(code[fdata->lasti*sizeof(_Py_CODEUNIT)] == SEND); + int jump = code[fdata->lasti*sizeof(_Py_CODEUNIT)+1]; + fdata->lasti += jump; if (_PyGen_FetchStopIterationValue(&val) == 0) { ret = gen_send(gen, val); Py_DECREF(val); @@ -964,13 +964,13 @@ gen_new_with_qualname(PyTypeObject *type, PyFrameObject *f, /* Copy the frame */ assert(f->f_fdata->frame_obj == NULL); assert(f->f_owns_frame); - _Py_framedata *frame = (_Py_framedata *)gen->gi_fdata; - _PyFrame_Copy((_Py_framedata *)f->_f_frame_data, frame); + _Py_framedata *fdata = (_Py_framedata *)gen->gi_fdata; + _PyFrame_Copy((_Py_framedata *)f->_f_frame_data, fdata); gen->gi_frame_valid = 1; - assert(frame->frame_obj == f); + assert(fdata->frame_obj == f); f->f_owns_frame = 0; - f->f_fdata = frame; - frame->is_generator = true; + f->f_fdata = fdata; + fdata->is_generator = true; assert(PyObject_GC_IsTracked((PyObject *)f)); gen->gi_code = PyFrame_GetCode(f); Py_INCREF(gen->gi_code); @@ -1316,11 +1316,11 @@ PyTypeObject _PyCoroWrapper_Type = { static PyObject * compute_cr_origin(int origin_depth, _Py_framedata *current_frame) { - _Py_framedata *frame = current_frame; + _Py_framedata *fdata = current_frame; /* First count how many frames we have */ int frame_count = 0; - for (; frame && frame_count < origin_depth; ++frame_count) { - frame = frame->previous; + for (; fdata && frame_count < origin_depth; ++frame_count) { + fdata = fdata->previous; } /* Now collect them */ @@ -1328,19 +1328,19 @@ compute_cr_origin(int origin_depth, _Py_framedata *current_frame) if (cr_origin == NULL) { return NULL; } - frame = current_frame; + fdata = current_frame; for (int i = 0; i < frame_count; ++i) { - PyCodeObject *code = frame->code; + PyCodeObject *code = fdata->code; PyObject *frameinfo = Py_BuildValue("OiO", code->co_filename, - PyCode_Addr2Line(frame->code, frame->lasti*sizeof(_Py_CODEUNIT)), + PyCode_Addr2Line(fdata->code, fdata->lasti*sizeof(_Py_CODEUNIT)), code->co_name); if (!frameinfo) { Py_DECREF(cr_origin); return NULL; } PyTuple_SET_ITEM(cr_origin, i, frameinfo); - frame = frame->previous; + fdata = fdata->previous; } return cr_origin; @@ -2053,7 +2053,7 @@ static PyObject * async_gen_athrow_send(PyAsyncGenAThrow *o, PyObject *arg) { PyGenObject *gen = (PyGenObject*)o->agt_gen; - _Py_framedata *frame = (_Py_framedata *)gen->gi_fdata; + _Py_framedata *fdata = (_Py_framedata *)gen->gi_fdata; PyObject *retval; if (o->agt_state == AWAITABLE_STATE_CLOSED) { @@ -2063,7 +2063,7 @@ async_gen_athrow_send(PyAsyncGenAThrow *o, PyObject *arg) return NULL; } - if (gen->gi_frame_valid == 0 || _PyFrameHasCompleted(frame)) { + if (gen->gi_frame_valid == 0 || _PyFrameHasCompleted(fdata)) { o->agt_state = AWAITABLE_STATE_CLOSED; PyErr_SetNone(PyExc_StopIteration); return NULL; diff --git a/Python/ceval.c b/Python/ceval.c index a8648159ef22a4..2c102f406cd40c 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(_Py_framedata *frame, int opcode, int oparg) +static void lltrace_instruction(_Py_framedata *fdata, int opcode, int oparg) { if (HAS_ARG(opcode)) { printf("%d: %d, %d\n", @@ -102,7 +102,7 @@ _PyEvalFramePushAndInit(PyThreadState *tstate, PyFunctionObject *func, PyObject *locals, PyObject* const* args, size_t argcount, PyObject *kwnames); static void -_PyEvalFrameClearAndPop(PyThreadState *tstate, _Py_framedata *frame); +_PyEvalFrameClearAndPop(PyThreadState *tstate, _Py_framedata *fdata); #define NAME_ERROR_MSG \ "name '%.200s' is not defined" @@ -1547,17 +1547,17 @@ trace_function_entry(PyThreadState *tstate, _Py_framedata *fdata) } static int -trace_function_exit(PyThreadState *tstate, _Py_framedata *frame, PyObject *retval) +trace_function_exit(PyThreadState *tstate, _Py_framedata *fdata, PyObject *retval) { if (tstate->c_tracefunc) { if (call_trace_protected(tstate->c_tracefunc, tstate->c_traceobj, - tstate, frame, PyTrace_RETURN, retval)) { + tstate, fdata, PyTrace_RETURN, retval)) { return -1; } } if (tstate->c_profilefunc) { if (call_trace_protected(tstate->c_profilefunc, tstate->c_profileobj, - tstate, frame, PyTrace_RETURN, retval)) { + tstate, fdata, PyTrace_RETURN, retval)) { return -1; } } @@ -1575,10 +1575,10 @@ skip_backwards_over_extended_args(PyCodeObject *code, int offset) } static _Py_framedata * -pop_frame(PyThreadState *tstate, _Py_framedata *frame) +pop_frame(PyThreadState *tstate, _Py_framedata *fdata) { - _Py_framedata *prev_frame = frame->previous; - _PyEvalFrameClearAndPop(tstate, frame); + _Py_framedata *prev_frame = fdata->previous; + _PyEvalFrameClearAndPop(tstate, fdata); return prev_frame; } @@ -1598,7 +1598,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, _Py_framedata *frame, int throwflag) +_PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwflag) { _Py_EnsureTstateNotNULL(tstate); CALL_STAT_INC(pyeval_calls); @@ -6247,20 +6247,20 @@ _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); - _Py_framedata *frame = _PyThreadState_BumpFramePointer(tstate, size); - if (frame == NULL) { + _Py_framedata *fdata = _PyThreadState_BumpFramePointer(tstate, size); + if (fdata == NULL) { goto fail; } - _PyFrame_InitializeSpecials(frame, func, locals, code->co_nlocalsplus); - PyObject **localsarray = &frame->localsplus[0]; + _PyFrame_InitializeSpecials(fdata, func, locals, code->co_nlocalsplus); + PyObject **localsarray = &fdata->localsplus[0]; for (int i = 0; i < code->co_nlocalsplus; i++) { localsarray[i] = NULL; } if (initialize_locals(tstate, func, localsarray, args, argcount, kwnames)) { - _PyFrame_Clear(frame); + _PyFrame_Clear(fdata); return NULL; } - return frame; + return fdata; fail: /* Consume the references */ for (size_t i = 0; i < argcount; i++) { @@ -6304,17 +6304,17 @@ _PyEval_Vector(PyThreadState *tstate, PyFunctionObject *func, Py_INCREF(args[i+argcount]); } } - _Py_framedata *frame = _PyEvalFramePushAndInit( + _Py_framedata *fdata = _PyEvalFramePushAndInit( tstate, func, locals, args, argcount, kwnames); - if (frame == NULL) { + if (fdata == NULL) { return NULL; } - PyObject *retval = _PyEval_EvalFrame(tstate, frame, 0); + PyObject *retval = _PyEval_EvalFrame(tstate, fdata, 0); assert( - _PyFrame_GetStackPointer(frame) == _PyFrame_Stackbase(frame) || - _PyFrame_GetStackPointer(frame) == frame->localsplus + _PyFrame_GetStackPointer(fdata) == _PyFrame_Stackbase(fdata) || + _PyFrame_GetStackPointer(fdata) == fdata->localsplus ); - _PyEvalFrameClearAndPop(tstate, frame); + _PyEvalFrameClearAndPop(tstate, fdata); return retval; } @@ -6735,7 +6735,7 @@ initialize_trace_info(PyTraceInfo *trace_info, _Py_framedata *fdata) static int call_trace(Py_tracefunc func, PyObject *obj, - PyThreadState *tstate, _Py_framedata *frame, + PyThreadState *tstate, _Py_framedata *fdata, int what, PyObject *arg) { int result; @@ -6743,13 +6743,13 @@ call_trace(Py_tracefunc func, PyObject *obj, return 0; tstate->tracing++; _PyThreadState_PauseTracing(tstate); - PyFrameObject *f = _PyFrame_GetFrameObject(frame); + PyFrameObject *f = _PyFrame_GetFrameObject(fdata); if (f == NULL) { return -1; } - assert (frame->lasti >= 0); - initialize_trace_info(&tstate->trace_info, frame); - f->f_lineno = _PyCode_CheckLineNumber(frame->lasti*sizeof(_Py_CODEUNIT), &tstate->trace_info.bounds); + assert (fdata->lasti >= 0); + initialize_trace_info(&tstate->trace_info, fdata); + f->f_lineno = _PyCode_CheckLineNumber(fdata->lasti*sizeof(_Py_CODEUNIT), &tstate->trace_info.bounds); result = func(obj, f, what, arg); f->f_lineno = 0; _PyThreadState_ResumeTracing(tstate); @@ -6776,7 +6776,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, _Py_framedata *frame, int instr_prev) + PyThreadState *tstate, _Py_framedata *fdata, int instr_prev) { int result = 0; @@ -6784,8 +6784,8 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj, represents a jump backwards, update the frame's line number and then call the trace function if we're tracing source lines. */ - initialize_trace_info(&tstate->trace_info, frame); - _Py_CODEUNIT prev = ((_Py_CODEUNIT *)PyBytes_AS_STRING(frame->code->co_code))[instr_prev]; + initialize_trace_info(&tstate->trace_info, fdata); + _Py_CODEUNIT prev = ((_Py_CODEUNIT *)PyBytes_AS_STRING(fdata->code->co_code))[instr_prev]; int lastline; if (_Py_OPCODE(prev) == RESUME && _Py_OPARG(prev) == 0) { lastline = -1; @@ -6793,23 +6793,23 @@ 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->lasti*sizeof(_Py_CODEUNIT), &tstate->trace_info.bounds); - PyFrameObject *f = _PyFrame_GetFrameObject(frame); + int line = _PyCode_CheckLineNumber(fdata->lasti*sizeof(_Py_CODEUNIT), &tstate->trace_info.bounds); + PyFrameObject *f = _PyFrame_GetFrameObject(fdata); if (f == NULL) { return -1; } 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->lasti < instr_prev && - _Py_OPCODE(frame->code->co_firstinstr[frame->lasti]) != SEND); + (fdata->lasti < instr_prev && + _Py_OPCODE(fdata->code->co_firstinstr[fdata->lasti]) != SEND); if (trace) { - result = call_trace(func, obj, tstate, frame, PyTrace_LINE, Py_None); + result = call_trace(func, obj, tstate, fdata, PyTrace_LINE, Py_None); } } /* Always emit an opcode event if we're tracing all opcodes. */ if (f->f_trace_opcodes) { - result = call_trace(func, obj, tstate, frame, PyTrace_OPCODE, Py_None); + result = call_trace(func, obj, tstate, fdata, PyTrace_OPCODE, Py_None); } return result; } @@ -6978,9 +6978,9 @@ PyEval_GetFrame(void) PyObject * _PyEval_GetBuiltins(PyThreadState *tstate) { - _Py_framedata *frame = tstate->cframe->current_frame; - if (frame != NULL) { - return frame->builtins; + _Py_framedata *fdata = tstate->cframe->current_frame; + if (fdata != NULL) { + return fdata->builtins; } return tstate->interp->builtins; } diff --git a/Python/frame.c b/Python/frame.c index 36890863845980..0b0850049b15ba 100644 --- a/Python/frame.c +++ b/Python/frame.c @@ -7,30 +7,30 @@ #include "opcode.h" int -_PyFrame_Traverse(_Py_framedata *frame, visitproc visit, void *arg) +_PyFrame_Traverse(_Py_framedata *fdata, visitproc visit, void *arg) { - Py_VISIT(frame->frame_obj); - Py_VISIT(frame->locals); - Py_VISIT(frame->func); - Py_VISIT(frame->code); + Py_VISIT(fdata->frame_obj); + Py_VISIT(fdata->locals); + Py_VISIT(fdata->func); + Py_VISIT(fdata->code); /* locals */ - PyObject **locals = _PyFrame_GetLocalsArray(frame); + PyObject **locals = _PyFrame_GetLocalsArray(fdata); int i = 0; /* locals and stack */ - for (; i <frame->stacktop; i++) { + for (; i <fdata->stacktop; i++) { Py_VISIT(locals[i]); } return 0; } PyFrameObject * -_PyFrame_MakeAndSetFrameObject(_Py_framedata *frame) +_PyFrame_MakeAndSetFrameObject(_Py_framedata *fdata) { - assert(frame->frame_obj == NULL); + assert(fdata->frame_obj == NULL); PyObject *error_type, *error_value, *error_traceback; PyErr_Fetch(&error_type, &error_value, &error_traceback); - PyFrameObject *f = _PyFrame_New_NoTrack(frame->code); + PyFrameObject *f = _PyFrame_New_NoTrack(fdata->code); if (f == NULL) { Py_XDECREF(error_type); Py_XDECREF(error_value); @@ -38,8 +38,8 @@ _PyFrame_MakeAndSetFrameObject(_Py_framedata *frame) } else { f->f_owns_frame = 0; - f->f_fdata = frame; - frame->frame_obj = f; + f->f_fdata = fdata; + fdata->frame_obj = f; PyErr_Restore(error_type, error_value, error_traceback); } return f; @@ -55,18 +55,18 @@ _PyFrame_Copy(_Py_framedata *src, _Py_framedata *dest) static void -take_ownership(PyFrameObject *f, _Py_framedata *frame) +take_ownership(PyFrameObject *f, _Py_framedata *fdata) { assert(f->f_owns_frame == 0); - Py_ssize_t size = ((char*)&frame->localsplus[frame->stacktop]) - (char *)frame; - memcpy((_Py_framedata *)f->_f_frame_data, frame, size); - frame = (_Py_framedata *)f->_f_frame_data; + Py_ssize_t size = ((char*)&fdata->localsplus[fdata->stacktop]) - (char *)fdata; + memcpy((_Py_framedata *)f->_f_frame_data, fdata, size); + fdata = (_Py_framedata *)f->_f_frame_data; f->f_owns_frame = 1; - f->f_fdata = frame; + f->f_fdata = fdata; assert(f->f_back == NULL); - if (frame->previous != NULL) { + if (fdata->previous != NULL) { /* Link PyFrameObjects.f_back and remove link through _Py_framedata.previous */ - PyFrameObject *back = _PyFrame_GetFrameObject(frame->previous); + PyFrameObject *back = _PyFrame_GetFrameObject(fdata->previous); if (back == NULL) { /* Memory error here. */ assert(PyErr_ExceptionMatches(PyExc_MemoryError)); @@ -76,7 +76,7 @@ take_ownership(PyFrameObject *f, _Py_framedata *frame) else { f->f_back = (PyFrameObject *)Py_NewRef(back); } - frame->previous = NULL; + fdata->previous = NULL; } if (!_PyObject_GC_IS_TRACKED((PyObject *)f)) { _PyObject_GC_TRACK((PyObject *)f); @@ -84,29 +84,29 @@ take_ownership(PyFrameObject *f, _Py_framedata *frame) } void -_PyFrame_Clear(_Py_framedata *frame) +_PyFrame_Clear(_Py_framedata *fdata) { /* It is the responsibility of the owning generator/coroutine * to have cleared the enclosing generator, if any. */ - assert(!frame->is_generator); - if (frame->frame_obj) { - PyFrameObject *f = frame->frame_obj; - frame->frame_obj = NULL; + assert(!fdata->is_generator); + if (fdata->frame_obj) { + PyFrameObject *f = fdata->frame_obj; + fdata->frame_obj = NULL; if (Py_REFCNT(f) > 1) { - take_ownership(f, frame); + take_ownership(f, fdata); Py_DECREF(f); return; } Py_DECREF(f); } - assert(frame->stacktop >= 0); - for (int i = 0; i < frame->stacktop; i++) { - Py_XDECREF(frame->localsplus[i]); + assert(fdata->stacktop >= 0); + for (int i = 0; i < fdata->stacktop; i++) { + Py_XDECREF(fdata->localsplus[i]); } - Py_XDECREF(frame->frame_obj); - Py_XDECREF(frame->locals); - Py_DECREF(frame->func); - Py_DECREF(frame->code); + Py_XDECREF(fdata->frame_obj); + Py_XDECREF(fdata->locals); + Py_DECREF(fdata->func); + Py_DECREF(fdata->code); } /* Consumes reference to func */ diff --git a/Python/pystate.c b/Python/pystate.c index 182406f6de2d53..0458c706642b62 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -1410,15 +1410,15 @@ _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) { - _Py_framedata *frame = t->cframe->current_frame; - if (frame == NULL) { + _Py_framedata *fdata = t->cframe->current_frame; + if (fdata == NULL) { continue; } PyObject *id = PyLong_FromUnsignedLong(t->thread_id); if (id == NULL) { goto fail; } - int stat = PyDict_SetItem(result, id, (PyObject *)_PyFrame_GetFrameObject(frame)); + int stat = PyDict_SetItem(result, id, (PyObject *)_PyFrame_GetFrameObject(fdata)); Py_DECREF(id); if (stat < 0) { goto fail; From 269a4a0aab65eaeb4d83b1015b8b1e56933bb864 Mon Sep 17 00:00:00 2001 From: Nick Coghlan <ncoghlan@gmail.com> Date: Sat, 12 Mar 2022 17:40:29 +1000 Subject: [PATCH 19/30] frame -> fdata in ceval.c & allow compilation --- Objects/genobject.c | 4 +- Python/ceval.c | 278 ++++++++++++++++++++++---------------------- 2 files changed, 141 insertions(+), 141 deletions(-) diff --git a/Objects/genobject.c b/Objects/genobject.c index f008cfbef2c1a6..548a8d9c066aad 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -431,7 +431,7 @@ _gen_throw(PyGenObject *gen, int close_on_genexit, PyFrameState state = fdata->state; fdata->state = FRAME_EXECUTING; err = gen_close_iter(yf); - frame->state = state; + fdata->state = state; Py_DECREF(yf); if (err < 0) return gen_send_ex(gen, Py_None, 1, 0); @@ -456,7 +456,7 @@ _gen_throw(PyGenObject *gen, int close_on_genexit, typ, val, tb); fdata->state = state; tstate->cframe->current_frame = prev; - frame->previous = NULL; + fdata->previous = NULL; } else { /* `yf` is an iterator or a coroutine-like object. */ PyObject *meth; diff --git a/Python/ceval.c b/Python/ceval.c index 2c102f406cd40c..83598e53a43424 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -1253,14 +1253,14 @@ eval_frame_handle_pending(PyThreadState *tstate) #ifdef Py_STATS #define INSTRUCTION_START(op) \ do { \ - frame->lasti = INSTR_OFFSET(); \ + fdata->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->lasti = INSTR_OFFSET(); next_instr++ +#define INSTRUCTION_START(op) fdata->lasti = INSTR_OFFSET(); next_instr++ #endif #if USE_COMPUTED_GOTOS @@ -1273,7 +1273,7 @@ eval_frame_handle_pending(PyThreadState *tstate) /* PRE_DISPATCH_GOTO() does lltrace if enabled. Normally a no-op */ #ifdef LLTRACE -#define PRE_DISPATCH_GOTO() if (lltrace) { lltrace_instruction(frame, opcode, oparg); } +#define PRE_DISPATCH_GOTO() if (lltrace) { lltrace_instruction(fdata, opcode, oparg); } #else #define PRE_DISPATCH_GOTO() ((void)0) #endif @@ -1323,7 +1323,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->code->co_code))[INSTR_OFFSET()]; \ + _Py_CODEUNIT word = ((_Py_CODEUNIT *)PyBytes_AS_STRING(fdata->code->co_code))[INSTR_OFFSET()]; \ opcode = _Py_OPCODE(word); \ oparg = _Py_OPARG(word); \ } while (0) @@ -1377,7 +1377,7 @@ eval_frame_handle_pending(PyThreadState *tstate) /* The stack can grow at most MAXINT deep, as co_nlocals and co_stacksize are ints. */ -#define STACK_LEVEL() ((int)(stack_pointer - _PyFrame_Stackbase(frame))) +#define STACK_LEVEL() ((int)(stack_pointer - _PyFrame_Stackbase(fdata))) #define EMPTY() (STACK_LEVEL() == 0) #define TOP() (stack_pointer[-1]) #define SECOND() (stack_pointer[-2]) @@ -1393,20 +1393,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->code->co_stacksize); } + assert(STACK_LEVEL() <= fdata->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->code->co_stacksize); \ + assert(STACK_LEVEL() <= fdata->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->code->co_stacksize); \ + assert(STACK_LEVEL() <= fdata->code->co_stacksize); \ } while (0) #else #define PUSH(v) BASIC_PUSH(v) @@ -1417,7 +1417,7 @@ eval_frame_handle_pending(PyThreadState *tstate) /* Local variable macros */ -#define GETLOCAL(i) (frame->localsplus[i]) +#define GETLOCAL(i) (fdata->localsplus[i]) /* The SETLOCAL() macro must not DECREF the local variable in-place and then store the new value; it must copy the old value to a temporary @@ -1440,9 +1440,9 @@ eval_frame_handle_pending(PyThreadState *tstate) #define UPDATE_PREV_INSTR_OPARG(instr, oparg) ((uint8_t*)(instr))[-1] = (oparg) -#define GLOBALS() frame->globals -#define BUILTINS() frame->builtins -#define LOCALS() frame->locals +#define GLOBALS() fdata->globals +#define BUILTINS() fdata->builtins +#define LOCALS() fdata->locals /* Shared opcode macros */ @@ -1464,7 +1464,7 @@ eval_frame_handle_pending(PyThreadState *tstate) #define TRACE_FUNCTION_EXIT() \ if (cframe.use_tracing) { \ - if (trace_function_exit(tstate, frame, retval)) { \ + if (trace_function_exit(tstate, fdata, retval)) { \ Py_DECREF(retval); \ goto exit_unwind; \ } \ @@ -1472,21 +1472,21 @@ eval_frame_handle_pending(PyThreadState *tstate) #define DTRACE_FUNCTION_EXIT() \ if (PyDTrace_FUNCTION_RETURN_ENABLED()) { \ - dtrace_function_return(frame); \ + dtrace_function_return(fdata); \ } #define TRACE_FUNCTION_UNWIND() \ if (cframe.use_tracing) { \ /* Since we are already unwinding, \ * we dont't care if this raises */ \ - trace_function_exit(tstate, frame, NULL); \ + trace_function_exit(tstate, fdata, NULL); \ } #define TRACE_FUNCTION_ENTRY() \ if (cframe.use_tracing) { \ - _PyFrame_SetStackPointer(frame, stack_pointer); \ - int err = trace_function_entry(tstate, frame); \ - stack_pointer = _PyFrame_GetStackPointer(frame); \ + _PyFrame_SetStackPointer(fdata, stack_pointer); \ + int err = trace_function_entry(tstate, fdata); \ + stack_pointer = _PyFrame_GetStackPointer(fdata); \ if (err) { \ goto error; \ } \ @@ -1494,15 +1494,15 @@ eval_frame_handle_pending(PyThreadState *tstate) #define TRACE_FUNCTION_THROW_ENTRY() \ if (cframe.use_tracing) { \ - assert(frame->stacktop >= 0); \ - if (trace_function_entry(tstate, frame)) { \ + assert(fdata->stacktop >= 0); \ + if (trace_function_entry(tstate, fdata)) { \ goto exit_unwind; \ } \ } #define DTRACE_FUNCTION_ENTRY() \ if (PyDTrace_FUNCTION_ENTRY_ENABLED()) { \ - dtrace_function_entry(frame); \ + dtrace_function_entry(fdata); \ } @@ -1628,10 +1628,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf cframe.previous = prev_cframe; tstate->cframe = &cframe; - frame->is_entry = true; + fdata->is_entry = true; /* Push frame */ - frame->previous = prev_cframe->current_frame; - cframe.current_frame = frame; + fdata->previous = prev_cframe->current_frame; + cframe.current_frame = fdata; /* support for generator.throw() */ if (throwflag) { @@ -1656,21 +1656,21 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf /* Sets the above local variables from the frame */ #define SET_LOCALS_FROM_FRAME() \ { \ - PyCodeObject *co = frame->code; \ + PyCodeObject *co = fdata->code; \ names = co->co_names; \ consts = co->co_consts; \ first_instr = co->co_firstinstr; \ } \ - assert(frame->lasti >= -1); \ - next_instr = first_instr + frame->lasti + 1; \ - stack_pointer = _PyFrame_GetStackPointer(frame); \ + assert(fdata->lasti >= -1); \ + next_instr = first_instr + fdata->lasti + 1; \ + stack_pointer = _PyFrame_GetStackPointer(fdata); \ /* Set stackdepth to -1. \ Update when returning or calling trace function. \ Having stackdepth <= 0 ensures that invalid \ values are not visible to the cycle GC. \ We choose -1 rather than 0 to assist debugging. \ */ \ - frame->stacktop = -1; + fdata->stacktop = -1; start_frame: @@ -1731,14 +1731,14 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf } TARGET(RESUME) { - int err = _Py_IncrementCountAndMaybeQuicken(frame->code); + int err = _Py_IncrementCountAndMaybeQuicken(fdata->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->code->co_firstinstr; + first_instr = fdata->code->co_firstinstr; next_instr = first_instr + nexti; } JUMP_TO_INSTRUCTION(RESUME_QUICK); @@ -1747,8 +1747,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf TARGET(RESUME_QUICK) { PREDICTED(RESUME_QUICK); assert(tstate->cframe == &cframe); - assert(frame == cframe.current_frame); - frame->state = FRAME_EXECUTING; + assert(fdata == cframe.current_frame); + fdata->state = FRAME_EXECUTING; if (_Py_atomic_load_relaxed(eval_breaker) && oparg < 2) { goto handle_eval_breaker; } @@ -2208,24 +2208,24 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf PyCodeObject *code = (PyCodeObject *)getitem->func_code; size_t size = code->co_nlocalsplus + code->co_stacksize + FRAME_SPECIALS_SIZE; assert(code->co_argcount == 2); - _Py_framedata *new_frame = _PyThreadState_BumpFramePointer(tstate, size); - if (new_frame == NULL) { + _Py_framedata *new_fdata = _PyThreadState_BumpFramePointer(tstate, size); + if (new_fdata == NULL) { goto error; } CALL_STAT_INC(frames_pushed); Py_INCREF(getitem); - _PyFrame_InitializeSpecials(new_frame, getitem, + _PyFrame_InitializeSpecials(new_fdata, getitem, NULL, code->co_nlocalsplus); STACK_SHRINK(2); - new_frame->localsplus[0] = container; - new_frame->localsplus[1] = sub; + new_fdata->localsplus[0] = container; + new_fdata->localsplus[1] = sub; for (int i = 2; i < code->co_nlocalsplus; i++) { - new_frame->localsplus[i] = NULL; + new_fdata->localsplus[i] = NULL; } - _PyFrame_SetStackPointer(frame, stack_pointer); - frame->lasti += INLINE_CACHE_ENTRIES_BINARY_SUBSCR; - new_frame->previous = frame; - frame = cframe.current_frame = new_frame; + _PyFrame_SetStackPointer(fdata, stack_pointer); + fdata->lasti += INLINE_CACHE_ENTRIES_BINARY_SUBSCR; + new_fdata->previous = fdata; + fdata = cframe.current_frame = new_fdata; CALL_STAT_INC(inlined_py_calls); goto start_frame; } @@ -2387,20 +2387,20 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf TARGET(RETURN_VALUE) { PyObject *retval = POP(); assert(EMPTY()); - frame->state = FRAME_RETURNED; - _PyFrame_SetStackPointer(frame, stack_pointer); + fdata->state = FRAME_RETURNED; + _PyFrame_SetStackPointer(fdata, stack_pointer); TRACE_FUNCTION_EXIT(); DTRACE_FUNCTION_EXIT(); _Py_LeaveRecursiveCall(tstate); - if (!frame->is_entry) { - frame = cframe.current_frame = pop_frame(tstate, frame); - _PyFrame_StackPush(frame, retval); + if (!fdata->is_entry) { + fdata = cframe.current_frame = pop_frame(tstate, fdata); + _PyFrame_StackPush(fdata, retval); goto resume_frame; } /* Restore previous cframe and return. */ tstate->cframe = cframe.previous; tstate->cframe->use_tracing = cframe.use_tracing; - assert(tstate->cframe->current_frame == frame->previous); + assert(tstate->cframe->current_frame == fdata->previous); assert(!_PyErr_Occurred(tstate)); return retval; } @@ -2536,7 +2536,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf } TARGET(SEND) { - assert(frame->is_entry); + assert(fdata->is_entry); assert(STACK_LEVEL() >= 2); PyObject *v = POP(); PyObject *receiver = TOP(); @@ -2554,7 +2554,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf if (retval == NULL) { if (tstate->c_tracefunc != NULL && _PyErr_ExceptionMatches(tstate, PyExc_StopIteration)) - call_exc_trace(tstate->c_tracefunc, tstate->c_traceobj, tstate, frame); + call_exc_trace(tstate->c_tracefunc, tstate->c_traceobj, tstate, fdata); if (_PyGen_FetchStopIterationValue(&retval) == 0) { gen_status = PYGEN_RETURN; } @@ -2586,7 +2586,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf TARGET(ASYNC_GEN_WRAP) { PyObject *v = TOP(); - assert(frame->code->co_flags & CO_ASYNC_GENERATOR); + assert(fdata->code->co_flags & CO_ASYNC_GENERATOR); PyObject *w = _PyAsyncGenValueWrapperNew(v); if (w == NULL) { goto error; @@ -2597,17 +2597,17 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf } TARGET(YIELD_VALUE) { - assert(frame->is_entry); + assert(fdata->is_entry); PyObject *retval = POP(); - frame->state = FRAME_SUSPENDED; - _PyFrame_SetStackPointer(frame, stack_pointer); + fdata->state = FRAME_SUSPENDED; + _PyFrame_SetStackPointer(fdata, stack_pointer); TRACE_FUNCTION_EXIT(); DTRACE_FUNCTION_EXIT(); _Py_LeaveRecursiveCall(tstate); /* Restore previous cframe and return. */ tstate->cframe = cframe.previous; tstate->cframe->use_tracing = cframe.use_tracing; - assert(tstate->cframe->current_frame == frame->previous); + assert(tstate->cframe->current_frame == fdata->previous); assert(!_PyErr_Occurred(tstate)); return retval; } @@ -2624,7 +2624,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf if (oparg) { PyObject *lasti = PEEK(oparg + 1); if (PyLong_Check(lasti)) { - frame->lasti = PyLong_AsLong(lasti); + fdata->lasti = PyLong_AsLong(lasti); assert(!_PyErr_Occurred(tstate)); } else { @@ -3088,15 +3088,15 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf Py_DECREF(oldobj); DISPATCH(); } - format_exc_unbound(tstate, frame->code, oparg); + format_exc_unbound(tstate, fdata->code, oparg); goto error; } TARGET(LOAD_CLASSDEREF) { PyObject *name, *value, *locals = LOCALS(); assert(locals); - assert(oparg >= 0 && oparg < frame->code->co_nlocalsplus); - name = PyTuple_GET_ITEM(frame->code->co_localsplusnames, oparg); + assert(oparg >= 0 && oparg < fdata->code->co_nlocalsplus); + name = PyTuple_GET_ITEM(fdata->code->co_localsplusnames, oparg); if (PyDict_CheckExact(locals)) { value = PyDict_GetItemWithError(locals, name); if (value != NULL) { @@ -3119,7 +3119,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf PyObject *cell = GETLOCAL(oparg); value = PyCell_GET(cell); if (value == NULL) { - format_exc_unbound(tstate, frame->code, oparg); + format_exc_unbound(tstate, fdata->code, oparg); goto error; } Py_INCREF(value); @@ -3132,7 +3132,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf PyObject *cell = GETLOCAL(oparg); PyObject *value = PyCell_GET(cell); if (value == NULL) { - format_exc_unbound(tstate, frame->code, oparg); + format_exc_unbound(tstate, fdata->code, oparg); goto error; } Py_INCREF(value); @@ -3151,14 +3151,14 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf TARGET(COPY_FREE_VARS) { /* Copy closure variables to free variables */ - PyCodeObject *co = frame->code; - PyObject *closure = frame->func->func_closure; + PyCodeObject *co = fdata->code; + PyObject *closure = fdata->func->func_closure; int offset = co->co_nlocals + co->co_nplaincellvars; assert(oparg == co->co_nfreevars); for (int i = 0; i < oparg; ++i) { PyObject *o = PyTuple_GET_ITEM(closure, i); Py_INCREF(o); - frame->localsplus[offset + i] = o; + fdata->localsplus[offset + i] = o; } DISPATCH(); } @@ -3887,7 +3887,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf PyObject *fromlist = POP(); PyObject *level = TOP(); PyObject *res; - res = import_name(tstate, frame, name, fromlist, level); + res = import_name(tstate, fdata, name, fromlist, level); Py_DECREF(level); Py_DECREF(fromlist); SET_TOP(res); @@ -3899,7 +3899,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf TARGET(IMPORT_STAR) { PyObject *from = POP(), *locals; int err; - if (_PyFrame_FastToLocalsWithError(frame) < 0) { + if (_PyFrame_FastToLocalsWithError(fdata) < 0) { Py_DECREF(from); goto error; } @@ -3912,7 +3912,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf goto error; } err = import_all_from(tstate, locals, from); - _PyFrame_LocalsToFast(frame, 0); + _PyFrame_LocalsToFast(fdata, 0); Py_DECREF(from); if (err != 0) goto error; @@ -4064,14 +4064,14 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf TARGET(JUMP_ABSOLUTE) { PREDICTED(JUMP_ABSOLUTE); - int err = _Py_IncrementCountAndMaybeQuicken(frame->code); + int err = _Py_IncrementCountAndMaybeQuicken(fdata->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->code->co_firstinstr; + first_instr = fdata->code->co_firstinstr; next_instr = first_instr + nexti; } JUMP_TO_INSTRUCTION(JUMP_ABSOLUTE_QUICK); @@ -4083,7 +4083,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf * generator or coroutine, so we deliberately do not check it here. * (see bpo-30039). */ - frame->state = FRAME_EXECUTING; + fdata->state = FRAME_EXECUTING; JUMPTO(oparg); DISPATCH(); } @@ -4188,7 +4188,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf PyObject *iter; if (PyCoro_CheckExact(iterable)) { /* `iterable` is a coroutine */ - if (!(frame->code->co_flags & (CO_COROUTINE | CO_ITERABLE_COROUTINE))) { + if (!(fdata->code->co_flags & (CO_COROUTINE | CO_ITERABLE_COROUTINE))) { /* and it is used in a 'yield from' expression of a regular generator. */ Py_DECREF(iterable); @@ -4232,7 +4232,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf goto error; } else if (tstate->c_tracefunc != NULL) { - call_exc_trace(tstate->c_tracefunc, tstate->c_traceobj, tstate, frame); + call_exc_trace(tstate->c_tracefunc, tstate->c_traceobj, tstate, fdata); } _PyErr_Clear(tstate); } @@ -4637,7 +4637,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf 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); - _Py_framedata *new_frame = _PyEvalFramePushAndInit( + _Py_framedata *new_fdata = _PyEvalFramePushAndInit( tstate, (PyFunctionObject *)function, locals, stack_pointer, positional_args, call_shape.kwnames ); @@ -4645,12 +4645,12 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf STACK_SHRINK(2-is_meth); // The frame has stolen all the arguments from the stack, // so there is no need to clean them up. - if (new_frame == NULL) { + if (new_fdata == NULL) { goto error; } - _PyFrame_SetStackPointer(frame, stack_pointer); - new_frame->previous = frame; - cframe.current_frame = frame = new_frame; + _PyFrame_SetStackPointer(fdata, stack_pointer); + new_fdata->previous = fdata; + cframe.current_frame = fdata = new_fdata; CALL_STAT_INC(inlined_py_calls); goto start_frame; } @@ -4746,22 +4746,22 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf PyCodeObject *code = (PyCodeObject *)func->func_code; DEOPT_IF(code->co_argcount != argcount, CALL); STAT_INC(CALL, hit); - _Py_framedata *new_frame = _PyFrame_Push(tstate, func); - if (new_frame == NULL) { + _Py_framedata *new_fdata = _PyFrame_Push(tstate, func); + if (new_fdata == NULL) { goto error; } CALL_STAT_INC(inlined_py_calls); STACK_SHRINK(argcount); for (int i = 0; i < argcount; i++) { - new_frame->localsplus[i] = stack_pointer[i]; + new_fdata->localsplus[i] = stack_pointer[i]; } for (int i = argcount; i < code->co_nlocalsplus; i++) { - new_frame->localsplus[i] = NULL; + new_fdata->localsplus[i] = NULL; } STACK_SHRINK(2-is_meth); - _PyFrame_SetStackPointer(frame, stack_pointer); - new_frame->previous = frame; - frame = cframe.current_frame = new_frame; + _PyFrame_SetStackPointer(fdata, stack_pointer); + new_fdata->previous = fdata; + fdata = cframe.current_frame = new_fdata; goto start_frame; } @@ -4781,28 +4781,28 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf int minargs = cache1->min_args; DEOPT_IF(argcount < minargs, CALL); STAT_INC(CALL, hit); - _Py_framedata *new_frame = _PyFrame_Push(tstate, func); - if (new_frame == NULL) { + _Py_framedata *new_fdata = _PyFrame_Push(tstate, func); + if (new_fdata == NULL) { goto error; } CALL_STAT_INC(inlined_py_calls); STACK_SHRINK(argcount); for (int i = 0; i < argcount; i++) { - new_frame->localsplus[i] = stack_pointer[i]; + new_fdata->localsplus[i] = stack_pointer[i]; } int def_offset = cache1->defaults_len - code->co_argcount; for (int i = argcount; i < code->co_argcount; i++) { PyObject *def = PyTuple_GET_ITEM(func->func_defaults, i + def_offset); Py_INCREF(def); - new_frame->localsplus[i] = def; + new_fdata->localsplus[i] = def; } for (int i = code->co_argcount; i < code->co_nlocalsplus; i++) { - new_frame->localsplus[i] = NULL; + new_fdata->localsplus[i] = NULL; } STACK_SHRINK(2-is_meth); - _PyFrame_SetStackPointer(frame, stack_pointer); - new_frame->previous = frame; - frame = cframe.current_frame = new_frame; + _PyFrame_SetStackPointer(fdata, stack_pointer); + new_fdata->previous = fdata; + fdata = cframe.current_frame = new_fdata; goto start_frame; } @@ -5293,35 +5293,35 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf } TARGET(RETURN_GENERATOR) { - PyGenObject *gen = (PyGenObject *)_Py_MakeCoro(frame->func); + PyGenObject *gen = (PyGenObject *)_Py_MakeCoro(fdata->func); if (gen == NULL) { goto error; } assert(EMPTY()); - _PyFrame_SetStackPointer(frame, stack_pointer); - _Py_framedata *gen_frame = (_Py_framedata *)gen->gi_fdata; - _PyFrame_Copy(frame, gen_frame); - assert(frame->frame_obj == NULL); + _PyFrame_SetStackPointer(fdata, stack_pointer); + _Py_framedata *gen_fdata = (_Py_framedata *)gen->gi_fdata; + _PyFrame_Copy(fdata, gen_fdata); + assert(fdata->frame_obj == NULL); gen->gi_frame_valid = 1; - gen_frame->is_generator = true; - gen_frame->state = FRAME_CREATED; + gen_fdata->is_generator = true; + gen_fdata->state = FRAME_CREATED; _Py_LeaveRecursiveCall(tstate); - if (!frame->is_entry) { - _Py_framedata *prev = frame->previous; - _PyThreadState_PopFrame(tstate, frame); - frame = cframe.current_frame = prev; - _PyFrame_StackPush(frame, (PyObject *)gen); + if (!fdata->is_entry) { + _Py_framedata *prev = fdata->previous; + _PyThreadState_PopFrame(tstate, fdata); + fdata = cframe.current_frame = prev; + _PyFrame_StackPush(fdata, (PyObject *)gen); goto resume_frame; } /* Make sure that frame is in a valid state */ - frame->stacktop = 0; - frame->locals = NULL; - Py_INCREF(frame->func); - Py_INCREF(frame->code); + fdata->stacktop = 0; + fdata->locals = NULL; + Py_INCREF(fdata->func); + Py_INCREF(fdata->code); /* Restore previous cframe and return. */ tstate->cframe = cframe.previous; tstate->cframe->use_tracing = cframe.use_tracing; - assert(tstate->cframe->current_frame == frame->previous); + assert(tstate->cframe->current_frame == fdata->previous); assert(!_PyErr_Occurred(tstate)); return (PyObject *)gen; } @@ -5472,8 +5472,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf #else case DO_TRACING: { #endif - int instr_prev = skip_backwards_over_extended_args(frame->code, frame->lasti); - frame->lasti = INSTR_OFFSET(); + int instr_prev = skip_backwards_over_extended_args(fdata->code, fdata->lasti); + fdata->lasti = INSTR_OFFSET(); TRACING_NEXTOPARG(); if (opcode == RESUME) { if (oparg < 2) { @@ -5483,10 +5483,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf TRACE_FUNCTION_ENTRY(); DTRACE_FUNCTION_ENTRY(); } - else if (frame->state > FRAME_CREATED) { + else if (fdata->state > FRAME_CREATED) { /* line-by-line tracing support */ if (PyDTrace_LINE_ENABLED()) { - maybe_dtrace_line(frame, &tstate->trace_info, instr_prev); + maybe_dtrace_line(fdata, &tstate->trace_info, instr_prev); } if (cframe.use_tracing && @@ -5494,21 +5494,21 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf int err; /* see maybe_call_line_trace() for expository comments */ - _PyFrame_SetStackPointer(frame, stack_pointer); + _PyFrame_SetStackPointer(fdata, stack_pointer); err = maybe_call_line_trace(tstate->c_tracefunc, tstate->c_traceobj, - tstate, frame, instr_prev); + tstate, fdata, instr_prev); if (err) { /* trace function raised an exception */ next_instr++; goto error; } /* Reload possibly changed frame fields */ - JUMPTO(frame->lasti); + JUMPTO(fdata->lasti); - stack_pointer = _PyFrame_GetStackPointer(frame); - frame->stacktop = -1; + stack_pointer = _PyFrame_GetStackPointer(fdata); + fdata->stacktop = -1; } } TRACING_NEXTOPARG(); @@ -5524,7 +5524,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _Py_framedata *fdata, int throwf #endif fprintf(stderr, "XXX lineno: %d, opcode: %d\n", - PyCode_Addr2Line(frame->code, frame->lasti*sizeof(_Py_CODEUNIT)), + PyCode_Addr2Line(fdata->code, fdata->lasti*sizeof(_Py_CODEUNIT)), opcode); _PyErr_SetString(tstate, PyExc_SystemError, "unknown opcode"); goto error; @@ -5610,7 +5610,7 @@ MISS_WITH_OPARG_COUNTER(STORE_SUBSCR) { format_exc_check_arg(tstate, PyExc_UnboundLocalError, UNBOUNDLOCAL_ERROR_MSG, - PyTuple_GetItem(frame->code->co_localsplusnames, oparg) + PyTuple_GetItem(fdata->code->co_localsplusnames, oparg) ); goto error; } @@ -5628,50 +5628,50 @@ MISS_WITH_OPARG_COUNTER(STORE_SUBSCR) #endif /* Log traceback info. */ - PyFrameObject *f = _PyFrame_GetFrameObject(frame); + PyFrameObject *f = _PyFrame_GetFrameObject(fdata); if (f != NULL) { PyTraceBack_Here(f); } if (tstate->c_tracefunc != NULL) { /* Make sure state is set to FRAME_UNWINDING for tracing */ - frame->state = FRAME_UNWINDING; + fdata->state = FRAME_UNWINDING; call_exc_trace(tstate->c_tracefunc, tstate->c_traceobj, - tstate, frame); + tstate, fdata); } exception_unwind: - frame->state = FRAME_UNWINDING; + fdata->state = FRAME_UNWINDING; /* We can't use fdata->lasti here, as RERAISE may have set it */ int offset = INSTR_OFFSET()-1; int level, handler, lasti; - if (get_exception_handler(frame->code, offset, &level, &handler, &lasti) == 0) { + if (get_exception_handler(fdata->code, offset, &level, &handler, &lasti) == 0) { // No handlers, so exit. assert(_PyErr_Occurred(tstate)); /* Pop remaining stack entries. */ - PyObject **stackbase = _PyFrame_Stackbase(frame); + PyObject **stackbase = _PyFrame_Stackbase(fdata); while (stack_pointer > stackbase) { PyObject *o = POP(); Py_XDECREF(o); } assert(STACK_LEVEL() == 0); - _PyFrame_SetStackPointer(frame, stack_pointer); - frame->state = FRAME_RAISED; + _PyFrame_SetStackPointer(fdata, stack_pointer); + fdata->state = FRAME_RAISED; TRACE_FUNCTION_UNWIND(); DTRACE_FUNCTION_EXIT(); goto exit_unwind; } assert(STACK_LEVEL() >= level); - PyObject **new_top = _PyFrame_Stackbase(frame) + level; + PyObject **new_top = _PyFrame_Stackbase(fdata) + level; while (stack_pointer > new_top) { PyObject *v = POP(); Py_XDECREF(v); } PyObject *exc, *val, *tb; if (lasti) { - PyObject *lasti = PyLong_FromLong(frame->lasti); + PyObject *lasti = PyLong_FromLong(fdata->lasti); if (lasti == NULL) { goto exception_unwind; } @@ -5692,21 +5692,21 @@ MISS_WITH_OPARG_COUNTER(STORE_SUBSCR) PUSH(val); JUMPTO(handler); /* Resume normal execution */ - frame->state = FRAME_EXECUTING; + fdata->state = FRAME_EXECUTING; DISPATCH(); } exit_unwind: assert(_PyErr_Occurred(tstate)); _Py_LeaveRecursiveCall(tstate); - if (frame->is_entry) { + if (fdata->is_entry) { /* Restore previous cframe and exit */ tstate->cframe = cframe.previous; tstate->cframe->use_tracing = cframe.use_tracing; - assert(tstate->cframe->current_frame == frame->previous); + assert(tstate->cframe->current_frame == fdata->previous); return NULL; } - frame = cframe.current_frame = pop_frame(tstate, frame); + fdata = cframe.current_frame = pop_frame(tstate, fdata); resume_with_error: SET_LOCALS_FROM_FRAME(); @@ -6277,13 +6277,13 @@ _PyEvalFramePushAndInit(PyThreadState *tstate, PyFunctionObject *func, } static void -_PyEvalFrameClearAndPop(PyThreadState *tstate, _Py_framedata * frame) +_PyEvalFrameClearAndPop(PyThreadState *tstate, _Py_framedata * fdata) { tstate->recursion_remaining--; - assert(frame->frame_obj == NULL || frame->frame_obj->f_owns_frame == 0); - _PyFrame_Clear(frame); + assert(fdata->frame_obj == NULL || fdata->frame_obj->f_owns_frame == 0); + _PyFrame_Clear(fdata); tstate->recursion_remaining++; - _PyThreadState_PopFrame(tstate, frame); + _PyThreadState_PopFrame(tstate, fdata); } PyObject * From 34cf0230b31bcff08d6e6043180b4a7c30931f1e Mon Sep 17 00:00:00 2001 From: Nick Coghlan <ncoghlan@gmail.com> Date: Sat, 12 Mar 2022 17:46:46 +1000 Subject: [PATCH 20/30] Disambiguate f_fdata and f_frame_data --- Include/internal/pycore_frame.h | 5 +++-- Objects/frameobject.c | 12 ++++++------ Objects/genobject.c | 2 +- Python/frame.c | 4 ++-- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Include/internal/pycore_frame.h b/Include/internal/pycore_frame.h index 2705884063428a..707d03735fd88a 100644 --- a/Include/internal/pycore_frame.h +++ b/Include/internal/pycore_frame.h @@ -47,7 +47,7 @@ struct _frame { 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]; + struct _Py_framedata *_f_owned_fdata[1]; }; extern PyFrameObject* _PyFrame_New_NoTrack(PyCodeObject *code); @@ -60,7 +60,8 @@ extern void _PyFrame_Fini(PyInterpreterState *interp); /* other API */ /* These values are chosen so that the inline functions below all - * compare fdata->state to zero. + * compare fdata->state to zero while keeping the property that most + * state transitions move to a higher value frame state. */ enum _framestate { FRAME_CREATED = -2, diff --git a/Objects/frameobject.c b/Objects/frameobject.c index 7b1bc93f698b6d..42169ac0390466 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -629,8 +629,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_fdata == (_Py_framedata *)f->_f_frame_data); - _Py_framedata *fdata = (_Py_framedata *)f->_f_frame_data; + assert(f->f_fdata == (_Py_framedata *)f->_f_owned_fdata); + _Py_framedata *fdata = (_Py_framedata *)f->_f_owned_fdata; /* Don't clear code object until the end */ co = fdata->code; fdata->code = NULL; @@ -707,7 +707,7 @@ static PyObject * frame_sizeof(PyFrameObject *f, PyObject *Py_UNUSED(ignored)) { Py_ssize_t res; - res = offsetof(PyFrameObject, _f_frame_data) + offsetof(_Py_framedata, localsplus); + res = offsetof(PyFrameObject, _f_owned_fdata) + offsetof(_Py_framedata, localsplus); PyCodeObject *code = f->f_fdata->code; res += (code->co_nlocalsplus+code->co_stacksize) * sizeof(PyObject *); return PyLong_FromSsize_t(res); @@ -737,7 +737,7 @@ static PyMethodDef frame_methods[] = { PyTypeObject PyFrame_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "frame", - offsetof(PyFrameObject, _f_frame_data) + + offsetof(PyFrameObject, _f_owned_fdata) + offsetof(_Py_framedata, localsplus), sizeof(PyObject *), (destructor)frame_dealloc, /* tp_dealloc */ @@ -827,8 +827,8 @@ PyFrame_New(PyThreadState *tstate, PyCodeObject *code, Py_DECREF(func); return NULL; } - init_frame((_Py_framedata *)f->_f_frame_data, func, locals); - f->f_fdata = (_Py_framedata *)f->_f_frame_data; + init_frame((_Py_framedata *)f->_f_owned_fdata, func, locals); + f->f_fdata = (_Py_framedata *)f->_f_owned_fdata; f->f_owns_frame = 1; Py_DECREF(func); _PyObject_GC_TRACK(f); diff --git a/Objects/genobject.c b/Objects/genobject.c index 548a8d9c066aad..dfb32f5ffb47dc 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -965,7 +965,7 @@ gen_new_with_qualname(PyTypeObject *type, PyFrameObject *f, assert(f->f_fdata->frame_obj == NULL); assert(f->f_owns_frame); _Py_framedata *fdata = (_Py_framedata *)gen->gi_fdata; - _PyFrame_Copy((_Py_framedata *)f->_f_frame_data, fdata); + _PyFrame_Copy((_Py_framedata *)f->_f_owned_fdata, fdata); gen->gi_frame_valid = 1; assert(fdata->frame_obj == f); f->f_owns_frame = 0; diff --git a/Python/frame.c b/Python/frame.c index 0b0850049b15ba..fc1da902cdd010 100644 --- a/Python/frame.c +++ b/Python/frame.c @@ -59,8 +59,8 @@ take_ownership(PyFrameObject *f, _Py_framedata *fdata) { assert(f->f_owns_frame == 0); Py_ssize_t size = ((char*)&fdata->localsplus[fdata->stacktop]) - (char *)fdata; - memcpy((_Py_framedata *)f->_f_frame_data, fdata, size); - fdata = (_Py_framedata *)f->_f_frame_data; + memcpy((_Py_framedata *)f->_f_owned_fdata, fdata, size); + fdata = (_Py_framedata *)f->_f_owned_fdata; f->f_owns_frame = 1; f->f_fdata = fdata; assert(f->f_back == NULL); From 3eba9183671441a24b1476b05d2ecf37ee4cdcc7 Mon Sep 17 00:00:00 2001 From: Nick Coghlan <ncoghlan@gmail.com> Date: Sat, 12 Mar 2022 20:03:34 +1000 Subject: [PATCH 21/30] Document the currently implemented conventions --- Include/internal/pycore_frame.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Include/internal/pycore_frame.h b/Include/internal/pycore_frame.h index 707d03735fd88a..c8ef81b0a3018c 100644 --- a/Include/internal/pycore_frame.h +++ b/Include/internal/pycore_frame.h @@ -25,15 +25,26 @@ extern "C" { * * full frame object fields have an "f_*" prefix * * frame data struct fields have no prefix * - * Variable naming conventions: + * Local variable and function argument naming conventions: * - * * "frame" and "f" are used for full frame objects + * * "frame", "f", and "frameobj" are used for full frame objects * * "fdata" is used for frame data structs * * Function/macro naming conventions: * - * * "PyFrame_*"" and "_PyFrame_*" functions accept a full frame object - * * "_Py_framedata_*" functions accept a frame data struct + * * "PyFrame_*" functions accept a full frame object + * * "_PyFrame_*" functions accept either a full frame object or a frame + * data struct. Check the specific function signatures for details. + * * Other public C API functions that relate to frames only accept full + * frame objects + * * Other private C API functions that relate to frames may accept either a + * full frame object or a frame data struct. 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 */ From e8a4adf3edc146118406c3f4ddcca3b11d3c7806 Mon Sep 17 00:00:00 2001 From: Nick Coghlan <ncoghlan@gmail.com> Date: Sat, 12 Mar 2022 20:17:03 +1000 Subject: [PATCH 22/30] Note the 'current_frame' exception --- Include/internal/pycore_frame.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Include/internal/pycore_frame.h b/Include/internal/pycore_frame.h index c8ef81b0a3018c..84efb61cb5c9b8 100644 --- a/Include/internal/pycore_frame.h +++ b/Include/internal/pycore_frame.h @@ -28,6 +28,7 @@ extern "C" { * Local variable and function argument naming conventions: * * * "frame", "f", and "frameobj" are used for full frame objects + * * Exception: "current_frame" in the thread state cframe struct is a frame data struct * * "fdata" is used for frame data structs * * Function/macro naming conventions: From 3d654a098c1f3ea265a165b79c6737cfb111ad28 Mon Sep 17 00:00:00 2001 From: Nick Coghlan <ncoghlan@gmail.com> Date: Sat, 12 Mar 2022 22:41:26 +1000 Subject: [PATCH 23/30] Fix test_gdb --- Tools/gdb/libpython.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py index 246771d0501cef..d01f62b8720331 100755 --- a/Tools/gdb/libpython.py +++ b/Tools/gdb/libpython.py @@ -985,7 +985,7 @@ def print_traceback(self): return return self._fdata.print_traceback() -class PyFramePtr: +class _Py_framedataPtr: def __init__(self, gdbval): self._gdbval = gdbval @@ -1045,7 +1045,7 @@ def is_entry(self): return self._f_special("is_entry", bool) def previous(self): - return self._f_special("previous", PyFramePtr) + return self._f_special("previous", _Py_framedataPtr) def iter_globals(self): ''' @@ -1793,16 +1793,16 @@ def is_gc_collect(self): def get_pyop(self): try: - frame = self._gdbframe.read_var('frame') - frame = PyFramePtr(frame) - if not frame.is_optimized_out(): - return frame + _gdbfdata = self._gdbframe.read_var('fdata') + fdata = _Py_framedataPtr(_gdbfdata) + if not fdata.is_optimized_out(): + return fdata cframe = self._gdbframe.read_var('cframe') if cframe is None: return None - frame = PyFramePtr(cframe["current_frame"]) - if frame and not frame.is_optimized_out(): - return frame + fdata = _Py_framedataPtr(cframe["current_frame"]) + if fdata and not fdata.is_optimized_out(): + return fdata return None except ValueError: return None From b09b114383e50c1528832678309aedd2bdc1e356 Mon Sep 17 00:00:00 2001 From: Nick Coghlan <ncoghlan@gmail.com> Date: Sat, 12 Mar 2022 23:56:22 +1000 Subject: [PATCH 24/30] Fix header file include guard var --- Include/internal/pycore_frame.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Include/internal/pycore_frame.h b/Include/internal/pycore_frame.h index 84efb61cb5c9b8..496c15498b3577 100644 --- a/Include/internal/pycore_frame.h +++ b/Include/internal/pycore_frame.h @@ -1,5 +1,5 @@ -#ifndef Py_INTERNAL_FRAMEDATA_H -#define Py_INTERNAL_FRAMEDATA_H +#ifndef Py_INTERNAL_FRAME_H +#define Py_INTERNAL_FRAME_H #ifdef __cplusplus extern "C" { #endif @@ -251,4 +251,4 @@ _PyFrame_Push(PyThreadState *tstate, PyFunctionObject *func); #ifdef __cplusplus } #endif -#endif /* !Py_INTERNAL_FRAMEDATA_H */ +#endif /* !Py_INTERNAL_FRAME_H */ From 9b51976d1526d2078a7463f96ea33b85e0a36e73 Mon Sep 17 00:00:00 2001 From: Nick Coghlan <ncoghlan@gmail.com> Date: Sat, 12 Mar 2022 23:57:24 +1000 Subject: [PATCH 25/30] Distinguish frame state error messages --- Python/ceval.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Python/ceval.c b/Python/ceval.c index a4c41572505c85..66a044516a21db 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -6959,7 +6959,7 @@ PyEval_GetLocals(void) PyThreadState *tstate = _PyThreadState_GET(); _Py_framedata *fdata = tstate->cframe->current_frame; if (fdata == NULL) { - _PyErr_SetString(tstate, PyExc_SystemError, "frame data does not exist"); + _PyErr_SetString(tstate, PyExc_SystemError, "cannot get locals; frame data does not exist"); return NULL; } @@ -6978,7 +6978,7 @@ PyEval_GetGlobals(void) PyThreadState *tstate = _PyThreadState_GET(); _Py_framedata *fdata = tstate->cframe->current_frame; if (fdata == NULL) { - _PyErr_SetString(tstate, PyExc_SystemError, "frame data does not exist"); + _PyErr_SetString(tstate, PyExc_SystemError, "cannot get globals; frame data does not exist"); return NULL; } return fdata->globals; From 0a3611ce409c93879ae40f04c431373603d2da05 Mon Sep 17 00:00:00 2001 From: Nick Coghlan <ncoghlan@gmail.com> Date: Sun, 13 Mar 2022 00:13:27 +1000 Subject: [PATCH 26/30] super() does not access C frame structs --- Objects/typeobject.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 1620df8124adfd..5a2cf38144c8d0 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -8933,7 +8933,7 @@ super_descr_get(PyObject *self, PyObject *obj, PyObject *type) } static int -super_init_without_args(_Py_framedata *cframe, PyCodeObject *co, +super_init_without_args(_Py_framedata *fdata, PyCodeObject *co, PyTypeObject **type_p, PyObject **obj_p) { if (co->co_argcount == 0) { @@ -8942,13 +8942,13 @@ super_init_without_args(_Py_framedata *cframe, PyCodeObject *co, return -1; } - assert(cframe->code->co_nlocalsplus > 0); - PyObject *firstarg = _PyFrame_GetLocalsArray(cframe)[0]; + assert(fdata->code->co_nlocalsplus > 0); + PyObject *firstarg = _PyFrame_GetLocalsArray(fdata)[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->lasti >= 0) { + if (fdata->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(_Py_framedata *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(fdata)[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(); - _Py_framedata *cframe = tstate->cframe->current_frame; - if (cframe == NULL) { + _Py_framedata *fdata = tstate->cframe->current_frame; + if (fdata == NULL) { PyErr_SetString(PyExc_RuntimeError, "super(): no current frame"); return -1; } - int res = super_init_without_args(cframe, cframe->code, &type, &obj); + int res = super_init_without_args(fdata, fdata->code, &type, &obj); if (res < 0) { return -1; From 08410cc4d9dcedd23e003a6ceb9cbb1eef6da8f8 Mon Sep 17 00:00:00 2001 From: Nick Coghlan <ncoghlan@gmail.com> Date: Sun, 13 Mar 2022 00:19:49 +1000 Subject: [PATCH 27/30] new_frame -> new_fdata in frame push --- Python/frame.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Python/frame.c b/Python/frame.c index fc1da902cdd010..3513cfa05787d1 100644 --- a/Python/frame.c +++ b/Python/frame.c @@ -116,11 +116,11 @@ _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); - _Py_framedata *new_frame = _PyThreadState_BumpFramePointer(tstate, size); - if (new_frame == NULL) { + _Py_framedata *new_fdata = _PyThreadState_BumpFramePointer(tstate, size); + if (new_fdata == NULL) { Py_DECREF(func); return NULL; } - _PyFrame_InitializeSpecials(new_frame, func, NULL, code->co_nlocalsplus); - return new_frame; + _PyFrame_InitializeSpecials(new_fdata, func, NULL, code->co_nlocalsplus); + return new_fdata; } From c694768ac6071e5b4d7a423d60cb040211644aad Mon Sep 17 00:00:00 2001 From: Nick Coghlan <ncoghlan@gmail.com> Date: Sun, 13 Mar 2022 00:32:30 +1000 Subject: [PATCH 28/30] Add missing error check in PyImport_Import --- Python/import.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Python/import.c b/Python/import.c index 982ec8cfe631a6..627c1ed7c66726 100644 --- a/Python/import.c +++ b/Python/import.c @@ -1988,6 +1988,9 @@ PyImport_Import(PyObject *module_name) goto err; } else { + if (PyErr_Occurred()) { + goto err; + } /* No globals -- use standard builtins, and fake globals */ builtins = PyImport_ImportModuleLevel("builtins", NULL, NULL, NULL, 0); From ba87ef39fce8518f932f4a12a76380484cfb49a1 Mon Sep 17 00:00:00 2001 From: Nick Coghlan <ncoghlan@gmail.com> Date: Sun, 13 Mar 2022 00:57:08 +1000 Subject: [PATCH 29/30] No Python frame seems legit for PyImport_Import() --- Python/import.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Python/import.c b/Python/import.c index 627c1ed7c66726..af908f50ec59c0 100644 --- a/Python/import.c +++ b/Python/import.c @@ -1989,7 +1989,9 @@ PyImport_Import(PyObject *module_name) } else { if (PyErr_Occurred()) { - goto err; + // It's legitimate to have no Python frame and hence no globals + // if importing from C (e.g. during startup, or when embedded) + PyErr_Clear(); } /* No globals -- use standard builtins, and fake globals */ builtins = PyImport_ImportModuleLevel("builtins", From 7168f7dfb8bbab53300ae171e9d7fbf0a9615f0a Mon Sep 17 00:00:00 2001 From: Nick Coghlan <ncoghlan@gmail.com> Date: Sun, 13 Mar 2022 01:15:36 +1000 Subject: [PATCH 30/30] Get test_gdb passing locally --- Tools/gdb/libpython.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py index d01f62b8720331..4dc44d60131a38 100755 --- a/Tools/gdb/libpython.py +++ b/Tools/gdb/libpython.py @@ -1042,10 +1042,10 @@ def _lasti(self): return self._special("lasti", int_from_int) def is_entry(self): - return self._f_special("is_entry", bool) + return self._special("is_entry", bool) def previous(self): - return self._f_special("previous", _Py_framedataPtr) + return self._special("previous", _Py_framedataPtr) def iter_globals(self): '''