Skip to content

ENH: Disable the alloc cache under address and memory sanitizers #29006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions numpy/_core/src/multiarray/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ indicate_hugepages(void *p, size_t size) {
}


/* Do not enable the alloc cache if the GIL is disabled, or if ASAN or MSAN
* instrumentation is enabled. The cache makes ASAN use-after-free or MSAN
* use-of-uninitialized-memory warnings less useful. */
#ifdef Py_GIL_DISABLED
#define USE_ALLOC_CACHE 0
#elif defined(__has_feature)
# if __has_feature(address_sanitizer) || __has_feature(memory_sanitizer)
# define USE_ALLOC_CACHE 0
# endif
#else
#define USE_ALLOC_CACHE 1
#endif


/* as the cache is managed in global variables verify the GIL is held */

/*
Expand All @@ -115,7 +129,7 @@ _npy_alloc_cache(npy_uintp nelem, npy_uintp esz, npy_uint msz,
assert((esz == 1 && cache == datacache) ||
(esz == sizeof(npy_intp) && cache == dimcache));
assert(PyGILState_Check());
#ifndef Py_GIL_DISABLED
#if USE_ALLOC_CACHE
if (nelem < msz) {
if (cache[nelem].available > 0) {
return cache[nelem].ptrs[--(cache[nelem].available)];
Expand All @@ -141,7 +155,7 @@ _npy_free_cache(void * p, npy_uintp nelem, npy_uint msz,
cache_bucket * cache, void (*dealloc)(void *))
{
assert(PyGILState_Check());
#ifndef Py_GIL_DISABLED
#if USE_ALLOC_CACHE
if (p != NULL && nelem < msz) {
if (cache[nelem].available < NCACHE) {
cache[nelem].ptrs[cache[nelem].available++] = p;
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy