@@ -1735,16 +1735,10 @@ compiler_body(struct compiler *c, location loc, asdl_stmt_seq *stmts)
1735
1735
static int
1736
1736
compiler_codegen (struct compiler * c , mod_ty mod )
1737
1737
{
1738
- _Py_DECLARE_STR (anon_module , "<module>" );
1739
- RETURN_IF_ERROR (
1740
- compiler_enter_scope (c , & _Py_STR (anon_module ), COMPILER_SCOPE_MODULE ,
1741
- mod , 1 ));
1742
-
1743
1738
location loc = LOCATION (1 , 1 , 0 , 0 );
1744
1739
switch (mod -> kind ) {
1745
1740
case Module_kind :
1746
1741
if (compiler_body (c , loc , mod -> v .Module .body ) < 0 ) {
1747
- compiler_exit_scope (c );
1748
1742
return ERROR ;
1749
1743
}
1750
1744
break ;
@@ -1753,10 +1747,10 @@ compiler_codegen(struct compiler *c, mod_ty mod)
1753
1747
ADDOP (c , loc , SETUP_ANNOTATIONS );
1754
1748
}
1755
1749
c -> c_interactive = 1 ;
1756
- VISIT_SEQ_IN_SCOPE (c , stmt , mod -> v .Interactive .body );
1750
+ VISIT_SEQ (c , stmt , mod -> v .Interactive .body );
1757
1751
break ;
1758
1752
case Expression_kind :
1759
- VISIT_IN_SCOPE (c , expr , mod -> v .Expression .body );
1753
+ VISIT (c , expr , mod -> v .Expression .body );
1760
1754
break ;
1761
1755
default :
1762
1756
PyErr_Format (PyExc_SystemError ,
@@ -1767,14 +1761,29 @@ compiler_codegen(struct compiler *c, mod_ty mod)
1767
1761
return SUCCESS ;
1768
1762
}
1769
1763
1764
+ static int
1765
+ compiler_enter_anonymous_scope (struct compiler * c , mod_ty mod )
1766
+ {
1767
+ _Py_DECLARE_STR (anon_module , "<module>" );
1768
+ RETURN_IF_ERROR (
1769
+ compiler_enter_scope (c , & _Py_STR (anon_module ), COMPILER_SCOPE_MODULE ,
1770
+ mod , 1 ));
1771
+ return SUCCESS ;
1772
+ }
1773
+
1770
1774
static PyCodeObject *
1771
1775
compiler_mod (struct compiler * c , mod_ty mod )
1772
1776
{
1777
+ PyCodeObject * co = NULL ;
1773
1778
int addNone = mod -> kind != Expression_kind ;
1774
- if (compiler_codegen (c , mod ) < 0 ) {
1779
+ if (compiler_enter_anonymous_scope (c , mod ) < 0 ) {
1775
1780
return NULL ;
1776
1781
}
1777
- PyCodeObject * co = optimize_and_assemble (c , addNone );
1782
+ if (compiler_codegen (c , mod ) < 0 ) {
1783
+ goto finally ;
1784
+ }
1785
+ co = optimize_and_assemble (c , addNone );
1786
+ finally :
1778
1787
compiler_exit_scope (c );
1779
1788
return co ;
1780
1789
}
@@ -7920,15 +7929,20 @@ _PyCompile_CodeGen(PyObject *ast, PyObject *filename, PyCompilerFlags *pflags,
7920
7929
return NULL ;
7921
7930
}
7922
7931
7932
+ metadata = PyDict_New ();
7933
+ if (metadata == NULL ) {
7934
+ return NULL ;
7935
+ }
7936
+
7937
+ if (compiler_enter_anonymous_scope (c , mod ) < 0 ) {
7938
+ return NULL ;
7939
+ }
7923
7940
if (compiler_codegen (c , mod ) < 0 ) {
7924
7941
goto finally ;
7925
7942
}
7926
7943
7927
7944
_PyCompile_CodeUnitMetadata * umd = & c -> u -> u_metadata ;
7928
- metadata = PyDict_New ();
7929
- if (metadata == NULL ) {
7930
- goto finally ;
7931
- }
7945
+
7932
7946
#define SET_MATADATA_ITEM (key , value ) \
7933
7947
if (value != NULL) { \
7934
7948
if (PyDict_SetItemString(metadata, key, value) < 0) goto finally; \
0 commit comments