@@ -523,6 +523,7 @@ analyze_name(PySTEntryObject *ste, PyObject *scopes, PyObject *name, long flags,
523
523
PyObject * bound , PyObject * local , PyObject * free ,
524
524
PyObject * global , PyObject * type_params , PySTEntryObject * class_entry )
525
525
{
526
+ int contains ;
526
527
if (flags & DEF_GLOBAL ) {
527
528
if (flags & DEF_NONLOCAL ) {
528
529
PyErr_Format (PyExc_SyntaxError ,
@@ -543,14 +544,22 @@ analyze_name(PySTEntryObject *ste, PyObject *scopes, PyObject *name, long flags,
543
544
"nonlocal declaration not allowed at module level" );
544
545
return error_at_directive (ste , name );
545
546
}
546
- if (!PySet_Contains (bound , name )) {
547
+ contains = PySet_Contains (bound , name );
548
+ if (contains < 0 ) {
549
+ return 0 ;
550
+ }
551
+ if (!contains ) {
547
552
PyErr_Format (PyExc_SyntaxError ,
548
553
"no binding for nonlocal '%U' found" ,
549
554
name );
550
555
551
556
return error_at_directive (ste , name );
552
557
}
553
- if (PySet_Contains (type_params , name )) {
558
+ contains = PySet_Contains (type_params , name );
559
+ if (contains < 0 ) {
560
+ return 0 ;
561
+ }
562
+ if (contains ) {
554
563
PyErr_Format (PyExc_SyntaxError ,
555
564
"nonlocal binding not allowed for type parameter '%U'" ,
556
565
name );
@@ -599,17 +608,29 @@ analyze_name(PySTEntryObject *ste, PyObject *scopes, PyObject *name, long flags,
599
608
Note that having a non-NULL bound implies that the block
600
609
is nested.
601
610
*/
602
- if (bound && PySet_Contains (bound , name )) {
603
- SET_SCOPE (scopes , name , FREE );
604
- ste -> ste_free = 1 ;
605
- return PySet_Add (free , name ) >= 0 ;
611
+ if (bound ) {
612
+ contains = PySet_Contains (bound , name );
613
+ if (contains < 0 ) {
614
+ return 0 ;
615
+ }
616
+ if (contains ) {
617
+ SET_SCOPE (scopes , name , FREE );
618
+ ste -> ste_free = 1 ;
619
+ return PySet_Add (free , name ) >= 0 ;
620
+ }
606
621
}
607
622
/* If a parent has a global statement, then call it global
608
623
explicit? It could also be global implicit.
609
624
*/
610
- if (global && PySet_Contains (global , name )) {
611
- SET_SCOPE (scopes , name , GLOBAL_IMPLICIT );
612
- return 1 ;
625
+ if (global ) {
626
+ contains = PySet_Contains (global , name );
627
+ if (contains < 0 ) {
628
+ return 0 ;
629
+ }
630
+ if (contains ) {
631
+ SET_SCOPE (scopes , name , GLOBAL_IMPLICIT );
632
+ return 1 ;
633
+ }
613
634
}
614
635
if (ste -> ste_nested )
615
636
ste -> ste_free = 1 ;
@@ -712,8 +733,19 @@ analyze_cells(PyObject *scopes, PyObject *free, PyObject *inlined_cells)
712
733
scope = PyLong_AS_LONG (v );
713
734
if (scope != LOCAL )
714
735
continue ;
715
- if (!PySet_Contains (free , name ) && !PySet_Contains (inlined_cells , name ))
716
- continue ;
736
+ int contains = PySet_Contains (free , name );
737
+ if (contains < 0 ) {
738
+ goto error ;
739
+ }
740
+ if (!contains ) {
741
+ contains = PySet_Contains (inlined_cells , name );
742
+ if (contains < 0 ) {
743
+ goto error ;
744
+ }
745
+ if (!contains ) {
746
+ continue ;
747
+ }
748
+ }
717
749
/* Replace LOCAL with CELL for this name, and remove
718
750
from free. It is safe to replace the value of name
719
751
in the dict, because it will not cause a resize.
@@ -764,7 +796,11 @@ update_symbols(PyObject *symbols, PyObject *scopes,
764
796
long scope , flags ;
765
797
assert (PyLong_Check (v ));
766
798
flags = PyLong_AS_LONG (v );
767
- if (PySet_Contains (inlined_cells , name )) {
799
+ int contains = PySet_Contains (inlined_cells , name );
800
+ if (contains < 0 ) {
801
+ return 0 ;
802
+ }
803
+ if (contains ) {
768
804
flags |= DEF_COMP_CELL ;
769
805
}
770
806
v_scope = PyDict_GetItemWithError (scopes , name );
@@ -822,9 +858,15 @@ update_symbols(PyObject *symbols, PyObject *scopes,
822
858
goto error ;
823
859
}
824
860
/* Handle global symbol */
825
- if (bound && !PySet_Contains (bound , name )) {
826
- Py_DECREF (name );
827
- continue ; /* it's a global */
861
+ if (bound ) {
862
+ int contains = PySet_Contains (bound , name );
863
+ if (contains < 0 ) {
864
+ goto error ;
865
+ }
866
+ if (!contains ) {
867
+ Py_DECREF (name );
868
+ continue ; /* it's a global */
869
+ }
828
870
}
829
871
/* Propagate new free symbol up the lexical stack */
830
872
if (PyDict_SetItem (symbols , name , v_free ) < 0 ) {
0 commit comments