@@ -1455,6 +1455,7 @@ symtable_enter_existing_block(struct symtable *st, PySTEntryObject* ste, bool ad
14551455
14561456 if (add_to_children && prev ) {
14571457 if (PyList_Append (prev -> ste_children , (PyObject * )ste ) < 0 ) {
1458+ symtable_exit_block (st );
14581459 return 0 ;
14591460 }
14601461 }
@@ -1466,21 +1467,27 @@ symtable_enter_block(struct symtable *st, identifier name, _Py_block_ty block,
14661467 void * ast , _Py_SourceLocation loc )
14671468{
14681469 PySTEntryObject * ste = ste_new (st , name , block , ast , loc );
1469- if (ste == NULL )
1470+ if (ste == NULL ) {
14701471 return 0 ;
1472+ }
14711473 int result = symtable_enter_existing_block (st , ste , /* add_to_children */ true);
14721474 Py_DECREF (ste );
1475+ if (result == 0 ) {
1476+ return 0 ;
1477+ }
14731478 if (block == AnnotationBlock || block == TypeVariableBlock || block == TypeAliasBlock ) {
14741479 _Py_DECLARE_STR (format , ".format" );
14751480 // We need to insert code that reads this "parameter" to the function.
14761481 if (!symtable_add_def (st , & _Py_STR (format ), DEF_PARAM , loc )) {
1482+ symtable_exit_block (st );
14771483 return 0 ;
14781484 }
14791485 if (!symtable_add_def (st , & _Py_STR (format ), USE , loc )) {
1486+ symtable_exit_block (st );
14801487 return 0 ;
14811488 }
14821489 }
1483- return result ;
1490+ return 1 ;
14841491}
14851492
14861493static long
@@ -1676,41 +1683,44 @@ symtable_enter_type_param_block(struct symtable *st, identifier name,
16761683 if (current_type == ClassBlock ) {
16771684 st -> st_cur -> ste_can_see_class_scope = 1 ;
16781685 if (!symtable_add_def (st , & _Py_ID (__classdict__ ), USE , loc )) {
1679- return 0 ;
1686+ goto error ;
16801687 }
16811688 }
16821689 if (kind == ClassDef_kind ) {
16831690 _Py_DECLARE_STR (type_params , ".type_params" );
16841691 // It gets "set" when we create the type params tuple and
16851692 // "used" when we build up the bases.
16861693 if (!symtable_add_def (st , & _Py_STR (type_params ), DEF_LOCAL , loc )) {
1687- return 0 ;
1694+ goto error ;
16881695 }
16891696 if (!symtable_add_def (st , & _Py_STR (type_params ), USE , loc )) {
1690- return 0 ;
1697+ goto error ;
16911698 }
16921699 // This is used for setting the generic base
16931700 _Py_DECLARE_STR (generic_base , ".generic_base" );
16941701 if (!symtable_add_def (st , & _Py_STR (generic_base ), DEF_LOCAL , loc )) {
1695- return 0 ;
1702+ goto error ;
16961703 }
16971704 if (!symtable_add_def (st , & _Py_STR (generic_base ), USE , loc )) {
1698- return 0 ;
1705+ goto error ;
16991706 }
17001707 }
17011708 if (has_defaults ) {
17021709 _Py_DECLARE_STR (defaults , ".defaults" );
17031710 if (!symtable_add_def (st , & _Py_STR (defaults ), DEF_PARAM , loc )) {
1704- return 0 ;
1711+ goto error ;
17051712 }
17061713 }
17071714 if (has_kwdefaults ) {
17081715 _Py_DECLARE_STR (kwdefaults , ".kwdefaults" );
17091716 if (!symtable_add_def (st , & _Py_STR (kwdefaults ), DEF_PARAM , loc )) {
1710- return 0 ;
1717+ goto error ;
17111718 }
17121719 }
17131720 return 1 ;
1721+ error :
1722+ symtable_exit_block (st );
1723+ return 0 ;
17141724}
17151725
17161726/* VISIT, VISIT_SEQ and VISIT_SEQ_TAIL take an ASDL type as their second argument.
0 commit comments