summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-07-11 20:04:12 (GMT)
committerGitHub <noreply@github.com>2023-07-11 20:04:12 (GMT)
commit4bf43710d1e1f19cc46b116b5d8524f6c75dabfa (patch)
treef005fe94ab083da1f9a21485f51373efa7cf8008 /Include
parentb444bfb0a325dea8c29f7b1828233b00fbf4a1cb (diff)
downloadcpython-4bf43710d1e1f19cc46b116b5d8524f6c75dabfa.zip
cpython-4bf43710d1e1f19cc46b116b5d8524f6c75dabfa.tar.gz
cpython-4bf43710d1e1f19cc46b116b5d8524f6c75dabfa.tar.bz2
gh-106307: C API: Add PyMapping_GetOptionalItem() function (GH-106308)
Also add PyMapping_GetOptionalItemString() function.
Diffstat (limited to 'Include')
-rw-r--r--Include/abstract.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/Include/abstract.h b/Include/abstract.h
index f47ea1a..dd91500 100644
--- a/Include/abstract.h
+++ b/Include/abstract.h
@@ -840,6 +840,21 @@ PyAPI_FUNC(PyObject *) PyMapping_Items(PyObject *o);
PyAPI_FUNC(PyObject *) PyMapping_GetItemString(PyObject *o,
const char *key);
+/* Variants of PyObject_GetItem() and PyMapping_GetItemString() which don't
+ raise KeyError if the key is not found.
+
+ If the key is found, return 1 and set *result to a new strong
+ reference to the corresponding value.
+ If the key is not found, return 0 and set *result to NULL;
+ the KeyError is silenced.
+ If an error other than KeyError is raised, return -1 and
+ set *result to NULL.
+*/
+#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030d0000
+PyAPI_FUNC(int) PyMapping_GetOptionalItem(PyObject *, PyObject *, PyObject **);
+PyAPI_FUNC(int) PyMapping_GetOptionalItemString(PyObject *, const char *, PyObject **);
+#endif
+
/* Map the string 'key' to the value 'v' in the mapping 'o'.
Returns -1 on failure.