diff options
author | Sam Gross <colesbury@gmail.com> | 2024-02-06 16:36:23 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-06 16:36:23 (GMT) |
commit | de61d4bd4db868ce49a729a283763b94f2fda961 (patch) | |
tree | 00f712e2df606a604cf86d1ce4d384db4d2f1478 /Include/cpython | |
parent | 0e2ab73dc31e0b8ea1827ec24bae93ae2644c617 (diff) | |
download | cpython-de61d4bd4db868ce49a729a283763b94f2fda961.zip cpython-de61d4bd4db868ce49a729a283763b94f2fda961.tar.gz cpython-de61d4bd4db868ce49a729a283763b94f2fda961.tar.bz2 |
gh-112066: Add `PyDict_SetDefaultRef` function. (#112123)
The `PyDict_SetDefaultRef` function is similar to `PyDict_SetDefault`,
but returns a strong reference through the optional `**result` pointer
instead of a borrowed reference.
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Diffstat (limited to 'Include/cpython')
-rw-r--r-- | Include/cpython/dictobject.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Include/cpython/dictobject.h b/Include/cpython/dictobject.h index 1720fe6..35b6a82 100644 --- a/Include/cpython/dictobject.h +++ b/Include/cpython/dictobject.h @@ -41,6 +41,16 @@ PyAPI_FUNC(PyObject *) _PyDict_GetItemStringWithError(PyObject *, const char *); PyAPI_FUNC(PyObject *) PyDict_SetDefault( PyObject *mp, PyObject *key, PyObject *defaultobj); +// Inserts `key` with a value `default_value`, if `key` is not already present +// in the dictionary. If `result` is not NULL, then the value associated +// with `key` is returned in `*result` (either the existing value, or the now +// inserted `default_value`). +// Returns: +// -1 on error +// 0 if `key` was not present and `default_value` was inserted +// 1 if `key` was present and `default_value` was not inserted +PyAPI_FUNC(int) PyDict_SetDefaultRef(PyObject *mp, PyObject *key, PyObject *default_value, PyObject **result); + /* Get the number of items of a dictionary. */ static inline Py_ssize_t PyDict_GET_SIZE(PyObject *op) { PyDictObject *mp; |