Skip to content

gh-122320: Limit dict key versions used by test_opcache. #132961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Lib/test/test_opcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
_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)
Expand Down Expand Up @@ -1029,6 +1039,8 @@ def write(items):

@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):
Expand Down
13 changes: 13 additions & 0 deletions Modules/_testinternalcapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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 */
};

Expand Down
19 changes: 18 additions & 1 deletion Modules/clinic/_testinternalcapi.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading