diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 006bc593c2a754..e95a6f465941d8 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -2471,27 +2471,13 @@ _PyDict_LoadGlobal(PyDictObject *globals, PyDictObject *builtins, PyObject *key) void _PyDict_LoadGlobalStackRef(PyDictObject *globals, PyDictObject *builtins, PyObject *key, _PyStackRef *res) { - Py_ssize_t ix; - Py_hash_t hash; - - hash = _PyObject_HashFast(key); - if (hash == -1) { + PyObject *obj = _PyDict_LoadGlobal(globals, builtins, key); + if (obj == NULL) { *res = PyStackRef_NULL; - return; } - - /* namespace 1: globals */ - ix = _Py_dict_lookup_threadsafe_stackref(globals, key, hash, res); - if (ix == DKIX_ERROR) { - *res = PyStackRef_NULL; - } - if (ix != DKIX_EMPTY && !PyStackRef_IsNull(*res)) { - return; + else { + *res = PyStackRef_FromPyObjectSteal(obj); } - - /* namespace 2: builtins */ - ix = _Py_dict_lookup_threadsafe_stackref(builtins, key, hash, res); - assert(ix >= 0 || PyStackRef_IsNull(*res)); } /* Consumes references to key and value */ diff --git a/Python/ceval.c b/Python/ceval.c index 3a3001b2719153..2310c7e59af530 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -3150,22 +3150,15 @@ void _PyEval_LoadGlobalStackRef(PyObject *globals, PyObject *builtins, PyObject *name, _PyStackRef *writeto) { if (PyDict_CheckExact(globals) && PyDict_CheckExact(builtins)) { - PyObject *res = _PyDict_LoadGlobal((PyDictObject *)globals, + _PyDict_LoadGlobalStackRef((PyDictObject *)globals, (PyDictObject *)builtins, - name); - if (res == NULL && !PyErr_Occurred()) { + name, writeto); + if (PyStackRef_IsNull(*writeto) && !PyErr_Occurred()) { /* _PyDict_LoadGlobal() returns NULL without raising * an exception if the key doesn't exist */ _PyEval_FormatExcCheckArg(PyThreadState_GET(), PyExc_NameError, NAME_ERROR_MSG, name); } - - if (res == NULL) { - *writeto = PyStackRef_NULL; - } - else { - *writeto = PyStackRef_FromPyObjectSteal(res); - } } else { /* Slow-path if globals or builtins is not a dict */