diff options
author | Sam Gross <colesbury@gmail.com> | 2024-05-07 00:12:39 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-07 00:12:39 (GMT) |
commit | 723d4d2fe8e77b398f0ccffcfa541149caaac6a1 (patch) | |
tree | 8d213981ac3bc060c5046acdc256015d2c821476 /Modules/_testinternalcapi.c | |
parent | 8d8275b0cf43f0e20c72a9641cbddc5044cdae04 (diff) | |
download | cpython-723d4d2fe8e77b398f0ccffcfa541149caaac6a1.zip cpython-723d4d2fe8e77b398f0ccffcfa541149caaac6a1.tar.gz cpython-723d4d2fe8e77b398f0ccffcfa541149caaac6a1.tar.bz2 |
gh-118527: Intern code consts in free-threaded build (#118667)
We already intern and immortalize most string constants. In the
free-threaded build, other constants can be a source of reference count
contention because they are shared by all threads running the same code
objects.
Diffstat (limited to 'Modules/_testinternalcapi.c')
-rw-r--r-- | Modules/_testinternalcapi.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Modules/_testinternalcapi.c b/Modules/_testinternalcapi.c index de98af3..e209c7e 100644 --- a/Modules/_testinternalcapi.c +++ b/Modules/_testinternalcapi.c @@ -1986,6 +1986,17 @@ set_immortalize_deferred(PyObject *self, PyObject *value) } static PyObject * +get_immortalize_deferred(PyObject *self, PyObject *Py_UNUSED(ignored)) +{ +#ifdef Py_GIL_DISABLED + PyInterpreterState *interp = PyInterpreterState_Get(); + return PyBool_FromLong(interp->gc.immortalize.enable_on_thread_created); +#else + Py_RETURN_FALSE; +#endif +} + +static PyObject * has_inline_values(PyObject *self, PyObject *obj) { if ((Py_TYPE(obj)->tp_flags & Py_TPFLAGS_INLINE_VALUES) && @@ -2081,6 +2092,7 @@ static PyMethodDef module_functions[] = { {"py_thread_id", get_py_thread_id, METH_NOARGS}, #endif {"set_immortalize_deferred", set_immortalize_deferred, METH_VARARGS}, + {"get_immortalize_deferred", get_immortalize_deferred, METH_NOARGS}, #ifdef _Py_TIER2 {"uop_symbols_test", _Py_uop_symbols_test, METH_NOARGS}, #endif |