Skip to content

Commit 480a337

Browse files
authored
gh-106320: Remove private _PyContext_NewHamtForTests() (#108434)
Move the function to the internal C API.
1 parent aa6f787 commit 480a337

File tree

5 files changed

+17
-15
lines changed

5 files changed

+17
-15
lines changed

Include/cpython/context.h

-4
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ PyAPI_FUNC(PyObject *) PyContextVar_Set(PyObject *var, PyObject *value);
6767
PyAPI_FUNC(int) PyContextVar_Reset(PyObject *var, PyObject *token);
6868

6969

70-
/* This method is exposed only for CPython tests. Don not use it. */
71-
PyAPI_FUNC(PyObject *) _PyContext_NewHamtForTests(void);
72-
73-
7470
#ifdef __cplusplus
7571
}
7672
#endif

Include/internal/pycore_context.h

+5
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,9 @@ struct _pycontexttokenobject {
6868
};
6969

7070

71+
// _testinternalcapi.hamt() used by tests.
72+
// Export for '_testcapi' shared extension
73+
PyAPI_FUNC(PyObject*) _PyContext_NewHamtForTests(void);
74+
75+
7176
#endif /* !Py_INTERNAL_CONTEXT_H */

Lib/test/test_context.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from test.support import threading_helper
1010

1111
try:
12-
from _testcapi import hamt
12+
from _testinternalcapi import hamt
1313
except ImportError:
1414
hamt = None
1515

@@ -431,7 +431,7 @@ class EqError(Exception):
431431
pass
432432

433433

434-
@unittest.skipIf(hamt is None, '_testcapi lacks "hamt()" function')
434+
@unittest.skipIf(hamt is None, '_testinternalcapi.hamt() not available')
435435
class HamtTest(unittest.TestCase):
436436

437437
def test_hashkey_helper_1(self):

Modules/_testcapimodule.c

-8
Original file line numberDiff line numberDiff line change
@@ -2125,13 +2125,6 @@ test_pythread_tss_key_state(PyObject *self, PyObject *args)
21252125
}
21262126

21272127

2128-
static PyObject*
2129-
new_hamt(PyObject *self, PyObject *args)
2130-
{
2131-
return _PyContext_NewHamtForTests();
2132-
}
2133-
2134-
21352128
/* def bad_get(self, obj, cls):
21362129
cls()
21372130
return repr(self)
@@ -3626,7 +3619,6 @@ static PyMethodDef TestMethods[] = {
36263619
{"W_STOPCODE", py_w_stopcode, METH_VARARGS},
36273620
#endif
36283621
{"test_pythread_tss_key_state", test_pythread_tss_key_state, METH_VARARGS},
3629-
{"hamt", new_hamt, METH_NOARGS},
36303622
{"bad_get", _PyCFunction_CAST(bad_get), METH_FASTCALL},
36313623
#ifdef Py_REF_DEBUG
36323624
{"negative_refcount", negative_refcount, METH_NOARGS},

Modules/_testinternalcapi.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
#include "pycore_atomic_funcs.h" // _Py_atomic_int_get()
1414
#include "pycore_bitutils.h" // _Py_bswap32()
1515
#include "pycore_bytesobject.h" // _PyBytes_Find()
16-
#include "pycore_compile.h" // _PyCompile_CodeGen, _PyCompile_OptimizeCfg, _PyCompile_Assemble, _PyCompile_CleanDoc
1716
#include "pycore_ceval.h" // _PyEval_AddPendingCall()
17+
#include "pycore_compile.h" // _PyCompile_CodeGen()
18+
#include "pycore_context.h" // _PyContext_NewHamtForTests()
1819
#include "pycore_dict.h" // _PyDictOrValues_GetValues()
1920
#include "pycore_fileutils.h" // _Py_normpath()
2021
#include "pycore_frame.h" // _PyInterpreterFrame
@@ -1564,6 +1565,13 @@ get_object_dict_values(PyObject *self, PyObject *obj)
15641565
}
15651566

15661567

1568+
static PyObject*
1569+
new_hamt(PyObject *self, PyObject *args)
1570+
{
1571+
return _PyContext_NewHamtForTests();
1572+
}
1573+
1574+
15671575
static PyMethodDef module_functions[] = {
15681576
{"get_configs", get_configs, METH_NOARGS},
15691577
{"get_recursion_depth", get_recursion_depth, METH_NOARGS},
@@ -1628,6 +1636,7 @@ static PyMethodDef module_functions[] = {
16281636
check_pyobject_uninitialized_is_freed, METH_NOARGS},
16291637
{"pymem_getallocatorsname", test_pymem_getallocatorsname, METH_NOARGS},
16301638
{"get_object_dict_values", get_object_dict_values, METH_O},
1639+
{"hamt", new_hamt, METH_NOARGS},
16311640
{NULL, NULL} /* sentinel */
16321641
};
16331642

0 commit comments

Comments
 (0)