@@ -498,21 +498,6 @@ error_at_directive(PySTEntryObject *ste, PyObject *name)
498
498
global: set of all symbol names explicitly declared as global
499
499
*/
500
500
501
- static long
502
- flags_in_symbols (PyObject * symbols , PyObject * name )
503
- {
504
- if (symbols == NULL ) {
505
- return 0 ;
506
- }
507
- PyObject * v = PyDict_GetItemWithError (symbols , name );
508
- if (v == NULL ) {
509
- assert (!PyErr_Occurred ());
510
- return 0 ;
511
- }
512
- assert (PyLong_CheckExact (v ));
513
- return PyLong_AS_LONG (v );
514
- }
515
-
516
501
#define SET_SCOPE (DICT , NAME , I ) { \
517
502
PyObject *o = PyLong_FromLong(I); \
518
503
if (!o) \
@@ -534,7 +519,7 @@ flags_in_symbols(PyObject *symbols, PyObject *name)
534
519
static int
535
520
analyze_name (PySTEntryObject * ste , PyObject * scopes , PyObject * name , long flags ,
536
521
PyObject * bound , PyObject * local , PyObject * free ,
537
- PyObject * global , PyObject * typeparams , PyObject * class_symbols )
522
+ PyObject * global , PyObject * typeparams , PySTEntryObject * class_entry )
538
523
{
539
524
if (flags & DEF_GLOBAL ) {
540
525
if (flags & DEF_NONLOCAL ) {
@@ -589,21 +574,23 @@ analyze_name(PySTEntryObject *ste
10000
, PyObject *scopes, PyObject *name, long flags,
589
574
}
590
575
return 1 ;
591
576
}
592
- // If we were passed class_symbols (i.e., we're in an ste_can_see_class_scope scope)
577
+ // If we were passed class_entry (i.e., we're in an ste_can_see_class_scope scope)
593
578
// and the bound name is in that set, then the name is potentially bound both by
594
579
// the immediately enclosing class namespace, and also by an outer function namespace.
595
580
// In that case, we want the runtime name resolution to look at only the class
596
581
// namespace and the globals (not the namespace providing the bound).
597
582
// Similarly, if the name is explicitly global in the class namespace (through the
598
583
// global statement), we want to also treat it as a global in this scope.
599
- long class_flags = flags_in_symbols (class_symbols , name );
600
- if (class_flags & DEF_GLOBAL ) {
601
- SET_SCOPE (scopes , name , GLOBAL_EXPLICIT );
602
- return 1 ;
603
- }
604
- else if (class_flags & DEF_BOUND && !(class_flags & DEF_NONLOCAL )) {
605
- SET_SCOPE (scopes , name , GLOBAL_IMPLICIT );
606
- return 1 ;
584
+ if (class_entry != NULL ) {
585
+ long class_flags = _PyST_GetSymbol (class_entry , name );
586
+ if (class_flags & DEF_GLOBAL ) {
587
+ SET_SCOPE (scopes , name , GLOBAL_EXPLICIT );
588
+ return 1 ;
589
+ }
590
+ else if (class_flags & DEF_BOUND && !(class_flags & DEF_NONLOCAL )) {
591
+ SET_SCOPE (scopes , name , GLOBAL_IMPLICIT );
592
+ return 1 ;
593
+ }
607
594
}
608
595
/* If an enclosing block has a binding for this name, it
609
596
is a free variable rather than a global variable.
@@ -873,12 +860,13 @@ update_symbols(PyObject *symbols, PyObject *scopes,
873
860
874
861
static int
875
862
analyze_child_block (PySTEntryObject * entry , PyObject * bound , PyObject * free ,
876
-
8000
PyObject * global , PyObject * typeparams , PyObject * class_symbols ,
877
- PyObject * * child_free );
863
+ PyObject * global , PyObject * typeparams ,
864
+ PySTEntryObject * class_entry , PyObject * * child_free );
878
865
879
866
static int
880
867
analyze_block (PySTEntryObject * ste , PyObject * bound , PyObject * free ,
881
- PyObject * global , PyObject * typeparams , PyObject * class_symbols )
868
+ PyObject * global , PyObject * typeparams ,
869
+ PySTEntryObject * class_entry )
882
870
{
883
871
PyObject * name , * v , * local = NULL , * scopes = NULL , * newbound = NULL ;
884
872
PyObject * newglobal = NULL , * newfree = NULL , * promote_to_cell = NULL ;
@@ -940,7 +928,7 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
940
928
while (PyDict_Next (ste -> ste_symbols , & pos , & name , & v )) {
941
929
long flags = PyLong_AS_LONG (v );
942
930
if (!analyze_name (ste , scopes , name , flags ,
943
- bound , local , free , global , typeparams , class_symbols ))
931
+ bound , local , free , global , typeparams , class_entry ))
944
932
goto error ;
945
933
}
946
934
@@ -987,13 +975,13 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
987
975
assert (c && PySTEntry_Check (c ));
988
976
entry = (PySTEntryObject * )c ;
989
977
990
- PyObject * new_class_symbols = NULL ;
978
+ PySTEntryObject * new_class_entry = NULL ;
991
979
if (entry -> ste_can_see_class_scope ) {
992
980
if (ste -> ste_type == ClassBlock ) {
993
- new_class_symbols = ste -> ste_symbols ;
981
+ new_class_entry = ste ;
994
982
}
995
- else if (class_symbols ) {
996
- new_class_symbols = class_symbols ;
983
+ else if (class_entry ) {
984
+ new_class_entry = class_entry ;
997
985
}
998
986
}
999
987
@@ -1003,7 +991,7 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
1003
991
!entry -> ste_generator ;
1004
992
1005
993
if (!analyze_child_block (entry , newbound , newfree , newglobal ,
1006
- typeparams , new_class_symbols , & child_free ))
994
+ typeparams , new_class_entry , & child_free ))
1007
995
{
1008
996
goto error ;
1009
997
}
@@ -1067,8 +1055,8 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
1067
1055
1068
1056
static int
1069
1057
analyze_child_block (PySTEntryObject * entry , PyObject * bound , PyObject * free ,
1070
- PyObject * global , PyObject * typeparams , PyObject * class_symbols ,
1071
- PyObject * * child_free )
1058
+ PyObject * global , PyObject * typeparams ,
1059
+ PySTEntryObject * class_entry , PyObject * * child_free )
1072
1060
{
1073
1061
PyObject * temp_bound = NULL , * temp_global = NULL , * temp_free = NULL ;
1074
1062
PyObject * temp_typeparams = NULL ;
@@ -1093,7 +1081,8 @@ analyze_child_block(PySTEntryObject *entry, PyObject *bound, PyObject *free,
1093
1081
if (!temp_typeparams )
1094
1082
goto error ;
1095
1083
1096
- if (!analyze_block (entry , temp_bound , temp_free , temp_global , temp_typeparams , class_symbols ))
1084
+ if (!analyze_block (entry , temp_bound , temp_free , temp_global ,
1085
+ temp_typeparams , class_entry ))
1097
1086
goto error ;
1098
1087
* child_free = temp_free ;
1099
1088
Py_DECREF (temp_bound );
0 commit comments