summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Schemenauer <nas-github@arctrix.com>2025-04-28 19:54:55 (GMT)
committerGitHub <noreply@github.com>2025-04-28 19:54:55 (GMT)
commit22f0730d40c9534672f745f35cf876ad63d450bb (patch)
treeabda628fabbabb11501cffcb73afc0cdead8efec
parent336322b34137d90b0db19545c09a77f050ba8de0 (diff)
downloadcpython-22f0730d40c9534672f745f35cf876ad63d450bb.zip
cpython-22f0730d40c9534672f745f35cf876ad63d450bb.tar.gz
cpython-22f0730d40c9534672f745f35cf876ad63d450bb.tar.bz2
gh-122320: Limit dict key versions used by test_opcache. (gh-132961)
The `test_load_global_module()` test consumes a lot of dict key versions. Skip the test if we have consumed half of the available versions that can be used for the "load global" cache.
-rw-r--r--Lib/test/test_opcache.py12
-rw-r--r--Modules/_testinternalcapi.c13
-rw-r--r--Modules/clinic/_testinternalcapi.c.h19
3 files changed, 43 insertions, 1 deletions
diff --git a/Lib/test/test_opcache.py b/Lib/test/test_opcache.py
index ac13246..21d7e62 100644
--- a/Lib/test/test_opcache.py
+++ b/Lib/test/test_opcache.py
@@ -16,6 +16,16 @@ if check_impl_detail(cpython=False):
_testinternalcapi = import_module("_testinternalcapi")
+def have_dict_key_versions():
+ # max version value that can be stored in the load global cache. This is
+ # determined by the type of module_keys_version and builtin_keys_version
+ # in _PyLoadGlobalCache, uint16_t.
+ max_version = 1<<16
+ # use a wide safety margin (use only half of what's available)
+ limit = max_version // 2
+ return _testinternalcapi.get_next_dict_keys_version() < limit
+
+
class TestBase(unittest.TestCase):
def assert_specialized(self, f, opname):
instructions = dis.get_instructions(f, adaptive=True)
@@ -1029,6 +1039,8 @@ class TestRacesDoNotCrash(TestBase):
@requires_specialization_ft
def test_load_global_module(self):
+ if not have_dict_key_versions():
+ raise unittest.SkipTest("Low on dict key versions")
def get_items():
items = []
for _ in range(self.ITEMS):
diff --git a/Modules/_testinternalcapi.c b/Modules/_testinternalcapi.c
index 99dca9f..353cb63 100644
--- a/Modules/_testinternalcapi.c
+++ b/Modules/_testinternalcapi.c
@@ -1985,6 +1985,18 @@ gh_119213_getargs_impl(PyObject *module, PyObject *spam)
return Py_NewRef(spam);
}
+/*[clinic input]
+get_next_dict_keys_version
+[clinic start generated code]*/
+
+static PyObject *
+get_next_dict_keys_version_impl(PyObject *module)
+/*[clinic end generated code: output=e5405a509cf9d423 input=bd1cee7c6b9d3a3c]*/
+{
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ uint32_t keys_version = interp->dict_state.next_keys_version;
+ return PyLong_FromLong(keys_version);
+}
static PyObject *
get_static_builtin_types(PyObject *self, PyObject *Py_UNUSED(ignored))
@@ -2124,6 +2136,7 @@ static PyMethodDef module_functions[] = {
{"get_tracked_heap_size", get_tracked_heap_size, METH_NOARGS},
{"is_static_immortal", is_static_immortal, METH_O},
{"incref_decref_delayed", incref_decref_delayed, METH_O},
+ GET_NEXT_DICT_KEYS_VERSION_METHODDEF
{NULL, NULL} /* sentinel */
};
diff --git a/Modules/clinic/_testinternalcapi.c.h b/Modules/clinic/_testinternalcapi.c.h
index 7dfc169..21f4ee3 100644
--- a/Modules/clinic/_testinternalcapi.c.h
+++ b/Modules/clinic/_testinternalcapi.c.h
@@ -375,4 +375,21 @@ skip_optional_pos:
exit:
return return_value;
}
-/*[clinic end generated code: output=da34166d2c147e7a input=a9049054013a1b77]*/
+
+PyDoc_STRVAR(get_next_dict_keys_version__doc__,
+"get_next_dict_keys_version($module, /)\n"
+"--\n"
+"\n");
+
+#define GET_NEXT_DICT_KEYS_VERSION_METHODDEF \
+ {"get_next_dict_keys_version", (PyCFunction)get_next_dict_keys_version, METH_NOARGS, get_next_dict_keys_version__doc__},
+
+static PyObject *
+get_next_dict_keys_version_impl(PyObject *module);
+
+static PyObject *
+get_next_dict_keys_version(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ return get_next_dict_keys_version_impl(module);
+}
+/*[clinic end generated code: output=fbd8b7e0cae8bac7 input=a9049054013a1b77]*/