Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure c->u was NULL when we entered compiler_mod? Can we assert that at the top of the function?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in _PyAST_Compile we initialise c:

cpython/Python/compile.c

Lines 1527 to 1532 in 9fd1a12

compiler *c = new_compiler(mod, filename, pflags, optimize, arena, module);
if (c == NULL) {
return NULL;
}
PyCodeObject *co = compiler_mod(c, mod);

But new_compiler doesn't set c->u.

_PyCompile_ExitScope(c);
}
return co;
}

Expand Down
Loading