Skip to content

Commit 47d56f1

Browse files
committed
Handle trace stack underflow
1 parent f2a5bba commit 47d56f1

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
@@ -596,6 +596,14 @@ translate_bytecode_to_trace(
596596
// Reserve space for nuops (+ SAVE_IP + EXIT_TRACE)
597597
int nuops = expansion->nuops;
598598
RESERVE(nuops, 0);
599+
if (expansion->uops[nuops-1].uop == _POP_FRAME) {
600+
// Check for trace stack underflow now:
601+
// We can't bail e.g. in the middle of
602+
// LOAD_CONST + _POP_FRAME.
603+
if (trace_stack_depth == 0) {
604+
DPRINTF(2, "Trace stack underflow\n");
605+
goto done;}
606+
}
599607
uint32_t orig_oparg = oparg; // For OPARG_TOP/BOTTOM
600608
for (int i = 0; i < nuops; i++) {
601609
oparg = orig_oparg;

0 commit comments

Comments
 (0)