8000 Remove redundant function · python/cpython@08d931c · GitHub
[go: up one dir, main page]

Skip to content

Commit 08d931c

Browse files
committed
Remove redundant function
1 parent d4e72a5 commit 08d931c

File tree

1 file changed

+26
-37
lines changed

1 file changed

+26
-37
lines changed

Python/symtable.c

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -498,21 +498,6 @@ error_at_directive(PySTEntryObject *ste, PyObject *name)
498498
global: set of all symbol names explicitly declared as global
499499
*/
500500

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-
516501
#define SET_SCOPE(DICT, NAME, I) { \
517502
PyObject *o = PyLong_FromLong(I); \
518503
if (!o) \
@@ -534,7 +519,7 @@ flags_in_symbols(PyObject *symbols, PyObject *name)
534519
static int
535520
analyze_name(PySTEntryObject *ste, PyObject *scopes, PyObject *name, long flags,
536521
PyObject *bound, PyObject *local, PyObject *free,
537-
PyObject *global, PyObject *typeparams, PyObject *class_symbols)
522+
PyObject *global, PyObject *typeparams, PySTEntryObject *class_entry)
538523
{
539524
if (flags & DEF_GLOBAL) {
540525
if (flags & DEF_NONLOCAL) {
@@ -589,21 +574,23 @@ analyze_name(PySTEntryObject *ste 10000 , PyObject *scopes, PyObject *name, long flags,
589574
}
590575
return 1;
591576
}
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)
593578
// and the bound name is in that set, then the name is potentially bound both by
594579
// the immediately enclosing class namespace, and also by an outer function namespace.
595580
// In that case, we want the runtime name resolution to look at only the class
596581
// namespace and the globals (not the namespace providing the bound).
597582
// Similarly, if the name is explicitly global in the class namespace (through the
598583
// 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+
}
607594
}
608595
/* If an enclosing block has a binding for this name, it
609596
is a free variable rather than a global variable.
@@ -873,12 +860,13 @@ update_symbols(PyObject *symbols, PyObject *scopes,
873860

874861
static int
875862
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);
878865

879866
static int
880867
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)
882870
{
883871
PyObject *name, *v, *local = NULL, *scopes = NULL, *newbound = NULL;
884872
PyObject *newglobal = NULL, *newfree = NULL, *promote_to_cell = NULL;
@@ -940,7 +928,7 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
940928
while (PyDict_Next(ste->ste_symbols, &pos, &name, &v)) {
941929
long flags = PyLong_AS_LONG(v);
942930
if (!analyze_name(ste, scopes, name, flags,
943-
bound, local, free, global, typeparams, class_symbols))
931+
bound, local, free, global, typeparams, class_entry))
944932
goto error;
945933
}
946934

@@ -987,13 +975,13 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
987975
assert(c && PySTEntry_Check(c));
988976
entry = (PySTEntryObject*)c;
989977

990-
PyObject *new_class_symbols = NULL;
978+
PySTEntryObject *new_class_entry = NULL;
991979
if (entry->ste_can_see_class_scope) {
992980
if (ste->ste_type == ClassBlock) {
993-
new_class_symbols = ste->ste_symbols;
981+
new_class_entry = ste;
994982
}
995-
else if (class_symbols) {
996-
new_class_symbols = class_symbols;
983+
else if (class_entry) {
984+
new_class_entry = class_entry;
997985
}
998986
}
999987

@@ -1003,7 +991,7 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
1003991
!entry->ste_generator;
1004992

1005993
if (!analyze_child_block(entry, newbound, newfree, newglobal,
1006-
typeparams, new_class_symbols, &child_free))
994+
typeparams, new_class_entry, &child_free))
1007995
{
1008996
goto error;
1009997
}
@@ -1067,8 +1055,8 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
10671055

10681056
static int
10691057
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)
10721060
{
10731061
PyObject *temp_bound = NULL, *temp_global = NULL, *temp_free = NULL;
10741062
PyObject *temp_typeparams = NULL;
@@ -1093,7 +1081,8 @@ analyze_child_block(PySTEntryObject *entry, PyObject *bound, PyObject *free,
10931081
if (!temp_typeparams)
10941082
goto error;
10951083

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))
10971086
goto error;
10981087
*child_free = temp_free;
10991088
Py_DECREF(temp_bound);

0 commit comments

Comments
 (0)
0