Skip to content

Commit 2fd11c0

Browse files
committed
BUG: disable the loop data cache in the nogil build
1 parent 12aa98e commit 2fd11c0

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

numpy/_core/src/umath/legacy_array_method.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,37 +33,43 @@ typedef struct {
3333

3434

3535
/* Use a free list, since we should normally only need one at a time */
36+
#ifndef Py_GIL_DISABLED
3637
#define NPY_LOOP_DATA_CACHE_SIZE 5
3738
static int loop_data_num_cached = 0;
3839
static legacy_array_method_auxdata *loop_data_cache[NPY_LOOP_DATA_CACHE_SIZE];
39-
40+
#else
41+
#define NPY_LOOP_DATA_CACHE_SIZE 0
42+
#endif
4043

4144
static void
4245
legacy_array_method_auxdata_free(NpyAuxData *data)
4346
{
47+
#if NPY_LOOP_DATA_CACHE_SIZE > 0
4448
if (loop_data_num_cached < NPY_LOOP_DATA_CACHE_SIZE) {
4549
loop_data_cache[loop_data_num_cached] = (
4650
(legacy_array_method_auxdata *)data);
4751
loop_data_num_cached++;
4852
}
49-
else {
53+
else
54+
#endif
55+
{
5056
PyMem_Free(data);
5157
}
5258
}
5359

54-
#undef NPY_LOOP_DATA_CACHE_SIZE
55-
56-
5760
NpyAuxData *
5861
get_new_loop_data(
5962
PyUFuncGenericFunction loop, void *user_data, int pyerr_check)
6063
{
6164
legacy_array_method_auxdata *data;
65+
#if NPY_LOOP_DATA_CACHE_SIZE > 0
6266
if (NPY_LIKELY(loop_data_num_cached > 0)) {
6367
loop_data_num_cached--;
6468
data = loop_data_cache[loop_data_num_cached];
6569
}
66-
else {
70+
else
71+
#endif
72+
{
6773
data = PyMem_Malloc(sizeof(legacy_array_method_auxdata));
6874
if (data == NULL) {
6975
return NULL;
@@ -77,6 +83,7 @@ get_new_loop_data(
7783
return (NpyAuxData *)data;
7884
}
7985

86+
#undef NPY_LOOP_DATA_CACHE_SIZE
8087

8188
/*
8289
* This is a thin wrapper around the legacy loop signature.

0 commit comments

Comments
 (0)