16
16
# include "mimalloc/internal.h" // for stats
17
17
#endif
18
18
19
+ #if defined(Py_GIL_DISABLED ) && !defined(WITH_MIMALLOC )
20
+ # error "Py_GIL_DISABLED requires WITH_MIMALLOC"
21
+ #endif
22
+
19
23
#undef uint
20
24
#define uint pymem_uint
21
25
@@ -153,7 +157,12 @@ void* _PyObject_Realloc(void *ctx, void *ptr, size_t size);
153
157
# define PYMALLOC_ALLOC {NULL, _PyObject_Malloc, _PyObject_Calloc, _PyObject_Realloc, _PyObject_Free}
154
158
#endif // WITH_PYMALLOC
155
159
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 )
157
166
# define PYRAW_ALLOC MALLOC_ALLOC
158
167
# define PYMEM_ALLOC PYMALLOC_ALLOC
159
168
# define PYOBJ_ALLOC PYMALLOC_ALLOC
@@ -350,7 +359,7 @@ _PyMem_GetAllocatorName(const char *name, PyMemAllocatorName *allocator)
350
359
else if (strcmp (name , "debug" ) == 0 ) {
351
360
* allocator = PYMEM_ALLOCATOR_DEBUG ;
352
361
}
353
- #ifdef WITH_PYMALLOC
362
+ #if defined( WITH_PYMALLOC ) && !defined( Py_GIL_DISABLED )
354
363
else if (strcmp (name , "pymalloc ") == 0 ) {
355
364
* allocator = PYMEM_ALLOCATOR_PYMALLOC ;
356
365
}
@@ -366,12 +375,14 @@ _PyMem_GetAllocatorName(const char *name, PyMemAllocatorName *allocator)
366
375
* allocator = PYMEM_ALLOCATOR_MIMALLOC_DEBUG ;
367
376
}
368
377
#endif
378
+ #ifndef Py_GIL_DISABLED
369
379
else if (strcmp (name , "malloc ") == 0 ) {
370
380
* allocator = PYMEM_ALLOCATOR_MALLOC ;
371
381
}
372
382
else if (strcmp (name , "malloc_debug" ) == 0 ) {
373
383
* allocator = PYMEM_ALLOCATOR_MALLOC_DEBUG ;
374
384
}
385
+ #endif
375
386
else {
376
387
/* unknown allocator */
377
388
return -1 ;
0 commit comments