Skip to content

Commit

Permalink
use PyStackRef_FromPyObjectSteal in _Py_dict_lookup_threadsafe_stackref
Browse files Browse the repository at this point in the history
  • Loading branch information
colesbury committed Sep 14, 2024
1 parent 64ed3e8 commit ced1ff3
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 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_FromPyObjectSteal(Py_NewRef(val));
}
return ix;
}

Expand Down Expand Up @@ -2483,20 +2488,18 @@ _PyDict_LoadGlobalStackRef(PyDictObject *globals, PyDictObject *builtins, PyObje
}

/* namespace 1: globals */
PyObject *value;
ix = _Py_dict_lookup_threadsafe(globals, key, hash, &value);
ix = _Py_dict_lookup_threadsafe_stackref(globals, key, hash, res);
if (ix == DKIX_ERROR) {
*res = PyStackRef_NULL;
return;
}
if (ix != DKIX_EMPTY && value != NULL) {
*res = PyStackRef_FromPyObjectSteal(value);
if (ix != DKIX_EMPTY && !PyStackRef_IsNull(*res)) {
return;
}

/* namespace 2: builtins */
ix = _Py_dict_lookup_threadsafe_stackref(builtins, key, hash, res);
assert(ix >= 0 || value == NULL);
assert(ix >= 0 || PyStackRef_IsNull(*res));
}

/* Consumes references to key and value */
Expand Down

0 comments on commit ced1ff3

Please sign in to comment.