Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Don't scan backwards in bytecode when looking for execution context.
  • Loading branch information
markshannon committed Mar 15, 2022
commit 1d67c85c84905cd6e8b2bde456bd730da1ecc29b
7 changes: 5 additions & 2 deletions Objects/genobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,12 @@ _PyGen_yf(PyGenObject *gen)
assert(code[0] != SEND);
return NULL;
}

if (code[(frame->f_lasti-1)*sizeof(_Py_CODEUNIT)] != SEND || frame->stacktop < 0)
int opcode = code[(frame->f_lasti+1)*sizeof(_Py_CODEUNIT)];
int oparg = code[(frame->f_lasti+1)*sizeof(_Py_CODEUNIT)+1];
if (opcode != RESUME || oparg < 2) {
/* Not in a yield from */
return NULL;
}
yf = _PyFrame_StackPeek(frame);
Py_INCREF(yf);
}
Expand Down
20 changes: 7 additions & 13 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -5443,7 +5433,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
#else
case DO_TRACING: {
#endif
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) {
Expand Down Expand Up @@ -6725,9 +6715,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 {
Expand Down