Skip to content

Commit 68dfa49

Browse files
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.
1 parent 4ff5690 commit 68dfa49

File tree

4 files changed

+183
-56
lines changed

4 files changed

+183
-56
lines changed

Include/internal/pycore_pymem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ typedef struct {
1818
} debug_alloc_api_t;
1919

2020
struct _pymem_allocators {
21+
PyThread_type_lock mutex;
2122
struct {
2223
PyMemAllocatorEx raw;
2324
PyMemAllocatorEx mem;

Include/internal/pycore_runtime_init.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ extern PyTypeObject _PyExc_MemoryError;
2525
#define _PyRuntimeState_INIT(runtime) \
2626
{ \
2727
.allocators = { \
28-
_pymem_allocators_standard_INIT(runtime), \
29-
_pymem_allocators_debug_INIT, \
30-
_pymem_allocators_obj_arena_INIT, \
28+
.standard = _pymem_allocators_standard_INIT(runtime), \
29+
.debug = _pymem_allocators_debug_INIT, \
30+
.obj_arena = _pymem_allocators_obj_arena_INIT, \
3131
}, \
3232
.obmalloc = _obmalloc_global_state_INIT, \
3333
.pyhash_state = pyhash_state_INIT, \

0 commit comments

Comments
 (0)