Skip to content

Commit

Permalink
pythongh-121459: Add missing return to _PyDict_LoadGlobalStackRef
Browse files Browse the repository at this point in the history
We need to return immediately if there's an error during dictionary
lookup.

Also avoid the conditional-if operator. The Windows 10 buildbot seems to
miscompile that for unknown reasons.
  • Loading branch information
colesbury committed Sep 14, 2024
1 parent 3880917 commit c8c59a1
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1550,7 +1550,12 @@ _Py_dict_lookup_threadsafe_stackref(PyDictObject *mp, PyObject *key, Py_hash_t h
{
PyObject *val;
Py_ssize_t ix = _Py_dict_lookup(mp, key, hash, &val);
*value_addr = val == NULL ? PyStackRef_NULL : PyStackRef_FromPyObjectNew(val);
if (val == NULL) {
*value_addr = PyStackRef_NULL;
}
else {
*value_addr = PyStackRef_FromPyObjectNew(val);
}
return ix;
}

Expand Down Expand Up @@ -2483,7 +2488,7 @@ _PyDict_LoadGlobalStackRef(PyDictObject *globals, PyDictObject *builtins, PyObje
/* namespace 1: globals */
ix = _Py_dict_lookup_threadsafe_stackref(globals, key, hash, res);
if (ix == DKIX_ERROR) {
*res = PyStackRef_NULL;
return;
}
if (ix != DKIX_EMPTY && !PyStackRef_IsNull(*res)) {
return;
Expand Down

0 comments on commit c8c59a1

Please sign in to comment.