From 89eda176b17dda588a19d6cfefd5face9c3a6c4b Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Fri, 10 Mar 2023 18:31:31 +0000 Subject: [PATCH 1/7] All any object as 'code' field in PyInterpreterFrame. --- Include/internal/pycore_frame.h | 22 +- Modules/_tracemalloc.c | 2 +- Objects/frameobject.c | 39 +- Objects/genobject.c | 6 +- Objects/typeobject.c | 4 +- Python/_warnings.c | 2 +- Python/bytecodes.c | 72 ++- Python/ceval.c | 24 +- Python/ceval_macros.h | 8 +- Python/frame.c | 12 +- Python/generated_cases.c.h | 810 ++++++++++++++++---------------- Python/instrumentation.c | 10 +- Python/intrinsics.c | 6 +- Python/legacy_tracing.c | 6 +- Python/perf_trampoline.c | 2 +- Python/traceback.c | 4 +- Tools/gdb/libpython.py | 25 +- 17 files changed, 535 insertions(+), 519 deletions(-) diff --git a/Include/internal/pycore_frame.h b/Include/internal/pycore_frame.h index d8d7fe9ef2ebde..e0301ea7bc2f11 100644 --- a/Include/internal/pycore_frame.h +++ b/Include/internal/pycore_frame.h @@ -48,7 +48,7 @@ enum _frameowner { }; typedef struct _PyInterpreterFrame { - PyCodeObject *f_code; /* Strong reference */ + PyObject *f_executable; /* Strong reference */ struct _PyInterpreterFrame *previous; PyObject *f_funcobj; /* Strong reference. Only valid if not on C stack */ PyObject *f_globals; /* Borrowed reference. Only valid if not on C stack */ @@ -74,20 +74,25 @@ typedef struct _PyInterpreterFrame { } _PyInterpreterFrame; #define _PyInterpreterFrame_LASTI(IF) \ - ((int)((IF)->prev_instr - _PyCode_CODE((IF)->f_code))) + ((int)((IF)->prev_instr - _PyCode_CODE(_PyFrame_GetCode(IF)))) + +static inline PyCodeObject *_PyFrame_GetCode(_PyInterpreterFrame *f) { + assert(PyCode_Check(f->f_executable)); + return (PyCodeObject *)f->f_executable; +} static inline PyObject **_PyFrame_Stackbase(_PyInterpreterFrame *f) { - return f->localsplus + f->f_code->co_nlocalsplus; + return f->localsplus + _PyFrame_GetCode(f)->co_nlocalsplus; } static inline PyObject *_PyFrame_StackPeek(_PyInterpreterFrame *f) { - assert(f->stacktop > f->f_code->co_nlocalsplus); + assert(f->stacktop > _PyFrame_GetCode(f)->co_nlocalsplus); assert(f->localsplus[f->stacktop-1] != NULL); return f->localsplus[f->stacktop-1]; } static inline PyObject *_PyFrame_StackPop(_PyInterpreterFrame *f) { - assert(f->stacktop > f->f_code->co_nlocalsplus); + assert(f->stacktop > _PyFrame_GetCode(f)->co_nlocalsplus); f->stacktop--; return f->localsplus[f->stacktop]; } @@ -120,7 +125,7 @@ _PyFrame_Initialize( PyObject *locals, PyCodeObject *code, int null_locals_from) { frame->f_funcobj = (PyObject *)func; - frame->f_code = (PyCodeObject *)Py_NewRef(code); + frame->f_executable = Py_NewRef(code); frame->f_builtins = func->func_builtins; frame->f_globals = func->func_globals; frame->f_locals = locals; @@ -173,8 +178,11 @@ _PyFrame_SetStackPointer(_PyInterpreterFrame *frame, PyObject **stack_pointer) static inline bool _PyFrame_IsIncomplete(_PyInterpreterFrame *frame) { + if (frame->owner == FRAME_OWNED_BY_CSTACK) { + return true; + } return frame->owner != FRAME_OWNED_BY_GENERATOR && - frame->prev_instr < _PyCode_CODE(frame->f_code) + frame->f_code->_co_firsttraceable; + frame->prev_instr < _PyCode_CODE(_PyFrame_GetCode(frame)) + _PyFrame_GetCode(frame)->_co_firsttraceable; } static inline _PyInterpreterFrame * diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c index d69c5636486da9..6f36df2fb2e3f2 100644 --- a/Modules/_tracemalloc.c +++ b/Modules/_tracemalloc.c @@ -263,7 +263,7 @@ tracemalloc_get_frame(_PyInterpreterFrame *pyframe, frame_t *frame) } frame->lineno = (unsigned int)lineno; - PyObject *filename = pyframe->f_code->co_filename; + PyObject *filename = _PyFrame_GetCode(pyframe)->co_filename; if (filename == NULL) { #ifdef TRACE_DEBUG diff --git a/Objects/frameobject.c b/Objects/frameobject.c index ef0070199ab2c0..bdaa9de2e9ea17 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -642,6 +642,7 @@ _PyFrame_GetState(PyFrameObject *frame) static int frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno, void *Py_UNUSED(ignored)) { + PyCodeObject *code = _PyFrame_GetCode(f->f_frame); if (p_new_lineno == NULL) { PyErr_SetString(PyExc_AttributeError, "cannot delete attribute"); return -1; @@ -719,7 +720,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 < code->co_firstlineno) { PyErr_Format(PyExc_ValueError, "line %d comes before the current code block", new_lineno); @@ -728,8 +729,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)Py_SIZE(f->f_frame->f_code); - int *lines = marklines(f->f_frame->f_code, len); + int len = (int)Py_SIZE(code); + int *lines = marklines(code, len); if (lines == NULL) { return -1; } @@ -743,7 +744,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(code, len); if (stacks == NULL) { PyMem_Free(lines); return -1; @@ -788,7 +789,7 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno, void *Py_UNUSED(ignore // in the new location. Rather than crashing or changing co_code, just bind // None instead: int unbound = 0; - for (int i = 0; i < f->f_frame->f_code->co_nlocalsplus; i++) { + for (int i = 0; i < code->co_nlocalsplus; i++) { // Counting every unbound local is overly-cautious, but a full flow // analysis (like we do in the compiler) is probably too expensive: unbound += f->f_frame->localsplus[i] == NULL; @@ -801,7 +802,7 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno, void *Py_UNUSED(ignore } // Do this in a second pass to avoid writing a bunch of Nones when // warnings are being treated as errors and the previous bit raises: - for (int i = 0; i < f->f_frame->f_code->co_nlocalsplus; i++) { + for (int i = 0; i < code->co_nlocalsplus; i++) { if (f->f_frame->localsplus[i] == NULL) { f->f_frame->localsplus[i] = Py_NewRef(Py_None); unbound--; @@ -833,7 +834,7 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno, void *Py_UNUSED(ignore /* Finally set the new lasti and return OK. */ f->f_last_traced_line = new_lineno; f->f_lineno = 0; - f->f_frame->prev_instr = _PyCode_CODE(f->f_frame->f_code) + best_addr; + f->f_frame->prev_instr = _PyCode_CODE(code) + best_addr; return 0; } @@ -888,15 +889,15 @@ frame_dealloc(PyFrameObject *f) } Py_TRASHCAN_BEGIN(f, frame_dealloc); - PyCodeObject *co = NULL; + PyObject *co = NULL; /* Kill all local variables including specials, if we own them */ if (f->f_frame->owner == FRAME_OWNED_BY_FRAME_OBJECT) { assert(f->f_frame == (_PyInterpreterFrame *)f->_f_frame_data); _PyInterpreterFrame *frame = (_PyInterpreterFrame *)f->_f_frame_data; /* Don't clear code object until the end */ - co = frame->f_code; - frame->f_code = NULL; + co = frame->f_executable; + frame->f_executable = NULL; Py_CLEAR(frame->f_funcobj); Py_CLEAR(frame->f_locals); PyObject **locals = _PyFrame_GetLocalsArray(frame); @@ -970,7 +971,7 @@ frame_sizeof(PyFrameObject *f, PyObject *Py_UNUSED(ignored)) { Py_ssize_t res; res = offsetof(PyFrameObject, _f_frame_data) + offsetof(_PyInterpreterFrame, localsplus); - PyCodeObject *code = f->f_frame->f_code; + PyCodeObject *code = _PyFrame_GetCode(f->f_frame); res += _PyFrame_NumSlotsForCodeObject(code) * sizeof(PyObject *); return PyLong_FromSsize_t(res); } @@ -982,7 +983,7 @@ static PyObject * frame_repr(PyFrameObject *f) { int lineno = PyFrame_GetLineNumber(f); - PyCodeObject *code = f->f_frame->f_code; + PyCodeObject *code = _PyFrame_GetCode(f->f_frame); return PyUnicode_FromFormat( "", f, code->co_filename, lineno, code->co_name); @@ -1105,7 +1106,7 @@ _PyFrame_OpAlreadyRan(_PyInterpreterFrame *frame, int opcode, int oparg) // This only works when opcode is a non-quickened form: assert(_PyOpcode_Deopt[opcode] == opcode); int check_oparg = 0; - for (_Py_CODEUNIT *instruction = _PyCode_CODE(frame->f_code); + for (_Py_CODEUNIT *instruction = _PyCode_CODE(_PyFrame_GetCode(frame)); instruction < frame->prev_instr; instruction++) { int check_opcode = _PyOpcode_Deopt[instruction->op.code]; @@ -1131,7 +1132,7 @@ frame_init_get_vars(_PyInterpreterFrame *frame) { // COPY_FREE_VARS has no quickened forms, so no need to use _PyOpcode_Deopt // here: - PyCodeObject *co = frame->f_code; + PyCodeObject *co = _PyFrame_GetCode(frame); int lasti = _PyInterpreterFrame_LASTI(frame); if (!(lasti < 0 && _PyCode_CODE(co)->op.code == COPY_FREE_VARS && PyFunction_Check(frame->f_funcobj))) @@ -1148,7 +1149,7 @@ frame_init_get_vars(_PyInterpreterFrame *frame) frame->localsplus[offset + i] = Py_NewRef(o); } // COPY_FREE_VARS doesn't have inline CACHEs, either: - frame->prev_instr = _PyCode_CODE(frame->f_code); + frame->prev_instr = _PyCode_CODE(_PyFrame_GetCode(frame)); } @@ -1216,7 +1217,7 @@ _PyFrame_FastToLocalsWithError(_PyInterpreterFrame *frame) frame_init_get_vars(frame); - PyCodeObject *co = frame->f_code; + PyCodeObject *co = _PyFrame_GetCode(frame); for (int i = 0; i < co->co_nlocalsplus; i++) { PyObject *value; // borrowed reference if (!frame_get_var(frame, co, i, &value)) { @@ -1256,7 +1257,7 @@ PyFrame_GetVar(PyFrameObject *frame_obj, PyObject *name) _PyInterpreterFrame *frame = frame_obj->f_frame; frame_init_get_vars(frame); - PyCodeObject *co = frame->f_code; + PyCodeObject *co = _PyFrame_GetCode(frame); for (int i = 0; i < co->co_nlocalsplus; i++) { PyObject *var_name = PyTuple_GET_ITEM(co->co_localsplusnames, i); if (!_PyUnicode_Equal(var_name, name)) { @@ -1330,7 +1331,7 @@ _PyFrame_LocalsToFast(_PyInterpreterFrame *frame, int clear) return; } fast = _PyFrame_GetLocalsArray(frame); - co = frame->f_code; + co = _PyFrame_GetCode(frame); PyObject *exc = PyErr_GetRaisedException(); for (int i = 0; i < co->co_nlocalsplus; i++) { @@ -1416,7 +1417,7 @@ PyFrame_GetCode(PyFrameObject *frame) { assert(frame != NULL); assert(!_PyFrame_IsIncomplete(frame->f_frame)); - PyCodeObject *code = frame->f_frame->f_code; + PyCodeObject *code = _PyFrame_GetCode(frame->f_frame); assert(code != NULL); return (PyCodeObject*)Py_NewRef(code); } diff --git a/Objects/genobject.c b/Objects/genobject.c index 6316fa9865fe65..eb81745d18a4fa 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -28,7 +28,7 @@ static const char *ASYNC_GEN_IGNORED_EXIT_MSG = static inline PyCodeObject * _PyGen_GetCode(PyGenObject *gen) { _PyInterpreterFrame *frame = (_PyInterpreterFrame *)(gen->gi_iframe); - return frame->f_code; + return _PyFrame_GetCode(frame); } PyCodeObject * @@ -939,7 +939,7 @@ static PyObject * gen_new_with_qualname(PyTypeObject *type, PyFrameObject *f, PyObject *name, PyObject *qualname) { - PyCodeObject *code = f->f_frame->f_code; + PyCodeObject *code = _PyFrame_GetCode(f->f_frame); int size = code->co_nlocalsplus + code->co_stacksize; PyGenObject *gen = PyObject_GC_NewVar(PyGenObject, type, size); if (gen == NULL) { @@ -1321,7 +1321,7 @@ compute_cr_origin(int origin_depth, _PyInterpreterFrame *current_frame) } frame = current_frame; for (int i = 0; i < frame_count; ++i) { - PyCodeObject *code = frame->f_code; + PyCodeObject *code = _PyFrame_GetCode(frame); int line = _PyInterpreterFrame_GetLine(frame); PyObject *frameinfo = Py_BuildValue("OiO", code->co_filename, line, code->co_name); diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 456b10ee01d6bc..e25caf397b34cf 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -10193,7 +10193,7 @@ super_init_without_args(_PyInterpreterFrame *cframe, PyCodeObject *co, return -1; } - assert(cframe->f_code->co_nlocalsplus > 0); + assert(_PyFrame_GetCode(cframe)->co_nlocalsplus > 0); PyObject *firstarg = _PyFrame_GetLocalsArray(cframe)[0]; // The first argument might be a cell. if (firstarg != NULL && (_PyLocals_GetKind(co->co_localspluskinds, 0) & CO_FAST_CELL)) { @@ -10286,7 +10286,7 @@ super_init_impl(PyObject *self, PyTypeObject *type, PyObject *obj) { "super(): no current frame"); return -1; } - int res = super_init_without_args(frame, frame->f_code, &type, &obj); + int res = super_init_without_args(frame, _PyFrame_GetCode(frame), &type, &obj); if (res < 0) { return -1; diff --git a/Python/_warnings.c b/Python/_warnings.c index d510381c365b66..b87da8cd10a569 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -901,7 +901,7 @@ setup_context(Py_ssize_t stack_level, } else { globals = f->f_frame->f_globals; - *filename = Py_NewRef(f->f_frame->f_code->co_filename); + *filename = Py_NewRef(_PyFrame_GetCode(f->f_frame)->co_filename); *lineno = PyFrame_GetLineNumber(f); Py_DECREF(f); } diff --git a/Python/bytecodes.c b/Python/bytecodes.c index e83894e8902872..22609c3b0787b2 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -137,8 +137,8 @@ dummy_func( assert(tstate->cframe == &cframe); assert(frame == cframe.current_frame); /* Possibly combine this with eval breaker */ - if (frame->f_code->_co_instrumentation_version != tstate->interp->monitoring_version) { - int err = _Py_Instrument(frame->f_code, tstate->interp); + if (_PyFrame_GetCode(frame)->_co_instrumentation_version != tstate->interp->monitoring_version) { + int err = _Py_Instrument(_PyFrame_GetCode(frame), tstate->interp); ERROR_IF(err, error); next_instr--; } @@ -152,8 +152,8 @@ dummy_func( * We need to check the eval breaker anyway, can we * combine the instrument verison check and the eval breaker test? */ - if (frame->f_code->_co_instrumentation_version != tstate->interp->monitoring_version) { - if (_Py_Instrument(frame->f_code, tstate->interp)) { + if (_PyFrame_GetCode(frame)->_co_instrumentation_version != tstate->interp->monitoring_version) { + if (_Py_Instrument(_PyFrame_GetCode(frame), tstate->interp)) { goto error; } next_instr--; @@ -195,7 +195,7 @@ dummy_func( } inst(LOAD_CONST, (-- value)) { - value = GETITEM(frame->f_code->co_consts, oparg); + value = GETITEM(CONSTS(), oparg); Py_INCREF(value); } @@ -619,8 +619,6 @@ dummy_func( inst(INTERPRETER_EXIT, (retval --)) { assert(frame == &entry_frame); assert(_PyFrame_IsIncomplete(frame)); - STACK_SHRINK(1); // Since we're not going to DISPATCH() - assert(EMPTY()); /* Restore previous cframe and return. */ tstate->cframe = cframe.previous; assert(tstate->cframe->current_frame == frame->previous); @@ -664,7 +662,7 @@ dummy_func( } inst(RETURN_CONST, (--)) { - PyObject *retval = GETITEM(frame->f_code->co_consts, oparg); + PyObject *retval = GETITEM(CONSTS(), oparg); Py_INCREF(retval); assert(EMPTY()); _PyFrame_SetStackPointer(frame, stack_pointer); @@ -680,7 +678,7 @@ dummy_func( } inst(INSTRUMENTED_RETURN_CONST, (--)) { - PyObject *retval = GETITEM(frame->f_code->co_consts, oparg); + PyObject *retval = GETITEM(_PyFrame_GetCode(frame)->co_consts, oparg); int err = _Py_call_instrumentation_arg( tstate, PY_MONITORING_EVENT_PY_RETURN, frame, next_instr-1, retval); @@ -924,7 +922,7 @@ dummy_func( if (oparg) { PyObject *lasti = values[0]; if (PyLong_Check(lasti)) { - frame->prev_instr = _PyCode_CODE(frame->f_code) + PyLong_AsLong(lasti); + frame->prev_instr = _PyCode_CODE(_PyFrame_GetCode(frame)) + PyLong_AsLong(lasti); assert(!_PyErr_Occurred(tstate)); } else { @@ -994,7 +992,7 @@ dummy_func( } inst(STORE_NAME, (v -- )) { - PyObject *name = GETITEM(frame->f_code->co_names, oparg); + PyObject *name = GETITEM(NAMES(), oparg); PyObject *ns = LOCALS(); int err; if (ns == NULL) { @@ -1012,7 +1010,7 @@ dummy_func( } inst(DELETE_NAME, (--)) { - PyObject *name = GETITEM(frame->f_code->co_names, oparg); + PyObject *name = GETITEM(NAMES(), oparg); PyObject *ns = LOCALS(); int err; if (ns == NULL) { @@ -1104,7 +1102,7 @@ dummy_func( inst(STORE_ATTR, (counter/1, unused/3, v, owner --)) { #if ENABLE_SPECIALIZATION if (ADAPTIVE_COUNTER_IS_ZERO(counter)) { - PyObject *name = GETITEM(frame->f_code->co_names, oparg); + PyObject *name = GETITEM(NAMES(), oparg); next_instr--; _Py_Specialize_StoreAttr(owner, next_instr, name); DISPATCH_SAME_OPARG(); @@ -1115,28 +1113,28 @@ dummy_func( #else (void)counter; // Unused. #endif /* ENABLE_SPECIALIZATION */ - PyObject *name = GETITEM(frame->f_code->co_names, oparg); + PyObject *name = GETITEM(NAMES(), oparg); int err = PyObject_SetAttr(owner, name, v); DECREF_INPUTS(); ERROR_IF(err, error); } inst(DELETE_ATTR, (owner --)) { - PyObject *name = GETITEM(frame->f_code->co_names, oparg); + PyObject *name = GETITEM(NAMES(), oparg); int err = PyObject_SetAttr(owner, name, (PyObject *)NULL); DECREF_INPUTS(); ERROR_IF(err, error); } inst(STORE_GLOBAL, (v --)) { - PyObject *name = GETITEM(frame->f_code->co_names, oparg); + PyObject *name = GETITEM(NAMES(), oparg); int err = PyDict_SetItem(GLOBALS(), name, v); DECREF_INPUTS(); ERROR_IF(err, error); } inst(DELETE_GLOBAL, (--)) { - PyObject *name = GETITEM(frame->f_code->co_names, oparg); + PyObject *name = GETITEM(NAMES(), oparg); int err; err = PyDict_DelItem(GLOBALS(), name); // Can't use ERROR_IF here. @@ -1150,7 +1148,7 @@ dummy_func( } inst(LOAD_NAME, ( -- v)) { - PyObject *name = GETITEM(frame->f_code->co_names, oparg); + PyObject *name = GETITEM(NAMES(), oparg); PyObject *locals = LOCALS(); if (locals == NULL) { _PyErr_Format(tstate, PyExc_SystemError, @@ -1220,7 +1218,7 @@ dummy_func( #if ENABLE_SPECIALIZATION _PyLoadGlobalCache *cache = (_PyLoadGlobalCache *)next_instr; if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) { - PyObject *name = GETITEM(frame->f_code->co_names, oparg>>1); + PyObject *name = GETITEM(NAMES(), oparg>>1); next_instr--; _Py_Specialize_LoadGlobal(GLOBALS(), BUILTINS(), next_instr, name); DISPATCH_SAME_OPARG(); @@ -1228,7 +1226,7 @@ dummy_func( STAT_INC(LOAD_GLOBAL, deferred); DECREMENT_ADAPTIVE_COUNTER(cache->counter); #endif /* ENABLE_SPECIALIZATION */ - PyObject *name = GETITEM(frame->f_code->co_names, oparg>>1); + PyObject *name = GETITEM(NAMES(), oparg>>1); if (PyDict_CheckExact(GLOBALS()) && PyDict_CheckExact(BUILTINS())) { @@ -1323,7 +1321,7 @@ dummy_func( // Can't use ERROR_IF here. // Fortunately we don't need its superpower. if (oldobj == NULL) { - format_exc_unbound(tstate, frame->f_code, oparg); + format_exc_unbound(tstate, _PyFrame_GetCode(frame), oparg); goto error; } PyCell_SET(cell, NULL); @@ -1333,8 +1331,8 @@ dummy_func( inst(LOAD_CLASSDEREF, ( -- value)) { PyObject *name, *locals = LOCALS(); assert(locals); - assert(oparg >= 0 && oparg < frame->f_code->co_nlocalsplus); - name = PyTuple_GET_ITEM(frame->f_code->co_localsplusnames, oparg); + assert(oparg >= 0 && oparg < _PyFrame_GetCode(frame)->co_nlocalsplus); + name = PyTuple_GET_ITEM(_PyFrame_GetCode(frame)->co_localsplusnames, oparg); if (PyDict_CheckExact(locals)) { value = PyDict_GetItemWithError(locals, name); if (value != NULL) { @@ -1357,7 +1355,7 @@ dummy_func( PyObject *cell = GETLOCAL(oparg); value = PyCell_GET(cell); if (value == NULL) { - format_exc_unbound(tstate, frame->f_code, oparg); + format_exc_unbound(tstate, _PyFrame_GetCode(frame), oparg); goto error; } Py_INCREF(value); @@ -1368,7 +1366,7 @@ dummy_func( PyObject *cell = GETLOCAL(oparg); value = PyCell_GET(cell); if (value == NULL) { - format_exc_unbound(tstate, frame->f_code, oparg); + format_exc_unbound(tstate, _PyFrame_GetCode(frame), oparg); ERROR_IF(true, error); } Py_INCREF(value); @@ -1383,7 +1381,7 @@ dummy_func( inst(COPY_FREE_VARS, (--)) { /* Copy closure variables to free variables */ - PyCodeObject *co = frame->f_code; + PyCodeObject *co = _PyFrame_GetCode(frame); assert(PyFunction_Check(frame->f_funcobj)); PyObject *closure = ((PyFunctionObject *)frame->f_funcobj)->func_closure; assert(oparg == co->co_nfreevars); @@ -1560,7 +1558,7 @@ dummy_func( }; inst(LOAD_SUPER_ATTR, (unused/9, global_super, class, self -- res2 if (oparg & 1), res)) { - PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 2); + PyObject *name = GETITEM(_PyFrame_GetCode(frame)->co_names, oparg >> 2); int load_method = oparg & 1; #if ENABLE_SPECIALIZATION _PySuperAttrCache *cache = (_PySuperAttrCache *)next_instr; @@ -1615,7 +1613,7 @@ dummy_func( #if ENABLE_SPECIALIZATION _PyAttrCache *cache = (_PyAttrCache *)next_instr; if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) { - PyObject *name = GETITEM(frame->f_code->co_names, oparg>>1); + PyObject *name = GETITEM(NAMES(), oparg>>1); next_instr--; _Py_Specialize_LoadAttr(owner, next_instr, name); DISPATCH_SAME_OPARG(); @@ -1623,7 +1621,7 @@ dummy_func( STAT_INC(LOAD_ATTR, deferred); DECREMENT_ADAPTIVE_COUNTER(cache->counter); #endif /* ENABLE_SPECIALIZATION */ - PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 1); + PyObject *name = GETITEM(NAMES(), oparg >> 1); if (oparg & 1) { /* Designed to work in tandem with CALL, pushes two values. */ PyObject* meth = NULL; @@ -1701,7 +1699,7 @@ dummy_func( PyDictObject *dict = (PyDictObject *)_PyDictOrValues_GetDict(dorv); DEOPT_IF(dict == NULL, LOAD_ATTR); assert(PyDict_CheckExact((PyObject *)dict)); - PyObject *name = GETITEM(frame->f_code->co_names, oparg>>1); + PyObject *name = GETITEM(NAMES(), oparg>>1); uint16_t hint = index; DEOPT_IF(hint >= (size_t)dict->ma_keys->dk_nentries, LOAD_ATTR); if (DK_IS_UNICODE(dict->ma_keys)) { @@ -1789,7 +1787,7 @@ dummy_func( DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), LOAD_ATTR); STAT_INC(LOAD_ATTR, hit); - PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 1); + PyObject *name = GETITEM(NAMES(), oparg >> 1); Py_INCREF(f); _PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, f, 2); // Manipulate stack directly because we exit with DISPATCH_INLINED(). @@ -1833,7 +1831,7 @@ dummy_func( PyDictObject *dict = (PyDictObject *)_PyDictOrValues_GetDict(dorv); DEOPT_IF(dict == NULL, STORE_ATTR); assert(PyDict_CheckExact((PyObject *)dict)); - PyObject *name = GETITEM(frame->f_code->co_names, oparg); + PyObject *name = GETITEM(NAMES(), oparg); DEOPT_IF(hint >= (size_t)dict->ma_keys->dk_nentries, STORE_ATTR); PyObject *old_value; uint64_t new_version; @@ -1996,14 +1994,14 @@ dummy_func( } inst(IMPORT_NAME, (level, fromlist -- res)) { - PyObject *name = GETITEM(frame->f_code->co_names, oparg); + PyObject *name = GETITEM(NAMES(), oparg); res = import_name(tstate, frame, name, fromlist, level); DECREF_INPUTS(); ERROR_IF(res == NULL, error); } inst(IMPORT_FROM, (from -- from, res)) { - PyObject *name = GETITEM(frame->f_code->co_names, oparg); + PyObject *name = GETITEM(NAMES(), oparg); res = import_from(tstate, from, name); ERROR_IF(res == NULL, error); } @@ -2139,7 +2137,7 @@ dummy_func( /* before: [obj]; after [getiter(obj)] */ if (PyCoro_CheckExact(iterable)) { /* `iterable` is a coroutine */ - if (!(frame->f_code->co_flags & (CO_COROUTINE | CO_ITERABLE_COROUTINE))) { + if (!(_PyFrame_GetCode(frame)->co_flags & (CO_COROUTINE | CO_ITERABLE_COROUTINE))) { /* and it is used in a 'yield from' expression of a regular generator. */ _PyErr_SetString(tstate, PyExc_TypeError, @@ -2471,8 +2469,8 @@ dummy_func( inst(KW_NAMES, (--)) { assert(kwnames == NULL); - assert(oparg < PyTuple_GET_SIZE(frame->f_code->co_consts)); - kwnames = GETITEM(frame->f_code->co_consts, oparg); + assert(oparg < PyTuple_GET_SIZE(CONSTS())); + kwnames = GETITEM(CONSTS(), oparg); } inst(INSTRUMENTED_CALL, ( -- )) { diff --git a/Python/ceval.c b/Python/ceval.c index 958689debc87f8..db0762cdd4305e 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -128,6 +128,9 @@ lltrace_instruction(_PyInterpreterFrame *frame, PyObject **stack_pointer, _Py_CODEUNIT *next_instr) { + if (frame->owner == FRAME_OWNED_BY_CSTACK) { + return; + } /* This dump_stack() operation is risky, since the repr() of some objects enters the interpreter recursively. It is also slow. So you might want to comment it out. */ @@ -136,7 +139,7 @@ lltrace_instruction(_PyInterpreterFrame *frame, int opcode = next_instr->op.code; const char *opname = _PyOpcode_OpName[opcode]; assert(opname != NULL); - int offset = (int)(next_instr - _PyCode_CODE(frame->f_code)); + int offset = (int)(next_instr - _PyCode_CODE(_PyFrame_GetCode(frame))); if (HAS_ARG((int)_PyOpcode_Deopt[opcode])) { printf("%d: %s %d\n", offset * 2, opname, oparg); } @@ -677,7 +680,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int entry_frame.f_globals = (PyObject*)0xaaa3; entry_frame.f_builtins = (PyObject*)0xaaa4; #endif - entry_frame.f_code = tstate->interp->interpreter_trampoline; + entry_frame.f_executable = Py_None; entry_frame.prev_instr = _PyCode_CODE(tstate->interp->interpreter_trampoline); entry_frame.stacktop = 0; @@ -701,7 +704,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int } /* Because this avoids the RESUME, * we need to update instrumentation */ - _Py_Instrument(frame->f_code, tstate->interp); + _Py_Instrument(_PyFrame_GetCode(frame), tstate->interp); monitor_throw(tstate, frame, frame->prev_instr); /* TO DO -- Monitor throw entry. */ goto resume_with_error; @@ -715,7 +718,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int /* Sets the above local variables from the frame */ #define SET_LOCALS_FROM_FRAME() \ - assert(_PyInterpreterFrame_LASTI(frame) >= -1); \ /* Jump back to the last instruction executed... */ \ next_instr = frame->prev_instr + 1; \ stack_pointer = _PyFrame_GetStackPointer(frame); @@ -784,7 +786,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int opcode = next_instr->op.code; _PyErr_Format(tstate, PyExc_SystemError, "%U:%d: unknown opcode %d", - frame->f_code->co_filename, + _PyFrame_GetCode(frame)->co_filename, _PyInterpreterFrame_GetLine(frame), opcode); goto error; @@ -799,7 +801,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int { format_exc_check_arg(tstate, PyExc_UnboundLocalError, UNBOUNDLOCAL_ERROR_MSG, - PyTuple_GetItem(frame->f_code->co_localsplusnames, oparg) + PyTuple_GetItem(_PyFrame_GetCode(frame)->co_localsplusnames, oparg) ); goto error; } @@ -839,7 +841,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int /* We can't use frame->f_lasti here, as RERAISE may have set it */ int offset = INSTR_OFFSET()-1; int level, handler, lasti; - if (get_exception_handler(frame->f_code, offset, &level, &handler, &lasti) == 0) { + if (get_exception_handler(_PyFrame_GetCode(frame), offset, &level, &handler, &lasti) == 0) { // No handlers, so exit. assert(_PyErr_Occurred(tstate)); @@ -1433,12 +1435,12 @@ clear_thread_frame(PyThreadState *tstate, _PyInterpreterFrame * frame) assert(frame->owner == FRAME_OWNED_BY_THREAD); // Make sure that this is, indeed, the top frame. We can't check this in // _PyThreadState_PopFrame, since f_code is already cleared at that point: - assert((PyObject **)frame + frame->f_code->co_framesize == + assert((PyObject **)frame + _PyFrame_GetCode(frame)->co_framesize == tstate->datastack_top); tstate->c_recursion_remaining--; assert(frame->frame_obj == NULL || frame->frame_obj->f_frame == frame); _PyFrame_ClearExceptCode(frame); - Py_DECREF(frame->f_code); + Py_DECREF(frame->f_executable); tstate->c_recursion_remaining++; _PyThreadState_PopFrame(tstate, frame); } @@ -1923,7 +1925,7 @@ do_monitor_exc(PyThreadState *tstate, _PyInterpreterFrame *frame, static inline int no_tools_for_event(PyThreadState *tstate, _PyInterpreterFrame *frame, int event) { - _PyCoMonitoringData *data = frame->f_code->_co_monitoring; + _PyCoMonitoringData *data = _PyFrame_GetCode(frame)->_co_monitoring; if (data) { if (data->active_monitors.tools[event] == 0) { return 1; @@ -2241,7 +2243,7 @@ PyEval_MergeCompilerFlags(PyCompilerFlags *cf) int result = cf->cf_flags != 0; if (current_frame != NULL) { - const int codeflags = current_frame->f_code->co_flags; + const int codeflags = _PyFrame_GetCode(current_frame)->co_flags; const int compilerflags = codeflags & PyCF_MASK; if (compilerflags) { result = 1; diff --git a/Python/ceval_macros.h b/Python/ceval_macros.h index 485771ac65a767..29ae76f050372b 100644 --- a/Python/ceval_macros.h +++ b/Python/ceval_macros.h @@ -137,13 +137,13 @@ GETITEM(PyObject *v, Py_ssize_t i) { /* Code access macros */ /* The integer overflow is checked by an assertion below. */ -#define INSTR_OFFSET() ((int)(next_instr - _PyCode_CODE(frame->f_code))) +#define INSTR_OFFSET() ((int)(next_instr - _PyCode_CODE(_PyFrame_GetCode(frame)))) #define NEXTOPARG() do { \ _Py_CODEUNIT word = *next_instr; \ opcode = word.op.code; \ oparg = word.op.arg; \ } while (0) -#define JUMPTO(x) (next_instr = _PyCode_CODE(frame->f_code) + (x)) +#define JUMPTO(x) (next_instr = _PyCode_CODE(_PyFrame_GetCode(frame)) + (x)) #define JUMPBY(x) (next_instr += (x)) /* OpCode prediction macros @@ -196,7 +196,7 @@ GETITEM(PyObject *v, Py_ssize_t i) { /* 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_SIZE() (frame->f_code->co_stacksize) +#define STACK_SIZE() (_PyFrame_GetCode(frame)->co_stacksize) #define EMPTY() (STACK_LEVEL() == 0) #define TOP() (stack_pointer[-1]) #define SECOND() (stack_pointer[-2]) @@ -279,6 +279,8 @@ GETITEM(PyObject *v, Py_ssize_t i) { #define GLOBALS() frame->f_globals #define BUILTINS() frame->f_builtins #define LOCALS() frame->f_locals +#define CONSTS() ((PyCodeObject *)frame->f_executable)->co_consts +#define NAMES() ((PyCodeObject *)frame->f_executable)->co_names #define DTRACE_FUNCTION_ENTRY() \ if (PyDTrace_FUNCTION_ENTRY_ENABLED()) { \ diff --git a/Python/frame.c b/Python/frame.c index c2c0be30113912..bffd705d1298f7 100644 --- a/Python/frame.c +++ b/Python/frame.c @@ -14,7 +14,7 @@ _PyFrame_Traverse(_PyInterpreterFrame *frame, visitproc visit, void *arg) Py_VISIT(frame->frame_obj); Py_VISIT(frame->f_locals); Py_VISIT(frame->f_funcobj); - Py_VISIT(frame->f_code); + Py_VISIT(_PyFrame_GetCode(frame)); /* locals */ PyObject **locals = _PyFrame_GetLocalsArray(frame); int i = 0; @@ -31,7 +31,7 @@ _PyFrame_MakeAndSetFrameObject(_PyInterpreterFrame *frame) assert(frame->frame_obj == NULL); PyObject *exc = PyErr_GetRaisedException(); - PyFrameObject *f = _PyFrame_New_NoTrack(frame->f_code); + PyFrameObject *f = _PyFrame_New_NoTrack(_PyFrame_GetCode(frame)); if (f == NULL) { Py_XDECREF(exc); return NULL; @@ -65,7 +65,7 @@ _PyFrame_MakeAndSetFrameObject(_PyInterpreterFrame *frame) void _PyFrame_Copy(_PyInterpreterFrame *src, _PyInterpreterFrame *dest) { - assert(src->stacktop >= src->f_code->co_nlocalsplus); + assert(src->stacktop >= _PyFrame_GetCode(src)->co_nlocalsplus); Py_ssize_t size = ((char*)&src->localsplus[src->stacktop]) - (char *)src; memcpy(dest, src, size); // Don't leave a dangling pointer to the old frame when creating generators @@ -81,7 +81,7 @@ take_ownership(PyFrameObject *f, _PyInterpreterFrame *frame) assert(frame->owner != FRAME_OWNED_BY_FRAME_OBJECT); assert(frame->owner != FRAME_CLEARED); Py_ssize_t size = ((char*)&frame->localsplus[frame->stacktop]) - (char *)frame; - Py_INCREF(frame->f_code); + Py_INCREF(_PyFrame_GetCode(frame)); memcpy((_PyInterpreterFrame *)f->_f_frame_data, frame, size); frame = (_PyInterpreterFrame *)f->_f_frame_data; f->f_frame = frame; @@ -89,7 +89,7 @@ take_ownership(PyFrameObject *f, _PyInterpreterFrame *frame) if (_PyFrame_IsIncomplete(frame)) { // This may be a newly-created generator or coroutine frame. Since it's // dead anyways, just pretend that the first RESUME ran: - PyCodeObject *code = frame->f_code; + PyCodeObject *code = _PyFrame_GetCode(frame); frame->prev_instr = _PyCode_CODE(code) + code->_co_firsttraceable; } assert(!_PyFrame_IsIncomplete(frame)); @@ -148,5 +148,5 @@ int _PyInterpreterFrame_GetLine(_PyInterpreterFrame *frame) { int addr = _PyInterpreterFrame_LASTI(frame) * sizeof(_Py_CODEUNIT); - return PyCode_Addr2Line(frame->f_code, addr); + return PyCode_Addr2Line(_PyFrame_GetCode(frame), addr); } diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index 069a7ced0a4c25..232915dc6d9a3a 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -12,8 +12,8 @@ assert(tstate->cframe == &cframe); assert(frame == cframe.current_frame); /* Possibly combine this with eval breaker */ - if (frame->f_code->_co_instrumentation_version != tstate->interp->monitoring_version) { - int err = _Py_Instrument(frame->f_code, tstate->interp); + if (_PyFrame_GetCode(frame)->_co_instrumentation_version != tstate->interp->monitoring_version) { + int err = _Py_Instrument(_PyFrame_GetCode(frame), tstate->interp); if (err) goto error; next_instr--; } @@ -30,8 +30,8 @@ * We need to check the eval breaker anyway, can we * combine the instrument verison check and the eval breaker test? */ - if (frame->f_code->_co_instrumentation_version != tstate->interp->monitoring_version) { - if (_Py_Instrument(frame->f_code, tstate->interp)) { + if (_PyFrame_GetCode(frame)->_co_instrumentation_version != tstate->interp->monitoring_version) { + if (_Py_Instrument(_PyFrame_GetCode(frame), tstate->interp)) { goto error; } next_instr--; @@ -96,7 +96,7 @@ PREDICTED(LOAD_CONST); PyObject *value; #line 198 "Python/bytecodes.c" - value = GETITEM(frame->f_code->co_consts, oparg); + value = GETITEM(CONSTS(), oparg); Py_INCREF(value); #line 102 "Python/generated_cases.c.h" STACK_GROW(1); @@ -157,7 +157,7 @@ { PyObject *value; #line 198 "Python/bytecodes.c" - value = GETITEM(frame->f_code->co_consts, oparg); + value = GETITEM(CONSTS(), oparg); Py_INCREF(value); #line 163 "Python/generated_cases.c.h" _tmp_1 = value; @@ -216,7 +216,7 @@ { PyObject *value; #line 198 "Python/bytecodes.c" - value = GETITEM(frame->f_code->co_consts, oparg); + value = GETITEM(CONSTS(), oparg); Py_INCREF(value); #line 222 "Python/generated_cases.c.h" _tmp_2 = value; @@ -900,20 +900,18 @@ #line 620 "Python/bytecodes.c" assert(frame == &entry_frame); assert(_PyFrame_IsIncomplete(frame)); - STACK_SHRINK(1); // Since we're not going to DISPATCH() - assert(EMPTY()); /* Restore previous cframe and return. */ tstate->cframe = cframe.previous; assert(tstate->cframe->current_frame == frame->previous); assert(!_PyErr_Occurred(tstate)); _Py_LeaveRecursiveCallTstate(tstate); return retval; - #line 912 "Python/generated_cases.c.h" + #line 910 "Python/generated_cases.c.h" } TARGET(RETURN_VALUE) { PyObject *retval = stack_pointer[-1]; - #line 633 "Python/bytecodes.c" + #line 631 "Python/bytecodes.c" STACK_SHRINK(1); assert(EMPTY()); _PyFrame_SetStackPointer(frame, stack_pointer); @@ -926,12 +924,12 @@ frame->prev_instr += frame->return_offset; _PyFrame_StackPush(frame, retval); goto resume_frame; - #line 930 "Python/generated_cases.c.h" + #line 928 "Python/generated_cases.c.h" } TARGET(INSTRUMENTED_RETURN_VALUE) { PyObject *retval = stack_pointer[-1]; - #line 648 "Python/bytecodes.c" + #line 646 "Python/bytecodes.c" int err = _Py_call_instrumentation_arg( tstate, PY_MONITORING_EVENT_PY_RETURN, frame, next_instr-1, retval); @@ -948,12 +946,12 @@ frame->prev_instr += frame->return_offset; _PyFrame_StackPush(frame, retval); goto resume_frame; - #line 952 "Python/generated_cases.c.h" + #line 950 "Python/generated_cases.c.h" } TARGET(RETURN_CONST) { - #line 667 "Python/bytecodes.c" - PyObject *retval = GETITEM(frame->f_code->co_consts, oparg); + #line 665 "Python/bytecodes.c" + PyObject *retval = GETITEM(CONSTS(), oparg); Py_INCREF(retval); assert(EMPTY()); _PyFrame_SetStackPointer(frame, stack_pointer); @@ -966,12 +964,12 @@ frame->prev_instr += frame->return_offset; _PyFrame_StackPush(frame, retval); goto resume_frame; - #line 970 "Python/generated_cases.c.h" + #line 968 "Python/generated_cases.c.h" } TARGET(INSTRUMENTED_RETURN_CONST) { - #line 683 "Python/bytecodes.c" - PyObject *retval = GETITEM(frame->f_code->co_consts, oparg); + #line 681 "Python/bytecodes.c" + PyObject *retval = GETITEM(_PyFrame_GetCode(frame)->co_consts, oparg); int err = _Py_call_instrumentation_arg( tstate, PY_MONITORING_EVENT_PY_RETURN, frame, next_instr-1, retval); @@ -988,13 +986,13 @@ frame->prev_instr += frame->return_offset; _PyFrame_StackPush(frame, retval); goto resume_frame; - #line 992 "Python/generated_cases.c.h" + #line 990 "Python/generated_cases.c.h" } TARGET(GET_AITER) { PyObject *obj = stack_pointer[-1]; PyObject *iter; - #line 703 "Python/bytecodes.c" + #line 701 "Python/bytecodes.c" unaryfunc getter = NULL; PyTypeObject *type = Py_TYPE(obj); @@ -1007,16 +1005,16 @@ "'async for' requires an object with " "__aiter__ method, got %.100s", type->tp_name); - #line 1011 "Python/generated_cases.c.h" + #line 1009 "Python/generated_cases.c.h" Py_DECREF(obj); - #line 716 "Python/bytecodes.c" + #line 714 "Python/bytecodes.c" if (true) goto pop_1_error; } iter = (*getter)(obj); - #line 1018 "Python/generated_cases.c.h" + #line 1016 "Python/generated_cases.c.h" Py_DECREF(obj); - #line 721 "Python/bytecodes.c" + #line 719 "Python/bytecodes.c" if (iter == NULL) goto pop_1_error; if (Py_TYPE(iter)->tp_as_async == NULL || @@ -1029,7 +1027,7 @@ Py_DECREF(iter); if (true) goto pop_1_error; } - #line 1033 "Python/generated_cases.c.h" + #line 1031 "Python/generated_cases.c.h" stack_pointer[-1] = iter; DISPATCH(); } @@ -1037,7 +1035,7 @@ TARGET(GET_ANEXT) { PyObject *aiter = stack_pointer[-1]; PyObject *awaitable; - #line 736 "Python/bytecodes.c" + #line 734 "Python/bytecodes.c" unaryfunc getter = NULL; PyObject *next_iter = NULL; PyTypeObject *type = Py_TYPE(aiter); @@ -1081,7 +1079,7 @@ } } - #line 1085 "Python/generated_cases.c.h" + #line 1083 "Python/generated_cases.c.h" STACK_GROW(1); stack_pointer[-1] = awaitable; PREDICT(LOAD_CONST); @@ -1092,16 +1090,16 @@ PREDICTED(GET_AWAITABLE); PyObject *iterable = stack_pointer[-1]; PyObject *iter; - #line 783 "Python/bytecodes.c" + #line 781 "Python/bytecodes.c" iter = _PyCoro_GetAwaitableIter(iterable); if (iter == NULL) { format_awaitable_error(tstate, Py_TYPE(iterable), oparg); } - #line 1103 "Python/generated_cases.c.h" + #line 1101 "Python/generated_cases.c.h" Py_DECREF(iterable); - #line 790 "Python/bytecodes.c" + #line 788 "Python/bytecodes.c" if (iter != NULL && PyCoro_CheckExact(iter)) { PyObject *yf = _PyGen_yf((PyGenObject*)iter); @@ -1119,7 +1117,7 @@ if (iter == NULL) goto pop_1_error; - #line 1123 "Python/generated_cases.c.h" + #line 1121 "Python/generated_cases.c.h" stack_pointer[-1] = iter; PREDICT(LOAD_CONST); DISPATCH(); @@ -1130,7 +1128,7 @@ PyObject *v = stack_pointer[-1]; PyObject *receiver = stack_pointer[-2]; PyObject *retval; - #line 816 "Python/bytecodes.c" + #line 814 "Python/bytecodes.c" #if ENABLE_SPECIALIZATION _PySendCache *cache = (_PySendCache *)next_instr; if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) { @@ -1176,7 +1174,7 @@ } } Py_DECREF(v); - #line 1180 "Python/generated_cases.c.h" + #line 1178 "Python/generated_cases.c.h" stack_pointer[-1] = retval; next_instr += 1; DISPATCH(); @@ -1185,7 +1183,7 @@ TARGET(SEND_GEN) { PyObject *v = stack_pointer[-1]; PyObject *receiver = stack_pointer[-2]; - #line 864 "Python/bytecodes.c" + #line 862 "Python/bytecodes.c" PyGenObject *gen = (PyGenObject *)receiver; DEOPT_IF(Py_TYPE(gen) != &PyGen_Type && Py_TYPE(gen) != &PyCoro_Type, SEND); @@ -1200,12 +1198,12 @@ tstate->exc_info = &gen->gi_exc_state; JUMPBY(INLINE_CACHE_ENTRIES_SEND); DISPATCH_INLINED(gen_frame); - #line 1204 "Python/generated_cases.c.h" + #line 1202 "Python/generated_cases.c.h" } TARGET(INSTRUMENTED_YIELD_VALUE) { PyObject *retval = stack_pointer[-1]; - #line 881 "Python/bytecodes.c" + #line 879 "Python/bytecodes.c" assert(frame != &entry_frame); PyGenObject *gen = _PyFrame_GetGenerator(frame); gen->gi_frame_state = FRAME_SUSPENDED; @@ -1222,12 +1220,12 @@ gen_frame->previous = NULL; _PyFrame_StackPush(frame, retval); goto resume_frame; - #line 1226 "Python/generated_cases.c.h" + #line 1224 "Python/generated_cases.c.h" } TARGET(YIELD_VALUE) { PyObject *retval = stack_pointer[-1]; - #line 900 "Python/bytecodes.c" + #line 898 "Python/bytecodes.c" // NOTE: It's important that YIELD_VALUE never raises an exception! // The compiler treats any exception raised here as a failed close() // or throw() call. @@ -1243,15 +1241,15 @@ gen_frame->previous = NULL; _PyFrame_StackPush(frame, retval); goto resume_frame; - #line 1247 "Python/generated_cases.c.h" + #line 1245 "Python/generated_cases.c.h" } TARGET(POP_EXCEPT) { PyObject *exc_value = stack_pointer[-1]; - #line 918 "Python/bytecodes.c" + #line 916 "Python/bytecodes.c" _PyErr_StackItem *exc_info = tstate->exc_info; Py_XSETREF(exc_info->exc_value, exc_value); - #line 1255 "Python/generated_cases.c.h" + #line 1253 "Python/generated_cases.c.h" STACK_SHRINK(1); DISPATCH(); } @@ -1259,12 +1257,12 @@ TARGET(RERAISE) { PyObject *exc = stack_pointer[-1]; PyObject **values = (stack_pointer - (1 + oparg)); - #line 923 "Python/bytecodes.c" + #line 921 "Python/bytecodes.c" assert(oparg >= 0 && oparg <= 2); if (oparg) { PyObject *lasti = values[0]; if (PyLong_Check(lasti)) { - frame->prev_instr = _PyCode_CODE(frame->f_code) + PyLong_AsLong(lasti); + frame->prev_instr = _PyCode_CODE(_PyFrame_GetCode(frame)) + PyLong_AsLong(lasti); assert(!_PyErr_Occurred(tstate)); } else { @@ -1277,26 +1275,26 @@ Py_INCREF(exc); _PyErr_SetRaisedException(tstate, exc); goto exception_unwind; - #line 1281 "Python/generated_cases.c.h" + #line 1279 "Python/generated_cases.c.h" } TARGET(END_ASYNC_FOR) { PyObject *exc = stack_pointer[-1]; PyObject *awaitable = stack_pointer[-2]; - #line 943 "Python/bytecodes.c" + #line 941 "Python/bytecodes.c" assert(exc && PyExceptionInstance_Check(exc)); if (PyErr_GivenExceptionMatches(exc, PyExc_StopAsyncIteration)) { - #line 1290 "Python/generated_cases.c.h" + #line 1288 "Python/generated_cases.c.h" Py_DECREF(awaitable); Py_DECREF(exc); - #line 946 "Python/bytecodes.c" + #line 944 "Python/bytecodes.c" } else { Py_INCREF(exc); _PyErr_SetRaisedException(tstate, exc); goto exception_unwind; } - #line 1300 "Python/generated_cases.c.h" + #line 1298 "Python/generated_cases.c.h" STACK_SHRINK(2); DISPATCH(); } @@ -1307,23 +1305,23 @@ PyObject *sub_iter = stack_pointer[-3]; PyObject *none; PyObject *value; - #line 955 "Python/bytecodes.c" + #line 953 "Python/bytecodes.c" assert(throwflag); assert(exc_value && PyExceptionInstance_Check(exc_value)); if (PyErr_GivenExceptionMatches(exc_value, PyExc_StopIteration)) { value = Py_NewRef(((PyStopIterationObject *)exc_value)->value); - #line 1316 "Python/generated_cases.c.h" + #line 1314 "Python/generated_cases.c.h" Py_DECREF(sub_iter); Py_DECREF(last_sent_val); Py_DECREF(exc_value); - #line 960 "Python/bytecodes.c" + #line 958 "Python/bytecodes.c" none = Py_NewRef(Py_None); } else { _PyErr_SetRaisedException(tstate, Py_NewRef(exc_value)); goto exception_unwind; } - #line 1327 "Python/generated_cases.c.h" + #line 1325 "Python/generated_cases.c.h" STACK_SHRINK(1); stack_pointer[-1] = value; stack_pointer[-2] = none; @@ -1332,9 +1330,9 @@ TARGET(LOAD_ASSERTION_ERROR) { PyObject *value; - #line 969 "Python/bytecodes.c" + #line 967 "Python/bytecodes.c" value = Py_NewRef(PyExc_AssertionError); - #line 1338 "Python/generated_cases.c.h" + #line 1336 "Python/generated_cases.c.h" STACK_GROW(1); stack_pointer[-1] = value; DISPATCH(); @@ -1342,7 +1340,7 @@ TARGET(LOAD_BUILD_CLASS) { PyObject *bc; - #line 973 "Python/bytecodes.c" + #line 971 "Python/bytecodes.c" if (PyDict_CheckExact(BUILTINS())) { bc = _PyDict_GetItemWithError(BUILTINS(), &_Py_ID(__build_class__)); @@ -1364,7 +1362,7 @@ if (true) goto error; } } - #line 1368 "Python/generated_cases.c.h" + #line 1366 "Python/generated_cases.c.h" STACK_GROW(1); stack_pointer[-1] = bc; DISPATCH(); @@ -1372,34 +1370,34 @@ TARGET(STORE_NAME) { PyObject *v = stack_pointer[-1]; - #line 997 "Python/bytecodes.c" - PyObject *name = GETITEM(frame->f_code->co_names, oparg); + #line 995 "Python/bytecodes.c" + PyObject *name = GETITEM(NAMES(), oparg); PyObject *ns = LOCALS(); int err; if (ns == NULL) { _PyErr_Format(tstate, PyExc_SystemError, "no locals found when storing %R", name); - #line 1383 "Python/generated_cases.c.h" + #line 1381 "Python/generated_cases.c.h" Py_DECREF(v); - #line 1004 "Python/bytecodes.c" + #line 1002 "Python/bytecodes.c" if (true) goto pop_1_error; } if (PyDict_CheckExact(ns)) err = PyDict_SetItem(ns, name, v); else err = PyObject_SetItem(ns, name, v); - #line 1392 "Python/generated_cases.c.h" + #line 1390 "Python/generated_cases.c.h" Py_DECREF(v); - #line 1011 "Python/bytecodes.c" + #line 1009 "Python/bytecodes.c" if (err) goto pop_1_error; - #line 1396 "Python/generated_cases.c.h" + #line 1394 "Python/generated_cases.c.h" STACK_SHRINK(1); DISPATCH(); } TARGET(DELETE_NAME) { - #line 1015 "Python/bytecodes.c" - PyObject *name = GETITEM(frame->f_code->co_names, oparg); + #line 1013 "Python/bytecodes.c" + PyObject *name = GETITEM(NAMES(), oparg); PyObject *ns = LOCALS(); int err; if (ns == NULL) { @@ -1415,7 +1413,7 @@ name); goto error; } - #line 1419 "Python/generated_cases.c.h" + #line 1417 "Python/generated_cases.c.h" DISPATCH(); } @@ -1423,7 +1421,7 @@ PREDICTED(UNPACK_SEQUENCE); static_assert(INLINE_CACHE_ENTRIES_UNPACK_SEQUENCE == 1, "incorrect cache size"); PyObject *seq = stack_pointer[-1]; - #line 1041 "Python/bytecodes.c" + #line 1039 "Python/bytecodes.c" #if ENABLE_SPECIALIZATION _PyUnpackSequenceCache *cache = (_PyUnpackSequenceCache *)next_instr; if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) { @@ -1436,11 +1434,11 @@ #endif /* ENABLE_SPECIALIZATION */ PyObject **top = stack_pointer + oparg - 1; int res = unpack_iterable(tstate, seq, oparg, -1, top); - #line 1440 "Python/generated_cases.c.h" + #line 1438 "Python/generated_cases.c.h" Py_DECREF(seq); - #line 1054 "Python/bytecodes.c" + #line 1052 "Python/bytecodes.c" if (res == 0) goto pop_1_error; - #line 1444 "Python/generated_cases.c.h" + #line 1442 "Python/generated_cases.c.h" STACK_SHRINK(1); STACK_GROW(oparg); next_instr += 1; @@ -1450,14 +1448,14 @@ TARGET(UNPACK_SEQUENCE_TWO_TUPLE) { PyObject *seq = stack_pointer[-1]; PyObject **values = stack_pointer - (1); - #line 1058 "Python/bytecodes.c" + #line 1056 "Python/bytecodes.c" DEOPT_IF(!PyTuple_CheckExact(seq), UNPACK_SEQUENCE); DEOPT_IF(PyTuple_GET_SIZE(seq) != 2, UNPACK_SEQUENCE); assert(oparg == 2); STAT_INC(UNPACK_SEQUENCE, hit); values[0] = Py_NewRef(PyTuple_GET_ITEM(seq, 1)); values[1] = Py_NewRef(PyTuple_GET_ITEM(seq, 0)); - #line 1461 "Python/generated_cases.c.h" + #line 1459 "Python/generated_cases.c.h" Py_DECREF(seq); STACK_SHRINK(1); STACK_GROW(oparg); @@ -1468,7 +1466,7 @@ TARGET(UNPACK_SEQUENCE_TUPLE) { PyObject *seq = stack_pointer[-1]; PyObject **values = stack_pointer - (1); - #line 1068 "Python/bytecodes.c" + #line 1066 "Python/bytecodes.c" DEOPT_IF(!PyTuple_CheckExact(seq), UNPACK_SEQUENCE); DEOPT_IF(PyTuple_GET_SIZE(seq) != oparg, UNPACK_SEQUENCE); STAT_INC(UNPACK_SEQUENCE, hit); @@ -1476,7 +1474,7 @@ for (int i = oparg; --i >= 0; ) { *values++ = Py_NewRef(items[i]); } - #line 1480 "Python/generated_cases.c.h" + #line 1478 "Python/generated_cases.c.h" Py_DECREF(seq); STACK_SHRINK(1); STACK_GROW(oparg); @@ -1487,7 +1485,7 @@ TARGET(UNPACK_SEQUENCE_LIST) { PyObject *seq = stack_pointer[-1]; PyObject **values = stack_pointer - (1); - #line 1079 "Python/bytecodes.c" + #line 1077 "Python/bytecodes.c" DEOPT_IF(!PyList_CheckExact(seq), UNPACK_SEQUENCE); DEOPT_IF(PyList_GET_SIZE(seq) != oparg, UNPACK_SEQUENCE); STAT_INC(UNPACK_SEQUENCE, hit); @@ -1495,7 +1493,7 @@ for (int i = oparg; --i >= 0; ) { *values++ = Py_NewRef(items[i]); } - #line 1499 "Python/generated_cases.c.h" + #line 1497 "Python/generated_cases.c.h" Py_DECREF(seq); STACK_SHRINK(1); STACK_GROW(oparg); @@ -1505,15 +1503,15 @@ TARGET(UNPACK_EX) { PyObject *seq = stack_pointer[-1]; - #line 1090 "Python/bytecodes.c" + #line 1088 "Python/bytecodes.c" int totalargs = 1 + (oparg & 0xFF) + (oparg >> 8); PyObject **top = stack_pointer + totalargs - 1; int res = unpack_iterable(tstate, seq, oparg & 0xFF, oparg >> 8, top); - #line 1513 "Python/generated_cases.c.h" + #line 1511 "Python/generated_cases.c.h" Py_DECREF(seq); - #line 1094 "Python/bytecodes.c" + #line 1092 "Python/bytecodes.c" if (res == 0) goto pop_1_error; - #line 1517 "Python/generated_cases.c.h" + #line 1515 "Python/generated_cases.c.h" STACK_GROW((oparg & 0xFF) + (oparg >> 8)); DISPATCH(); } @@ -1524,10 +1522,10 @@ PyObject *owner = stack_pointer[-1]; PyObject *v = stack_pointer[-2]; uint16_t counter = read_u16(&next_instr[0].cache); - #line 1105 "Python/bytecodes.c" + #line 1103 "Python/bytecodes.c" #if ENABLE_SPECIALIZATION if (ADAPTIVE_COUNTER_IS_ZERO(counter)) { - PyObject *name = GETITEM(frame->f_code->co_names, oparg); + PyObject *name = GETITEM(NAMES(), oparg); next_instr--; _Py_Specialize_StoreAttr(owner, next_instr, name); DISPATCH_SAME_OPARG(); @@ -1538,14 +1536,14 @@ #else (void)counter; // Unused. #endif /* ENABLE_SPECIALIZATION */ - PyObject *name = GETITEM(frame->f_code->co_names, oparg); + PyObject *name = GETITEM(NAMES(), oparg); int err = PyObject_SetAttr(owner, name, v); - #line 1544 "Python/generated_cases.c.h" + #line 1542 "Python/generated_cases.c.h" Py_DECREF(v); Py_DECREF(owner); - #line 1121 "Python/bytecodes.c" + #line 1119 "Python/bytecodes.c" if (err) goto pop_2_error; - #line 1549 "Python/generated_cases.c.h" + #line 1547 "Python/generated_cases.c.h" STACK_SHRINK(2); next_instr += 4; DISPATCH(); @@ -1553,35 +1551,35 @@ TARGET(DELETE_ATTR) { PyObject *owner = stack_pointer[-1]; - #line 1125 "Python/bytecodes.c" - PyObject *name = GETITEM(frame->f_code->co_names, oparg); + #line 1123 "Python/bytecodes.c" + PyObject *name = GETITEM(NAMES(), oparg); int err = PyObject_SetAttr(owner, name, (PyObject *)NULL); - #line 1560 "Python/generated_cases.c.h" + #line 1558 "Python/generated_cases.c.h" Py_DECREF(owner); - #line 1128 "Python/bytecodes.c" + #line 1126 "Python/bytecodes.c" if (err) goto pop_1_error; - #line 1564 "Python/generated_cases.c.h" + #line 1562 "Python/generated_cases.c.h" STACK_SHRINK(1); DISPATCH(); } TARGET(STORE_GLOBAL) { PyObject *v = stack_pointer[-1]; - #line 1132 "Python/bytecodes.c" - PyObject *name = GETITEM(frame->f_code->co_names, oparg); + #line 1130 "Python/bytecodes.c" + PyObject *name = GETITEM(NAMES(), oparg); int err = PyDict_SetItem(GLOBALS(), name, v); - #line 1574 "Python/generated_cases.c.h" + #line 1572 "Python/generated_cases.c.h" Py_DECREF(v); - #line 1135 "Python/bytecodes.c" + #line 1133 "Python/bytecodes.c" if (err) goto pop_1_error; - #line 1578 "Python/generated_cases.c.h" + #line 1576 "Python/generated_cases.c.h" STACK_SHRINK(1); DISPATCH(); } TARGET(DELETE_GLOBAL) { - #line 1139 "Python/bytecodes.c" - PyObject *name = GETITEM(frame->f_code->co_names, oparg); + #line 1137 "Python/bytecodes.c" + PyObject *name = GETITEM(NAMES(), oparg); int err; err = PyDict_DelItem(GLOBALS(), name); // Can't use ERROR_IF here. @@ -1592,14 +1590,14 @@ } goto error; } - #line 1596 "Python/generated_cases.c.h" + #line 1594 "Python/generated_cases.c.h" DISPATCH(); } TARGET(LOAD_NAME) { PyObject *v; - #line 1153 "Python/bytecodes.c" - PyObject *name = GETITEM(frame->f_code->co_names, oparg); + #line 1151 "Python/bytecodes.c" + PyObject *name = GETITEM(NAMES(), oparg); PyObject *locals = LOCALS(); if (locals == NULL) { _PyErr_Format(tstate, PyExc_SystemError, @@ -1657,7 +1655,7 @@ } } } - #line 1661 "Python/generated_cases.c.h" + #line 1659 "Python/generated_cases.c.h" STACK_GROW(1); stack_pointer[-1] = v; DISPATCH(); @@ -1668,11 +1666,11 @@ static_assert(INLINE_CACHE_ENTRIES_LOAD_GLOBAL == 4, "incorrect cache size"); PyObject *null = NULL; PyObject *v; - #line 1220 "Python/bytecodes.c" + #line 1218 "Python/bytecodes.c" #if ENABLE_SPECIALIZATION _PyLoadGlobalCache *cache = (_PyLoadGlobalCache *)next_instr; if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) { - PyObject *name = GETITEM(frame->f_code->co_names, oparg>>1); + PyObject *name = GETITEM(NAMES(), oparg>>1); next_instr--; _Py_Specialize_LoadGlobal(GLOBALS(), BUILTINS(), next_instr, name); DISPATCH_SAME_OPARG(); @@ -1680,7 +1678,7 @@ STAT_INC(LOAD_GLOBAL, deferred); DECREMENT_ADAPTIVE_COUNTER(cache->counter); #endif /* ENABLE_SPECIALIZATION */ - PyObject *name = GETITEM(frame->f_code->co_names, oparg>>1); + PyObject *name = GETITEM(NAMES(), oparg>>1); if (PyDict_CheckExact(GLOBALS()) && PyDict_CheckExact(BUILTINS())) { @@ -1720,7 +1718,7 @@ } } null = NULL; - #line 1724 "Python/generated_cases.c.h" + #line 1722 "Python/generated_cases.c.h" STACK_GROW(1); STACK_GROW(((oparg & 1) ? 1 : 0)); stack_pointer[-1] = v; @@ -1734,7 +1732,7 @@ PyObject *res; uint16_t index = read_u16(&next_instr[1].cache); uint16_t version = read_u16(&next_instr[2].cache); - #line 1274 "Python/bytecodes.c" + #line 1272 "Python/bytecodes.c" DEOPT_IF(!PyDict_CheckExact(GLOBALS()), LOAD_GLOBAL); PyDictObject *dict = (PyDictObject *)GLOBALS(); DEOPT_IF(dict->ma_keys->dk_version != version, LOAD_GLOBAL); @@ -1745,7 +1743,7 @@ Py_INCREF(res); STAT_INC(LOAD_GLOBAL, hit); null = NULL; - #line 1749 "Python/generated_cases.c.h" + #line 1747 "Python/generated_cases.c.h" STACK_GROW(1); STACK_GROW(((oparg & 1) ? 1 : 0)); stack_pointer[-1] = res; @@ -1760,7 +1758,7 @@ uint16_t index = read_u16(&next_instr[1].cache); uint16_t mod_version = read_u16(&next_instr[2].cache); uint16_t bltn_version = read_u16(&next_instr[3].cache); - #line 1287 "Python/bytecodes.c" + #line 1285 "Python/bytecodes.c" DEOPT_IF(!PyDict_CheckExact(GLOBALS()), LOAD_GLOBAL); DEOPT_IF(!PyDict_CheckExact(BUILTINS()), LOAD_GLOBAL); PyDictObject *mdict = (PyDictObject *)GLOBALS(); @@ -1775,7 +1773,7 @@ Py_INCREF(res); STAT_INC(LOAD_GLOBAL, hit); null = NULL; - #line 1779 "Python/generated_cases.c.h" + #line 1777 "Python/generated_cases.c.h" STACK_GROW(1); STACK_GROW(((oparg & 1) ? 1 : 0)); stack_pointer[-1] = res; @@ -1785,16 +1783,16 @@ } TARGET(DELETE_FAST) { - #line 1304 "Python/bytecodes.c" + #line 1302 "Python/bytecodes.c" PyObject *v = GETLOCAL(oparg); if (v == NULL) goto unbound_local_error; SETLOCAL(oparg, NULL); - #line 1793 "Python/generated_cases.c.h" + #line 1791 "Python/generated_cases.c.h" DISPATCH(); } TARGET(MAKE_CELL) { - #line 1310 "Python/bytecodes.c" + #line 1308 "Python/bytecodes.c" // "initial" is probably NULL but not if it's an arg (or set // via PyFrame_LocalsToFast() before MAKE_CELL has run). PyObject *initial = GETLOCAL(oparg); @@ -1803,33 +1801,33 @@ goto resume_with_error; } SETLOCAL(oparg, cell); - #line 1807 "Python/generated_cases.c.h" + #line 1805 "Python/generated_cases.c.h" DISPATCH(); } TARGET(DELETE_DEREF) { - #line 1321 "Python/bytecodes.c" + #line 1319 "Python/bytecodes.c" PyObject *cell = GETLOCAL(oparg); PyObject *oldobj = PyCell_GET(cell); // Can't use ERROR_IF here. // Fortunately we don't need its superpower. if (oldobj == NULL) { - format_exc_unbound(tstate, frame->f_code, oparg); + format_exc_unbound(tstate, _PyFrame_GetCode(frame), oparg); goto error; } PyCell_SET(cell, NULL); Py_DECREF(oldobj); - #line 1823 "Python/generated_cases.c.h" + #line 1821 "Python/generated_cases.c.h" DISPATCH(); } TARGET(LOAD_CLASSDEREF) { PyObject *value; - #line 1334 "Python/bytecodes.c" + #line 1332 "Python/bytecodes.c" PyObject *name, *locals = LOCALS(); assert(locals); - assert(oparg >= 0 && oparg < frame->f_code->co_nlocalsplus); - name = PyTuple_GET_ITEM(frame->f_code->co_localsplusnames, oparg); + assert(oparg >= 0 && oparg < _PyFrame_GetCode(frame)->co_nlocalsplus); + name = PyTuple_GET_ITEM(_PyFrame_GetCode(frame)->co_localsplusnames, oparg); if (PyDict_CheckExact(locals)) { value = PyDict_GetItemWithError(locals, name); if (value != NULL) { @@ -1852,12 +1850,12 @@ PyObject *cell = GETLOCAL(oparg); value = PyCell_GET(cell); if (value == NULL) { - format_exc_unbound(tstate, frame->f_code, oparg); + format_exc_unbound(tstate, _PyFrame_GetCode(frame), oparg); goto error; } Py_INCREF(value); } - #line 1861 "Python/generated_cases.c.h" + #line 1859 "Python/generated_cases.c.h" STACK_GROW(1); stack_pointer[-1] = value; DISPATCH(); @@ -1865,15 +1863,15 @@ TARGET(LOAD_DEREF) { PyObject *value; - #line 1368 "Python/bytecodes.c" + #line 1366 "Python/bytecodes.c" PyObject *cell = GETLOCAL(oparg); value = PyCell_GET(cell); if (value == NULL) { - format_exc_unbound(tstate, frame->f_code, oparg); + format_exc_unbound(tstate, _PyFrame_GetCode(frame), oparg); if (true) goto error; } Py_INCREF(value); - #line 1877 "Python/generated_cases.c.h" + #line 1875 "Python/generated_cases.c.h" STACK_GROW(1); stack_pointer[-1] = value; DISPATCH(); @@ -1881,20 +1879,20 @@ TARGET(STORE_DEREF) { PyObject *v = stack_pointer[-1]; - #line 1378 "Python/bytecodes.c" + #line 1376 "Python/bytecodes.c" PyObject *cell = GETLOCAL(oparg); PyObject *oldobj = PyCell_GET(cell); PyCell_SET(cell, v); Py_XDECREF(oldobj); - #line 1890 "Python/generated_cases.c.h" + #line 1888 "Python/generated_cases.c.h" STACK_SHRINK(1); DISPATCH(); } TARGET(COPY_FREE_VARS) { - #line 1385 "Python/bytecodes.c" + #line 1383 "Python/bytecodes.c" /* Copy closure variables to free variables */ - PyCodeObject *co = frame->f_code; + PyCodeObject *co = _PyFrame_GetCode(frame); assert(PyFunction_Check(frame->f_funcobj)); PyObject *closure = ((PyFunctionObject *)frame->f_funcobj)->func_closure; assert(oparg == co->co_nfreevars); @@ -1903,22 +1901,22 @@ PyObject *o = PyTuple_GET_ITEM(closure, i); frame->localsplus[offset + i] = Py_NewRef(o); } - #line 1907 "Python/generated_cases.c.h" + #line 1905 "Python/generated_cases.c.h" DISPATCH(); } TARGET(BUILD_STRING) { PyObject **pieces = (stack_pointer - oparg); PyObject *str; - #line 1398 "Python/bytecodes.c" + #line 1396 "Python/bytecodes.c" str = _PyUnicode_JoinArray(&_Py_STR(empty), pieces, oparg); - #line 1916 "Python/generated_cases.c.h" + #line 1914 "Python/generated_cases.c.h" for (int _i = oparg; --_i >= 0;) { Py_DECREF(pieces[_i]); } - #line 1400 "Python/bytecodes.c" + #line 1398 "Python/bytecodes.c" if (str == NULL) { STACK_SHRINK(oparg); goto error; } - #line 1922 "Python/generated_cases.c.h" + #line 1920 "Python/generated_cases.c.h" STACK_SHRINK(oparg); STACK_GROW(1); stack_pointer[-1] = str; @@ -1928,10 +1926,10 @@ TARGET(BUILD_TUPLE) { PyObject **values = (stack_pointer - oparg); PyObject *tup; - #line 1404 "Python/bytecodes.c" + #line 1402 "Python/bytecodes.c" tup = _PyTuple_FromArraySteal(values, oparg); if (tup == NULL) { STACK_SHRINK(oparg); goto error; } - #line 1935 "Python/generated_cases.c.h" + #line 1933 "Python/generated_cases.c.h" STACK_SHRINK(oparg); STACK_GROW(1); stack_pointer[-1] = tup; @@ -1941,10 +1939,10 @@ TARGET(BUILD_LIST) { PyObject **values = (stack_pointer - oparg); PyObject *list; - #line 1409 "Python/bytecodes.c" + #line 1407 "Python/bytecodes.c" list = _PyList_FromArraySteal(values, oparg); if (list == NULL) { STACK_SHRINK(oparg); goto error; } - #line 1948 "Python/generated_cases.c.h" + #line 1946 "Python/generated_cases.c.h" STACK_SHRINK(oparg); STACK_GROW(1); stack_pointer[-1] = list; @@ -1954,7 +1952,7 @@ TARGET(LIST_EXTEND) { PyObject *iterable = stack_pointer[-1]; PyObject *list = stack_pointer[-(2 + (oparg-1))]; - #line 1414 "Python/bytecodes.c" + #line 1412 "Python/bytecodes.c" PyObject *none_val = _PyList_Extend((PyListObject *)list, iterable); if (none_val == NULL) { if (_PyErr_ExceptionMatches(tstate, PyExc_TypeError) && @@ -1965,13 +1963,13 @@ "Value after * must be an iterable, not %.200s", Py_TYPE(iterable)->tp_name); } - #line 1969 "Python/generated_cases.c.h" + #line 1967 "Python/generated_cases.c.h" Py_DECREF(iterable); - #line 1425 "Python/bytecodes.c" + #line 1423 "Python/bytecodes.c" if (true) goto pop_1_error; } Py_DECREF(none_val); - #line 1975 "Python/generated_cases.c.h" + #line 1973 "Python/generated_cases.c.h" Py_DECREF(iterable); STACK_SHRINK(1); DISPATCH(); @@ -1980,13 +1978,13 @@ TARGET(SET_UPDATE) { PyObject *iterable = stack_pointer[-1]; PyObject *set = stack_pointer[-(2 + (oparg-1))]; - #line 1432 "Python/bytecodes.c" + #line 1430 "Python/bytecodes.c" int err = _PySet_Update(set, iterable); - #line 1986 "Python/generated_cases.c.h" + #line 1984 "Python/generated_cases.c.h" Py_DECREF(iterable); - #line 1434 "Python/bytecodes.c" + #line 1432 "Python/bytecodes.c" if (err < 0) goto pop_1_error; - #line 1990 "Python/generated_cases.c.h" + #line 1988 "Python/generated_cases.c.h" STACK_SHRINK(1); DISPATCH(); } @@ -1994,7 +1992,7 @@ TARGET(BUILD_SET) { PyObject **values = (stack_pointer - oparg); PyObject *set; - #line 1438 "Python/bytecodes.c" + #line 1436 "Python/bytecodes.c" set = PySet_New(NULL); if (set == NULL) goto error; @@ -2009,7 +2007,7 @@ Py_DECREF(set); if (true) { STACK_SHRINK(oparg); goto error; } } - #line 2013 "Python/generated_cases.c.h" + #line 2011 "Python/generated_cases.c.h" STACK_SHRINK(oparg); STACK_GROW(1); stack_pointer[-1] = set; @@ -2019,7 +2017,7 @@ TARGET(BUILD_MAP) { PyObject **values = (stack_pointer - oparg*2); PyObject *map; - #line 1455 "Python/bytecodes.c" + #line 1453 "Python/bytecodes.c" map = _PyDict_FromItems( values, 2, values+1, 2, @@ -2027,13 +2025,13 @@ if (map == NULL) goto error; - #line 2031 "Python/generated_cases.c.h" + #line 2029 "Python/generated_cases.c.h" for (int _i = oparg*2; --_i >= 0;) { Py_DECREF(values[_i]); } - #line 1463 "Python/bytecodes.c" + #line 1461 "Python/bytecodes.c" if (map == NULL) { STACK_SHRINK(oparg*2); goto error; } - #line 2037 "Python/generated_cases.c.h" + #line 2035 "Python/generated_cases.c.h" STACK_SHRINK(oparg*2); STACK_GROW(1); stack_pointer[-1] = map; @@ -2041,7 +2039,7 @@ } TARGET(SETUP_ANNOTATIONS) { - #line 1467 "Python/bytecodes.c" + #line 1465 "Python/bytecodes.c" int err; PyObject *ann_dict; if (LOCALS() == NULL) { @@ -2081,7 +2079,7 @@ Py_DECREF(ann_dict); } } - #line 2085 "Python/generated_cases.c.h" + #line 2083 "Python/generated_cases.c.h" DISPATCH(); } @@ -2089,7 +2087,7 @@ PyObject *keys = stack_pointer[-1]; PyObject **values = (stack_pointer - (1 + oparg)); PyObject *map; - #line 1509 "Python/bytecodes.c" + #line 1507 "Python/bytecodes.c" if (!PyTuple_CheckExact(keys) || PyTuple_GET_SIZE(keys) != (Py_ssize_t)oparg) { _PyErr_SetString(tstate, PyExc_SystemError, @@ -2099,14 +2097,14 @@ map = _PyDict_FromItems( &PyTuple_GET_ITEM(keys, 0), 1, values, 1, oparg); - #line 2103 "Python/generated_cases.c.h" + #line 2101 "Python/generated_cases.c.h" for (int _i = oparg; --_i >= 0;) { Py_DECREF(values[_i]); } Py_DECREF(keys); - #line 1519 "Python/bytecodes.c" + #line 1517 "Python/bytecodes.c" if (map == NULL) { STACK_SHRINK(oparg); goto pop_1_error; } - #line 2110 "Python/generated_cases.c.h" + #line 2108 "Python/generated_cases.c.h" STACK_SHRINK(oparg); stack_pointer[-1] = map; DISPATCH(); @@ -2114,7 +2112,7 @@ TARGET(DICT_UPDATE) { PyObject *update = stack_pointer[-1]; - #line 1523 "Python/bytecodes.c" + #line 1521 "Python/bytecodes.c" PyObject *dict = PEEK(oparg + 1); // update is still on the stack if (PyDict_Update(dict, update) < 0) { if (_PyErr_ExceptionMatches(tstate, PyExc_AttributeError)) { @@ -2122,12 +2120,12 @@ "'%.200s' object is not a mapping", Py_TYPE(update)->tp_name); } - #line 2126 "Python/generated_cases.c.h" + #line 2124 "Python/generated_cases.c.h" Py_DECREF(update); - #line 1531 "Python/bytecodes.c" + #line 1529 "Python/bytecodes.c" if (true) goto pop_1_error; } - #line 2131 "Python/generated_cases.c.h" + #line 2129 "Python/generated_cases.c.h" Py_DECREF(update); STACK_SHRINK(1); DISPATCH(); @@ -2135,17 +2133,17 @@ TARGET(DICT_MERGE) { PyObject *update = stack_pointer[-1]; - #line 1537 "Python/bytecodes.c" + #line 1535 "Python/bytecodes.c" PyObject *dict = PEEK(oparg + 1); // update is still on the stack if (_PyDict_MergeEx(dict, update, 2) < 0) { format_kwargs_error(tstate, PEEK(3 + oparg), update); - #line 2144 "Python/generated_cases.c.h" + #line 2142 "Python/generated_cases.c.h" Py_DECREF(update); - #line 1542 "Python/bytecodes.c" + #line 1540 "Python/bytecodes.c" if (true) goto pop_1_error; } - #line 2149 "Python/generated_cases.c.h" + #line 2147 "Python/generated_cases.c.h" Py_DECREF(update); STACK_SHRINK(1); PREDICT(CALL_FUNCTION_EX); @@ -2155,13 +2153,13 @@ TARGET(MAP_ADD) { PyObject *value = stack_pointer[-1]; PyObject *key = stack_pointer[-2]; - #line 1549 "Python/bytecodes.c" + #line 1547 "Python/bytecodes.c" PyObject *dict = PEEK(oparg + 2); // key, value are still on the stack assert(PyDict_CheckExact(dict)); /* dict[key] = value */ // Do not DECREF INPUTS because the function steals the references if (_PyDict_SetItem_Take2((PyDictObject *)dict, key, value) != 0) goto pop_2_error; - #line 2165 "Python/generated_cases.c.h" + #line 2163 "Python/generated_cases.c.h" STACK_SHRINK(2); PREDICT(JUMP_BACKWARD); DISPATCH(); @@ -2175,8 +2173,8 @@ PyObject *global_super = stack_pointer[-3]; PyObject *res2 = NULL; PyObject *res; - #line 1563 "Python/bytecodes.c" - PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 2); + #line 1561 "Python/bytecodes.c" + PyObject *name = GETITEM(_PyFrame_GetCode(frame)->co_names, oparg >> 2); int load_method = oparg & 1; #if ENABLE_SPECIALIZATION _PySuperAttrCache *cache = (_PySuperAttrCache *)next_instr; @@ -2193,16 +2191,16 @@ // handle any case whose performance we care about PyObject *stack[] = {class, self}; PyObject *super = PyObject_Vectorcall(global_super, stack, oparg & 2, NULL); - #line 2197 "Python/generated_cases.c.h" + #line 2195 "Python/generated_cases.c.h" Py_DECREF(global_super); Py_DECREF(class); Py_DECREF(self); - #line 1581 "Python/bytecodes.c" + #line 1579 "Python/bytecodes.c" if (super == NULL) goto pop_3_error; res = PyObject_GetAttr(super, name); Py_DECREF(super); if (res == NULL) goto pop_3_error; - #line 2206 "Python/generated_cases.c.h" + #line 2204 "Python/generated_cases.c.h" STACK_SHRINK(2); STACK_GROW(((oparg & 1) ? 1 : 0)); stack_pointer[-1] = res; @@ -2220,7 +2218,7 @@ uint32_t class_version = read_u32(&next_instr[1].cache); uint32_t self_type_version = read_u32(&next_instr[3].cache); PyObject *method = read_obj(&next_instr[5].cache); - #line 1588 "Python/bytecodes.c" + #line 1586 "Python/bytecodes.c" DEOPT_IF(global_super != (PyObject *)&PySuper_Type, LOAD_SUPER_ATTR); DEOPT_IF(!PyType_Check(class), LOAD_SUPER_ATTR); DEOPT_IF(((PyTypeObject *)class)->tp_version_tag != class_version, LOAD_SUPER_ATTR); @@ -2231,7 +2229,7 @@ Py_INCREF(res2); Py_DECREF(global_super); Py_DECREF(class); - #line 2235 "Python/generated_cases.c.h" + #line 2233 "Python/generated_cases.c.h" STACK_SHRINK(1); stack_pointer[-1] = res; stack_pointer[-2] = res2; @@ -2245,11 +2243,11 @@ PyObject *owner = stack_pointer[-1]; PyObject *res2 = NULL; PyObject *res; - #line 1615 "Python/bytecodes.c" + #line 1613 "Python/bytecodes.c" #if ENABLE_SPECIALIZATION _PyAttrCache *cache = (_PyAttrCache *)next_instr; if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) { - PyObject *name = GETITEM(frame->f_code->co_names, oparg>>1); + PyObject *name = GETITEM(NAMES(), oparg>>1); next_instr--; _Py_Specialize_LoadAttr(owner, next_instr, name); DISPATCH_SAME_OPARG(); @@ -2257,7 +2255,7 @@ STAT_INC(LOAD_ATTR, deferred); DECREMENT_ADAPTIVE_COUNTER(cache->counter); #endif /* ENABLE_SPECIALIZATION */ - PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 1); + PyObject *name = GETITEM(NAMES(), oparg >> 1); if (oparg & 1) { /* Designed to work in tandem with CALL, pushes two values. */ PyObject* meth = NULL; @@ -2279,9 +2277,9 @@ NULL | meth | arg1 | ... | argN */ - #line 2283 "Python/generated_cases.c.h" + #line 2281 "Python/generated_cases.c.h" Py_DECREF(owner); - #line 1649 "Python/bytecodes.c" + #line 1647 "Python/bytecodes.c" if (meth == NULL) goto pop_1_error; res2 = NULL; res = meth; @@ -2290,12 +2288,12 @@ else { /* Classic, pushes one value. */ res = PyObject_GetAttr(owner, name); - #line 2294 "Python/generated_cases.c.h" + #line 2292 "Python/generated_cases.c.h" Py_DECREF(owner); - #line 1658 "Python/bytecodes.c" + #line 1656 "Python/bytecodes.c" if (res == NULL) goto pop_1_error; } - #line 2299 "Python/generated_cases.c.h" + #line 2297 "Python/generated_cases.c.h" STACK_GROW(((oparg & 1) ? 1 : 0)); stack_pointer[-1] = res; if (oparg & 1) { stack_pointer[-(1 + ((oparg & 1) ? 1 : 0))] = res2; } @@ -2309,7 +2307,7 @@ PyObject *res; uint32_t type_version = read_u32(&next_instr[1].cache); uint16_t index = read_u16(&next_instr[3].cache); - #line 1663 "Python/bytecodes.c" + #line 1661 "Python/bytecodes.c" PyTypeObject *tp = Py_TYPE(owner); assert(type_version != 0); DEOPT_IF(tp->tp_version_tag != type_version, LOAD_ATTR); @@ -2322,7 +2320,7 @@ STAT_INC(LOAD_ATTR, hit); Py_INCREF(res); res2 = NULL; - #line 2326 "Python/generated_cases.c.h" + #line 2324 "Python/generated_cases.c.h" Py_DECREF(owner); STACK_GROW(((oparg & 1) ? 1 : 0)); stack_pointer[-1] = res; @@ -2337,7 +2335,7 @@ PyObject *res; uint32_t type_version = read_u32(&next_instr[1].cache); uint16_t index = read_u16(&next_instr[3].cache); - #line 1679 "Python/bytecodes.c" + #line 1677 "Python/bytecodes.c" DEOPT_IF(!PyModule_CheckExact(owner), LOAD_ATTR); PyDictObject *dict = (PyDictObject *)((PyModuleObject *)owner)->md_dict; assert(dict != NULL); @@ -2350,7 +2348,7 @@ STAT_INC(LOAD_ATTR, hit); Py_INCREF(res); res2 = NULL; - #line 2354 "Python/generated_cases.c.h" + #line 2352 "Python/generated_cases.c.h" Py_DECREF(owner); STACK_GROW(((oparg & 1) ? 1 : 0)); stack_pointer[-1] = res; @@ -2365,7 +2363,7 @@ PyObject *res; uint32_t type_version = read_u32(&next_instr[1].cache); uint16_t index = read_u16(&next_instr[3].cache); - #line 1695 "Python/bytecodes.c" + #line 1693 "Python/bytecodes.c" PyTypeObject *tp = Py_TYPE(owner); assert(type_version != 0); DEOPT_IF(tp->tp_version_tag != type_version, LOAD_ATTR); @@ -2375,7 +2373,7 @@ PyDictObject *dict = (PyDictObject *)_PyDictOrValues_GetDict(dorv); DEOPT_IF(dict == NULL, LOAD_ATTR); assert(PyDict_CheckExact((PyObject *)dict)); - PyObject *name = GETITEM(frame->f_code->co_names, oparg>>1); + PyObject *name = GETITEM(NAMES(), oparg>>1); uint16_t hint = index; DEOPT_IF(hint >= (size_t)dict->ma_keys->dk_nentries, LOAD_ATTR); if (DK_IS_UNICODE(dict->ma_keys)) { @@ -2392,7 +2390,7 @@ STAT_INC(LOAD_ATTR, hit); Py_INCREF(res); res2 = NULL; - #line 2396 "Python/generated_cases.c.h" + #line 2394 "Python/generated_cases.c.h" Py_DECREF(owner); STACK_GROW(((oparg & 1) ? 1 : 0)); stack_pointer[-1] = res; @@ -2407,7 +2405,7 @@ PyObject *res; uint32_t type_version = read_u32(&next_instr[1].cache); uint16_t index = read_u16(&next_instr[3].cache); - #line 1725 "Python/bytecodes.c" + #line 1723 "Python/bytecodes.c" PyTypeObject *tp = Py_TYPE(owner); assert(type_version != 0); DEOPT_IF(tp->tp_version_tag != type_version, LOAD_ATTR); @@ -2417,7 +2415,7 @@ STAT_INC(LOAD_ATTR, hit); Py_INCREF(res); res2 = NULL; - #line 2421 "Python/generated_cases.c.h" + #line 2419 "Python/generated_cases.c.h" Py_DECREF(owner); STACK_GROW(((oparg & 1) ? 1 : 0)); stack_pointer[-1] = res; @@ -2432,7 +2430,7 @@ PyObject *res; uint32_t type_version = read_u32(&next_instr[1].cache); PyObject *descr = read_obj(&next_instr[5].cache); - #line 1738 "Python/bytecodes.c" + #line 1736 "Python/bytecodes.c" DEOPT_IF(!PyType_Check(cls), LOAD_ATTR); DEOPT_IF(((PyTypeObject *)cls)->tp_version_tag != type_version, @@ -2444,7 +2442,7 @@ res = descr; assert(res != NULL); Py_INCREF(res); - #line 2448 "Python/generated_cases.c.h" + #line 2446 "Python/generated_cases.c.h" Py_DECREF(cls); STACK_GROW(((oparg & 1) ? 1 : 0)); stack_pointer[-1] = res; @@ -2458,7 +2456,7 @@ uint32_t type_version = read_u32(&next_instr[1].cache); uint32_t func_version = read_u32(&next_instr[3].cache); PyObject *fget = read_obj(&next_instr[5].cache); - #line 1753 "Python/bytecodes.c" + #line 1751 "Python/bytecodes.c" DEOPT_IF(tstate->interp->eval_frame, LOAD_ATTR); PyTypeObject *cls = Py_TYPE(owner); @@ -2482,7 +2480,7 @@ JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR); frame->return_offset = 0; DISPATCH_INLINED(new_frame); - #line 2486 "Python/generated_cases.c.h" + #line 2484 "Python/generated_cases.c.h" } TARGET(LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN) { @@ -2490,7 +2488,7 @@ uint32_t type_version = read_u32(&next_instr[1].cache); uint32_t func_version = read_u32(&next_instr[3].cache); PyObject *getattribute = read_obj(&next_instr[5].cache); - #line 1779 "Python/bytecodes.c" + #line 1777 "Python/bytecodes.c" DEOPT_IF(tstate->interp->eval_frame, LOAD_ATTR); PyTypeObject *cls = Py_TYPE(owner); DEOPT_IF(cls->tp_version_tag != type_version, LOAD_ATTR); @@ -2504,7 +2502,7 @@ DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), LOAD_ATTR); STAT_INC(LOAD_ATTR, hit); - PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 1); + PyObject *name = GETITEM(NAMES(), oparg >> 1); Py_INCREF(f); _PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, f, 2); // Manipulate stack directly because we exit with DISPATCH_INLINED(). @@ -2516,7 +2514,7 @@ JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR); frame->return_offset = 0; DISPATCH_INLINED(new_frame); - #line 2520 "Python/generated_cases.c.h" + #line 2518 "Python/generated_cases.c.h" } TARGET(STORE_ATTR_INSTANCE_VALUE) { @@ -2524,7 +2522,7 @@ PyObject *value = stack_pointer[-2]; uint32_t type_version = read_u32(&next_instr[1].cache); uint16_t index = read_u16(&next_instr[3].cache); - #line 1807 "Python/bytecodes.c" + #line 1805 "Python/bytecodes.c" PyTypeObject *tp = Py_TYPE(owner); assert(type_version != 0); DEOPT_IF(tp->tp_version_tag != type_version, STORE_ATTR); @@ -2542,7 +2540,7 @@ Py_DECREF(old_value); } Py_DECREF(owner); - #line 2546 "Python/generated_cases.c.h" + #line 2544 "Python/generated_cases.c.h" STACK_SHRINK(2); next_instr += 4; DISPATCH(); @@ -2553,7 +2551,7 @@ PyObject *value = stack_pointer[-2]; uint32_t type_version = read_u32(&next_instr[1].cache); uint16_t hint = read_u16(&next_instr[3].cache); - #line 1827 "Python/bytecodes.c" + #line 1825 "Python/bytecodes.c" PyTypeObject *tp = Py_TYPE(owner); assert(type_version != 0); DEOPT_IF(tp->tp_version_tag != type_version, STORE_ATTR); @@ -2563,7 +2561,7 @@ PyDictObject *dict = (PyDictObject *)_PyDictOrValues_GetDict(dorv); DEOPT_IF(dict == NULL, STORE_ATTR); assert(PyDict_CheckExact((PyObject *)dict)); - PyObject *name = GETITEM(frame->f_code->co_names, oparg); + PyObject *name = GETITEM(NAMES(), oparg); DEOPT_IF(hint >= (size_t)dict->ma_keys->dk_nentries, STORE_ATTR); PyObject *old_value; uint64_t new_version; @@ -2592,7 +2590,7 @@ /* PEP 509 */ dict->ma_version_tag = new_version; Py_DECREF(owner); - #line 2596 "Python/generated_cases.c.h" + #line 2594 "Python/generated_cases.c.h" STACK_SHRINK(2); next_instr += 4; DISPATCH(); @@ -2603,7 +2601,7 @@ PyObject *value = stack_pointer[-2]; uint32_t type_version = read_u32(&next_instr[1].cache); uint16_t index = read_u16(&next_instr[3].cache); - #line 1868 "Python/bytecodes.c" + #line 1866 "Python/bytecodes.c" PyTypeObject *tp = Py_TYPE(owner); assert(type_version != 0); DEOPT_IF(tp->tp_version_tag != type_version, STORE_ATTR); @@ -2613,7 +2611,7 @@ *(PyObject **)addr = value; Py_XDECREF(old_value); Py_DECREF(owner); - #line 2617 "Python/generated_cases.c.h" + #line 2615 "Python/generated_cases.c.h" STACK_SHRINK(2); next_instr += 4; DISPATCH(); @@ -2625,7 +2623,7 @@ PyObject *right = stack_pointer[-1]; PyObject *left = stack_pointer[-2]; PyObject *res; - #line 1887 "Python/bytecodes.c" + #line 1885 "Python/bytecodes.c" #if ENABLE_SPECIALIZATION _PyCompareOpCache *cache = (_PyCompareOpCache *)next_instr; if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) { @@ -2638,12 +2636,12 @@ #endif /* ENABLE_SPECIALIZATION */ assert((oparg >> 4) <= Py_GE); res = PyObject_RichCompare(left, right, oparg>>4); - #line 2642 "Python/generated_cases.c.h" + #line 2640 "Python/generated_cases.c.h" Py_DECREF(left); Py_DECREF(right); - #line 1900 "Python/bytecodes.c" + #line 1898 "Python/bytecodes.c" if (res == NULL) goto pop_2_error; - #line 2647 "Python/generated_cases.c.h" + #line 2645 "Python/generated_cases.c.h" STACK_SHRINK(1); stack_pointer[-1] = res; next_instr += 1; @@ -2654,7 +2652,7 @@ PyObject *right = stack_pointer[-1]; PyObject *left = stack_pointer[-2]; PyObject *res; - #line 1904 "Python/bytecodes.c" + #line 1902 "Python/bytecodes.c" DEOPT_IF(!PyFloat_CheckExact(left), COMPARE_OP); DEOPT_IF(!PyFloat_CheckExact(right), COMPARE_OP); STAT_INC(COMPARE_OP, hit); @@ -2666,7 +2664,7 @@ _Py_DECREF_SPECIALIZED(right, _PyFloat_ExactDealloc); res = (sign_ish & oparg) ? Py_True : Py_False; Py_INCREF(res); - #line 2670 "Python/generated_cases.c.h" + #line 2668 "Python/generated_cases.c.h" STACK_SHRINK(1); stack_pointer[-1] = res; next_instr += 1; @@ -2677,7 +2675,7 @@ PyObject *right = stack_pointer[-1]; PyObject *left = stack_pointer[-2]; PyObject *res; - #line 1919 "Python/bytecodes.c" + #line 1917 "Python/bytecodes.c" DEOPT_IF(!PyLong_CheckExact(left), COMPARE_OP); DEOPT_IF(!PyLong_CheckExact(right), COMPARE_OP); DEOPT_IF(!_PyLong_IsCompact((PyLongObject *)left), COMPARE_OP); @@ -2693,7 +2691,7 @@ _Py_DECREF_SPECIALIZED(right, (destructor)PyObject_Free); res = (sign_ish & oparg) ? Py_True : Py_False; Py_INCREF(res); - #line 2697 "Python/generated_cases.c.h" + #line 2695 "Python/generated_cases.c.h" STACK_SHRINK(1); stack_pointer[-1] = res; next_instr += 1; @@ -2704,7 +2702,7 @@ PyObject *right = stack_pointer[-1]; PyObject *left = stack_pointer[-2]; PyObject *res; - #line 1938 "Python/bytecodes.c" + #line 1936 "Python/bytecodes.c" DEOPT_IF(!PyUnicode_CheckExact(left), COMPARE_OP); DEOPT_IF(!PyUnicode_CheckExact(right), COMPARE_OP); STAT_INC(COMPARE_OP, hit); @@ -2717,7 +2715,7 @@ assert(COMPARISON_NOT_EQUALS + 1 == COMPARISON_EQUALS); res = ((COMPARISON_NOT_EQUALS + eq) & oparg) ? Py_True : Py_False; Py_INCREF(res); - #line 2721 "Python/generated_cases.c.h" + #line 2719 "Python/generated_cases.c.h" STACK_SHRINK(1); stack_pointer[-1] = res; next_instr += 1; @@ -2728,14 +2726,14 @@ PyObject *right = stack_pointer[-1]; PyObject *left = stack_pointer[-2]; PyObject *b; - #line 1953 "Python/bytecodes.c" + #line 1951 "Python/bytecodes.c" int res = Py_Is(left, right) ^ oparg; - #line 2734 "Python/generated_cases.c.h" + #line 2732 "Python/generated_cases.c.h" Py_DECREF(left); Py_DECREF(right); - #line 1955 "Python/bytecodes.c" + #line 1953 "Python/bytecodes.c" b = Py_NewRef(res ? Py_True : Py_False); - #line 2739 "Python/generated_cases.c.h" + #line 2737 "Python/generated_cases.c.h" STACK_SHRINK(1); stack_pointer[-1] = b; DISPATCH(); @@ -2745,15 +2743,15 @@ PyObject *right = stack_pointer[-1]; PyObject *left = stack_pointer[-2]; PyObject *b; - #line 1959 "Python/bytecodes.c" + #line 1957 "Python/bytecodes.c" int res = PySequence_Contains(right, left); - #line 2751 "Python/generated_cases.c.h" + #line 2749 "Python/generated_cases.c.h" Py_DECREF(left); Py_DECREF(right); - #line 1961 "Python/bytecodes.c" + #line 1959 "Python/bytecodes.c" if (res < 0) goto pop_2_error; b = Py_NewRef((res^oparg) ? Py_True : Py_False); - #line 2757 "Python/generated_cases.c.h" + #line 2755 "Python/generated_cases.c.h" STACK_SHRINK(1); stack_pointer[-1] = b; DISPATCH(); @@ -2764,12 +2762,12 @@ PyObject *exc_value = stack_pointer[-2]; PyObject *rest; PyObject *match; - #line 1966 "Python/bytecodes.c" + #line 1964 "Python/bytecodes.c" if (check_except_star_type_valid(tstate, match_type) < 0) { - #line 2770 "Python/generated_cases.c.h" + #line 2768 "Python/generated_cases.c.h" Py_DECREF(exc_value); Py_DECREF(match_type); - #line 1968 "Python/bytecodes.c" + #line 1966 "Python/bytecodes.c" if (true) goto pop_2_error; } @@ -2777,10 +2775,10 @@ rest = NULL; int res = exception_group_match(exc_value, match_type, &match, &rest); - #line 2781 "Python/generated_cases.c.h" + #line 2779 "Python/generated_cases.c.h" Py_DECREF(exc_value); Py_DECREF(match_type); - #line 1976 "Python/bytecodes.c" + #line 1974 "Python/bytecodes.c" if (res < 0) goto pop_2_error; assert((match == NULL) == (rest == NULL)); @@ -2789,7 +2787,7 @@ if (!Py_IsNone(match)) { PyErr_SetHandledException(match); } - #line 2793 "Python/generated_cases.c.h" + #line 2791 "Python/generated_cases.c.h" stack_pointer[-1] = match; stack_pointer[-2] = rest; DISPATCH(); @@ -2799,21 +2797,21 @@ PyObject *right = stack_pointer[-1]; PyObject *left = stack_pointer[-2]; PyObject *b; - #line 1987 "Python/bytecodes.c" + #line 1985 "Python/bytecodes.c" assert(PyExceptionInstance_Check(left)); if (check_except_type_valid(tstate, right) < 0) { - #line 2806 "Python/generated_cases.c.h" + #line 2804 "Python/generated_cases.c.h" Py_DECREF(right); - #line 1990 "Python/bytecodes.c" + #line 1988 "Python/bytecodes.c" if (true) goto pop_1_error; } int res = PyErr_GivenExceptionMatches(left, right); - #line 2813 "Python/generated_cases.c.h" + #line 2811 "Python/generated_cases.c.h" Py_DECREF(right); - #line 1995 "Python/bytecodes.c" + #line 1993 "Python/bytecodes.c" b = Py_NewRef(res ? Py_True : Py_False); - #line 2817 "Python/generated_cases.c.h" + #line 2815 "Python/generated_cases.c.h" stack_pointer[-1] = b; DISPATCH(); } @@ -2822,15 +2820,15 @@ PyObject *fromlist = stack_pointer[-1]; PyObject *level = stack_pointer[-2]; PyObject *res; - #line 1999 "Python/bytecodes.c" - PyObject *name = GETITEM(frame->f_code->co_names, oparg); + #line 1997 "Python/bytecodes.c" + PyObject *name = GETITEM(NAMES(), oparg); res = import_name(tstate, frame, name, fromlist, level); - #line 2829 "Python/generated_cases.c.h" + #line 2827 "Python/generated_cases.c.h" Py_DECREF(level); Py_DECREF(fromlist); - #line 2002 "Python/bytecodes.c" + #line 2000 "Python/bytecodes.c" if (res == NULL) goto pop_2_error; - #line 2834 "Python/generated_cases.c.h" + #line 2832 "Python/generated_cases.c.h" STACK_SHRINK(1); stack_pointer[-1] = res; DISPATCH(); @@ -2839,29 +2837,29 @@ TARGET(IMPORT_FROM) { PyObject *from = stack_pointer[-1]; PyObject *res; - #line 2006 "Python/bytecodes.c" - PyObject *name = GETITEM(frame->f_code->co_names, oparg); + #line 2004 "Python/bytecodes.c" + PyObject *name = GETITEM(NAMES(), oparg); res = import_from(tstate, from, name); if (res == NULL) goto error; - #line 2847 "Python/generated_cases.c.h" + #line 2845 "Python/generated_cases.c.h" STACK_GROW(1); stack_pointer[-1] = res; DISPATCH(); } TARGET(JUMP_FORWARD) { - #line 2012 "Python/bytecodes.c" + #line 2010 "Python/bytecodes.c" JUMPBY(oparg); - #line 2856 "Python/generated_cases.c.h" + #line 2854 "Python/generated_cases.c.h" DISPATCH(); } TARGET(JUMP_BACKWARD) { PREDICTED(JUMP_BACKWARD); - #line 2016 "Python/bytecodes.c" + #line 2014 "Python/bytecodes.c" assert(oparg < INSTR_OFFSET()); JUMPBY(-oparg); - #line 2865 "Python/generated_cases.c.h" + #line 2863 "Python/generated_cases.c.h" CHECK_EVAL_BREAKER(); DISPATCH(); } @@ -2869,7 +2867,7 @@ TARGET(POP_JUMP_IF_FALSE) { PREDICTED(POP_JUMP_IF_FALSE); PyObject *cond = stack_pointer[-1]; - #line 2022 "Python/bytecodes.c" + #line 2020 "Python/bytecodes.c" if (Py_IsTrue(cond)) { _Py_DECREF_NO_DEALLOC(cond); } @@ -2879,9 +2877,9 @@ } else { int err = PyObject_IsTrue(cond); - #line 2883 "Python/generated_cases.c.h" + #line 2881 "Python/generated_cases.c.h" Py_DECREF(cond); - #line 2032 "Python/bytecodes.c" + #line 2030 "Python/bytecodes.c" if (err == 0) { JUMPBY(oparg); } @@ -2889,14 +2887,14 @@ if (err < 0) goto pop_1_error; } } - #line 2893 "Python/generated_cases.c.h" + #line 2891 "Python/generated_cases.c.h" STACK_SHRINK(1); DISPATCH(); } TARGET(POP_JUMP_IF_TRUE) { PyObject *cond = stack_pointer[-1]; - #line 2042 "Python/bytecodes.c" + #line 2040 "Python/bytecodes.c" if (Py_IsFalse(cond)) { _Py_DECREF_NO_DEALLOC(cond); } @@ -2906,9 +2904,9 @@ } else { int err = PyObject_IsTrue(cond); - #line 2910 "Python/generated_cases.c.h" + #line 2908 "Python/generated_cases.c.h" Py_DECREF(cond); - #line 2052 "Python/bytecodes.c" + #line 2050 "Python/bytecodes.c" if (err > 0) { JUMPBY(oparg); } @@ -2916,67 +2914,67 @@ if (err < 0) goto pop_1_error; } } - #line 2920 "Python/generated_cases.c.h" + #line 2918 "Python/generated_cases.c.h" STACK_SHRINK(1); DISPATCH(); } TARGET(POP_JUMP_IF_NOT_NONE) { PyObject *value = stack_pointer[-1]; - #line 2062 "Python/bytecodes.c" + #line 2060 "Python/bytecodes.c" if (!Py_IsNone(value)) { - #line 2929 "Python/generated_cases.c.h" + #line 2927 "Python/generated_cases.c.h" Py_DECREF(value); - #line 2064 "Python/bytecodes.c" + #line 2062 "Python/bytecodes.c" JUMPBY(oparg); } else { _Py_DECREF_NO_DEALLOC(value); } - #line 2937 "Python/generated_cases.c.h" + #line 2935 "Python/generated_cases.c.h" STACK_SHRINK(1); DISPATCH(); } TARGET(POP_JUMP_IF_NONE) { PyObject *value = stack_pointer[-1]; - #line 2072 "Python/bytecodes.c" + #line 2070 "Python/bytecodes.c" if (Py_IsNone(value)) { _Py_DECREF_NO_DEALLOC(value); JUMPBY(oparg); } else { - #line 2950 "Python/generated_cases.c.h" + #line 2948 "Python/generated_cases.c.h" Py_DECREF(value); - #line 2078 "Python/bytecodes.c" + #line 2076 "Python/bytecodes.c" } - #line 2954 "Python/generated_cases.c.h" + #line 2952 "Python/generated_cases.c.h" STACK_SHRINK(1); DISPATCH(); } TARGET(JUMP_BACKWARD_NO_INTERRUPT) { - #line 2082 "Python/bytecodes.c" + #line 2080 "Python/bytecodes.c" /* This bytecode is used in the `yield from` or `await` loop. * If there is an interrupt, we want it handled in the innermost * generator or coroutine, so we deliberately do not check it here. * (see bpo-30039). */ JUMPBY(-oparg); - #line 2967 "Python/generated_cases.c.h" + #line 2965 "Python/generated_cases.c.h" DISPATCH(); } TARGET(GET_LEN) { PyObject *obj = stack_pointer[-1]; PyObject *len_o; - #line 2091 "Python/bytecodes.c" + #line 2089 "Python/bytecodes.c" // PUSH(len(TOS)) Py_ssize_t len_i = PyObject_Length(obj); if (len_i < 0) goto error; len_o = PyLong_FromSsize_t(len_i); if (len_o == NULL) goto error; - #line 2980 "Python/generated_cases.c.h" + #line 2978 "Python/generated_cases.c.h" STACK_GROW(1); stack_pointer[-1] = len_o; DISPATCH(); @@ -2987,16 +2985,16 @@ PyObject *type = stack_pointer[-2]; PyObject *subject = stack_pointer[-3]; PyObject *attrs; - #line 2099 "Python/bytecodes.c" + #line 2097 "Python/bytecodes.c" // Pop TOS and TOS1. Set TOS to a tuple of attributes on success, or // None on failure. assert(PyTuple_CheckExact(names)); attrs = match_class(tstate, subject, type, oparg, names); - #line 2996 "Python/generated_cases.c.h" + #line 2994 "Python/generated_cases.c.h" Py_DECREF(subject); Py_DECREF(type); Py_DECREF(names); - #line 2104 "Python/bytecodes.c" + #line 2102 "Python/bytecodes.c" if (attrs) { assert(PyTuple_CheckExact(attrs)); // Success! } @@ -3004,7 +3002,7 @@ if (_PyErr_Occurred(tstate)) goto pop_3_error; attrs = Py_NewRef(Py_None); // Failure! } - #line 3008 "Python/generated_cases.c.h" + #line 3006 "Python/generated_cases.c.h" STACK_SHRINK(2); stack_pointer[-1] = attrs; DISPATCH(); @@ -3013,10 +3011,10 @@ TARGET(MATCH_MAPPING) { PyObject *subject = stack_pointer[-1]; PyObject *res; - #line 2114 "Python/bytecodes.c" + #line 2112 "Python/bytecodes.c" int match = Py_TYPE(subject)->tp_flags & Py_TPFLAGS_MAPPING; res = Py_NewRef(match ? Py_True : Py_False); - #line 3020 "Python/generated_cases.c.h" + #line 3018 "Python/generated_cases.c.h" STACK_GROW(1); stack_pointer[-1] = res; PREDICT(POP_JUMP_IF_FALSE); @@ -3026,10 +3024,10 @@ TARGET(MATCH_SEQUENCE) { PyObject *subject = stack_pointer[-1]; PyObject *res; - #line 2120 "Python/bytecodes.c" + #line 2118 "Python/bytecodes.c" int match = Py_TYPE(subject)->tp_flags & Py_TPFLAGS_SEQUENCE; res = Py_NewRef(match ? Py_True : Py_False); - #line 3033 "Python/generated_cases.c.h" + #line 3031 "Python/generated_cases.c.h" STACK_GROW(1); stack_pointer[-1] = res; PREDICT(POP_JUMP_IF_FALSE); @@ -3040,11 +3038,11 @@ PyObject *keys = stack_pointer[-1]; PyObject *subject = stack_pointer[-2]; PyObject *values_or_none; - #line 2126 "Python/bytecodes.c" + #line 2124 "Python/bytecodes.c" // On successful match, PUSH(values). Otherwise, PUSH(None). values_or_none = match_keys(tstate, subject, keys); if (values_or_none == NULL) goto error; - #line 3048 "Python/generated_cases.c.h" + #line 3046 "Python/generated_cases.c.h" STACK_GROW(1); stack_pointer[-1] = values_or_none; DISPATCH(); @@ -3053,14 +3051,14 @@ TARGET(GET_ITER) { PyObject *iterable = stack_pointer[-1]; PyObject *iter; - #line 2132 "Python/bytecodes.c" + #line 2130 "Python/bytecodes.c" /* before: [obj]; after [getiter(obj)] */ iter = PyObject_GetIter(iterable); - #line 3060 "Python/generated_cases.c.h" + #line 3058 "Python/generated_cases.c.h" Py_DECREF(iterable); - #line 2135 "Python/bytecodes.c" + #line 2133 "Python/bytecodes.c" if (iter == NULL) goto pop_1_error; - #line 3064 "Python/generated_cases.c.h" + #line 3062 "Python/generated_cases.c.h" stack_pointer[-1] = iter; DISPATCH(); } @@ -3068,11 +3066,11 @@ TARGET(GET_YIELD_FROM_ITER) { PyObject *iterable = stack_pointer[-1]; PyObject *iter; - #line 2139 "Python/bytecodes.c" + #line 2137 "Python/bytecodes.c" /* before: [obj]; after [getiter(obj)] */ if (PyCoro_CheckExact(iterable)) { /* `iterable` is a coroutine */ - if (!(frame->f_code->co_flags & (CO_COROUTINE | CO_ITERABLE_COROUTINE))) { + if (!(_PyFrame_GetCode(frame)->co_flags & (CO_COROUTINE | CO_ITERABLE_COROUTINE))) { /* and it is used in a 'yield from' expression of a regular generator. */ _PyErr_SetString(tstate, PyExc_TypeError, @@ -3091,11 +3089,11 @@ if (iter == NULL) { goto error; } - #line 3095 "Python/generated_cases.c.h" + #line 3093 "Python/generated_cases.c.h" Py_DECREF(iterable); - #line 2162 "Python/bytecodes.c" + #line 2160 "Python/bytecodes.c" } - #line 3099 "Python/generated_cases.c.h" + #line 3097 "Python/generated_cases.c.h" stack_pointer[-1] = iter; PREDICT(LOAD_CONST); DISPATCH(); @@ -3106,7 +3104,7 @@ static_assert(INLINE_CACHE_ENTRIES_FOR_ITER == 1, "incorrect cache size"); PyObject *iter = stack_pointer[-1]; PyObject *next; - #line 2181 "Python/bytecodes.c" + #line 2179 "Python/bytecodes.c" #if ENABLE_SPECIALIZATION _PyForIterCache *cache = (_PyForIterCache *)next_instr; if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) { @@ -3137,7 +3135,7 @@ DISPATCH(); } // Common case: no jump, leave it to the code generator - #line 3141 "Python/generated_cases.c.h" + #line 3139 "Python/generated_cases.c.h" STACK_GROW(1); stack_pointer[-1] = next; next_instr += 1; @@ -3145,7 +3143,7 @@ } TARGET(INSTRUMENTED_FOR_ITER) { - #line 2214 "Python/bytecodes.c" + #line 2212 "Python/bytecodes.c" _Py_CODEUNIT *here = next_instr-1; _Py_CODEUNIT *target; PyObject *iter = TOP(); @@ -3171,14 +3169,14 @@ target = next_instr + INLINE_CACHE_ENTRIES_FOR_ITER + oparg + 1; } INSTRUMENTED_JUMP(here, target, PY_MONITORING_EVENT_BRANCH); - #line 3175 "Python/generated_cases.c.h" + #line 3173 "Python/generated_cases.c.h" DISPATCH(); } TARGET(FOR_ITER_LIST) { PyObject *iter = stack_pointer[-1]; PyObject *next; - #line 2242 "Python/bytecodes.c" + #line 2240 "Python/bytecodes.c" DEOPT_IF(Py_TYPE(iter) != &PyListIter_Type, FOR_ITER); _PyListIterObject *it = (_PyListIterObject *)iter; STAT_INC(FOR_ITER, hit); @@ -3198,7 +3196,7 @@ DISPATCH(); end_for_iter_list: // Common case: no jump, leave it to the code generator - #line 3202 "Python/generated_cases.c.h" + #line 3200 "Python/generated_cases.c.h" STACK_GROW(1); stack_pointer[-1] = next; next_instr += 1; @@ -3208,7 +3206,7 @@ TARGET(FOR_ITER_TUPLE) { PyObject *iter = stack_pointer[-1]; PyObject *next; - #line 2264 "Python/bytecodes.c" + #line 2262 "Python/bytecodes.c" _PyTupleIterObject *it = (_PyTupleIterObject *)iter; DEOPT_IF(Py_TYPE(it) != &PyTupleIter_Type, FOR_ITER); STAT_INC(FOR_ITER, hit); @@ -3228,7 +3226,7 @@ DISPATCH(); end_for_iter_tuple: // Common case: no jump, leave it to the code generator - #line 3232 "Python/generated_cases.c.h" + #line 3230 "Python/generated_cases.c.h" STACK_GROW(1); stack_pointer[-1] = next; next_instr += 1; @@ -3238,7 +3236,7 @@ TARGET(FOR_ITER_RANGE) { PyObject *iter = stack_pointer[-1]; PyObject *next; - #line 2286 "Python/bytecodes.c" + #line 2284 "Python/bytecodes.c" _PyRangeIterObject *r = (_PyRangeIterObject *)iter; DEOPT_IF(Py_TYPE(r) != &PyRangeIter_Type, FOR_ITER); STAT_INC(FOR_ITER, hit); @@ -3256,7 +3254,7 @@ if (next == NULL) { goto error; } - #line 3260 "Python/generated_cases.c.h" + #line 3258 "Python/generated_cases.c.h" STACK_GROW(1); stack_pointer[-1] = next; next_instr += 1; @@ -3265,7 +3263,7 @@ TARGET(FOR_ITER_GEN) { PyObject *iter = stack_pointer[-1]; - #line 2306 "Python/bytecodes.c" + #line 2304 "Python/bytecodes.c" PyGenObject *gen = (PyGenObject *)iter; DEOPT_IF(Py_TYPE(gen) != &PyGen_Type, FOR_ITER); DEOPT_IF(gen->gi_frame_state >= FRAME_EXECUTING, FOR_ITER); @@ -3280,14 +3278,14 @@ assert(next_instr[oparg].op.code == END_FOR || next_instr[oparg].op.code == INSTRUMENTED_END_FOR); DISPATCH_INLINED(gen_frame); - #line 3284 "Python/generated_cases.c.h" + #line 3282 "Python/generated_cases.c.h" } TARGET(BEFORE_ASYNC_WITH) { PyObject *mgr = stack_pointer[-1]; PyObject *exit; PyObject *res; - #line 2323 "Python/bytecodes.c" + #line 2321 "Python/bytecodes.c" PyObject *enter = _PyObject_LookupSpecial(mgr, &_Py_ID(__aenter__)); if (enter == NULL) { if (!_PyErr_Occurred(tstate)) { @@ -3310,16 +3308,16 @@ Py_DECREF(enter); goto error; } - #line 3314 "Python/generated_cases.c.h" + #line 3312 "Python/generated_cases.c.h" Py_DECREF(mgr); - #line 2346 "Python/bytecodes.c" + #line 2344 "Python/bytecodes.c" res = _PyObject_CallNoArgs(enter); Py_DECREF(enter); if (res == NULL) { Py_DECREF(exit); if (true) goto pop_1_error; } - #line 3323 "Python/generated_cases.c.h" + #line 3321 "Python/generated_cases.c.h" STACK_GROW(1); stack_pointer[-1] = res; stack_pointer[-2] = exit; @@ -3331,7 +3329,7 @@ PyObject *mgr = stack_pointer[-1]; PyObject *exit; PyObject *res; - #line 2356 "Python/bytecodes.c" + #line 2354 "Python/bytecodes.c" /* pop the context manager, push its __exit__ and the * value returned from calling its __enter__ */ @@ -3357,16 +3355,16 @@ Py_DECREF(enter); goto error; } - #line 3361 "Python/generated_cases.c.h" + #line 3359 "Python/generated_cases.c.h" Py_DECREF(mgr); - #line 2382 "Python/bytecodes.c" + #line 2380 "Python/bytecodes.c" res = _PyObject_CallNoArgs(enter); Py_DECREF(enter); if (res == NULL) { Py_DECREF(exit); if (true) goto pop_1_error; } - #line 3370 "Python/generated_cases.c.h" + #line 3368 "Python/generated_cases.c.h" STACK_GROW(1); stack_pointer[-1] = res; stack_pointer[-2] = exit; @@ -3378,7 +3376,7 @@ PyObject *lasti = stack_pointer[-3]; PyObject *exit_func = stack_pointer[-4]; PyObject *res; - #line 2391 "Python/bytecodes.c" + #line 2389 "Python/bytecodes.c" /* At the top of the stack are 4 values: - val: TOP = exc_info() - unused: SECOND = previous exception @@ -3399,7 +3397,7 @@ res = PyObject_Vectorcall(exit_func, stack + 1, 3 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL); if (res == NULL) goto error; - #line 3403 "Python/generated_cases.c.h" + #line 3401 "Python/generated_cases.c.h" STACK_GROW(1); stack_pointer[-1] = res; DISPATCH(); @@ -3408,7 +3406,7 @@ TARGET(PUSH_EXC_INFO) { PyObject *new_exc = stack_pointer[-1]; PyObject *prev_exc; - #line 2414 "Python/bytecodes.c" + #line 2412 "Python/bytecodes.c" _PyErr_StackItem *exc_info = tstate->exc_info; if (exc_info->exc_value != NULL) { prev_exc = exc_info->exc_value; @@ -3418,7 +3416,7 @@ } assert(PyExceptionInstance_Check(new_exc)); exc_info->exc_value = Py_NewRef(new_exc); - #line 3422 "Python/generated_cases.c.h" + #line 3420 "Python/generated_cases.c.h" STACK_GROW(1); stack_pointer[-1] = new_exc; stack_pointer[-2] = prev_exc; @@ -3432,7 +3430,7 @@ uint32_t type_version = read_u32(&next_instr[1].cache); uint32_t keys_version = read_u32(&next_instr[3].cache); PyObject *descr = read_obj(&next_instr[5].cache); - #line 2426 "Python/bytecodes.c" + #line 2424 "Python/bytecodes.c" /* Cached method object */ PyTypeObject *self_cls = Py_TYPE(self); assert(type_version != 0); @@ -3449,7 +3447,7 @@ assert(_PyType_HasFeature(Py_TYPE(res2), Py_TPFLAGS_METHOD_DESCRIPTOR)); res = self; assert(oparg & 1); - #line 3453 "Python/generated_cases.c.h" + #line 3451 "Python/generated_cases.c.h" STACK_GROW(((oparg & 1) ? 1 : 0)); stack_pointer[-1] = res; if (oparg & 1) { stack_pointer[-(1 + ((oparg & 1) ? 1 : 0))] = res2; } @@ -3463,7 +3461,7 @@ PyObject *res; uint32_t type_version = read_u32(&next_instr[1].cache); PyObject *descr = read_obj(&next_instr[5].cache); - #line 2445 "Python/bytecodes.c" + #line 2443 "Python/bytecodes.c" PyTypeObject *self_cls = Py_TYPE(self); DEOPT_IF(self_cls->tp_version_tag != type_version, LOAD_ATTR); assert(self_cls->tp_dictoffset == 0); @@ -3473,7 +3471,7 @@ res2 = Py_NewRef(descr); res = self; assert(oparg & 1); - #line 3477 "Python/generated_cases.c.h" + #line 3475 "Python/generated_cases.c.h" STACK_GROW(((oparg & 1) ? 1 : 0)); stack_pointer[-1] = res; if (oparg & 1) { stack_pointer[-(1 + ((oparg & 1) ? 1 : 0))] = res2; } @@ -3487,7 +3485,7 @@ PyObject *res; uint32_t type_version = read_u32(&next_instr[1].cache); PyObject *descr = read_obj(&next_instr[5].cache); - #line 2457 "Python/bytecodes.c" + #line 2455 "Python/bytecodes.c" PyTypeObject *self_cls = Py_TYPE(self); DEOPT_IF(self_cls->tp_version_tag != type_version, LOAD_ATTR); Py_ssize_t dictoffset = self_cls->tp_dictoffset; @@ -3501,7 +3499,7 @@ res2 = Py_NewRef(descr); res = self; assert(oparg & 1); - #line 3505 "Python/generated_cases.c.h" + #line 3503 "Python/generated_cases.c.h" STACK_GROW(((oparg & 1) ? 1 : 0)); stack_pointer[-1] = res; if (oparg & 1) { stack_pointer[-(1 + ((oparg & 1) ? 1 : 0))] = res2; } @@ -3510,16 +3508,16 @@ } TARGET(KW_NAMES) { - #line 2473 "Python/bytecodes.c" + #line 2471 "Python/bytecodes.c" assert(kwnames == NULL); - assert(oparg < PyTuple_GET_SIZE(frame->f_code->co_consts)); - kwnames = GETITEM(frame->f_code->co_consts, oparg); - #line 3518 "Python/generated_cases.c.h" + assert(oparg < PyTuple_GET_SIZE(CONSTS())); + kwnames = GETITEM(CONSTS(), oparg); + #line 3516 "Python/generated_cases.c.h" DISPATCH(); } TARGET(INSTRUMENTED_CALL) { - #line 2479 "Python/bytecodes.c" + #line 2477 "Python/bytecodes.c" int is_meth = PEEK(oparg+2) != NULL; int total_args = oparg + is_meth; PyObject *function = PEEK(total_args + 1); @@ -3532,7 +3530,7 @@ _PyCallCache *cache = (_PyCallCache *)next_instr; INCREMENT_ADAPTIVE_COUNTER(cache->counter); GO_TO_INSTRUCTION(CALL); - #line 3536 "Python/generated_cases.c.h" + #line 3534 "Python/generated_cases.c.h" } TARGET(CALL) { @@ -3542,7 +3540,7 @@ PyObject *callable = stack_pointer[-(1 + oparg)]; PyObject *method = stack_pointer[-(2 + oparg)]; PyObject *res; - #line 2524 "Python/bytecodes.c" + #line 2522 "Python/bytecodes.c" int is_meth = method != NULL; int total_args = oparg; if (is_meth) { @@ -3624,7 +3622,7 @@ Py_DECREF(args[i]); } if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; } - #line 3628 "Python/generated_cases.c.h" + #line 3626 "Python/generated_cases.c.h" STACK_SHRINK(oparg); STACK_SHRINK(1); stack_pointer[-1] = res; @@ -3636,7 +3634,7 @@ TARGET(CALL_BOUND_METHOD_EXACT_ARGS) { PyObject *callable = stack_pointer[-(1 + oparg)]; PyObject *method = stack_pointer[-(2 + oparg)]; - #line 2612 "Python/bytecodes.c" + #line 2610 "Python/bytecodes.c" DEOPT_IF(method != NULL, CALL); DEOPT_IF(Py_TYPE(callable) != &PyMethod_Type, CALL); STAT_INC(CALL, hit); @@ -3646,7 +3644,7 @@ PEEK(oparg + 2) = Py_NewRef(meth); // method Py_DECREF(callable); GO_TO_INSTRUCTION(CALL_PY_EXACT_ARGS); - #line 3650 "Python/generated_cases.c.h" + #line 3648 "Python/generated_cases.c.h" } TARGET(CALL_PY_EXACT_ARGS) { @@ -3655,7 +3653,7 @@ PyObject *callable = stack_pointer[-(1 + oparg)]; PyObject *method = stack_pointer[-(2 + oparg)]; uint32_t func_version = read_u32(&next_instr[1].cache); - #line 2624 "Python/bytecodes.c" + #line 2622 "Python/bytecodes.c" assert(kwnames == NULL); DEOPT_IF(tstate->interp->eval_frame, CALL); int is_meth = method != NULL; @@ -3681,7 +3679,7 @@ JUMPBY(INLINE_CACHE_ENTRIES_CALL); frame->return_offset = 0; DISPATCH_INLINED(new_frame); - #line 3685 "Python/generated_cases.c.h" + #line 3683 "Python/generated_cases.c.h" } TARGET(CALL_PY_WITH_DEFAULTS) { @@ -3689,7 +3687,7 @@ PyObject *callable = stack_pointer[-(1 + oparg)]; PyObject *method = stack_pointer[-(2 + oparg)]; uint32_t func_version = read_u32(&next_instr[1].cache); - #line 2652 "Python/bytecodes.c" + #line 2650 "Python/bytecodes.c" assert(kwnames == NULL); DEOPT_IF(tstate->interp->eval_frame, CALL); int is_meth = method != NULL; @@ -3725,7 +3723,7 @@ JUMPBY(INLINE_CACHE_ENTRIES_CALL); frame->return_offset = 0; DISPATCH_INLINED(new_frame); - #line 3729 "Python/generated_cases.c.h" + #line 3727 "Python/generated_cases.c.h" } TARGET(CALL_NO_KW_TYPE_1) { @@ -3733,7 +3731,7 @@ PyObject *callable = stack_pointer[-(1 + oparg)]; PyObject *null = stack_pointer[-(2 + oparg)]; PyObject *res; - #line 2690 "Python/bytecodes.c" + #line 2688 "Python/bytecodes.c" assert(kwnames == NULL); assert(oparg == 1); DEOPT_IF(null != NULL, CALL); @@ -3743,7 +3741,7 @@ res = Py_NewRef(Py_TYPE(obj)); Py_DECREF(obj); Py_DECREF(&PyType_Type); // I.e., callable - #line 3747 "Python/generated_cases.c.h" + #line 3745 "Python/generated_cases.c.h" STACK_SHRINK(oparg); STACK_SHRINK(1); stack_pointer[-1] = res; @@ -3756,7 +3754,7 @@ PyObject *callable = stack_pointer[-(1 + oparg)]; PyObject *null = stack_pointer[-(2 + oparg)]; PyObject *res; - #line 2702 "Python/bytecodes.c" + #line 2700 "Python/bytecodes.c" assert(kwnames == NULL); assert(oparg == 1); DEOPT_IF(null != NULL, CALL); @@ -3767,7 +3765,7 @@ Py_DECREF(arg); Py_DECREF(&PyUnicode_Type); // I.e., callable if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; } - #line 3771 "Python/generated_cases.c.h" + #line 3769 "Python/generated_cases.c.h" STACK_SHRINK(oparg); STACK_SHRINK(1); stack_pointer[-1] = res; @@ -3781,7 +3779,7 @@ PyObject *callable = stack_pointer[-(1 + oparg)]; PyObject *null = stack_pointer[-(2 + oparg)]; PyObject *res; - #line 2716 "Python/bytecodes.c" + #line 2714 "Python/bytecodes.c" assert(kwnames == NULL); assert(oparg == 1); DEOPT_IF(null != NULL, CALL); @@ -3792,7 +3790,7 @@ Py_DECREF(arg); Py_DECREF(&PyTuple_Type); // I.e., tuple if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; } - #line 3796 "Python/generated_cases.c.h" + #line 3794 "Python/generated_cases.c.h" STACK_SHRINK(oparg); STACK_SHRINK(1); stack_pointer[-1] = res; @@ -3806,7 +3804,7 @@ PyObject *callable = stack_pointer[-(1 + oparg)]; PyObject *method = stack_pointer[-(2 + oparg)]; PyObject *res; - #line 2730 "Python/bytecodes.c" + #line 2728 "Python/bytecodes.c" int is_meth = method != NULL; int total_args = oparg; if (is_meth) { @@ -3828,7 +3826,7 @@ } Py_DECREF(tp); if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; } - #line 3832 "Python/generated_cases.c.h" + #line 3830 "Python/generated_cases.c.h" STACK_SHRINK(oparg); STACK_SHRINK(1); stack_pointer[-1] = res; @@ -3842,7 +3840,7 @@ PyObject *callable = stack_pointer[-(1 + oparg)]; PyObject *method = stack_pointer[-(2 + oparg)]; PyObject *res; - #line 2755 "Python/bytecodes.c" + #line 2753 "Python/bytecodes.c" /* Builtin METH_O functions */ assert(kwnames == NULL); int is_meth = method != NULL; @@ -3870,7 +3868,7 @@ Py_DECREF(arg); Py_DECREF(callable); if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; } - #line 3874 "Python/generated_cases.c.h" + #line 3872 "Python/generated_cases.c.h" STACK_SHRINK(oparg); STACK_SHRINK(1); stack_pointer[-1] = res; @@ -3884,7 +3882,7 @@ PyObject *callable = stack_pointer[-(1 + oparg)]; PyObject *method = stack_pointer[-(2 + oparg)]; PyObject *res; - #line 2786 "Python/bytecodes.c" + #line 2784 "Python/bytecodes.c" /* Builtin METH_FASTCALL functions, without keywords */ assert(kwnames == NULL); int is_meth = method != NULL; @@ -3916,7 +3914,7 @@ 'invalid'). In those cases an exception is set, so we must handle it. */ - #line 3920 "Python/generated_cases.c.h" + #line 3918 "Python/generated_cases.c.h" STACK_SHRINK(oparg); STACK_SHRINK(1); stack_pointer[-1] = res; @@ -3930,7 +3928,7 @@ PyObject *callable = stack_pointer[-(1 + oparg)]; PyObject *method = stack_pointer[-(2 + oparg)]; PyObject *res; - #line 2821 "Python/bytecodes.c" + #line 2819 "Python/bytecodes.c" /* Builtin METH_FASTCALL | METH_KEYWORDS functions */ int is_meth = method != NULL; int total_args = oparg; @@ -3962,7 +3960,7 @@ } Py_DECREF(callable); if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; } - #line 3966 "Python/generated_cases.c.h" + #line 3964 "Python/generated_cases.c.h" STACK_SHRINK(oparg); STACK_SHRINK(1); stack_pointer[-1] = res; @@ -3976,7 +3974,7 @@ PyObject *callable = stack_pointer[-(1 + oparg)]; PyObject *method = stack_pointer[-(2 + oparg)]; PyObject *res; - #line 2856 "Python/bytecodes.c" + #line 2854 "Python/bytecodes.c" assert(kwnames == NULL); /* len(o) */ int is_meth = method != NULL; @@ -4001,7 +3999,7 @@ Py_DECREF(callable); Py_DECREF(arg); if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; } - #line 4005 "Python/generated_cases.c.h" + #line 4003 "Python/generated_cases.c.h" STACK_SHRINK(oparg); STACK_SHRINK(1); stack_pointer[-1] = res; @@ -4014,7 +4012,7 @@ PyObject *callable = stack_pointer[-(1 + oparg)]; PyObject *method = stack_pointer[-(2 + oparg)]; PyObject *res; - #line 2883 "Python/bytecodes.c" + #line 2881 "Python/bytecodes.c" assert(kwnames == NULL); /* isinstance(o, o2) */ int is_meth = method != NULL; @@ -4041,7 +4039,7 @@ Py_DECREF(cls); Py_DECREF(callable); if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; } - #line 4045 "Python/generated_cases.c.h" + #line 4043 "Python/generated_cases.c.h" STACK_SHRINK(oparg); STACK_SHRINK(1); stack_pointer[-1] = res; @@ -4053,7 +4051,7 @@ PyObject **args = (stack_pointer - oparg); PyObject *self = stack_pointer[-(1 + oparg)]; PyObject *method = stack_pointer[-(2 + oparg)]; - #line 2913 "Python/bytecodes.c" + #line 2911 "Python/bytecodes.c" assert(kwnames == NULL); assert(oparg == 1); assert(method != NULL); @@ -4071,14 +4069,14 @@ JUMPBY(INLINE_CACHE_ENTRIES_CALL + 1); assert(next_instr[-1].op.code == POP_TOP); DISPATCH(); - #line 4075 "Python/generated_cases.c.h" + #line 4073 "Python/generated_cases.c.h" } TARGET(CALL_NO_KW_METHOD_DESCRIPTOR_O) { PyObject **args = (stack_pointer - oparg); PyObject *method = stack_pointer[-(2 + oparg)]; PyObject *res; - #line 2933 "Python/bytecodes.c" + #line 2931 "Python/bytecodes.c" assert(kwnames == NULL); int is_meth = method != NULL; int total_args = oparg; @@ -4109,7 +4107,7 @@ Py_DECREF(arg); Py_DECREF(callable); if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; } - #line 4113 "Python/generated_cases.c.h" + #line 4111 "Python/generated_cases.c.h" STACK_SHRINK(oparg); STACK_SHRINK(1); stack_pointer[-1] = res; @@ -4122,7 +4120,7 @@ PyObject **args = (stack_pointer - oparg); PyObject *method = stack_pointer[-(2 + oparg)]; PyObject *res; - #line 2967 "Python/bytecodes.c" + #line 2965 "Python/bytecodes.c" int is_meth = method != NULL; int total_args = oparg; if (is_meth) { @@ -4151,7 +4149,7 @@ } Py_DECREF(callable); if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; } - #line 4155 "Python/generated_cases.c.h" + #line 4153 "Python/generated_cases.c.h" STACK_SHRINK(oparg); STACK_SHRINK(1); stack_pointer[-1] = res; @@ -4164,7 +4162,7 @@ PyObject **args = (stack_pointer - oparg); PyObject *method = stack_pointer[-(2 + oparg)]; PyObject *res; - #line 2999 "Python/bytecodes.c" + #line 2997 "Python/bytecodes.c" assert(kwnames == NULL); assert(oparg == 0 || oparg == 1); int is_meth = method != NULL; @@ -4193,7 +4191,7 @@ Py_DECREF(self); Py_DECREF(callable); if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; } - #line 4197 "Python/generated_cases.c.h" + #line 4195 "Python/generated_cases.c.h" STACK_SHRINK(oparg); STACK_SHRINK(1); stack_pointer[-1] = res; @@ -4206,7 +4204,7 @@ PyObject **args = (stack_pointer - oparg); PyObject *method = stack_pointer[-(2 + oparg)]; PyObject *res; - #line 3031 "Python/bytecodes.c" + #line 3029 "Python/bytecodes.c" assert(kwnames == NULL); int is_meth = method != NULL; int total_args = oparg; @@ -4234,7 +4232,7 @@ } Py_DECREF(callable); if (res == NULL) { STACK_SHRINK(oparg); goto pop_2_error; } - #line 4238 "Python/generated_cases.c.h" + #line 4236 "Python/generated_cases.c.h" STACK_SHRINK(oparg); STACK_SHRINK(1); stack_pointer[-1] = res; @@ -4244,9 +4242,9 @@ } TARGET(INSTRUMENTED_CALL_FUNCTION_EX) { - #line 3062 "Python/bytecodes.c" + #line 3060 "Python/bytecodes.c" GO_TO_INSTRUCTION(CALL_FUNCTION_EX); - #line 4250 "Python/generated_cases.c.h" + #line 4248 "Python/generated_cases.c.h" } TARGET(CALL_FUNCTION_EX) { @@ -4255,7 +4253,7 @@ PyObject *callargs = stack_pointer[-(1 + ((oparg & 1) ? 1 : 0))]; PyObject *func = stack_pointer[-(2 + ((oparg & 1) ? 1 : 0))]; PyObject *result; - #line 3066 "Python/bytecodes.c" + #line 3064 "Python/bytecodes.c" // DICT_MERGE is called before this opcode if there are kwargs. // It converts all dict subtypes in kwargs into regular dicts. assert(kwargs == NULL || PyDict_CheckExact(kwargs)); @@ -4317,14 +4315,14 @@ } result = PyObject_Call(func, callargs, kwargs); } - #line 4321 "Python/generated_cases.c.h" + #line 4319 "Python/generated_cases.c.h" Py_DECREF(func); Py_DECREF(callargs); Py_XDECREF(kwargs); - #line 3128 "Python/bytecodes.c" + #line 3126 "Python/bytecodes.c" assert(PEEK(3 + (oparg & 1)) == NULL); if (result == NULL) { STACK_SHRINK(((oparg & 1) ? 1 : 0)); goto pop_3_error; } - #line 4328 "Python/generated_cases.c.h" + #line 4326 "Python/generated_cases.c.h" STACK_SHRINK(((oparg & 1) ? 1 : 0)); STACK_SHRINK(2); stack_pointer[-1] = result; @@ -4339,7 +4337,7 @@ PyObject *kwdefaults = (oparg & 0x02) ? stack_pointer[-(1 + ((oparg & 0x08) ? 1 : 0) + ((oparg & 0x04) ? 1 : 0) + ((oparg & 0x02) ? 1 : 0))] : NULL; PyObject *defaults = (oparg & 0x01) ? stack_pointer[-(1 + ((oparg & 0x08) ? 1 : 0) + ((oparg & 0x04) ? 1 : 0) + ((oparg & 0x02) ? 1 : 0) + ((oparg & 0x01) ? 1 : 0))] : NULL; PyObject *func; - #line 3138 "Python/bytecodes.c" + #line 3136 "Python/bytecodes.c" PyFunctionObject *func_obj = (PyFunctionObject *) PyFunction_New(codeobj, GLOBALS()); @@ -4368,14 +4366,14 @@ func_obj->func_version = ((PyCodeObject *)codeobj)->co_version; func = (PyObject *)func_obj; - #line 4372 "Python/generated_cases.c.h" + #line 4370 "Python/generated_cases.c.h" STACK_SHRINK(((oparg & 0x01) ? 1 : 0) + ((oparg & 0x02) ? 1 : 0) + ((oparg & 0x04) ? 1 : 0) + ((oparg & 0x08) ? 1 : 0)); stack_pointer[-1] = func; DISPATCH(); } TARGET(RETURN_GENERATOR) { - #line 3169 "Python/bytecodes.c" + #line 3167 "Python/bytecodes.c" assert(PyFunction_Check(frame->f_funcobj)); PyFunctionObject *func = (PyFunctionObject *)frame->f_funcobj; PyGenObject *gen = (PyGenObject *)_Py_MakeCoro(func); @@ -4396,7 +4394,7 @@ frame = cframe.current_frame = prev; _PyFrame_StackPush(frame, (PyObject *)gen); goto resume_frame; - #line 4400 "Python/generated_cases.c.h" + #line 4398 "Python/generated_cases.c.h" } TARGET(BUILD_SLICE) { @@ -4404,15 +4402,15 @@ PyObject *stop = stack_pointer[-(1 + ((oparg == 3) ? 1 : 0))]; PyObject *start = stack_pointer[-(2 + ((oparg == 3) ? 1 : 0))]; PyObject *slice; - #line 3192 "Python/bytecodes.c" + #line 3190 "Python/bytecodes.c" slice = PySlice_New(start, stop, step); - #line 4410 "Python/generated_cases.c.h" + #line 4408 "Python/generated_cases.c.h" Py_DECREF(start); Py_DECREF(stop); Py_XDECREF(step); - #line 3194 "Python/bytecodes.c" + #line 3192 "Python/bytecodes.c" if (slice == NULL) { STACK_SHRINK(((oparg == 3) ? 1 : 0)); goto pop_2_error; } - #line 4416 "Python/generated_cases.c.h" + #line 4414 "Python/generated_cases.c.h" STACK_SHRINK(((oparg == 3) ? 1 : 0)); STACK_SHRINK(1); stack_pointer[-1] = slice; @@ -4423,7 +4421,7 @@ PyObject *fmt_spec = ((oparg & FVS_MASK) == FVS_HAVE_SPEC) ? stack_pointer[-((((oparg & FVS_MASK) == FVS_HAVE_SPEC) ? 1 : 0))] : NULL; PyObject *value = stack_pointer[-(1 + (((oparg & FVS_MASK) == FVS_HAVE_SPEC) ? 1 : 0))]; PyObject *result; - #line 3198 "Python/bytecodes.c" + #line 3196 "Python/bytecodes.c" /* Handles f-string value formatting. */ PyObject *(*conv_fn)(PyObject *); int which_conversion = oparg & FVC_MASK; @@ -4458,7 +4456,7 @@ Py_DECREF(value); Py_XDECREF(fmt_spec); if (result == NULL) { STACK_SHRINK((((oparg & FVS_MASK) == FVS_HAVE_SPEC) ? 1 : 0)); goto pop_1_error; } - #line 4462 "Python/generated_cases.c.h" + #line 4460 "Python/generated_cases.c.h" STACK_SHRINK((((oparg & FVS_MASK) == FVS_HAVE_SPEC) ? 1 : 0)); stack_pointer[-1] = result; DISPATCH(); @@ -4467,10 +4465,10 @@ TARGET(COPY) { PyObject *bottom = stack_pointer[-(1 + (oparg-1))]; PyObject *top; - #line 3235 "Python/bytecodes.c" + #line 3233 "Python/bytecodes.c" assert(oparg > 0); top = Py_NewRef(bottom); - #line 4474 "Python/generated_cases.c.h" + #line 4472 "Python/generated_cases.c.h" STACK_GROW(1); stack_pointer[-1] = top; DISPATCH(); @@ -4482,7 +4480,7 @@ PyObject *rhs = stack_pointer[-1]; PyObject *lhs = stack_pointer[-2]; PyObject *res; - #line 3240 "Python/bytecodes.c" + #line 3238 "Python/bytecodes.c" #if ENABLE_SPECIALIZATION _PyBinaryOpCache *cache = (_PyBinaryOpCache *)next_instr; if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) { @@ -4497,12 +4495,12 @@ assert((unsigned)oparg < Py_ARRAY_LENGTH(binary_ops)); assert(binary_ops[oparg]); res = binary_ops[oparg](lhs, rhs); - #line 4501 "Python/generated_cases.c.h" + #line 4499 "Python/generated_cases.c.h" Py_DECREF(lhs); Py_DECREF(rhs); - #line 3255 "Python/bytecodes.c" + #line 3253 "Python/bytecodes.c" if (res == NULL) goto pop_2_error; - #line 4506 "Python/generated_cases.c.h" + #line 4504 "Python/generated_cases.c.h" STACK_SHRINK(1); stack_pointer[-1] = res; next_instr += 1; @@ -4512,16 +4510,16 @@ TARGET(SWAP) { PyObject *top = stack_pointer[-1]; PyObject *bottom = stack_pointer[-(2 + (oparg-2))]; - #line 3260 "Python/bytecodes.c" + #line 3258 "Python/bytecodes.c" assert(oparg >= 2); - #line 4518 "Python/generated_cases.c.h" + #line 4516 "Python/generated_cases.c.h" stack_pointer[-1] = bottom; stack_pointer[-(2 + (oparg-2))] = top; DISPATCH(); } TARGET(INSTRUMENTED_LINE) { - #line 3264 "Python/bytecodes.c" + #line 3262 "Python/bytecodes.c" _Py_CODEUNIT *here = next_instr-1; _PyFrame_SetStackPointer(frame, stack_pointer); int original_opcode = _Py_call_instrumentation_line( @@ -4541,11 +4539,11 @@ } opcode = original_opcode; DISPATCH_GOTO(); - #line 4545 "Python/generated_cases.c.h" + #line 4543 "Python/generated_cases.c.h" } TARGET(INSTRUMENTED_INSTRUCTION) { - #line 3286 "Python/bytecodes.c" + #line 3284 "Python/bytecodes.c" int next_opcode = _Py_call_instrumentation_instruction( tstate, frame, next_instr-1); if (next_opcode < 0) goto error; @@ -4557,26 +4555,26 @@ assert(next_opcode > 0 && next_opcode < 256); opcode = next_opcode; DISPATCH_GOTO(); - #line 4561 "Python/generated_cases.c.h" + #line 4559 "Python/generated_cases.c.h" } TARGET(INSTRUMENTED_JUMP_FORWARD) { - #line 3300 "Python/bytecodes.c" + #line 3298 "Python/bytecodes.c" INSTRUMENTED_JUMP(next_instr-1, next_instr+oparg, PY_MONITORING_EVENT_JUMP); - #line 4567 "Python/generated_cases.c.h" + #line 4565 "Python/generated_cases.c.h" DISPATCH(); } TARGET(INSTRUMENTED_JUMP_BACKWARD) { - #line 3304 "Python/bytecodes.c" + #line 3302 "Python/bytecodes.c" INSTRUMENTED_JUMP(next_instr-1, next_instr-oparg, PY_MONITORING_EVENT_JUMP); - #line 4574 "Python/generated_cases.c.h" + #line 4572 "Python/generated_cases.c.h" CHECK_EVAL_BREAKER(); DISPATCH(); } TARGET(INSTRUMENTED_POP_JUMP_IF_TRUE) { - #line 3309 "Python/bytecodes.c" + #line 3307 "Python/bytecodes.c" PyObject *cond = POP(); int err = PyObject_IsTrue(cond); Py_DECREF(cond); @@ -4585,12 +4583,12 @@ assert(err == 0 || err == 1); int offset = err*oparg; INSTRUMENTED_JUMP(here, next_instr + offset, PY_MONITORING_EVENT_BRANCH); - #line 4589 "Python/generated_cases.c.h" + #line 4587 "Python/generated_cases.c.h" DISPATCH(); } TARGET(INSTRUMENTED_POP_JUMP_IF_FALSE) { - #line 3320 "Python/bytecodes.c" + #line 3318 "Python/bytecodes.c" PyObject *cond = POP(); int err = PyObject_IsTrue(cond); Py_DECREF(cond); @@ -4599,12 +4597,12 @@ assert(err == 0 || err == 1); int offset = (1-err)*oparg; INSTRUMENTED_JUMP(here, next_instr + offset, PY_MONITORING_EVENT_BRANCH); - #line 4603 "Python/generated_cases.c.h" + #line 4601 "Python/generated_cases.c.h" DISPATCH(); } TARGET(INSTRUMENTED_POP_JUMP_IF_NONE) { - #line 3331 "Python/bytecodes.c" + #line 3329 "Python/bytecodes.c" PyObject *value = POP(); _Py_CODEUNIT *here = next_instr-1; int offset; @@ -4617,12 +4615,12 @@ offset = 0; } INSTRUMENTED_JUMP(here, next_instr + offset, PY_MONITORING_EVENT_BRANCH); - #line 4621 "Python/generated_cases.c.h" + #line 4619 "Python/generated_cases.c.h" DISPATCH(); } TARGET(INSTRUMENTED_POP_JUMP_IF_NOT_NONE) { - #line 3346 "Python/bytecodes.c" + #line 3344 "Python/bytecodes.c" PyObject *value = POP(); _Py_CODEUNIT *here = next_instr-1; int offset; @@ -4635,30 +4633,30 @@ offset = oparg; } INSTRUMENTED_JUMP(here, next_instr + offset, PY_MONITORING_EVENT_BRANCH); - #line 4639 "Python/generated_cases.c.h" + #line 4637 "Python/generated_cases.c.h" DISPATCH(); } TARGET(EXTENDED_ARG) { - #line 3361 "Python/bytecodes.c" + #line 3359 "Python/bytecodes.c" assert(oparg); opcode = next_instr->op.code; oparg = oparg << 8 | next_instr->op.arg; PRE_DISPATCH_GOTO(); DISPATCH_GOTO(); - #line 4650 "Python/generated_cases.c.h" + #line 4648 "Python/generated_cases.c.h" } TARGET(CACHE) { - #line 3369 "Python/bytecodes.c" + #line 3367 "Python/bytecodes.c" assert(0 && "Executing a cache."); Py_UNREACHABLE(); - #line 4657 "Python/generated_cases.c.h" + #line 4655 "Python/generated_cases.c.h" } TARGET(RESERVED) { - #line 3374 "Python/bytecodes.c" + #line 3372 "Python/bytecodes.c" assert(0 && "Executing RESERVED instruction."); Py_UNREACHABLE(); - #line 4664 "Python/generated_cases.c.h" + #line 4662 "Python/generated_cases.c.h" } diff --git a/Python/instrumentation.c b/Python/instrumentation.c index a1423240609699..43c077a016f6d1 100644 --- a/Python/instrumentation.c +++ b/Python/instrumentation.c @@ -931,7 +931,7 @@ call_instrumentation_vector( } assert(!_PyErr_Occurred(tstate)); assert(args[0] == NULL); - PyCodeObject *code = frame->f_code; + PyCodeObject *code = _PyFrame_GetCode(frame); assert(code->_co_instrumentation_version == tstate->interp->monitoring_version); assert(is_version_up_to_date(code, tstate->interp)); assert(instrumentation_cross_checks(tstate->interp, code)); @@ -1011,7 +1011,7 @@ _Py_call_instrumentation_jump( event == PY_MONITORING_EVENT_BRANCH); assert(frame->prev_instr == instr); frame->prev_instr = target; - PyCodeObject *code = frame->f_code; + PyCodeObject *code = _PyFrame_GetCode(frame); int to = (int)(target - _PyCode_CODE(code)); PyObject *to_obj = PyLong_FromLong(to * (int)sizeof(_Py_CODEUNIT)); if (to_obj == NULL) { @@ -1079,7 +1079,7 @@ int _Py_call_instrumentation_line(PyThreadState *tstate, _PyInterpreterFrame* frame, _Py_CODEUNIT *instr) { frame->prev_instr = instr; - PyCodeObject *code = frame->f_code; + PyCodeObject *code = _PyFrame_GetCode(frame); assert(is_version_up_to_date(code, tstate->interp)); assert(instrumentation_cross_checks(tstate->interp, code)); int i = (int)(instr - _PyCode_CODE(code)); @@ -1134,7 +1134,7 @@ _Py_call_instrumentation_line(PyThreadState *tstate, _PyInterpreterFrame* frame, int _Py_call_instrumentation_instruction(PyThreadState *tstate, _PyInterpreterFrame* frame, _Py_CODEUNIT *instr) { - PyCodeObject *code = frame->f_code; + PyCodeObject *code = _PyFrame_GetCode(frame); assert(is_version_up_to_date(code, tstate->interp)); assert(instrumentation_cross_checks(tstate->interp, code)); int offset = (int)(instr - _PyCode_CODE(code)); @@ -1560,7 +1560,7 @@ instrument_all_executing_code_objects(PyInterpreterState *interp) { _PyInterpreterFrame *frame = ts->cframe->current_frame; while (frame) { if (frame->owner != FRAME_OWNED_BY_CSTACK) { - if (_Py_Instrument(frame->f_code, interp)) { + if (_Py_Instrument(_PyFrame_GetCode(frame), interp)) { return -1; } } diff --git a/Python/intrinsics.c b/Python/intrinsics.c index cca29d859902a4..a68f66555803c5 100644 --- a/Python/intrinsics.c +++ b/Python/intrinsics.c @@ -151,14 +151,14 @@ stopiteration_error(PyThreadState* tstate, PyObject *exc) const char *msg = NULL; if (PyErr_GivenExceptionMatches(exc, PyExc_StopIteration)) { msg = "generator raised StopIteration"; - if (frame->f_code->co_flags & CO_ASYNC_GENERATOR) { + if (_PyFrame_GetCode(frame)->co_flags & CO_ASYNC_GENERATOR) { msg = "async generator raised StopIteration"; } - else if (frame->f_code->co_flags & CO_COROUTINE) { + else if (_PyFrame_GetCode(frame)->co_flags & CO_COROUTINE) { msg = "coroutine raised StopIteration"; } } - else if ((frame->f_code->co_flags & CO_ASYNC_GENERATOR) && + else if ((_PyFrame_GetCode(frame)->co_flags & CO_ASYNC_GENERATOR) && PyErr_GivenExceptionMatches(exc, PyExc_StopAsyncIteration)) { /* code in `gen` raised a StopAsyncIteration error: diff --git a/Python/legacy_tracing.c b/Python/legacy_tracing.c index e509e63a087a52..3f6841ac9e605f 100644 --- a/Python/legacy_tracing.c +++ b/Python/legacy_tracing.c @@ -244,7 +244,7 @@ sys_trace_line_func( "Missing frame when calling trace function."); return NULL; } - assert(args[0] == (PyObject *)frame->f_frame->f_code); + assert(args[0] == (PyObject *)_PyFrame_GetCode(frame->f_frame)); if (frame ->f_last_traced_line == line) { /* Already traced this line */ Py_RETURN_NONE; @@ -279,7 +279,7 @@ sys_trace_jump_func( } PyCodeObject *code = (PyCodeObject *)args[0]; assert(PyCode_Check(code)); - assert(code == frame->f_frame->f_code); + assert(code == _PyFrame_GetCode(frame->f_frame)); /* We can call _Py_Instrumentation_GetLine because we always set * line events for tracing */ int to_line = _Py_Instrumentation_GetLine(code, to); @@ -309,7 +309,7 @@ sys_trace_exception_handled( PyFrameObject *frame = PyEval_GetFrame(); PyCodeObject *code = (PyCodeObject *)args[0]; assert(PyCode_Check(code)); - assert(code == frame->f_frame->f_code); + assert(code == _PyFrame_GetCode(frame->f_frame)); assert(PyLong_Check(args[1])); int offset = _PyLong_AsInt(args[1])/sizeof(_Py_CODEUNIT); /* We can call _Py_Instrumentation_GetLine because we always set diff --git a/Python/perf_trampoline.c b/Python/perf_trampoline.c index 1957ab82c33951..a4ab2e6e2a3f80 100644 --- a/Python/perf_trampoline.c +++ b/Python/perf_trampoline.c @@ -377,7 +377,7 @@ py_trampoline_evaluator(PyThreadState *ts, _PyInterpreterFrame *frame, perf_status == PERF_STATUS_NO_INIT) { goto default_eval; } - PyCodeObject *co = frame->f_code; + PyCodeObject *co = _PyFrame_GetCode(frame); py_trampoline f = NULL; assert(extra_code_index != -1); int ret = _PyCode_GetExtra((PyObject *)co, extra_code_index, (void **)&f); diff --git a/Python/traceback.c b/Python/traceback.c index 097f69c76abfe1..0e3dbb6d3293eb 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -789,7 +789,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 = _PyFrame_GetCode(frame->f_frame); const Py_ssize_t source_line_len = PyUnicode_GET_LENGTH(source_line); int start_line; @@ -1168,7 +1168,7 @@ _Py_DumpASCII(int fd, PyObject *text) static void dump_frame(int fd, _PyInterpreterFrame *frame) { - PyCodeObject *code = frame->f_code; + PyCodeObject *code =_PyFrame_GetCode(frame); PUTS(fd, " File "); if (code->co_filename != NULL && PyUnicode_Check(code->co_filename)) diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py index e38bd59e20a305..0ad05e22250cc6 100755 --- a/Tools/gdb/libpython.py +++ b/Tools/gdb/libpython.py @@ -1034,14 +1034,18 @@ def __init__(self, gdbval): self._gdbval = gdbval if not self.is_optimized_out(): - self.co = self._f_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.co_nlocals = int_from_int(self.co.field('co_nlocals')) - pnames = self.co.field('co_localsplusnames') - self.co_localsplusnames = PyTupleObjectPtr.from_pyobject_ptr(pnames) + try: + self.co = self._f_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.co_nlocals = int_from_int(self.co.field('co_nlocals')) + pnames = self.co.field('co_localsplusnames') + self.co_localsplusnames = PyTupleObjectPtr.from_pyobject_ptr(pnames) + self._is_code = True + except: + self._is_code = False def is_optimized_out(self): return self._gdbval.is_optimized_out @@ -1076,7 +1080,10 @@ def _f_builtins(self): return self._f_special("f_builtins") def _f_code(self): - return self._f_special("f_code", PyCodeObjectPtr.from_pyobject_ptr) + return self._f_special("f_executable", PyCodeObjectPtr.from_pyobject_ptr) + + def _f_executable(self): + return self._f_special("f_executable", PyObjectPtr.from_pyobject_ptr) def _f_nlocalsplus(self): return self._f_special("nlocalsplus", int_from_int) From 5a256101ce4ab5a86cd41c7de8d614c1e1eeb064 Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Fri, 5 May 2023 15:48:30 +0100 Subject: [PATCH 2/7] Add table describing possible executable classes for out-of-process debuggers. --- Include/internal/pycore_frame.h | 8 ++++++++ Python/frame.c | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/Include/internal/pycore_frame.h b/Include/internal/pycore_frame.h index e0301ea7bc2f11..34ed732c45a011 100644 --- a/Include/internal/pycore_frame.h +++ b/Include/internal/pycore_frame.h @@ -283,6 +283,14 @@ PyGenObject *_PyFrame_GetGenerator(_PyInterpreterFrame *frame) return (PyGenObject *)(((char *)frame) - offset_in_gen); } +#define PY_EXECUTABLE_KIND_SKIP 0 +#define PY_EXECUTABLE_KIND_PY_FUNCTION 1 +#define PY_EXECUTABLE_KIND_BUILTIN_FUNCTION 3 +#define PY_EXECUTABLE_KIND_METHOD_DESCRIPTOR 4 +#define PY_EXECUTABLE_KINDS 5 + +const PyAPI_DATA(PyTypeObject *) const PyUnstable_ExecutableKinds[PY_EXECUTABLE_KINDS+1]; + #ifdef __cplusplus } #endif diff --git a/Python/frame.c b/Python/frame.c index bffd705d1298f7..9b954cbd9978e7 100644 --- a/Python/frame.c +++ b/Python/frame.c @@ -150,3 +150,11 @@ _PyInterpreterFrame_GetLine(_PyInterpreterFrame *frame) int addr = _PyInterpreterFrame_LASTI(frame) * sizeof(_Py_CODEUNIT); return PyCode_Addr2Line(_PyFrame_GetCode(frame), addr); } + +const PyTypeObject *const PyUnstable_ExecutableKinds[PY_EXECUTABLE_KINDS+1] = { + [PY_EXECUTABLE_KIND_SKIP] = &_PyNone_Type, + [PY_EXECUTABLE_KIND_PY_FUNCTION] = &PyCode_Type, + [PY_EXECUTABLE_KIND_BUILTIN_FUNCTION] = &PyMethod_Type, + [PY_EXECUTABLE_KIND_METHOD_DESCRIPTOR] = &PyMethodDescr_Type, + [PY_EXECUTABLE_KINDS] = NULL, +}; From 067ca16ae2ca319203fcb97509b6690a1562e980 Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Fri, 5 May 2023 16:08:46 +0100 Subject: [PATCH 3/7] Remove shim code object creation code as it is no longer needed. --- Include/internal/pycore_code.h | 13 ------ Include/internal/pycore_frame.h | 2 +- Include/internal/pycore_interp.h | 1 - Objects/codeobject.c | 73 -------------------------------- Python/ceval.c | 11 +++-- Python/pylifecycle.c | 20 --------- Python/pystate.c | 1 - 7 files changed, 9 insertions(+), 112 deletions(-) diff --git a/Include/internal/pycore_code.h b/Include/internal/pycore_code.h index 86fd48b63ef8e4..19091826ad1145 100644 --- a/Include/internal/pycore_code.h +++ b/Include/internal/pycore_code.h @@ -449,19 +449,6 @@ adaptive_counter_backoff(uint16_t counter) { return adaptive_counter_bits(value, backoff); } - -/* Line array cache for tracing */ - -typedef struct _PyShimCodeDef { - const uint8_t *code; - int codelen; - int stacksize; - const char *cname; -} _PyShimCodeDef; - -extern PyCodeObject * -_Py_MakeShimCode(const _PyShimCodeDef *code); - extern uint32_t _Py_next_func_version; diff --git a/Include/internal/pycore_frame.h b/Include/internal/pycore_frame.h index 34ed732c45a011..7a69c79e536ae6 100644 --- a/Include/internal/pycore_frame.h +++ b/Include/internal/pycore_frame.h @@ -289,7 +289,7 @@ PyGenObject *_PyFrame_GetGenerator(_PyInterpreterFrame *frame) #define PY_EXECUTABLE_KIND_METHOD_DESCRIPTOR 4 #define PY_EXECUTABLE_KINDS 5 -const PyAPI_DATA(PyTypeObject *) const PyUnstable_ExecutableKinds[PY_EXECUTABLE_KINDS+1]; +PyAPI_DATA(const PyTypeObject *) const PyUnstable_ExecutableKinds[PY_EXECUTABLE_KINDS+1]; #ifdef __cplusplus } diff --git a/Include/internal/pycore_interp.h b/Include/internal/pycore_interp.h index 7276ce35ba68f0..c802ebca5f3bf7 100644 --- a/Include/internal/pycore_interp.h +++ b/Include/internal/pycore_interp.h @@ -152,7 +152,6 @@ struct _is { struct ast_state ast; struct types_state types; struct callable_cache callable_cache; - PyCodeObject *interpreter_trampoline; _Py_Monitors monitors; bool f_opcode_trace_set; diff --git a/Objects/codeobject.c b/Objects/codeobject.c index 9b54c610581174..554664d2e7290f 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -2324,76 +2324,3 @@ _PyStaticCode_Init(PyCodeObject *co) } #define MAX_CODE_UNITS_PER_LOC_ENTRY 8 - -PyCodeObject * -_Py_MakeShimCode(const _PyShimCodeDef *codedef) -{ - PyObject *name = NULL; - PyObject *co_code = NULL; - PyObject *lines = NULL; - PyCodeObject *codeobj = NULL; - uint8_t *loc_table = NULL; - - name = _PyUnicode_FromASCII(codedef->cname, strlen(codedef->cname)); - if (name == NULL) { - goto cleanup; - } - co_code = PyBytes_FromStringAndSize( - (const char *)codedef->code, codedef->codelen); - if (co_code == NULL) { - goto cleanup; - } - int code_units = codedef->codelen / sizeof(_Py_CODEUNIT); - int loc_entries = (code_units + MAX_CODE_UNITS_PER_LOC_ENTRY - 1) / - MAX_CODE_UNITS_PER_LOC_ENTRY; - loc_table = PyMem_Malloc(loc_entries); - if (loc_table == NULL) { - PyErr_NoMemory(); - goto cleanup; - } - for (int i = 0; i < loc_entries-1; i++) { - loc_table[i] = 0x80 | (PY_CODE_LOCATION_INFO_NONE << 3) | 7; - code_units -= MAX_CODE_UNITS_PER_LOC_ENTRY; - } - assert(loc_entries > 0); - assert(code_units > 0 && code_units <= MAX_CODE_UNITS_PER_LOC_ENTRY); - loc_table[loc_entries-1] = 0x80 | - (PY_CODE_LOCATION_INFO_NONE << 3) | (code_units-1); - lines = PyBytes_FromStringAndSize((const char *)loc_table, loc_entries); - PyMem_Free(loc_table); - if (lines == NULL) { - goto cleanup; - } - _Py_DECLARE_STR(shim_name, ""); - struct _PyCodeConstructor con = { - .filename = &_Py_STR(shim_name), - .name = name, - .qualname = name, - .flags = CO_NEWLOCALS | CO_OPTIMIZED, - - .code = co_code, - .firstlineno = 1, - .linetable = lines, - - .consts = (PyObject *)&_Py_SINGLETON(tuple_empty), - .names = (PyObject *)&_Py_SINGLETON(tuple_empty), - - .localsplusnames = (PyObject *)&_Py_SINGLETON(tuple_empty), - .localspluskinds = (PyObject *)&_Py_SINGLETON(bytes_empty), - - .argcount = 0, - .posonlyargcount = 0, - .kwonlyargcount = 0, - - .stacksize = codedef->stacksize, - - .exceptiontable = (PyObject *)&_Py_SINGLETON(bytes_empty), - }; - - codeobj = _PyCode_New(&con); -cleanup: - Py_XDECREF(name); - Py_XDECREF(co_code); - Py_XDECREF(lines); - return codeobj; -} diff --git a/Python/ceval.c b/Python/ceval.c index db0762cdd4305e..b8f55e13ada40b 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -623,6 +623,13 @@ static inline void _Py_LeaveRecursiveCallPy(PyThreadState *tstate) { tstate->py_recursion_remaining++; } +static const _Py_CODEUNIT _Py_INTERPRETER_TRAMPOLINE_INSTRUCTIONS[] = { + /* Put a NOP at the start, so that the IP points into + * the code, rather than before it */ + { .op.code = NOP, .op.arg = 0 }, + { .op.code = INTERPRETER_EXIT, .op.arg = 0 }, + { .op.code = RESUME, .op.arg = 0 } +}; /* Disable unused label warnings. They are handy for debugging, even if computed gotos aren't used. */ @@ -671,7 +678,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int cframe.previous = prev_cframe; tstate->cframe = &cframe; - assert(tstate->interp->interpreter_trampoline != NULL); #ifdef Py_DEBUG /* Set these to invalid but identifiable values for debugging. */ entry_frame.f_funcobj = (PyObject*)0xaaa0; @@ -681,8 +687,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int entry_frame.f_builtins = (PyObject*)0xaaa4; #endif entry_frame.f_executable = Py_None; - entry_frame.prev_instr = - _PyCode_CODE(tstate->interp->interpreter_trampoline); + entry_frame.prev_instr = (_Py_CODEUNIT *)_Py_INTERPRETER_TRAMPOLINE_INSTRUCTIONS; entry_frame.stacktop = 0; entry_frame.owner = FRAME_OWNED_BY_CSTACK; entry_frame.return_offset = 0; diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 97957d3f17e6db..2e304ec41a5e21 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -729,22 +729,6 @@ pycore_init_types(PyInterpreterState *interp) return _PyStatus_OK(); } -static const uint8_t INTERPRETER_TRAMPOLINE_INSTRUCTIONS[] = { - /* Put a NOP at the start, so that the IP points into - * the code, rather than before it */ - NOP, 0, - INTERPRETER_EXIT, 0, - /* RESUME at end makes sure that the frame appears incomplete */ - RESUME, 0 -}; - -static const _PyShimCodeDef INTERPRETER_TRAMPOLINE_CODEDEF = { - INTERPRETER_TRAMPOLINE_INSTRUCTIONS, - sizeof(INTERPRETER_TRAMPOLINE_INSTRUCTIONS), - 1, - "" -}; - static PyStatus pycore_init_builtins(PyThreadState *tstate) { @@ -778,10 +762,6 @@ pycore_init_builtins(PyThreadState *tstate) PyObject *object__getattribute__ = _PyType_Lookup(&PyBaseObject_Type, &_Py_ID(__getattribute__)); assert(object__getattribute__); interp->callable_cache.object__getattribute__ = object__getattribute__; - interp->interpreter_trampoline = _Py_MakeShimCode(&INTERPRETER_TRAMPOLINE_CODEDEF); - if (interp->interpreter_trampoline == NULL) { - return _PyStatus_ERR("failed to create interpreter trampoline."); - } if (_PyBuiltins_AddExceptions(bimod) < 0) { return _PyStatus_ERR("failed to add exceptions to builtins"); } diff --git a/Python/pystate.c b/Python/pystate.c index f09d37657f9c27..eece063f98e6c9 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -886,7 +886,6 @@ interpreter_clear(PyInterpreterState *interp, PyThreadState *tstate) PyDict_Clear(interp->builtins); Py_CLEAR(interp->sysdict); Py_CLEAR(interp->builtins); - Py_CLEAR(interp->interpreter_trampoline); for (int i=0; i < DICT_MAX_WATCHERS; i++) { interp->dict_state.watchers[i] = NULL; From 5f083ac69ef273fd0d2f1d410e69ade3a0c5c8e7 Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Fri, 5 May 2023 16:16:50 +0100 Subject: [PATCH 4/7] Make lltrace a bit more robust w.r.t. non-standard frames. --- Python/ceval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/ceval.c b/Python/ceval.c index b8f55e13ada40b..df322d1e0149c8 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -152,7 +152,7 @@ static void lltrace_resume_frame(_PyInterpreterFrame *frame) { PyObject *fobj = frame->f_funcobj; - if (frame->owner == FRAME_OWNED_BY_CSTACK || + if (!PyCode_Check(frame->f_executable) || fobj == NULL || !PyFunction_Check(fobj) ) { From 1f4a4f9d0b7f68888d0f4d75378791f85f4ad9c3 Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Fri, 5 May 2023 16:18:17 +0100 Subject: [PATCH 5/7] Address code review --- Python/ceval_macros.h | 4 ++-- Tools/gdb/libpython.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Python/ceval_macros.h b/Python/ceval_macros.h index 29ae76f050372b..cd08ae73edaad5 100644 --- a/Python/ceval_macros.h +++ b/Python/ceval_macros.h @@ -279,8 +279,8 @@ GETITEM(PyObject *v, Py_ssize_t i) { #define GLOBALS() frame->f_globals #define BUILTINS() frame->f_builtins #define LOCALS() frame->f_locals -#define CONSTS() ((PyCodeObject *)frame->f_executable)->co_consts -#define NAMES() ((PyCodeObject *)frame->f_executable)->co_names +#define CONSTS() _PyFrame_GetCode(frame)->co_consts +#define NAMES() _PyFrame_GetCode(frame)->co_names #define DTRACE_FUNCTION_ENTRY() \ if (PyDTrace_FUNCTION_ENTRY_ENABLED()) { \ diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py index 0ad05e22250cc6..d74e71fa5a58c8 100755 --- a/Tools/gdb/libpython.py +++ b/Tools/gdb/libpython.py @@ -1083,7 +1083,7 @@ def _f_code(self): return self._f_special("f_executable", PyCodeObjectPtr.from_pyobject_ptr) def _f_executable(self): - return self._f_special("f_executable", PyObjectPtr.from_pyobject_ptr) + return self._f_special("f_executable") def _f_nlocalsplus(self): return self._f_special("nlocalsplus", int_from_int) From d037c5054deaca6512c7d96ef70f71aa9bf3defa Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Thu, 8 Jun 2023 21:31:02 +0100 Subject: [PATCH 6/7] Keep Tools/c-analyzer/check-c-globals.py happy --- Tools/c-analyzer/cpython/ignored.tsv | 1 + 1 file changed, 1 insertion(+) diff --git a/Tools/c-analyzer/cpython/ignored.tsv b/Tools/c-analyzer/cpython/ignored.tsv index 607976f5afdc68..0238406d097fcb 100644 --- a/Tools/c-analyzer/cpython/ignored.tsv +++ b/Tools/c-analyzer/cpython/ignored.tsv @@ -321,6 +321,7 @@ Parser/parser.c - soft_keywords - Parser/tokenizer.c - type_comment_prefix - Python/ast_opt.c fold_unaryop ops - Python/ceval.c - binary_ops - +Python/ceval.c - _Py_INTERPRETER_TRAMPOLINE_INSTRUCTIONS - Python/codecs.c - Py_hexdigits - Python/codecs.c - ucnhash_capi - Python/codecs.c _PyCodecRegistry_Init methods - From cd79fbea69c0a969ae0910013ea05d1855045ab6 Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Fri, 9 Jun 2023 10:48:31 +0100 Subject: [PATCH 7/7] Add news. --- .../2023-06-09-10-48-17.gh-issue-100987.mK-xny.rst | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2023-06-09-10-48-17.gh-issue-100987.mK-xny.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-06-09-10-48-17.gh-issue-100987.mK-xny.rst b/Misc/NEWS.d/next/Core and Builtins/2023-06-09-10-48-17.gh-issue-100987.mK-xny.rst new file mode 100644 index 00000000000000..e25789e711c35d --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2023-06-09-10-48-17.gh-issue-100987.mK-xny.rst @@ -0,0 +1,4 @@ +Allow objects other than code objects as the "executable" in internal +frames. In the long term, this can help tools like Cython and PySpy interact +more efficiently. In the shorter term, it allows us to perform some +optimizations more simply.