diff --git a/Include/cpython/context.h b/Include/cpython/context.h index 9879fc7192e..a3249fc29b0 100644 --- a/Include/cpython/context.h +++ b/Include/cpython/context.h @@ -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 diff --git a/Include/internal/pycore_context.h b/Include/internal/pycore_context.h index f1898cf8733..ec884e9e0f5 100644 --- a/Include/internal/pycore_context.h +++ b/Include/internal/pycore_context.h @@ -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 */ diff --git a/Lib/test/test_context.py b/Lib/test/test_context.py index b1aece4f5c9..b72d5addc6b 100644 --- a/Lib/test/test_context.py +++ b/Lib/test/test_context.py @@ -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): diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index a7a98d1eea5..7086d321d4a 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -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}, diff --git a/Modules/_testinternalcapi.c b/Modules/_testinternalcapi.c index 7b98885189f..9b45d59987d 100644 --- a/Modules/_testinternalcapi.c +++ b/Modules/_testinternalcapi.c @@ -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 */ };