1 #ifndef Py_INTERNAL_MIMALLOC_H 2 #define Py_INTERNAL_MIMALLOC_H 3 4 #ifndef Py_BUILD_CORE 5 # error "this header requires Py_BUILD_CORE define" 6 #endif 7 8 #if defined(MIMALLOC_H) || defined(MIMALLOC_TYPES_H) 9 # error "pycore_mimalloc.h must be included before mimalloc.h" 10 #endif 11 12 typedef enum { 13 _Py_MIMALLOC_HEAP_MEM = 0, // PyMem_Malloc() and friends 14 _Py_MIMALLOC_HEAP_OBJECT = 1, // non-GC objects 15 _Py_MIMALLOC_HEAP_GC = 2, // GC objects without pre-header 16 _Py_MIMALLOC_HEAP_GC_PRE = 3, // GC objects with pre-header 17 _Py_MIMALLOC_HEAP_COUNT 18 } _Py_mimalloc_heap_id; 19 20 #include "pycore_pymem.h" 21 22 #ifdef WITH_MIMALLOC 23 # ifdef Py_GIL_DISABLED 24 # define MI_PRIM_THREAD_ID _Py_ThreadId 25 # endif 26 # define MI_DEBUG_UNINIT PYMEM_CLEANBYTE 27 # define MI_DEBUG_FREED PYMEM_DEADBYTE 28 # define MI_DEBUG_PADDING PYMEM_FORBIDDENBYTE 29 #ifdef Py_DEBUG 30 # define MI_DEBUG 2 31 #else 32 # define MI_DEBUG 0 33 #endif 34 35 #ifdef _Py_THREAD_SANITIZER 36 # define MI_TSAN 1 37 #endif 38 39 #ifdef __cplusplus 40 extern "C++" { 41 #endif 42 43 #include "mimalloc/mimalloc.h" 44 #include "mimalloc/mimalloc/types.h" 45 #include "mimalloc/mimalloc/internal.h" 46 47 #ifdef __cplusplus 48 } 49 #endif 50 51 #endif 52 53 #ifdef Py_GIL_DISABLED 54 struct _mimalloc_interp_state { 55 // When exiting, threads place any segments with live blocks in this 56 // shared pool for other threads to claim and reuse. 57 mi_abandoned_pool_t abandoned_pool; 58 }; 59 60 struct _mimalloc_thread_state { 61 mi_heap_t *current_object_heap; 62 mi_heap_t heaps[_Py_MIMALLOC_HEAP_COUNT]; 63 mi_tld_t tld; 64 int initialized; 65 struct llist_node page_list; 66 }; 67 #endif 68 69 #endif // Py_INTERNAL_MIMALLOC_H 70