summaryrefslogtreecommitdiffstats
path: root/Python/symtable.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2020-10-26 06:43:39 (GMT)
committerGitHub <noreply@github.com>2020-10-26 06:43:39 (GMT)
commitfb5db7ec58624cab0797b4050735be865d380823 (patch)
tree7b0421bb759ba01f0d735296738472faa4ce11b8 /Python/symtable.c
parent96a9eed2457c05af6953890d89463704c9d99c57 (diff)
downloadcpython-fb5db7ec58624cab0797b4050735be865d380823.zip
cpython-fb5db7ec58624cab0797b4050735be865d380823.tar.gz
cpython-fb5db7ec58624cab0797b4050735be865d380823.tar.bz2
bpo-42006: Stop using PyDict_GetItem, PyDict_GetItemString and _PyDict_GetItemId. (GH-22648)
These functions are considered not safe because they suppress all internal errors and can return wrong result. PyDict_GetItemString and _PyDict_GetItemId can also silence current exception in rare cases. Remove no longer used _PyDict_GetItemId. Add _PyDict_ContainsId and rename _PyDict_Contains into _PyDict_Contains_KnownHash.
Diffstat (limited to 'Python/symtable.c')
-rw-r--r--Python/symtable.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/Python/symtable.c b/Python/symtable.c
index 4a98e79..0464cd8 100644
--- a/Python/symtable.c
+++ b/Python/symtable.c
@@ -392,7 +392,7 @@ PySymtable_Lookup(struct symtable *st, void *key)
static long
_PyST_GetSymbol(PySTEntryObject *ste, PyObject *name)
{
- PyObject *v = PyDict_GetItem(ste->ste_symbols, name);
+ PyObject *v = PyDict_GetItemWithError(ste->ste_symbols, name);
if (!v)
return 0;
assert(PyLong_Check(v));
@@ -634,7 +634,7 @@ update_symbols(PyObject *symbols, PyObject *scopes,
long scope, flags;
assert(PyLong_Check(v));
flags = PyLong_AS_LONG(v);
- v_scope = PyDict_GetItem(scopes, name);
+ v_scope = PyDict_GetItemWithError(scopes, name);
assert(v_scope && PyLong_Check(v_scope));
scope = PyLong_AS_LONG(v_scope);
flags |= (scope << SCOPE_OFFSET);
@@ -1071,9 +1071,12 @@ symtable_add_def_helper(struct symtable *st, PyObject *name, int flag, struct _s
/* XXX need to update DEF_GLOBAL for other flags too;
perhaps only DEF_FREE_GLOBAL */
val = flag;
- if ((o = PyDict_GetItem(st->st_global, mangled))) {
+ if ((o = PyDict_GetItemWithError(st->st_global, mangled))) {
val |= PyLong_AS_LONG(o);
}
+ else if (PyErr_Occurred()) {
+ goto error;
+ }
o = PyLong_FromLong(val);
if (o == NULL)
goto error;