summaryrefslogtreecommitdiffstats
path: root/Python/pystate.c
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2023-01-23 15:30:20 (GMT)
committerGitHub <noreply@github.com>2023-01-23 15:30:20 (GMT)
commit7b20a0f55a16b3e2d274cc478e4d04bd8a836a9f (patch)
treec2b341aca1b1298d230d44a76be1960a62d77cd6 /Python/pystate.c
parent984387f39a3385ed5699bd7e21797c348e543b19 (diff)
downloadcpython-7b20a0f55a16b3e2d274cc478e4d04bd8a836a9f.zip
cpython-7b20a0f55a16b3e2d274cc478e4d04bd8a836a9f.tar.gz
cpython-7b20a0f55a16b3e2d274cc478e4d04bd8a836a9f.tar.bz2
gh-59956: Allow the "Trashcan" Mechanism to Work Without a Thread State (gh-101209)
We've factored out a struct from the two PyThreadState fields. This accomplishes two things: * make it clear that the trashcan-related code doesn't need any other parts of PyThreadState * allows us to use the trashcan mechanism even when there isn't a "current" thread state We still expect the caller to hold the GIL. https://github.com/python/cpython/issues/59956
Diffstat (limited to 'Python/pystate.c')
-rw-r--r--Python/pystate.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/Python/pystate.c b/Python/pystate.c
index 5c1636a..d31c1f1 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -400,6 +400,11 @@ _PyRuntimeState_Init(_PyRuntimeState *runtime)
return status;
}
+ if (PyThread_tss_create(&runtime->trashTSSkey) != 0) {
+ _PyRuntimeState_Fini(runtime);
+ return _PyStatus_NO_MEMORY();
+ }
+
init_runtime(runtime, open_code_hook, open_code_userdata, audit_hook_head,
unicode_next_index, lock1, lock2, lock3, lock4);
@@ -413,6 +418,10 @@ _PyRuntimeState_Fini(_PyRuntimeState *runtime)
current_tss_fini(runtime);
}
+ if (PyThread_tss_is_created(&runtime->trashTSSkey)) {
+ PyThread_tss_delete(&runtime->trashTSSkey);
+ }
+
/* Force the allocator used by _PyRuntimeState_Init(). */
PyMemAllocatorEx old_alloc;
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
@@ -471,6 +480,13 @@ _PyRuntimeState_ReInitThreads(_PyRuntimeState *runtime)
return status;
}
+ if (PyThread_tss_is_created(&runtime->trashTSSkey)) {
+ PyThread_tss_delete(&runtime->trashTSSkey);
+ }
+ if (PyThread_tss_create(&runtime->trashTSSkey) != 0) {
+ return _PyStatus_NO_MEMORY();
+ }
+
return _PyStatus_OK();
}
#endif