]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-105766: Document that Custom Allocators Must Be Thread-Safe (gh-107519)
authorEric Snow <ericsnowcurrently@gmail.com>
Mon, 31 Jul 2023 23:11:15 +0000 (17:11 -0600)
committerGitHub <noreply@github.com>
Mon, 31 Jul 2023 23:11:15 +0000 (23:11 +0000)
Doc/c-api/memory.rst
Doc/whatsnew/3.12.rst

index 8968b26b64320aa747b8f4e2569d3bcccd142976..1df8c2b911ca8f18c24a70b1e2bfc8bd1bcb88c1 100644 (file)
@@ -476,6 +476,10 @@ Customize Memory Allocators
    thread-safe: the :term:`GIL <global interpreter lock>` is not held when the
    allocator is called.
 
+   For the remaining domains, the allocator must also be thread-safe:
+   the allocator may be called in different interpreters that do not
+   share a ``GIL``.
+
    If the new allocator is not a hook (does not call the previous allocator),
    the :c:func:`PyMem_SetupDebugHooks` function must be called to reinstall the
    debug hooks on top on the new allocator.
@@ -500,6 +504,8 @@ Customize Memory Allocators
           **must** wrap the existing allocator. Substituting the current
           allocator for some other arbitrary one is **not supported**.
 
+   .. versionchanged:: 3.12
+      All allocators must be thread-safe.
 
 
 .. c:function:: void PyMem_SetupDebugHooks(void)
index 0ac4a3df8fefa3d19e79f87c574af4862e54bff0..a5cb325cedb220a7e4611b7cc811a314d7ae0c1a 100644 (file)
@@ -1880,6 +1880,13 @@ Porting to Python 3.12
   * :c:func:`PyUnstable_Long_IsCompact`
   * :c:func:`PyUnstable_Long_CompactValue`
 
+* Custom allocators, set via :c:func:`PyMem_SetAllocator`, are now
+  required to be thread-safe, regardless of memory domain.  Allocators
+  that don't have their own state, including "hooks", are not affected.
+  If your custom allocator is not already thread-safe and you need
+  guidance then please create a new GitHub issue
+  and CC ``@ericsnowcurrently``.
+
 Deprecated
 ----------