diff options
author | Mark Shannon <mark@hotpy.org> | 2022-03-16 00:08:37 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-16 00:08:37 (GMT) |
commit | 49e1e1e1bd59cac1855b1ef4dec05d649ebcd81a (patch) | |
tree | 469b96fea3812743db73838530169650576cfd11 /Python/ceval.c | |
parent | a4674f0194067a801f6c6bdb4fc6448e3a40e069 (diff) | |
download | cpython-49e1e1e1bd59cac1855b1ef4dec05d649ebcd81a.zip cpython-49e1e1e1bd59cac1855b1ef4dec05d649ebcd81a.tar.gz cpython-49e1e1e1bd59cac1855b1ef4dec05d649ebcd81a.tar.bz2 |
bpo-46841: Don't scan backwards in bytecode (GH-31901)
Diffstat (limited to 'Python/ceval.c')
-rw-r--r-- | Python/ceval.c | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index d0fc31e..81759ad 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -1565,16 +1565,6 @@ trace_function_exit(PyThreadState *tstate, _PyInterpreterFrame *frame, PyObject return 0; } -static int -skip_backwards_over_extended_args(PyCodeObject *code, int offset) -{ - _Py_CODEUNIT *instrs = (_Py_CODEUNIT *)PyBytes_AS_STRING(code->co_code); - while (offset > 0 && _Py_OPCODE(instrs[offset-1]) == EXTENDED_ARG) { - offset--; - } - return offset; -} - static _PyInterpreterFrame * pop_frame(PyThreadState *tstate, _PyInterpreterFrame *frame) { @@ -5445,7 +5435,7 @@ handle_eval_breaker: #endif { if (tstate->tracing == 0) { - int instr_prev = skip_backwards_over_extended_args(frame->f_code, frame->f_lasti); + int instr_prev = frame->f_lasti; frame->f_lasti = INSTR_OFFSET(); TRACING_NEXTOPARG(); if (opcode == RESUME) { @@ -6737,9 +6727,13 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj, then call the trace function if we're tracing source lines. */ initialize_trace_info(&tstate->trace_info, frame); - _Py_CODEUNIT prev = ((_Py_CODEUNIT *)PyBytes_AS_STRING(frame->f_code->co_code))[instr_prev]; + int entry_point = 0; + _Py_CODEUNIT *code = (_Py_CODEUNIT *)PyBytes_AS_STRING(frame->f_code->co_code); + while (_Py_OPCODE(code[entry_point]) != RESUME) { + entry_point++; + } int lastline; - if (_Py_OPCODE(prev) == RESUME && _Py_OPARG(prev) == 0) { + if (instr_prev <= entry_point) { lastline = -1; } else { |