Skip to content

Commit 68d8bb9

Browse files
StanFromIrelandmiss-islington
authored andcommitted
gh-151112: Fix crash in compiler_mod() when entering the current compilation unit fails (GH-151234)
(cherry picked from commit 937d89c) Co-authored-by: Stan Ulbrych <stan@python.org>
1 parent bbcd28e commit 68d8bb9

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

Python/compile.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,12 +853,15 @@ compiler_mod(compiler *c, mod_ty mod)
853853
{
854854
PyCodeObject *co = NULL;
855855
int addNone = mod->kind != Expression_kind;
856+
assert(c->u == NULL);
856857
if (compiler_codegen(c, mod) < 0) {
857858
goto finally;
858859
}
859860
co = _PyCompile_OptimizeAndAssemble(c, addNone);
860861
finally:
861-
_PyCompile_ExitScope(c);
862+
if (c->u != NULL) {
863+
_PyCompile_ExitScope(c);
864+
}
862865
return co;
863866
}
864867

0 commit comments

Comments
 (0)