Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0506cf6

Browse files
authored
Merge pull request#29006 from hawkinsp/asan
ENH: Disable the alloc cache under address and memory sanitizers
2 parentsc2d5e00 +6167ca8 commit0506cf6

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

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

Lines 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+
#ifdefPy_GIL_DISABLED
106+
#defineUSE_ALLOC_CACHE 0
107+
#elif defined(__has_feature)
108+
# if__has_feature(address_sanitizer)||__has_feature(memory_sanitizer)
109+
# defineUSE_ALLOC_CACHE 0
110+
# endif
111+
#else
112+
#defineUSE_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-
#ifndefPy_GIL_DISABLED
132+
#ifUSE_ALLOC_CACHE
119133
if (nelem<msz) {
120134
if (cache[nelem].available>0) {
121135
returncache[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-
#ifndefPy_GIL_DISABLED
158+
#ifUSE_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)

[8]ページ先頭

©2009-2025 Movatter.jp