@@ -1655,16 +1655,10 @@ compiler_body(struct compiler *c, location loc, asdl_stmt_seq *stmts)
1655
1655
static int
1656
1656
compiler_codegen (struct compiler * c , mod_ty mod )
1657
1657
{
1658
- _Py_DECLARE_STR (anon_module , "<module>" );
1659
- RETURN_IF_ERROR (
1660
- compiler_enter_scope (c , & _Py_STR (anon_module ), COMPILER_SCOPE_MODULE ,
1661
- mod , 1 ));
1662
-
1663
1658
location loc = LOCATION (1 , 1 , 0 , 0 );
1664
1659
switch (mod -> kind ) {
1665
1660
case Module_kind :
1666
1661
if (compiler_body (c , loc , mod -> v .Module .body ) < 0 ) {
1667
- compiler_exit_scope (c );
1668
1662
return ERROR ;
1669
1663
}
1670
1664
break ;
@@ -1691,6 +1685,11 @@ static PyCodeObject *
1691
1685
compiler_mod (struct compiler * c , mod_ty mod )
1692
1686
{
1693
1687
int addNone = mod -> kind != Expression_kind ;
1688
+ _Py_DECLARE_STR (anon_module , "<module>" );
1689
+ if (compiler_enter_scope (c , & _Py_STR (anon_module ), COMPILER_SCOPE_MODULE ,
1690
+ mod , 1 ) < 0 ) {
1691
+ return NULL ;
1692
+ }
1694
1693
if (compiler_codegen (c , mod ) < 0 ) {
1695
1694
return NULL ;
1696
1695
}
@@ -7261,27 +7260,33 @@ _PyCompile_CodeGen(PyObject *ast, PyObject *filename, PyCompilerFlags *pflags,
7261
7260
int optimize )
7262
7261
{
7263
7262
PyObject * res = NULL ;
7263
+ struct compiler * c = NULL ;
7264
+ PyArena * arena = NULL ;
7264
7265
7265
7266
if (!PyAST_Check (ast )) {
7266
7267
PyErr_SetString (PyExc_TypeError , "expected an AST" );
7267
7268
return NULL ;
7268
7269
}
7269
7270
7270
- PyArena * arena = _PyArena_New ();
7271
+ arena = _PyArena_New ();
7271
7272
if (arena == NULL ) {
7272
- return NULL ;
7273
+ goto end ;
7273
7274
}
7274
7275
7275
7276
mod_ty mod = PyAST_obj2mod (ast , arena , 0 /* exec */ );
7276
7277
if (mod == NULL || !_PyAST_Validate (mod )) {
7277
- _PyArena_Free (arena );
7278
- return NULL ;
7278
+ goto end ;
7279
7279
}
7280
7280
7281
- struct compiler * c = new_compiler (mod , filename , pflags , optimize , arena );
7281
+ c = new_compiler (mod , filename , pflags , optimize , arena );
7282
7282
if (c == NULL ) {
7283
- _PyArena_Free (arena );
7284
- return NULL ;
7283
+ goto end ;
7284
+ }
7285
+
7286
+ _Py_DECLARE_STR (anon_module , "<module>" );
7287
+ if (compiler_enter_scope (c , & _Py_STR (anon_module ), COMPILER_SCOPE_MODULE ,
7288
+ mod , 1 ) < 0 ) {
7289
+ goto end ;
7285
7290
}
7286
7291
7287
7292
if (compiler_codegen (c , mod ) < 0 ) {
@@ -7292,8 +7297,13 @@ _PyCompile_CodeGen(PyObject *ast, PyObject *filename, PyCompilerFlags *pflags,
7292
7297
7293
7298
finally :
7294
7299
compiler_exit_scope (c );
7295
- compiler_free (c );
7296
- _PyArena_Free (arena );
7300
+ end :
7301
+ if (c != NULL ) {
7302
+ compiler_free (c );
7303
+ }
7304
+ if (arena != NULL ) {
7305
+ _PyArena_Free (arena );
7306
+ }
7297
7307
return res ;
7298
7308
}
7299
7309
0 commit comments