Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 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
3 changes: 2 additions & 1 deletion Include/internal/pycore_dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ extern PyObject *_PyDict_FromKeys(PyObject *, PyObject *, PyObject *);

/* Gets a version number unique to the current state of the keys of dict, if possible.
* Returns the version number, or zero if it was not possible to get a version number. */
extern uint32_t _PyDictKeys_GetVersionForCurrentState(
// Export for '_testinternalcapi' extension
PyAPI_FUNC(uint32_t) _PyDictKeys_GetVersionForCurrentState(
PyInterpreterState *interp, PyDictKeysObject *dictkeys);

extern size_t _PyDict_KeysSize(PyDictKeysObject *keys);
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_opcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,9 @@ def assert_races_do_not_crash(
# Reset:
if check_items:
for item in items:
# Checking for overflow
if _testinternalcapi.is_version_overflowed(item.__globals__):
return unittest.skip("Version number is overflowed; no rerun is possible")
item.__code__ = item.__code__.replace()
else:
read.__code__ = read.__code__.replace()
Expand Down
19 changes: 19 additions & 0 deletions Modules/_testinternalcapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -2034,6 +2034,24 @@ gh_119213_getargs_impl(PyObject *module, PyObject *spam)
return Py_NewRef(spam);
}

/*[clinic input]
is_version_overflowed

dict: object(type="PyDictObject *", subclass_of="&PyDict_Type")

[clinic start generated code]*/

static PyObject *
is_version_overflowed_impl(PyObject *module, PyDictObject *dict)
/*[clinic end generated code: output=e7d20960c423d073 input=a68a26cde1cc7a9e]*/
{
PyInterpreterState *interp = _PyInterpreterState_GET();
uint32_t keys_version = _PyDictKeys_GetVersionForCurrentState(interp, dict->ma_keys);
if (keys_version != (uint16_t)keys_version){
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;
}

static PyObject *
get_static_builtin_types(PyObject *self, PyObject *Py_UNUSED(ignored))
Expand Down Expand Up @@ -2145,6 +2163,7 @@ static PyMethodDef module_functions[] = {
GH_119213_GETARGS_METHODDEF
{"get_static_builtin_types", get_static_builtin_types, METH_NOARGS},
{"identify_type_slot_wrappers", identify_type_slot_wrappers, METH_NOARGS},
IS_VERSION_OVERFLOWED_METHODDEF
{NULL, NULL} /* sentinel */
};

Expand Down
60 changes: 59 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