]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-112529: Use _PyThread_Id() in mimalloc in free-threaded build (#115488)
authorSam Gross <colesbury@gmail.com>
Wed, 14 Feb 2024 21:41:29 +0000 (16:41 -0500)
committerGitHub <noreply@github.com>
Wed, 14 Feb 2024 21:41:29 +0000 (16:41 -0500)
The free-threaded GC uses mimallocs segment thread IDs to restore
the overwritten `ob_tid` thread ids in PyObjects. For that reason, it's
important that PyObjects and mimalloc use the same identifiers.

Include/internal/mimalloc/mimalloc/prim.h
Include/internal/pycore_mimalloc.h

index 4b9e4dc4194d776288d62342308317f4530aa1a7..8a60d528458e6c2d5af8914c618dfb509cd0465f 100644 (file)
@@ -131,7 +131,13 @@ extern bool _mi_process_is_initialized;             // has mi_process_init been
 
 static inline mi_threadid_t _mi_prim_thread_id(void) mi_attr_noexcept;
 
-#if defined(_WIN32)
+#ifdef MI_PRIM_THREAD_ID
+
+static inline mi_threadid_t _mi_prim_thread_id(void) mi_attr_noexcept {
+  return MI_PRIM_THREAD_ID();
+}
+
+#elif defined(_WIN32)
 
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
index 1e7ed5a4ca62e20c576a2e542fecb4241c41a67c..14c98108ec131e0f8c52ef5f80e4586e9b911f4e 100644 (file)
@@ -20,9 +20,12 @@ typedef enum {
 #include "pycore_pymem.h"
 
 #ifdef WITH_MIMALLOC
-#define MI_DEBUG_UNINIT     PYMEM_CLEANBYTE
-#define MI_DEBUG_FREED      PYMEM_DEADBYTE
-#define MI_DEBUG_PADDING    PYMEM_FORBIDDENBYTE
+#  ifdef Py_GIL_DISABLED
+#    define MI_PRIM_THREAD_ID   _Py_ThreadId
+#  endif
+#  define MI_DEBUG_UNINIT     PYMEM_CLEANBYTE
+#  define MI_DEBUG_FREED      PYMEM_DEADBYTE
+#  define MI_DEBUG_PADDING    PYMEM_FORBIDDENBYTE
 #ifdef Py_DEBUG
 #  define MI_DEBUG 1
 #else