summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-06-08 22:35:53 (GMT)
committerGitHub <noreply@github.com>2023-06-08 22:35:53 (GMT)
commit77c03a3b7241a8476665db89f058bb6eb15f8abb (patch)
treec345b60f5be8dc9a610f69b9d314dc3f472e9f92 /Include
parent3eccd95f56f2c360ec39a37e15ce7e9c3f134528 (diff)
downloadcpython-77c03a3b7241a8476665db89f058bb6eb15f8abb.zip
cpython-77c03a3b7241a8476665db89f058bb6eb15f8abb.tar.gz
cpython-77c03a3b7241a8476665db89f058bb6eb15f8abb.tar.bz2
[3.12] gh-100227: Lock Around Modification of the Global Allocators State (gh-105516) (gh-105532)
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. (cherry picked from commit 68dfa496278aa21585eb4654d5f7ef13ef76cb50) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
Diffstat (limited to 'Include')
-rw-r--r--Include/internal/pycore_pymem.h1
-rw-r--r--Include/internal/pycore_runtime_init.h6
2 files changed, 4 insertions, 3 deletions
diff --git a/Include/internal/pycore_pymem.h b/Include/internal/pycore_pymem.h
index 4cc953d..c2f0325 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, \