Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 70d28d8

Browse files
committed
Fix bad line events
1 parent 2312b53 commit 70d28d8

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

Python/bytecodes.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2182,7 +2182,14 @@ dummy_func(
21822182
JUMPBY(1-oparg);
21832183
#if ENABLE_SPECIALIZATION
21842184
here[1].cache += (1 << OPTIMIZER_BITS_IN_COUNTER);
2185-
if (here[1].cache > tstate->interp->optimizer_backedge_threshold) {
2185+
if (here[1].cache > tstate->interp->optimizer_backedge_threshold &&
2186+
// Double-check that the opcode isn't instrumented or something:
2187+
here->op.code == JUMP_BACKWARD &&
2188+
// _PyOptimizer_BackEdge is going to change frame->prev_instr,
2189+
// which breaks line event calculations:
2190+
next_instr->op.code != INSTRUMENTED_LINE
2191+
)
2192+
{
21862193
OBJECT_STAT_INC(optimization_attempts);
21872194
frame = _PyOptimizer_BackEdge(frame, here, next_instr, stack_pointer);
21882195
if (frame == NULL) {

Python/generated_cases.c.h

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/optimizer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ PyUnstable_SetOptimizer(_PyOptimizerObject *optimizer)
155155
_PyInterpreterFrame *
156156
_PyOptimizer_BackEdge(_PyInterpreterFrame *frame, _Py_CODEUNIT *src, _Py_CODEUNIT *dest, PyObject **stack_pointer)
157157
{
158+
assert(src->op.code == JUMP_BACKWARD);
158159
PyCodeObject *code = (PyCodeObject *)frame->f_executable;
159160
assert(PyCode_Check(code));
160161
PyInterpreterState *interp = _PyInterpreterState_GET();

0 commit comments

Comments
 (0)