From 6c856bca161d26f26ce94b3794b4e60d9ec8267e Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Wed, 10 Jun 2026 11:30:32 +0100 Subject: [PATCH 1/2] Fix crash in `compiler_mod()` when entering the current compilation unit fails --- Python/compile.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Python/compile.c b/Python/compile.c index eb9fc827bea40a8..8202c27dd63012d 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -898,7 +898,9 @@ compiler_mod(compiler *c, mod_ty mod) } co = _PyCompile_OptimizeAndAssemble(c, addNone); finally: - _PyCompile_ExitScope(c); + if (c->u != NULL) { + _PyCompile_ExitScope(c); + } return co; } From 9f0e7d671dd43f6aee1f38b86b8458e27760a662 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Wed, 10 Jun 2026 17:32:48 +0100 Subject: [PATCH 2/2] Add assert for c->u being NULL --- Python/compile.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Python/compile.c b/Python/compile.c index 8202c27dd63012d..e223ef42a42e22b 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -893,6 +893,7 @@ compiler_mod(compiler *c, mod_ty mod) { PyCodeObject *co = NULL; int addNone = mod->kind != Expression_kind; + assert(c->u == NULL); if (compiler_codegen(c, mod) < 0) { goto finally; }