Skip to content

Commit 1a2df4a

Browse files
serhiy-storchakaaisk
authored andcommitted
pythongh-111789: Use PyDict_GetItemRef() in Python/symtable.c (pythongh-112084)
1 parent 7af6836 commit 1a2df4a

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

Python/symtable.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -497,18 +497,14 @@ _PySymtable_Lookup(struct symtable *st, void *key)
497497
k = PyLong_FromVoidPtr(key);
498498
if (k == NULL)
499499
return NULL;
500-
v = PyDict_GetItemWithError(st->st_blocks, k);
501-
Py_DECREF(k);
502-
503-
if (v) {
504-
assert(PySTEntry_Check(v));
505-
}
506-
else if (!PyErr_Occurred()) {
500+
if (PyDict_GetItemRef(st->st_blocks, k, &v) == 0) {
507501
PyErr_SetString(PyExc_KeyError,
508502
"unknown symbol table entry");
509503
}
504+
Py_DECREF(k);
510505

511-
return (PySTEntryObject *)Py_XNewRef(v);
506+
assert(v == NULL || PySTEntry_Check(v));
507+
return (PySTEntryObject *)v;
512508
}
513509

514510
long

0 commit comments

Comments
 (0)