mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
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.
This commit is contained in:
parent
96a9eed245
commit
fb5db7ec58
17 changed files with 259 additions and 142 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue