@@ -1452,6 +1452,7 @@ symtable_enter_existing_block(struct symtable *st, PySTEntryObject* ste, bool ad
14521452
14531453 if (add_to_children && prev ) {
14541454 if (PyList_Append (prev -> ste_children , (PyObject * )ste ) < 0 ) {
1455+ symtable_exit_block (st );
14551456 return 0 ;
14561457 }
14571458 }
@@ -1463,21 +1464,27 @@ symtable_enter_block(struct symtable *st, identifier name, _Py_block_ty block,
14631464 void * ast , _Py_SourceLocation loc )
14641465{
14651466 PySTEntryObject * ste = ste_new (st , name , block , ast , loc );
1466- if (ste == NULL )
1467+ if (ste == NULL ) {
14671468 return 0 ;
1469+ }
14681470 int result = symtable_enter_existing_block (st , ste , /* add_to_children */ true);
14691471 Py_DECREF (ste );
1472+ if (result == 0 ) {
1473+ return 0 ;
1474+ }
14701475 if (block == AnnotationBlock || block == TypeVariableBlock || block == TypeAliasBlock ) {
14711476 _Py_DECLARE_STR (format , ".format" );
14721477 // We need to insert code that reads this "parameter" to the function.
14731478 if (!symtable_add_def (st , & _Py_STR (format ), DEF_PARAM , loc )) {
1479+ symtable_exit_block (st );
14741480 return 0 ;
14751481 }
14761482 if (!symtable_add_def (st , & _Py_STR (format ), USE , loc )) {
1483+ symtable_exit_block (st );
14771484 return 0 ;
14781485 }
14791486 }
1480- return result ;
1487+ return 1 ;
14811488}
14821489
14831490static long
@@ -1673,41 +1680,44 @@ symtable_enter_type_param_block(struct symtable *st, identifier name,
16731680 if (current_type == ClassBlock ) {
16741681 st -> st_cur -> ste_can_see_class_scope = 1 ;
16751682 if (!symtable_add_def (st , & _Py_ID (__classdict__ ), USE , loc )) {
1676- return 0 ;
1683+ goto error ;
16771684 }
16781685 }
16791686 if (kind == ClassDef_kind ) {
16801687 _Py_DECLARE_STR (type_params , ".type_params" );
16811688 // It gets "set" when we create the type params tuple and
16821689 // "used" when we build up the bases.
16831690 if (!symtable_add_def (st , & _Py_STR (type_params ), DEF_LOCAL , loc )) {
1684- return 0 ;
1691+ goto error ;
16851692 }
16861693 if (!symtable_add_def (st , & _Py_STR (type_params ), USE , loc )) {
1687- return 0 ;
1694+ goto error ;
16881695 }
16891696 // This is used for setting the generic base
16901697 _Py_DECLARE_STR (generic_base , ".generic_base" );
16911698 if (!symtable_add_def (st , & _Py_STR (generic_base ), DEF_LOCAL , loc )) {
1692- return 0 ;
1699+ goto error ;
16931700 }
16941701 if (!symtable_add_def (st , & _Py_STR (generic_base ), USE , loc )) {
1695- return 0 ;
1702+ goto error ;
16961703 }
16971704 }
16981705 if (has_defaults ) {
16991706 _Py_DECLARE_STR (defaults , ".defaults" );
17001707 if (!symtable_add_def (st , & _Py_STR (defaults ), DEF_PARAM , loc )) {
1701- return 0 ;
1708+ goto error ;
17021709 }
17031710 }
17041711 if (has_kwdefaults ) {
17051712 _Py_DECLARE_STR (kwdefaults , ".kwdefaults" );
17061713 if (!symtable_add_def (st , & _Py_STR (kwdefaults ), DEF_PARAM , loc )) {
1707- return 0 ;
1714+ goto error ;
17081715 }
17091716 }
17101717 return 1 ;
1718+ error :
1719+ symtable_exit_block (st );
1720+ return 0 ;
17111721}
17121722
17131723/* VISIT, VISIT_SEQ and VIST_SEQ_TAIL take an ASDL type as their second argument.
0 commit comments