]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-106320: Remove private _PyContext_NewHamtForTests() (#108434)
authorVictor Stinner <vstinner@python.org>
Thu, 24 Aug 2023 17:37:41 +0000 (19:37 +0200)
committerGitHub <noreply@github.com>
Thu, 24 Aug 2023 17:37:41 +0000 (19:37 +0200)
Move the function to the internal C API.

Include/cpython/context.h
Include/internal/pycore_context.h
Lib/test/test_context.py
Modules/_testcapimodule.c
Modules/_testinternalcapi.c

index 9879fc7192ebb8f60fe81c6fc8682316ca5b336b..a3249fc29b082e4230488e9345948eaa7f502c09 100644 (file)
@@ -67,10 +67,6 @@ PyAPI_FUNC(PyObject *) PyContextVar_Set(PyObject *var, PyObject *value);
 PyAPI_FUNC(int) PyContextVar_Reset(PyObject *var, PyObject *token);
 
 
-/* This method is exposed only for CPython tests. Don not use it. */
-PyAPI_FUNC(PyObject *) _PyContext_NewHamtForTests(void);
-
-
 #ifdef __cplusplus
 }
 #endif
index f1898cf873312bcbc4ce9f09bd231c1c5f89a332..ec884e9e0f55a928efe781ab938ebd57472817ba 100644 (file)
@@ -68,4 +68,9 @@ struct _pycontexttokenobject {
 };
 
 
+// _testinternalcapi.hamt() used by tests.
+// Export for '_testcapi' shared extension
+PyAPI_FUNC(PyObject*) _PyContext_NewHamtForTests(void);
+
+
 #endif /* !Py_INTERNAL_CONTEXT_H */
index b1aece4f5c9c495b9fd8b74b8e0990e34d07fb45..b72d5addc6bd7d550e17dbcdae14c4eef4eb8371 100644 (file)
@@ -9,7 +9,7 @@ import weakref
 from test.support import threading_helper
 
 try:
-    from _testcapi import hamt
+    from _testinternalcapi import hamt
 except ImportError:
     hamt = None
 
@@ -431,7 +431,7 @@ class EqError(Exception):
     pass
 
 
-@unittest.skipIf(hamt is None, '_testcapi lacks "hamt()" function')
+@unittest.skipIf(hamt is None, '_testinternalcapi.hamt() not available')
 class HamtTest(unittest.TestCase):
 
     def test_hashkey_helper_1(self):
index a7a98d1eea5bd15f810c95823bc8dc6719e66e53..7086d321d4aaa24f91f284a09113da80d6ee6d1a 100644 (file)
@@ -2125,13 +2125,6 @@ test_pythread_tss_key_state(PyObject *self, PyObject *args)
 }
 
 
-static PyObject*
-new_hamt(PyObject *self, PyObject *args)
-{
-    return _PyContext_NewHamtForTests();
-}
-
-
 /* def bad_get(self, obj, cls):
        cls()
        return repr(self)
@@ -3626,7 +3619,6 @@ static PyMethodDef TestMethods[] = {
     {"W_STOPCODE", py_w_stopcode, METH_VARARGS},
 #endif
     {"test_pythread_tss_key_state", test_pythread_tss_key_state, METH_VARARGS},
-    {"hamt", new_hamt, METH_NOARGS},
     {"bad_get", _PyCFunction_CAST(bad_get), METH_FASTCALL},
 #ifdef Py_REF_DEBUG
     {"negative_refcount", negative_refcount, METH_NOARGS},
index 7b98885189f5c07f274f7782fa36cba0a95ff376..9b45d59987dca687b19e46a3d82b3f87bb9bbcf8 100644 (file)
@@ -13,8 +13,9 @@
 #include "pycore_atomic_funcs.h"  // _Py_atomic_int_get()
 #include "pycore_bitutils.h"      // _Py_bswap32()
 #include "pycore_bytesobject.h"   // _PyBytes_Find()
-#include "pycore_compile.h"       // _PyCompile_CodeGen, _PyCompile_OptimizeCfg, _PyCompile_Assemble, _PyCompile_CleanDoc
 #include "pycore_ceval.h"         // _PyEval_AddPendingCall()
+#include "pycore_compile.h"       // _PyCompile_CodeGen()
+#include "pycore_context.h"       // _PyContext_NewHamtForTests()
 #include "pycore_dict.h"          // _PyDictOrValues_GetValues()
 #include "pycore_fileutils.h"     // _Py_normpath()
 #include "pycore_frame.h"         // _PyInterpreterFrame
@@ -1564,6 +1565,13 @@ get_object_dict_values(PyObject *self, PyObject *obj)
 }
 
 
+static PyObject*
+new_hamt(PyObject *self, PyObject *args)
+{
+    return _PyContext_NewHamtForTests();
+}
+
+
 static PyMethodDef module_functions[] = {
     {"get_configs", get_configs, METH_NOARGS},
     {"get_recursion_depth", get_recursion_depth, METH_NOARGS},
@@ -1628,6 +1636,7 @@ static PyMethodDef module_functions[] = {
                               check_pyobject_uninitialized_is_freed, METH_NOARGS},
     {"pymem_getallocatorsname", test_pymem_getallocatorsname, METH_NOARGS},
     {"get_object_dict_values", get_object_dict_values, METH_O},
+    {"hamt", new_hamt, METH_NOARGS},
     {NULL, NULL} /* sentinel */
 };