8000 gh-100227: Make the Global Interned Dict Safe for Isolated Interpreters by ericsnowcurrently · Pull Request #102925 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-100227: Make the Global Interned Dict Safe for Isolated Interpreters #102925

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
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Add _PyRuntime.cached_objects.main_tstate.
  • Loading branch information
ericsnowcurrently committed Mar 22, 2023
commit cba9e34b991f77d28510dc63c636896a21c257fd
4 changes: 4 additions & 0 deletions Include/internal/pycore_global_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ extern "C" {

struct _Py_cached_objects {
PyObject *interned_strings;
/* A thread state tied to the main interpreter,
used exclusively for when a global object (e.g. interned strings)
is resized (i.e. deallocated + allocated) from an arbitrary thread. */
PyThreadState main_tstate;
};

#define _Py_GLOBAL_OBJECT(NAME) \
Expand Down
3 changes: 3 additions & 0 deletions Include/internal/pycore_runtime_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ extern PyTypeObject _PyExc_MemoryError;
.types = { \
.next_version_tag = 1, \
}, \
.cached_objects = { \
.main_tstate = _PyThreadState_INIT, \
}, \
.static_objects = { \
.singletons = { \
.small_ints = _Py_small_ints_INIT, \
Expand Down
4 changes: 4 additions & 0 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,8 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
return status;
}

_PyThreadState_InitDetached(&runtime->cached_objects.main_tstate, interp);

*tstate_p = tstate;
return _PyStatus_OK();
}
Expand Down Expand Up @@ -1928,6 +1930,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);

Expand Down
0