From a24107b04c1277e3c1105f98aff5bfa3a98b33a0 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 25 Feb 2019 17:59:46 +0200 Subject: bpo-35459: Use PyDict_GetItemWithError() instead of PyDict_GetItem(). (GH-11112) --- Python/symtable.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'Python/symtable.c') diff --git a/Python/symtable.c b/Python/symtable.c index cade3045b3..6e2df2f3c9 100644 --- a/Python/symtable.c +++ b/Python/symtable.c @@ -359,12 +359,12 @@ PySymtable_Lookup(struct symtable *st, void *key) k = PyLong_FromVoidPtr(key); if (k == NULL) return NULL; - v = PyDict_GetItem(st->st_blocks, k); + v = PyDict_GetItemWithError(st->st_blocks, k); if (v) { assert(PySTEntry_Check(v)); Py_INCREF(v); } - else { + else if (!PyErr_Occurred()) { PyErr_SetString(PyExc_KeyError, "unknown symbol table entry"); } @@ -637,7 +637,7 @@ update_symbols(PyObject *symbols, PyObject *scopes, } while ((name = PyIter_Next(itr))) { - v = PyDict_GetItem(symbols, name); + v = PyDict_GetItemWithError(symbols, name); /* Handle symbol that already exists in this scope */ if (v) { @@ -662,6 +662,9 @@ update_symbols(PyObject *symbols, PyObject *scopes, Py_DECREF(name); continue; } + else if (PyErr_Occurred()) { + goto error; + } /* Handle global symbol */ if (bound && !PySet_Contains(bound, name)) { Py_DECREF(name); @@ -991,7 +994,7 @@ symtable_add_def_helper(struct symtable *st, PyObject *name, int flag, struct _s if (!mangled) return 0; dict = ste->ste_symbols; - if ((o = PyDict_GetItem(dict, mangled))) { + if ((o = PyDict_GetItemWithError(dict, mangled))) { val = PyLong_AS_LONG(o); if ((flag & DEF_PARAM) && (val & DEF_PARAM)) { /* Is it better to use 'mangled' or 'name' here? */ @@ -1002,8 +1005,13 @@ symtable_add_def_helper(struct symtable *st, PyObject *name, int flag, struct _s goto error; } val |= flag; - } else + } + else if (PyErr_Occurred()) { + goto error; + } + else { val = flag; + } o = PyLong_FromLong(val); if (o == NULL) goto error; -- cgit v1.2.1