Skip to content

Commit ce7433e

Browse files
committed
no more climbing in _PyST_GetSymbol - symbol table is honest now
1 parent 8b37711 commit ce7433e

1 file changed

Lines changed: 14 additions & 18 deletions

File tree

Python/symtable.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -545,26 +545,22 @@ _PySymtable_LookupOptional(struct symtable *st, void *key,
545545
long
546546
_PyST_GetSymbol(PySTEntryObject *ste, PyObject *name)
547547
{
548-
while (ste != NULL) {
549-
PyObject *v;
550-
if (PyDict_GetItemRef(ste->ste_symbols, name, &v) < 0) {
551-
return -1;
552-
}
553-
if (v != NULL) {
554-
long symbol = PyLong_AsLong(v);
555-
Py_DECREF(v);
556-
if (symbol < 0) {
557-
if (!PyErr_Occurred()) {
558-
PyErr_SetString(PyExc_SystemError, "invalid symbol");
559-
}
560-
return -1;
561-
}
562-
return symbol;
548+
PyObject *v;
549+
if (PyDict_GetItemRef(ste->ste_symbols, name, &v) < 0) {
550+
return -1;
551+
}
552+
if (v == NULL) {
553+
return 0;
554+
}
555+
long symbol = PyLong_AsLong(v);
556+
Py_DECREF(v);
557+
if (symbol < 0) {
558+
if (!PyErr_Occurred()) {
559+
PyErr_SetString(PyExc_SystemError, "invalid symbol");
563560
}
564-
assert(ste->ste_parent == NULL || ste->ste_type == InlinedComprehensionBlock);
565-
ste = ste->ste_parent;
561+
return -1;
566562
}
567-
return 0;
563+
return symbol;
568564
}
569565

570566
int

0 commit comments

Comments
 (0)