Skip to content

Commit d90ecaf

Browse files
committed
Don't trace into functions if func_version != co_version
Seems to fix test_opcache, playing games with func.__code__ = func.__code__.replace().
1 parent 8d95157 commit d90ecaf

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Python/optimizer.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,14 @@ translate_bytecode_to_trace(
684684
ADD_TO_TRACE(SAVE_IP, 0, 0);
685685
goto done;
686686
}
687+
if (new_code->co_version != func_version) {
688+
// func.__code__ was updated.
689+
// Perhaps it may happen again, so don't bother tracing.
690+
// TODO: Reason about this -- is it better to bail or not?
691+
DPRINTF(2, "Bailing because co_version != func_version\n");
692+
ADD_TO_TRACE(SAVE_IP, 0, 0);
693+
goto done;
694+
}
687695
// Increment IP to the return address
688696
instr += _PyOpcode_Caches[_PyOpcode_Deopt[opcode]] + 1;
689697
TRACE_STACK_PUSH();

0 commit comments

Comments
 (0)