From e6d16caa7c1b8de99a63c2f1ac0d40f6cfcf28aa Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Mon, 31 Jul 2023 16:17:53 -0600 Subject: [PATCH 1/3] Document that custom allocators must be thread-safe. --- Doc/c-api/memory.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Doc/c-api/memory.rst b/Doc/c-api/memory.rst index 8968b26b64320a..1df8c2b911ca8f 100644 --- a/Doc/c-api/memory.rst +++ b/Doc/c-api/memory.rst @@ -476,6 +476,10 @@ Customize Memory Allocators thread-safe: the :term:`GIL ` 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) From c268cf249a36ba5d12b4086e441ea24de2770f0a Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Mon, 31 Jul 2023 16:28:57 -0600 Subject: [PATCH 2/3] Add a What's New entry. --- Doc/whatsnew/3.12.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index 99500e1f321468..ed4ce0ef845e27 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -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 ---------- From c2c7735e388e87db665caec9fd0325e0e6d2a72e Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Mon, 31 Jul 2023 17:01:13 -0600 Subject: [PATCH 3/3] Fix a typo. --- Doc/whatsnew/3.12.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index ed4ce0ef845e27..dcbc4ac56dddc7 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -1881,7 +1881,7 @@ Porting to Python 3.12 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`. + and CC ``@ericsnowcurrently``. Deprecated ----------