8000 Merge pull request #29046 from charris/backport-29041 · numpy/numpy@78f0dbd · GitHub
[go: up one dir, main page]

Skip to content

Commit 78f0dbd

Browse files
authored
Merge pull request #29046 from charris/backport-29041
BUG: Fix cache use regression
2 parents b0b0ae4 + 975458f commit 78f0dbd

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

numpy/_core/src/multiarray/alloc.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,21 @@
2727
#endif
2828
#endif
2929

30-
#define NBUCKETS 1024 /* number of buckets for data*/
31-
#define NBUCKETS_DIM 16 /* number of buckets for dimensions/strides */
32-
#define NCACHE 7 /* number of cache entries per bucket */
30+
/* Do not enable the alloc cache if the GIL is disabled, or if ASAN or MSAN
31+
* instrumentation is enabled. The cache makes ASAN use-after-free or MSAN
32+
* use-of-uninitialized-memory warnings less useful. */
33+
#define USE_ALLOC_CACHE 1
34+
#ifdef Py_GIL_DISABLED
35+
# define USE_ALLOC_CACHE 0
36+
#elif defined(__has_feature)
37+
# if __has_feature(address_sanitizer) || __has_feature(memory_sanitizer)
38+
# define USE_ALLOC_CACHE 0
39+
# endif
40+
#endif
41+
42+
# define NBUCKETS 1024 /* number of buckets for data*/
43+
# define NBUCKETS_DIM 16 /* number of buckets for dimensions/strides */
44+
# define NCACHE 7 /* number of cache entries per bucket */
3345
/* this structure fits neatly into a cacheline */
3446
typedef struct {
3547
npy_uintp available; /* number of cached pointers */
@@ -38,7 +50,6 @@ typedef struct {
3850
static cache_bucket datacache[NBUCKETS];
3951
static cache_bucket dimcache[NBUCKETS_DIM];
4052

41-
4253
/*
4354
* This function tells whether NumPy attempts to call `madvise` with
4455
* `MADV_HUGEPAGE`. `madvise` is only ever used on linux, so the value
@@ -99,20 +110,6 @@ indicate_hugepages(void *p, size_t size) {
99110
}
100111

101112

102-
/* Do not enable the alloc cache if the GIL is disabled, or if ASAN or MSAN
103-
* instrumentation is enabled. The cache makes ASAN use-after-free or MSAN
104-
* use-of-uninitialized-memory warnings less useful. */
105-
#ifdef Py_GIL_DISABLED
106-
#define USE_ALLOC_CACHE 0
107-
#elif defined(__has_feature)
108-
# if __has_feature(address_sanitizer) || __has_feature(memory_sanitizer)
109-
# define USE_ALLOC_CACHE 0
110-
# endif
111-
#else
112-
#define USE_ALLOC_CACHE 1
113-
#endif
114-
115-
116113
/* as the cache is managed in global variables verify the GIL is held */
117114

118115
/*

0 commit comments

Comments
 (0)
0