1616# include "mimalloc/internal.h" // for stats
1717#endif
1818
19+ #if defined(Py_GIL_DISABLED ) && !defined(WITH_MIMALLOC )
20+ # error "Py_GIL_DISABLED requires WITH_MIMALLOC"
21+ #endif
22+
1923#undef uint
2024#define uint pymem_uint
2125
@@ -153,7 +157,12 @@ void* _PyObject_Realloc(void *ctx, void *ptr, size_t size);
153157# define PYMALLOC_ALLOC {NULL, _PyObject_Malloc, _PyObject_Calloc, _PyObject_Realloc, _PyObject_Free}
154158#endif // WITH_PYMALLOC
155159
156- #if defined(WITH_PYMALLOC )
160+ #if defined(Py_GIL_DISABLED )
161+ // Py_GIL_DISABLED requires using mimalloc for "mem" and "obj" domains.
162+ # define PYRAW_ALLOC MALLOC_ALLOC
163+ # define PYMEM_ALLOC MIMALLOC_ALLOC
164+ # define PYOBJ_ALLOC MIMALLOC_OBJALLOC
165+ #elif defined(WITH_PYMALLOC )
157166# define PYRAW_ALLOC MALLOC_ALLOC
158167# define PYMEM_ALLOC PYMALLOC_ALLOC
159168# define PYOBJ_ALLOC PYMALLOC_ALLOC
@@ -350,7 +359,7 @@ _PyMem_GetAllocatorName(const char *name, PyMemAllocatorName *allocator)
350359 else if (strcmp (name , "debug" ) == 0 ) {
351360 * allocator = PYMEM_ALLOCATOR_DEBUG ;
352361 }
353- #ifdef WITH_PYMALLOC
362+ #if defined( WITH_PYMALLOC ) && !defined( Py_GIL_DISABLED )
354363 else if (strcmp (name , "pymalloc ") == 0 ) {
355364 * allocator = PYMEM_ALLOCATOR_PYMALLOC ;
356365 }
@@ -366,12 +375,14 @@ _PyMem_GetAllocatorName(const char *name, PyMemAllocatorName *allocator)
366375 * allocator = PYMEM_ALLOCATOR_MIMALLOC_DEBUG ;
367376 }
368377#endif
378+ #ifndef Py_GIL_DISABLED
369379 else if (strcmp (name , "malloc ") == 0 ) {
370380 * allocator = PYMEM_ALLOCATOR_MALLOC ;
371381 }
372382 else if (strcmp (name , "malloc_debug" ) == 0 ) {
373383 * allocator = PYMEM_ALLOCATOR_MALLOC_DEBUG ;
374384 }
385+ #endif
375386 else {
376387 /* unknown allocator */
377388 return -1 ;
0 commit comments