Skip to content

Commit fc4532a

Browse files
[3.12] gh-105766: Document that Custom Allocators Must Be Thread-Safe (gh-107519) (gh-107522)
gh-105766: Document that Custom Allocators Must Be Thread-Safe (gh-107519) (cherry picked from commit db361a3) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
1 parent 31cd12a commit fc4532a

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Doc/c-api/memory.rst

+6
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,10 @@ Customize Memory Allocators
476476
thread-safe: the :term:`GIL <global interpreter lock>` is not held when the
477477
allocator is called.
478478
479+
For the remaining domains, the allocator must also be thread-safe:
480+
the allocator may be called in different interpreters that do not
481+
share a ``GIL``.
482+
479483
If the new allocator is not a hook (does not call the previous allocator),
480484
the :c:func:`PyMem_SetupDebugHooks` function must be called to reinstall the
481485
debug hooks on top on the new allocator.
@@ -500,6 +504,8 @@ Customize Memory Allocators
500504
**must** wrap the existing allocator. Substituting the current
501505
allocator for some other arbitrary one is **not supported**.
502506
507+
.. versionchanged:: 3.12
508+
All allocators must be thread-safe.
503509
504510
505511
.. c:function:: void PyMem_SetupDebugHooks(void)

Doc/whatsnew/3.12.rst

+7
Original file line numberDiff line numberDiff line change
@@ -1922,6 +1922,13 @@ Porting to Python 3.12
19221922
* :c:func:`PyUnstable_Long_IsCompact`
19231923
* :c:func:`PyUnstable_Long_CompactValue`
19241924

1925+
* Custom allocators, set via :c:func:`PyMem_SetAllocator`, are now
1926+
required to be thread-safe, regardless of memory domain. Allocators
1927+
that don't have their own state, including "hooks", are not affected.
1928+
If your custom allocator is not already thread-safe and you need
1929+
guidance then please create a new GitHub issue
1930+
and CC ``@ericsnowcurrently``.
1931+
19251932
Deprecated
19261933
----------
19271934

0 commit comments

Comments
 (0)