diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2023-06-24 23:36:34 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-24 23:36:34 (GMT) |
commit | 9cd366462b8c45c5cd9e99b76047b517cece939e (patch) | |
tree | 94f1544c6b39638c4b0d44e9dcba2be8f486aedd /Modules/_hashopenssl.c | |
parent | 746c0f3d8fddb2a88028707b18930243c86ce437 (diff) | |
download | cpython-9cd366462b8c45c5cd9e99b76047b517cece939e.zip cpython-9cd366462b8c45c5cd9e99b76047b517cece939e.tar.gz cpython-9cd366462b8c45c5cd9e99b76047b517cece939e.tar.bz2 |
[3.12] gh-106033: Get rid of new occurrences of PyDict_GetItem and Py… (#106041)
[3.12] 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.
(cherry picked from commit 1d33d5378058671bfabb6f4d4b5bfd4726973ff9)
Diffstat (limited to 'Modules/_hashopenssl.c')
-rw-r--r-- | Modules/_hashopenssl.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c index 4b425f4..af6d1b2 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; } |