diff options
author | Victor Stinner <vstinner@python.org> | 2021-02-21 11:02:04 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-21 11:02:04 (GMT) |
commit | d5fc99873769f0d0d5c5d5d99059177a75a4e46e (patch) | |
tree | 62651f8f8bea0fa001c79f8932437926e3879efe /Objects/dictobject.c | |
parent | 38b6c2acd4bba666bd64779c42b9d91cbee19274 (diff) | |
download | cpython-d5fc99873769f0d0d5c5d5d99059177a75a4e46e.zip cpython-d5fc99873769f0d0d5c5d5d99059177a75a4e46e.tar.gz cpython-d5fc99873769f0d0d5c5d5d99059177a75a4e46e.tar.bz2 |
bpo-42093: Cleanup _PyDict_GetItemHint() (GH-24582)
* No longer save/restore the current exception. It is no longer used
with an exception raised.
* No longer clear the current exception on error: it's now up to the
caller.
Diffstat (limited to 'Objects/dictobject.c')
-rw-r--r-- | Objects/dictobject.c | 35 |
1 files changed, 4 insertions, 31 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 773eda0..6ca82a7 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -1439,11 +1439,8 @@ PyDict_GetItem(PyObject *op, PyObject *key) Py_ssize_t _PyDict_GetItemHint(PyDictObject *mp, PyObject *key, - Py_ssize_t hint, PyObject **value) + Py_ssize_t hint, PyObject **value) { - Py_hash_t hash; - PyThreadState *tstate; - assert(*value == NULL); assert(PyDict_CheckExact((PyObject*)mp)); assert(PyUnicode_CheckExact(key)); @@ -1467,39 +1464,15 @@ _PyDict_GetItemHint(PyDictObject *mp, PyObject *key, } } - if ((hash = ((PyASCIIObject *) key)->hash) == -1) - { + Py_hash_t hash = ((PyASCIIObject *) key)->hash; + if (hash == -1) { hash = PyObject_Hash(key); if (hash == -1) { - PyErr_Clear(); - return -1; - } - } - - // We can arrive here with a NULL tstate during initialization: try - // running "python -Wi" for an example related to string interning - tstate = _PyThreadState_UncheckedGet(); - Py_ssize_t ix = 0; - if (tstate != NULL && tstate->curexc_type != NULL) { - /* preserve the existing exception */ - PyObject *err_type, *err_value, *err_tb; - PyErr_Fetch(&err_type, &err_value, &err_tb); - ix = (mp->ma_keys->dk_lookup)(mp, key, hash, value); - /* ignore errors */ - PyErr_Restore(err_type, err_value, err_tb); - if (ix < 0) { - return -1; - } - } - else { - ix = (mp->ma_keys->dk_lookup)(mp, key, hash, value); - if (ix < 0) { - PyErr_Clear(); return -1; } } - return ix; + return (mp->ma_keys->dk_lookup)(mp, key, hash, value); } /* Same as PyDict_GetItemWithError() but with hash supplied by caller. |