gh-121459: Add missing return to _PyDict_LoadGlobalStackRef (#124085)

We need to return immediately if there's an error during dictionary
lookup.

Also avoid the conditional-if operator. MSVC versions through v19.27 miscompile
compound literals with side effects within a conditional operator. This caused
crashes in the Windows10 buildbot.
This commit is contained in:
Sam Gross 2024-09-14 14:29:55 -04:00 committed by GitHub
parent 9dacf430c2
commit 401fff7423
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 2 deletions

View File

@ -1550,7 +1550,12 @@ _Py_dict_lookup_threadsafe_stackref(PyDictObject *mp, PyObject *key, Py_hash_t h
{ {
PyObject *val; PyObject *val;
Py_ssize_t ix = _Py_dict_lookup(mp, key, hash, &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; return ix;
} }
@ -2483,7 +2488,7 @@ _PyDict_LoadGlobalStackRef(PyDictObject *globals, PyDictObject *builtins, PyObje
/* namespace 1: globals */ /* namespace 1: globals */
ix = _Py_dict_lookup_threadsafe_stackref(globals, key, hash, res); ix = _Py_dict_lookup_threadsafe_stackref(globals, key, hash, res);
if (ix == DKIX_ERROR) { if (ix == DKIX_ERROR) {
*res = PyStackRef_NULL; return;
} }
if (ix != DKIX_EMPTY && !PyStackRef_IsNull(*res)) { if (ix != DKIX_EMPTY && !PyStackRef_IsNull(*res)) {
return; return;