]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-106320: Remove private _PyDict C API (#107145)
authorVictor Stinner <vstinner@python.org>
Mon, 24 Jul 2023 14:02:03 +0000 (16:02 +0200)
committerGitHub <noreply@github.com>
Mon, 24 Jul 2023 14:02:03 +0000 (14:02 +0000)
Move private _PyDict functions to the internal C API (pycore_dict.h):

* _PyDict_Contains_KnownHash()
* _PyDict_DebugMallocStats()
* _PyDict_DelItemIf()
* _PyDict_GetItemWithError()
* _PyDict_HasOnlyStringKeys()
* _PyDict_MaybeUntrack()
* _PyDict_MergeEx()

No longer export these functions.

Include/cpython/dictobject.h
Include/internal/pycore_dict.h
Modules/_weakref.c
Modules/gcmodule.c
Objects/setobject.c
Python/_warnings.c
Python/bltinmodule.c
Python/getargs.c
Python/sysmodule.c

index ddada922020aa4c907c2eef9494d0f416fb94061..2a42794fdf0c85aa02f49c22974c28b8cd3b4e46 100644 (file)
@@ -34,7 +34,6 @@ typedef struct {
 
 PyAPI_FUNC(PyObject *) _PyDict_GetItem_KnownHash(PyObject *mp, PyObject *key,
                                        Py_hash_t hash);
-PyAPI_FUNC(PyObject *) _PyDict_GetItemWithError(PyObject *dp, PyObject *key);
 PyAPI_FUNC(PyObject *) _PyDict_GetItemIdWithError(PyObject *dp,
                                                   _Py_Identifier *key);
 PyAPI_FUNC(PyObject *) _PyDict_GetItemStringWithError(PyObject *, const char *);
@@ -44,8 +43,7 @@ PyAPI_FUNC(int) _PyDict_SetItem_KnownHash(PyObject *mp, PyObject *key,
                                           PyObject *item, Py_hash_t hash);
 PyAPI_FUNC(int) _PyDict_DelItem_KnownHash(PyObject *mp, PyObject *key,
                                           Py_hash_t hash);
-PyAPI_FUNC(int) _PyDict_DelItemIf(PyObject *mp, PyObject *key,
-                                  int (*predicate)(PyObject *value));
+
 PyAPI_FUNC(int) _PyDict_Next(
     PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value, Py_hash_t *hash);
 
@@ -58,25 +56,16 @@ static inline Py_ssize_t PyDict_GET_SIZE(PyObject *op) {
 }
 #define PyDict_GET_SIZE(op) PyDict_GET_SIZE(_PyObject_CAST(op))
 
-PyAPI_FUNC(int) _PyDict_Contains_KnownHash(PyObject *, PyObject *, Py_hash_t);
 PyAPI_FUNC(int) _PyDict_ContainsId(PyObject *, _Py_Identifier *);
+
 PyAPI_FUNC(PyObject *) _PyDict_NewPresized(Py_ssize_t minused);
-PyAPI_FUNC(void) _PyDict_MaybeUntrack(PyObject *mp);
-PyAPI_FUNC(int) _PyDict_HasOnlyStringKeys(PyObject *mp);
 PyAPI_FUNC(Py_ssize_t) _PyDict_SizeOf(PyDictObject *);
 PyAPI_FUNC(PyObject *) _PyDict_Pop(PyObject *, PyObject *, PyObject *);
 #define _PyDict_HasSplitTable(d) ((d)->ma_values != NULL)
 
-/* Like PyDict_Merge, but override can be 0, 1 or 2.  If override is 0,
-   the first occurrence of a key wins, if override is 1, the last occurrence
-   of a key wins, if override is 2, a KeyError with conflicting key as
-   argument is raised.
-*/
-PyAPI_FUNC(int) _PyDict_MergeEx(PyObject *mp, PyObject *other, int override);
 PyAPI_FUNC(int) _PyDict_SetItemId(PyObject *dp, _Py_Identifier *key, PyObject *item);
 
 PyAPI_FUNC(int) _PyDict_DelItemId(PyObject *mp, _Py_Identifier *key);
-PyAPI_FUNC(void) _PyDict_DebugMallocStats(FILE *out);
 
 /* _PyDictView */
 
index 6253e0841ad3492eabdddf710b37e069a6a4e0fa..26a913435ef9cf566d185c3bc6ee10c49cb6615c 100644 (file)
@@ -12,6 +12,26 @@ extern "C" {
 #include "pycore_dict_state.h"
 #include "pycore_runtime.h"         // _PyRuntime
 
+// Unsafe flavor of PyDict_GetItemWithError(): no error checking
+extern PyObject* _PyDict_GetItemWithError(PyObject *dp, PyObject *key);
+
+extern int _PyDict_Contains_KnownHash(PyObject *, PyObject *, Py_hash_t);
+
+extern int _PyDict_DelItemIf(PyObject *mp, PyObject *key,
+                             int (*predicate)(PyObject *value));
+
+extern int _PyDict_HasOnlyStringKeys(PyObject *mp);
+
+extern void _PyDict_MaybeUntrack(PyObject *mp);
+
+/* Like PyDict_Merge, but override can be 0, 1 or 2.  If override is 0,
+   the first occurrence of a key wins, if override is 1, the last occurrence
+   of a key wins, if override is 2, a KeyError with conflicting key as
+   argument is raised.
+*/
+extern int _PyDict_MergeEx(PyObject *mp, PyObject *other, int override);
+
+extern void _PyDict_DebugMallocStats(FILE *out);
 
 /* runtime lifecycle */
 
index b5d80cbd731a281a8ee3d3b454ed9bb238289a43..dcb2984e3e8177706c529b2c584ef60356163bd9 100644 (file)
@@ -1,4 +1,5 @@
 #include "Python.h"
+#include "pycore_dict.h"          // _PyDict_DelItemIf()
 #include "pycore_object.h"        // _PyObject_GET_WEAKREFS_LISTPTR
 #include "pycore_weakref.h"       // _PyWeakref_IS_DEAD()
 
index 97644a7cee774f107c70385e8ba57efbd8f1eee7..246c0a9e160aa9956f5911f60c335bd1d3b00901 100644 (file)
 
 #include "Python.h"
 #include "pycore_context.h"
+#include "pycore_dict.h"          // _PyDict_MaybeUntrack()
 #include "pycore_initconfig.h"
-#include "pycore_interp.h"      // PyInterpreterState.gc
+#include "pycore_interp.h"        // PyInterpreterState.gc
 #include "pycore_object.h"
 #include "pycore_pyerrors.h"
-#include "pycore_pystate.h"     // _PyThreadState_GET()
-#include "pycore_weakref.h"     // _PyWeakref_ClearRef()
+#include "pycore_pystate.h"       // _PyThreadState_GET()
+#include "pycore_weakref.h"       // _PyWeakref_ClearRef()
 #include "pydtrace.h"
 
 typedef struct _gc_runtime_state GCState;
index 2f12320254ec94b2a1851263d6f2b885e00fede2..c96b62e38ec27e508d54a4fe47eaea762e53a225 100644 (file)
@@ -32,6 +32,7 @@
 */
 
 #include "Python.h"
+#include "pycore_dict.h"          // _PyDict_Contains_KnownHash()
 #include "pycore_modsupport.h"    // _PyArg_NoKwnames()
 #include "pycore_object.h"        // _PyObject_GC_UNTRACK()
 #include "pycore_setobject.h"     // _PySet_NextEntry() definition
index 82e621243a0c15810ae91578d7b8494f17fe8a92..40ec5f613d5bf469f8179992f01f00eacd865dc9 100644 (file)
@@ -1,4 +1,5 @@
 #include "Python.h"
+#include "pycore_dict.h"          // _PyDict_GetItemWithError()
 #include "pycore_frame.h"
 #include "pycore_initconfig.h"
 #include "pycore_interp.h"        // PyInterpreterState.warnings
index 7d77fd5c0c328efe66fd36314bdc00eec8844417..9baf233614879e955c3f50854c75b3c95f62e69f 100644 (file)
@@ -6,6 +6,7 @@
 #include "pycore_call.h"          // _PyObject_CallNoArgs()
 #include "pycore_ceval.h"         // _PyEval_Vector()
 #include "pycore_compile.h"       // _PyAST_Compile()
+#include "pycore_dict.h"          // _PyDict_GetItemWithError()
 #include "pycore_long.h"          // _PyLong_CompactValue
 #include "pycore_modsupport.h"    // _PyArg_NoKwnames()
 #include "pycore_object.h"        // _Py_AddToAllObjects()
index 45befab4f8bc37ff0c7224e1526a7c3e7899a29d..efcf2e333af8daa6af39e4e804d94511caa97010 100644 (file)
@@ -2,8 +2,9 @@
 /* New getargs implementation */
 
 #include "Python.h"
-#include "pycore_tuple.h"         // _PyTuple_ITEMS()
+#include "pycore_dict.h"          // _PyDict_HasOnlyStringKeys()
 #include "pycore_pylifecycle.h"   // _PyArg_Fini
+#include "pycore_tuple.h"         // _PyTuple_ITEMS()
 
 #include <ctype.h>
 #include <float.h>
index fb033a6b5634acf1005094fcb98f4dda0f1046c4..be026d95ba7e77119cf5dcf7bfb0531bf6eeb5c6 100644 (file)
@@ -17,6 +17,7 @@ Data members:
 #include "Python.h"
 #include "pycore_call.h"          // _PyObject_CallNoArgs()
 #include "pycore_ceval.h"         // _PyEval_SetAsyncGenFinalizer()
+#include "pycore_dict.h"          // _PyDict_GetItemWithError()
 #include "pycore_frame.h"         // _PyInterpreterFrame
 #include "pycore_initconfig.h"    // _PyStatus_EXCEPTION()
 #include "pycore_long.h"          // _PY_LONG_MAX_STR_DIGITS_THRESHOLD