Skip to content

Commit 958f653

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 dc5ebe3 commit 958f653

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
@@ -893,12 +893,15 @@ compiler_mod(compiler *c, mod_ty mod)
893893
{
894894
PyCodeObject *co = NULL;
895895
int addNone = mod->kind != Expression_kind;
896+
assert(c->u == NULL);
896897
if (compiler_codegen(c, mod) < 0) {
897898
goto finally;
898899
}
899900
co = _PyCompile_OptimizeAndAssemble(c, addNone);
900901
finally:
901-
_PyCompile_ExitScope(c);
902+
if (c->u != NULL) {
903+
_PyCompile_ExitScope(c);
904+
}
902905
return co;
903906
}
904907

0 commit comments

Comments
 (0)