Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-105766: Document that Custom Allocators Must Be Thread-Safe #107519

Merged
merged 3 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Doc/c-api/memory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions Doc/whatsnew/3.12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1876,6 +1876,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
----------

Expand Down