File tree 1 file changed +14
-3
lines changed
1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -328,9 +328,20 @@ struct NpyAuxData_tag {
328
328
#define NPY_USE_PYMEM 1
329
329
330
330
#if NPY_USE_PYMEM == 1
331
- #define PyArray_malloc PyMem_Malloc
332
- #define PyArray_free PyMem_Free
333
- #define PyArray_realloc PyMem_Realloc
331
+ /* numpy sometimes calls PyArray_malloc() with the GIL released. On Python
332
+ 3.3 and older, it was safe to call PyMem_Malloc() with the GIL released.
333
+ On Python 3.4 and newer, it's better to use PyMem_RawMalloc() to be able
334
+ to use tracemalloc. On Python 3.6, calling PyMem_Malloc() with the GIL
335
+ released is now a fatal error in debug mode. */
336
+ # if PY_VERSION_HEX >= 0x03040000
337
+ # define PyArray_malloc PyMem_RawMalloc
338
+ # define PyArray_free PyMem_RawFree
339
+ # define PyArray_realloc PyMem_RawRealloc
340
+ # else
341
+ # define PyArray_malloc PyMem_Malloc
342
+ # define PyArray_free PyMem_Free
343
+ # define PyArray_realloc PyMem_Realloc
344
+ # endif
334
345
#else
335
346
#define PyArray_malloc malloc
336
347
#define PyArray_free free
You can’t perform that action at this time.
0 commit comments