GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ENH: Disable the alloc cache under address and memory sanitizers · numpy/numpy@2e256fd

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • numpy/_core/src/multiarray
    • alloc.c
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎numpy/_core/src/multiarray/alloc.c‎

Copy file name to clipboardExpand all lines: numpy/_core/src/multiarray/alloc.c
+16-2Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,20 @@ indicate_hugepages(void *p, size_t size) {
9999
}
100100

101101

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+
102116
/* as the cache is managed in global variables verify the GIL is held */
103117

104118
/*
@@ -115,7 +129,7 @@ _npy_alloc_cache(npy_uintp nelem, npy_uintp esz, npy_uint msz,
115129
assert((esz == 1 && cache == datacache) ||
116130
(esz == sizeof(npy_intp) && cache == dimcache));
117131
assert(PyGILState_Check());
118-
#ifndef Py_GIL_DISABLED
132+
#if USE_ALLOC_CACHE
119133
if (nelem < msz) {
120134
if (cache[nelem].available > 0) {
121135
return cache[nelem].ptrs[--(cache[nelem].available)];
@@ -141,7 +155,7 @@ _npy_free_cache(void * p, npy_uintp nelem, npy_uint msz,
141155
cache_bucket * cache, void (*dealloc)(void *))
142156
{
143157
assert(PyGILState_Check());
144-
#ifndef Py_GIL_DISABLED
158+
#if USE_ALLOC_CACHE
145159
if (p != NULL && nelem < msz) {
146160
if (cache[nelem].available < NCACHE) {
147161
cache[nelem].ptrs[cache[nelem].available++] = p;

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.