Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f27d04f

Browse files
committed
Disable MI_DEBUG in ASAN builds
1 parent 399500e commit f27d04f

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

Include/internal/pycore_mimalloc.h

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,31 @@
1414
#define MI_DEBUG_FREED PYMEM_DEADBYTE
1515
#define MI_DEBUG_PADDING PYMEM_FORBIDDENBYTE
1616

17+
/* ASAN builds don't use MI_DEBUG. ASAN + MI_DEBUG triggers additional
18+
* checks, which can cause mimalloc to print warnings to stderr. The
19+
* warnings break some tests.
20+
*
21+
* mi_usable_size: pointer might not point to a valid heap region:
22+
* ...
23+
* yes, the previous pointer ... was valid after all
24+
*/
25+
#if defined(__has_feature)
26+
# if __has_feature(address_sanitizer)
27+
# define MI_DEBUG 0
28+
# endif
29+
#elif defined(__GNUC__) && defined(__SANITIZE_ADDRESS__)
30+
# define MI_DEBUG 0
31+
#endif
32+
33+
/* Perform additional checks in debug builds, see mimalloc-types.h
34+
* - enable basic and internal assertion checks with MI_DEBUG 2
35+
* - check for double free, invalid pointer free
36+
* - use guard pages to check for buffer overflows
37+
*/
1738
#ifdef Py_DEBUG
18-
// see mimalloc-types.h
19-
// basic and internal assertion checks
20-
# define MI_DEBUG 2
21-
// check for double free, buffer overflows and invalid pointer free
39+
# ifndef MI_DEBUG
40+
# define MI_DEBUG 2
41+
# endif
2242
# define MI_SECURE 4
2343
#elif defined(PY_MIMALLOC_SECURE)
2444
# define MI_SECURE PY_MIMALLOC_SECURE

Objects/obmalloc.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,6 @@ _PyMem_RawFree(void *Py_UNUSED(ctx), void *ptr)
136136

137137
#ifdef WITH_MIMALLOC
138138

139-
static void
140-
_PyMimalloc_Config(void) {
141-
/* XXX Some options cannot be changed because
142-
PyRuntime_Initialize() -> alloc_for_runtime()
143-
allocates memory, which initializes mimalloc.
144-
145-
verbose logging breaks some tests in debug mode:
146-
"pointer might not point to a valid heap region"
147-
*/
148-
mi_option_disable(mi_option_verbose);
149-
}
150-
151139
static void *
152140
_PyMimalloc_Malloc(void *ctx, size_t size)
153141
{
@@ -442,9 +430,6 @@ _PyMem_SetupAllocators(PyMemAllocatorName allocator)
442430
PyMem_SetupDebugHooks();
443431
}
444432

445-
// set global mimalloc flags
446-
_PyMimalloc_Config();
447-
448433
break;
449434
}
450435
#endif

0 commit comments

Comments
 (0)