diff options
author | Sam Gross <colesbury@gmail.com> | 2025-02-20 11:31:15 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-20 11:31:15 -0500 |
commit | ca22147547413229a933e3d9cac21cbecf1183fe (patch) | |
tree | d7b4da0377507121dd38266ce5049d5c7d4cb5f4 /Python/pystate.c | |
parent | 568db400ff07240a5ed6f263af281405ccaec716 (diff) | |
download | cpython-ca22147547413229a933e3d9cac21cbecf1183fe.tar.gz cpython-ca22147547413229a933e3d9cac21cbecf1183fe.zip |
gh-111924: Fix data races when swapping allocators (gh-130287)
CPython current temporarily changes `PYMEM_DOMAIN_RAW` to the default
allocator during initialization and shutdown. The motivation is to
ensure that core runtime structures are allocated and freed using the
same allocator. However, modifying the current allocator changes global
state and is not thread-safe even with the GIL. Other threads may be
allocating or freeing objects use PYMEM_DOMAIN_RAW; they are not
required to hold the GIL to call PyMem_RawMalloc/PyMem_RawFree.
This adds new internal-only functions like `_PyMem_DefaultRawMalloc`
that aren't affected by calls to `PyMem_SetAllocator()`, so they're
appropriate for Python runtime initialization and finalization. Use
these calls in places where we previously swapped to the default raw
allocator.
Diffstat (limited to 'Python/pystate.c')
-rw-r--r-- | Python/pystate.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/Python/pystate.c b/Python/pystate.c index 4caef2260ae..09b83cdeb1f 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -16,7 +16,7 @@ #include "pycore_parking_lot.h" // _PyParkingLot_AfterFork() #include "pycore_pyerrors.h" // _PyErr_Clear() #include "pycore_pylifecycle.h" // _PyAST_Fini() -#include "pycore_pymem.h" // _PyMem_SetDefaultAllocator() +#include "pycore_pymem.h" // _PyMem_DebugEnabled() #include "pycore_pystate.h" #include "pycore_runtime_init.h" // _PyRuntimeState_INIT #include "pycore_stackref.h" // Py_STACKREF_DEBUG |