summaryrefslogtreecommitdiffstats
path: root/Modules/_threadmodule.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 /Modules/_threadmodule.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 'Modules/_threadmodule.c')
-rw-r--r--Modules/_threadmodule.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index 77baba4..56ed8a2 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -816,10 +816,14 @@ local_clear(localobject *self)
for(tstate = PyInterpreterState_ThreadHead(tstate->interp);
tstate;
tstate = PyThreadState_Next(tstate))
- if (tstate->dict && PyDict_GetItem(tstate->dict, self->key)) {
- if (PyDict_DelItem(tstate->dict, self->key)) {
+ if (tstate->dict) {
+ PyObject *v = _PyDict_Pop(tstate->dict, self->key, Py_None);
+ if (v == NULL) {
PyErr_Clear();
}
+ else {
+ Py_DECREF(v);
+ }
}
}
return 0;