]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-151112: Fix crash in `compiler_mod()` when entering the current compilation unit...
authorStan Ulbrych <stan@python.org>
Thu, 11 Jun 2026 14:52:11 +0000 (15:52 +0100)
committerGitHub <noreply@github.com>
Thu, 11 Jun 2026 14:52:11 +0000 (15:52 +0100)
Python/compile.c

index eb9fc827bea40a8000b2a6f6a1ae206a81c8439f..e223ef42a42e22b6bce39be3ad90f5bc0be6e93e 100644 (file)
@@ -893,12 +893,15 @@ 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;
     }
     co = _PyCompile_OptimizeAndAssemble(c, addNone);
 finally:
-    _PyCompile_ExitScope(c);
+    if (c->u != NULL) {
+        _PyCompile_ExitScope(c);
+    }
     return co;
 }