]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-141726: Add PyDict_SetDefaultRef() to the Stable ABI (#141727)
authorda-woods <dw-git@d-woods.co.uk>
Wed, 19 Nov 2025 11:38:10 +0000 (11:38 +0000)
committerGitHub <noreply@github.com>
Wed, 19 Nov 2025 11:38:10 +0000 (11:38 +0000)
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Doc/data/stable_abi.dat
Include/cpython/dictobject.h
Include/dictobject.h
Lib/test/test_stable_abi_ctypes.py
Misc/NEWS.d/next/C_API/2025-11-18-18-36-15.gh-issue-141726.ILrhyK.rst [new file with mode: 0644]
Misc/stable_abi.toml
PC/python3dll.c

index 5cbf3771950fc072a7872eff12cf2cfaabf6f8d7..95e032655cf0ccf186afb85fb2f40dd093f625a8 100644 (file)
@@ -160,6 +160,7 @@ func,PyDict_Merge,3.2,,
 func,PyDict_MergeFromSeq2,3.2,,
 func,PyDict_New,3.2,,
 func,PyDict_Next,3.2,,
+func,PyDict_SetDefaultRef,3.15,,
 func,PyDict_SetItem,3.2,,
 func,PyDict_SetItemString,3.2,,
 func,PyDict_Size,3.2,,
index df9ec7050fca1a99f66a4f5c70e60f15ded89ca7..5f2f7b6d4f56bd3b18f627359b3fe3ea835f8e66 100644 (file)
@@ -39,16 +39,6 @@ Py_DEPRECATED(3.14) PyAPI_FUNC(PyObject *) _PyDict_GetItemStringWithError(PyObje
 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;
index 1bbeec1ab699e7581d592bce151186582b6c3c82..0384e3131dcdb52540b8dd71e0195087f0eafec1 100644 (file)
@@ -68,6 +68,18 @@ PyAPI_FUNC(int) PyDict_GetItemRef(PyObject *mp, PyObject *key, PyObject **result
 PyAPI_FUNC(int) PyDict_GetItemStringRef(PyObject *mp, const char *key, PyObject **result);
 #endif
 
+#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030F0000
+// 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);
+#endif
+
 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000
 PyAPI_FUNC(PyObject *) PyObject_GenericGetDict(PyObject *, void *);
 #endif
index 7167646ecc6734d45fad14faf68cbb30db6fd19a..bc834f5a6816f357ae7e40a19007549e42cbbe98 100644 (file)
@@ -165,6 +165,7 @@ SYMBOL_NAMES = (
     "PyDict_MergeFromSeq2",
     "PyDict_New",
     "PyDict_Next",
+    "PyDict_SetDefaultRef",
     "PyDict_SetItem",
     "PyDict_SetItemString",
     "PyDict_Size",
diff --git a/Misc/NEWS.d/next/C_API/2025-11-18-18-36-15.gh-issue-141726.ILrhyK.rst b/Misc/NEWS.d/next/C_API/2025-11-18-18-36-15.gh-issue-141726.ILrhyK.rst
new file mode 100644 (file)
index 0000000..3fdad5c
--- /dev/null
@@ -0,0 +1 @@
+Add :c:func:`PyDict_SetDefaultRef` to the Stable ABI.
index 7ee6cf1dae5a3310bce26ab2368d7f8ab7c04b61..5c503f81d3299a960ba543185c64d530e17610bd 100644 (file)
     added = '3.15'
 [const.Py_mod_token]
     added = '3.15'
+[function.PyDict_SetDefaultRef]
+    added = '3.15'
index 99e0f05fe03209d1e58bf05dd735f947d8788e10..35db1a660a762f2ff04c03a70a8c7ba77677eea2 100755 (executable)
@@ -191,6 +191,7 @@ EXPORT_FUNC(PyDict_Merge)
 EXPORT_FUNC(PyDict_MergeFromSeq2)
 EXPORT_FUNC(PyDict_New)
 EXPORT_FUNC(PyDict_Next)
+EXPORT_FUNC(PyDict_SetDefaultRef)
 EXPORT_FUNC(PyDict_SetItem)
 EXPORT_FUNC(PyDict_SetItemString)
 EXPORT_FUNC(PyDict_Size)