diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2023-06-08 20:06:54 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-08 20:06:54 (GMT) |
commit | 68dfa496278aa21585eb4654d5f7ef13ef76cb50 (patch) | |
tree | 3a3cd54110d87512915634682f18818577c57ffe /Include | |
parent | 4ff5690e591b7d11cf11e34bf61004e2ea58ab3c (diff) | |
download | cpython-68dfa496278aa21585eb4654d5f7ef13ef76cb50.zip cpython-68dfa496278aa21585eb4654d5f7ef13ef76cb50.tar.gz cpython-68dfa496278aa21585eb4654d5f7ef13ef76cb50.tar.bz2 |
gh-100227: Lock Around Modification of the Global Allocators State (gh-105516)
The risk of a race with this state is relatively low, but we play it safe anyway. We do avoid using the lock in performance-sensitive cases where the risk of a race is very, very low.
Diffstat (limited to 'Include')
-rw-r--r-- | Include/internal/pycore_pymem.h | 1 | ||||
-rw-r--r-- | Include/internal/pycore_runtime_init.h | 6 |
2 files changed, 4 insertions, 3 deletions
diff --git a/Include/internal/pycore_pymem.h b/Include/internal/pycore_pymem.h index a555f37..81a707a 100644 --- a/Include/internal/pycore_pymem.h +++ b/Include/internal/pycore_pymem.h @@ -18,6 +18,7 @@ typedef struct { } debug_alloc_api_t; struct _pymem_allocators { + PyThread_type_lock mutex; struct { PyMemAllocatorEx raw; PyMemAllocatorEx mem; diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index 3b1444f..b507de0 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -25,9 +25,9 @@ extern PyTypeObject _PyExc_MemoryError; #define _PyRuntimeState_INIT(runtime) \ { \ .allocators = { \ - _pymem_allocators_standard_INIT(runtime), \ - _pymem_allocators_debug_INIT, \ - _pymem_allocators_obj_arena_INIT, \ + .standard = _pymem_allocators_standard_INIT(runtime), \ + .debug = _pymem_allocators_debug_INIT, \ + .obj_arena = _pymem_allocators_obj_arena_INIT, \ }, \ .obmalloc = _obmalloc_global_state_INIT, \ .pyhash_state = pyhash_state_INIT, \ |