@@ -1735,16 +1735,10 @@ compiler_body(struct compiler *c, location loc, asdl_stmt_seq *stmts)
17351735static int
17361736compiler_codegen (struct compiler * c , mod_ty mod )
17371737{
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-
17431738 location loc = LOCATION (1 , 1 , 0 , 0 );
17441739 switch (mod -> kind ) {
17451740 case Module_kind :
17461741 if (compiler_body (c , loc , mod -> v .Module .body ) < 0 ) {
1747- compiler_exit_scope (c );
17481742 return ERROR ;
17491743 }
17501744 break ;
@@ -1753,10 +1747,10 @@ compiler_codegen(struct compiler *c, mod_ty mod)
17531747 ADDOP (c , loc , SETUP_ANNOTATIONS );
17541748 }
17551749 c -> c_interactive = 1 ;
1756- VISIT_SEQ_IN_SCOPE (c , stmt , mod -> v .Interactive .body );
1750+ VISIT_SEQ (c , stmt , mod -> v .Interactive .body );
17571751 break ;
17581752 case Expression_kind :
1759- VISIT_IN_SCOPE (c , expr , mod -> v .Expression .body );
1753+ VISIT (c , expr , mod -> v .Expression .body );
17601754 break ;
17611755 default :
17621756 PyErr_Format (PyExc_SystemError ,
@@ -1767,14 +1761,29 @@ compiler_codegen(struct compiler *c, mod_ty mod)
17671761 return SUCCESS ;
17681762}
17691763
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+
17701774static PyCodeObject *
17711775compiler_mod (struct compiler * c , mod_ty mod )
17721776{
1777+ PyCodeObject * co = NULL ;
17731778 int addNone = mod -> kind != Expression_kind ;
1774- if (compiler_codegen (c , mod ) < 0 ) {
1779+ if (compiler_enter_anonymous_scope (c , mod ) < 0 ) {
17751780 return NULL ;
17761781 }
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 :
17781787 compiler_exit_scope (c );
17791788 return co ;
17801789}
@@ -7920,15 +7929,20 @@ _PyCompile_CodeGen(PyObject *ast, PyObject *filename, PyCompilerFlags *pflags,
79207929 return NULL ;
79217930 }
79227931
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+ }
79237940 if (compiler_codegen (c , mod ) < 0 ) {
79247941 goto finally ;
79257942 }
79267943
79277944 _PyCompile_CodeUnitMetadata * umd = & c -> u -> u_metadata ;
7928- metadata = PyDict_New ();
7929- if (metadata == NULL ) {
7930- goto finally ;
7931- }
7945+
79327946#define SET_MATADATA_ITEM (key , value ) \
79337947 if (value != NULL) { \
79347948 if (PyDict_SetItemString(metadata, key, value) < 0) goto finally; \
0 commit comments