gh-112529: Use _PyThread_Id() in mimalloc in free-threaded build (#115488)

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.
This commit is contained in:
Sam Gross 2024-02-14 16:41:29 -05:00 committed by GitHub
parent a95b1a56bb
commit 326119d373
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 4 deletions

View 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>

View 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