The PyDict_SetDefault(mp, key, defaultobj)
function returns a borrowed reference to the value corresponding to key. This poses a thread-safety issue particularly for the case where key
is already in the dict. In the --disable-gil
builds, the returned value may no longer be valid if another thread concurrently modifies the dict.
int PyDict_SetDefaultRef(PyObject *dict, PyObject *key, PyObject *default_value, PyObject **value)
;
The **value
pointer is optional. If it is NULL, it is not used.
*value
to a new reference to the current value (if value
is not NULL), and return 1.*value
to a new reference to default_value
(if value is not NULL), and return 0.*value
to NULL
if value
is not NULL
, and return -1.Ideally, this new function would be public and part of the stable ABI so that it could be used by all extensions, but even an internal-only function would unblock some of the nogil changes.
EDIT: Updated with @vstinner's proposal
Linked PRsPyDict_SetDefaultRef
function. #112123PyDict_SetDefaultRef
in place of PyDict_SetDefault
. #112211RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4