Skip to content

Commit 631e989

Browse files
committed
Merge pull request numpy#7404 from haypo/raw_malloc
Use PyMem_RawMalloc on Python 3.4 and newer
2 parents 3509704 + 383a44e commit 631e989

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

numpy/core/include/numpy/ndarraytypes.h

+14-3
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,20 @@ struct NpyAuxData_tag {
328328
#define NPY_USE_PYMEM 1
329329

330330
#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
334345
#else
335346
#define PyArray_malloc malloc
336347
#define PyArray_free free

0 commit comments

Comments
 (0)