diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2023-03-22 18:30:04 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-22 18:30:04 -0600 |
commit | 87be8d95228ee95de9045cf2952311d20dc5de45 (patch) | |
tree | 2f7172f22aaae687b17a04de208d79b757f68a7f /Python/pylifecycle.c | |
parent | 8709697292c67254ba836d7e88d1eba08c4a351a (diff) | |
download | cpython-git-87be8d95228ee95de9045cf2952311d20dc5de45.tar.gz |
gh-100227: Make the Global Interned Dict Safe for Isolated Interpreters (gh-102925)
This is effectively two changes. The first (the bulk of the change) is where we add _Py_AddToGlobalDict() (and _PyRuntime.cached_objects.main_tstate, etc.). The second (much smaller) change is where we update PyUnicode_InternInPlace() to use _Py_AddToGlobalDict() instead of calling PyDict_SetDefault() directly.
Basically, _Py_AddToGlobalDict() is a wrapper around PyDict_SetDefault() that should be used whenever we need to add a value to a runtime-global dict object (in the few cases where we are leaving the container global rather than moving it to PyInterpreterState, e.g. the interned strings dict). _Py_AddToGlobalDict() does all the necessary work to make sure the target global dict is shared safely between isolated interpreters. This is especially important as we move the obmalloc state to each interpreter (gh-101660), as well as, potentially, the GIL (PEP 684).
https://github.com/python/cpython/issues/100227
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r-- | Python/pylifecycle.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 8110d94ba1..5d7f862183 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -636,6 +636,8 @@ pycore_create_interpreter(_PyRuntimeState *runtime, return status; } + _PyThreadState_InitDetached(&runtime->cached_objects.main_tstate, interp); + *tstate_p = tstate; return _PyStatus_OK(); } @@ -1932,6 +1934,8 @@ Py_FinalizeEx(void) // XXX Do this sooner during finalization. // XXX Ensure finalizer errors are handled properly. + _PyThreadState_ClearDetached(&runtime->cached_objects.main_tstate); + finalize_interp_clear(tstate); finalize_interp_delete(tstate->interp); |