summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-06-23 17:10:32 (GMT)
committerGitHub <noreply@github.com>2023-06-23 17:10:32 (GMT)
commit1d33d5378058671bfabb6f4d4b5bfd4726973ff9 (patch)
treec522809e945151a3525780025b88475695445ad3 /Modules
parent41ad4dfc04c201728ce9fa12b1a96922dd15a368 (diff)
downloadcpython-1d33d5378058671bfabb6f4d4b5bfd4726973ff9.zip
cpython-1d33d5378058671bfabb6f4d4b5bfd4726973ff9.tar.gz
cpython-1d33d5378058671bfabb6f4d4b5bfd4726973ff9.tar.bz2
gh-106033: Get rid of new occurrences of PyDict_GetItem and PyObject_HasAttr (GH-106034)
These functions are broken by design because they discard any exceptions raised inside, including MemoryError and KeyboardInterrupt. They should not be used in new code.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_hashopenssl.c13
-rw-r--r--Modules/_testcapi/code.c2
2 files changed, 8 insertions, 7 deletions
diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c
index c018a76..259db80 100644
--- a/Modules/_hashopenssl.c
+++ b/Modules/_hashopenssl.c
@@ -383,14 +383,15 @@ py_digest_by_digestmod(PyObject *module, PyObject *digestmod, enum Py_hash_type
} else {
_hashlibstate *state = get_hashlib_state(module);
// borrowed ref
- name_obj = PyDict_GetItem(state->constructs, digestmod);
+ name_obj = PyDict_GetItemWithError(state->constructs, digestmod);
}
if (name_obj == NULL) {
- _hashlibstate *state = get_hashlib_state(module);
- PyErr_Clear();
- PyErr_Format(
- state->unsupported_digestmod_error,
- "Unsupported digestmod %R", digestmod);
+ if (!PyErr_Occurred()) {
+ _hashlibstate *state = get_hashlib_state(module);
+ PyErr_Format(
+ state->unsupported_digestmod_error,
+ "Unsupported digestmod %R", digestmod);
+ }
return NULL;
}
diff --git a/Modules/_testcapi/code.c b/Modules/_testcapi/code.c
index 84c668c..cadaf5e 100644
--- a/Modules/_testcapi/code.c
+++ b/Modules/_testcapi/code.c
@@ -9,7 +9,7 @@ get_code_extra_index(PyInterpreterState* interp) {
PyObject *interp_dict = PyInterpreterState_GetDict(interp); // borrowed
assert(interp_dict); // real users would handle missing dict... somehow
- PyObject *index_obj = PyDict_GetItemString(interp_dict, key); // borrowed
+ PyObject *index_obj = _PyDict_GetItemStringWithError(interp_dict, key); // borrowed
Py_ssize_t index = 0;
if (!index_obj) {
if (PyErr_Occurred()) {