@@ -502,6 +502,7 @@ analyze_name(PySTEntryObject *ste, PyObject *scopes, PyObject *name, long flags,
502
502
PyObject * bound , PyObject * local , PyObject * free ,
503
503
PyObject * global )
504
504
{
505
+ int contains ;
505
506
if (flags & DEF_GLOBAL ) {
506
507
if (flags & DEF_NONLOCAL ) {
507
508
PyErr_Format (PyExc_SyntaxError ,
@@ -522,7 +523,11 @@ analyze_name(PySTEntryObject *ste, PyObject *scopes, PyObject *name, long flags,
522
523
"nonlocal declaration not allowed at module level" );
523
524
return error_at_directive (ste , name );
524
525
}
525
- if (!PySet_Contains (bound , name )) {
526
+ contains = PySet_Contains (bound , name );
527
+ if (contains < 0 ) {
528
+ return 0 ;
529
+ }
530
+ if (!contains ) {
526
531
PyErr_Format (PyExc_SyntaxError ,
527
532
"no binding for nonlocal '%U' found" ,
528
533
name );
@@ -546,17 +551,29 @@ analyze_name(PySTEntryObject *ste, PyObject *scopes, PyObject *name, long flags,
546
551
Note that having a non-NULL bound implies that the block
547
552
is nested.
548
553
*/
549
- if (bound && PySet_Contains (bound , name )) {
550
- SET_SCOPE (scopes , name , FREE );
551
- ste -> ste_free = 1 ;
552
- return PySet_Add (free , name ) >= 0 ;
554
+ if (bound ) {
555
+ contains = PySet_Contains (bound , name );
556
+ if (contains < 0 ) {
557
+ return 0 ;
558
+ }
559
+ if (contains ) {
560
+ SET_SCOPE (scopes , name , FREE );
561
+ ste -> ste_free = 1 ;
562
+ return PySet_Add (free , name ) >= 0 ;
563
+ }
553
564
}
554
565
/* If a parent has a global statement, then call it global
555
566
explicit? It could also be global implicit.
556
567
*/
557
- if (global && PySet_Contains (global , name )) {
558
- SET_SCOPE (scopes , name , GLOBAL_IMPLICIT );
559
- return 1 ;
568
+ if (global ) {
569
+ contains = PySet_Contains (global , name );
570
+ if (contains < 0 ) {
571
+ return 0 ;
572
+ }
573
+ if (contains ) {
574
+ SET_SCOPE (scopes , name , GLOBAL_IMPLICIT );
575
+ return 1 ;
576
+ }
560
577
}
561
578
if (ste -> ste_nested )
562
579
ste -> ste_free = 1 ;
@@ -590,8 +607,13 @@ analyze_cells(PyObject *scopes, PyObject *free)
590
607
scope = PyLong_AS_LONG (v );
591
608
if (scope != LOCAL )
592
609
continue ;
593
- if (!PySet_Contains (free , name ))
610
+ int contains = PySet_Contains (free , name );
611
+ if (contains < 0 ) {
612
+ goto error ;
613
+ }
614
+ if (!contains ) {
594
615
continue ;
616
+ }
595
617
/* Replace LOCAL with CELL for this name, and remove
596
618
from free. It is safe to replace the value of name
597
619
in the dict, because it will not cause a resize.
@@ -691,9 +713,15 @@ update_symbols(PyObject *symbols, PyObject *scopes,
691
713
goto error ;
692
714
}
693
715
/* Handle global symbol */
694
- if (bound && !PySet_Contains (bound , name )) {
695
- Py_DECREF (name );
696
- continue ; /* it's a global */
716
+ if (bound ) {
717
+ int contains = PySet_Contains (bound , name );
718
+ if (contains < 0 ) {
719
+ goto error ;
720
+ }
721
+ if (!contains ) {
722
+ Py_DECREF (name );
723
+ continue ; /* it's a global */
724
+ }
697
725
}
698
726
/* Propagate new free symbol up the lexical stack */
699
727
if (PyDict_SetItem (symbols , name , v_free ) < 0 ) {
0 commit comments