Skip to content

Commit ab719e1

Browse files
committed
MNT: disable the coercion cache for the nogil build
1 parent fd3a52b commit ab719e1

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

numpy/_core/src/multiarray/array_coercion.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,10 +614,13 @@ update_shape(int curr_ndim, int *max_ndim,
614614
return success;
615615
}
616616

617-
617+
#ifndef Py_GIL_DISABLED
618618
#define COERCION_CACHE_CACHE_SIZE 5
619619
static int _coercion_cache_num = 0;
620620
static coercion_cache_obj *_coercion_cache_cache[COERCION_CACHE_CACHE_SIZE];
621+
#else
622+
#define COERCION_CACHE_CACHE_SIZE 0
623+
#endif
621624

622625
/*
623626
* Steals a reference to the object.
@@ -628,11 +631,14 @@ npy_new_coercion_cache(
628631
coercion_cache_obj ***next_ptr, int ndim)
629632
{
630633
coercion_cache_obj *cache;
634+
#if COERCION_CACHE_CACHE_SIZE > 0
631635
if (_coercion_cache_num > 0) {
632636
_coercion_cache_num--;
633637
cache = _coercion_cache_cache[_coercion_cache_num];
634638
}
635-
else {
639+
else
640+
#endif
641+
{
636642
cache = PyMem_Malloc(sizeof(coercion_cache_obj));
637643
}
638644
if (cache == NULL) {
@@ -661,11 +667,14 @@ npy_unlink_coercion_cache(coercion_cache_obj *current)
661667
{
662668
coercion_cache_obj *next = current->next;
663669
Py_DECREF(current->arr_or_sequence);
670+
#if COERCION_CACHE_CACHE_SIZE > 0
664671
if (_coercion_cache_num < COERCION_CACHE_CACHE_SIZE) {
665672
_coercion_cache_cache[_coercion_cache_num] = current;
666673
_coercion_cache_num++;
667674
}
668-
else {
675+
else
676+
#endif
677+
{
669678
PyMem_Free(current);
670679
}
671680
return next;

0 commit comments

Comments
 (0)