gh-117657: Disable the function/code cache in free-threaded builds (#118301)

This is only used by the specializing interpreter and the tier 2
optimizer, both of which are disabled in free-threaded builds.
This commit is contained in:
mpage 2024-05-03 13:21:04 -07:00 • committed by GitHub
parent 5248596781
commit 37d0950022
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 23 additions and 1 deletions

View file

@ -287,6 +287,7 @@ functions is running.
void
_PyFunction_SetVersion(PyFunctionObject *func, uint32_t version)
{
#ifndef Py_GIL_DISABLED
PyInterpreterState *interp = _PyInterpreterState_GET();
if (func->func_version != 0) {
struct _func_version_cache_item *slot =
@ -297,7 +298,9 @@ _PyFunction_SetVersion(PyFunctionObject *func, uint32_t version)
// Leave slot->code alone, there may be use for it.
}
}
#endif
func->func_version = version;
#ifndef Py_GIL_DISABLED
if (version != 0) {
struct _func_version_cache_item *slot =
interp->func_state.func_version_cache
@ -305,11 +308,13 @@ _PyFunction_SetVersion(PyFunctionObject *func, uint32_t version)
slot->func = func;
slot->code = func->func_code;
}
#endif
}
void
_PyFunction_ClearCodeByVersion(uint32_t version)
{
#ifndef Py_GIL_DISABLED
PyInterpreterState *interp = _PyInterpreterState_GET();
struct _func_version_cache_item *slot =
interp->func_state.func_version_cache
@ -322,11 +327,15 @@ _PyFunction_ClearCodeByVersion(uint32_t version)
slot->func = NULL;
}
}
#endif
}
PyFunctionObject *
_PyFunction_LookupByVersion(uint32_t version, PyObject **p_code)
{
#ifdef Py_GIL_DISABLED
return NULL;
#else
PyInterpreterState *interp = _PyInterpreterState_GET();
struct _func_version_cache_item *slot =
interp->func_state.func_version_cache
@ -346,6 +355,7 @@ _PyFunction_LookupByVersion(uint32_t version, PyObject **p_code)
return slot->func;
}
return NULL;
#endif
}
uint32_t