summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-08-24 20:01:50 (GMT)
committerGitHub <noreply@github.com>2023-08-24 20:01:50 (GMT)
commit26893016a7f204b2e7138fc9ce04525a651c202e (patch)
tree994751eab58657e125b23a426fb5441612ec5ad2 /Modules
parentc3d580b238fb1b5a72d5608ff7905e9ad726d1bb (diff)
downloadcpython-26893016a7f204b2e7138fc9ce04525a651c202e.zip
cpython-26893016a7f204b2e7138fc9ce04525a651c202e.tar.gz
cpython-26893016a7f204b2e7138fc9ce04525a651c202e.tar.bz2
gh-106320: Remove private _PyDict functions (#108449)
Move private functions to the internal C API (pycore_dict.h): * _PyDictView_Intersect() * _PyDictView_New() * _PyDict_ContainsId() * _PyDict_DelItemId() * _PyDict_DelItem_KnownHash() * _PyDict_GetItemIdWithError() * _PyDict_GetItem_KnownHash() * _PyDict_HasSplitTable() * _PyDict_NewPresized() * _PyDict_Next() * _PyDict_Pop() * _PyDict_SetItemId() * _PyDict_SetItem_KnownHash() * _PyDict_SizeOf() No longer export most of these functions. Move also the _PyDictViewObject structure to the internal C API. Move dict_getitem_knownhash() function from _testcapi to the _testinternalcapi extension. Update test_capi.test_dict for this change.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_asynciomodule.c1
-rw-r--r--Modules/_collectionsmodule.c1
-rw-r--r--Modules/_ctypes/stgdict.c1
-rw-r--r--Modules/_sre/sre.c1
-rw-r--r--Modules/_testcapimodule.c21
-rw-r--r--Modules/_testinternalcapi.c22
-rw-r--r--Modules/_threadmodule.c4
-rw-r--r--Modules/socketmodule.c1
8 files changed, 29 insertions, 23 deletions
diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c
index 6266dc8..c66a862 100644
--- a/Modules/_asynciomodule.c
+++ b/Modules/_asynciomodule.c
@@ -3,6 +3,7 @@
#endif
#include "Python.h"
+#include "pycore_dict.h" // _PyDict_GetItem_KnownHash()
#include "pycore_moduleobject.h" // _PyModule_GetState()
#include "pycore_pyerrors.h" // _PyErr_ClearExcState()
#include "pycore_pylifecycle.h" // _Py_IsInterpreterFinalizing()
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index f2915f8..c8cd53d 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -1,5 +1,6 @@
#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
+#include "pycore_dict.h" // _PyDict_GetItem_KnownHash()
#include "pycore_long.h" // _PyLong_GetZero()
#include "pycore_moduleobject.h" // _PyModule_GetState()
#include "pycore_typeobject.h" // _PyType_GetModuleState()
diff --git a/Modules/_ctypes/stgdict.c b/Modules/_ctypes/stgdict.c
index 3348ebd..54291a7 100644
--- a/Modules/_ctypes/stgdict.c
+++ b/Modules/_ctypes/stgdict.c
@@ -9,6 +9,7 @@
#endif
#include "pycore_call.h" // _PyObject_CallNoArgs()
+#include "pycore_dict.h" // _PyDict_SizeOf()
#include <ffi.h>
#ifdef MS_WIN32
# include <malloc.h>
diff --git a/Modules/_sre/sre.c b/Modules/_sre/sre.c
index c4e43a0..3872c36 100644
--- a/Modules/_sre/sre.c
+++ b/Modules/_sre/sre.c
@@ -39,6 +39,7 @@ static const char copyright[] =
" SRE 2.2.2 Copyright (c) 1997-2002 by Secret Labs AB ";
#include "Python.h"
+#include "pycore_dict.h" // _PyDict_Next()
#include "pycore_long.h" // _PyLong_GetZero()
#include "pycore_moduleobject.h" // _PyModule_GetState()
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 6a1eba3..20b9632 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -271,26 +271,6 @@ test_dict_iteration(PyObject* self, PyObject *Py_UNUSED(ignored))
Py_RETURN_NONE;
}
-static PyObject*
-dict_getitem_knownhash(PyObject *self, PyObject *args)
-{
- PyObject *mp, *key, *result;
- Py_ssize_t hash;
-
- if (!PyArg_ParseTuple(args, "OOn:dict_getitem_knownhash",
- &mp, &key, &hash)) {
- return NULL;
- }
-
- result = _PyDict_GetItem_KnownHash(mp, key, (Py_hash_t)hash);
- if (result == NULL && !PyErr_Occurred()) {
- _PyErr_SetKeyError(key);
- return NULL;
- }
-
- return Py_XNewRef(result);
-}
-
/* Issue #4701: Check that PyObject_Hash implicitly calls
* PyType_Ready if it hasn't already been called
*/
@@ -3353,7 +3333,6 @@ static PyMethodDef TestMethods[] = {
{"test_sizeof_c_types", test_sizeof_c_types, METH_NOARGS},
{"test_list_api", test_list_api, METH_NOARGS},
{"test_dict_iteration", test_dict_iteration, METH_NOARGS},
- {"dict_getitem_knownhash", dict_getitem_knownhash, METH_VARARGS},
{"test_lazy_hash_inheritance", test_lazy_hash_inheritance,METH_NOARGS},
{"test_xincref_doesnt_leak",test_xincref_doesnt_leak, METH_NOARGS},
{"test_incref_doesnt_leak", test_incref_doesnt_leak, METH_NOARGS},
diff --git a/Modules/_testinternalcapi.c b/Modules/_testinternalcapi.c
index 9b45d59..3e3dfec 100644
--- a/Modules/_testinternalcapi.c
+++ b/Modules/_testinternalcapi.c
@@ -1572,6 +1572,27 @@ new_hamt(PyObject *self, PyObject *args)
}
+static PyObject*
+dict_getitem_knownhash(PyObject *self, PyObject *args)
+{
+ PyObject *mp, *key, *result;
+ Py_ssize_t hash;
+
+ if (!PyArg_ParseTuple(args, "OOn:dict_getitem_knownhash",
+ &mp, &key, &hash)) {
+ return NULL;
+ }
+
+ result = _PyDict_GetItem_KnownHash(mp, key, (Py_hash_t)hash);
+ if (result == NULL && !PyErr_Occurred()) {
+ _PyErr_SetKeyError(key);
+ return NULL;
+ }
+
+ return Py_XNewRef(result);
+}
+
+
static PyMethodDef module_functions[] = {
{"get_configs", get_configs, METH_NOARGS},
{"get_recursion_depth", get_recursion_depth, METH_NOARGS},
@@ -1637,6 +1658,7 @@ static PyMethodDef module_functions[] = {
{"pymem_getallocatorsname", test_pymem_getallocatorsname, METH_NOARGS},
{"get_object_dict_values", get_object_dict_values, METH_O},
{"hamt", new_hamt, METH_NOARGS},
+ {"dict_getitem_knownhash", dict_getitem_knownhash, METH_VARARGS},
{NULL, NULL} /* sentinel */
};
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index 984747c..229abfb 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -4,14 +4,14 @@
#include "Python.h"
#include "pycore_ceval.h" // _PyEval_MakePendingCalls()
+#include "pycore_dict.h" // _PyDict_Pop()
#include "pycore_interp.h" // _PyInterpreterState.threads.count
#include "pycore_moduleobject.h" // _PyModule_GetState()
#include "pycore_pylifecycle.h"
#include "pycore_pystate.h" // _PyThreadState_SetCurrent()
#include "pycore_weakref.h" // _PyWeakref_GET_REF()
-#include <stddef.h> // offsetof()
-
+#include <stddef.h> // offsetof()
#ifdef HAVE_SIGNAL_H
# include <signal.h> // SIGINT
#endif
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 392a56d..d1ac1ff 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -106,6 +106,7 @@ Local naming conventions:
#endif
#include "Python.h"
+#include "pycore_dict.h" // _PyDict_Pop()
#include "pycore_fileutils.h" // _Py_set_inheritable()
#include "pycore_moduleobject.h" // _PyModule_GetState