diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2019-02-25 17:59:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-25 17:59:46 +0200 |
commit | a24107b04c1277e3c1105f98aff5bfa3a98b33a0 (patch) | |
tree | 55aa5a700e08e3ba27b0361df2b1043be5c4701a /Python/symtable.c | |
parent | a180b007d96fe68b32f11dec720fbd0cd5b6758a (diff) | |
download | cpython-git-a24107b04c1277e3c1105f98aff5bfa3a98b33a0.tar.gz |
bpo-35459: Use PyDict_GetItemWithError() instead of PyDict_GetItem(). (GH-11112)
Diffstat (limited to 'Python/symtable.c')
-rw-r--r-- | Python/symtable.c | 18 |
1 files changed, 13 insertions, 5 deletions
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; |