-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-112529: Track if debug allocator is used as underlying allocator #113747
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -439,12 +439,14 @@ set_up_allocators_unlocked(PyMemAllocatorName allocator) | |
(void)set_default_allocator_unlocked(PYMEM_DOMAIN_RAW, pydebug, NULL); | ||
(void)set_default_allocator_unlocked(PYMEM_DOMAIN_MEM, pydebug, NULL); | ||
(void)set_default_allocator_unlocked(PYMEM_DOMAIN_OBJ, pydebug, NULL); | ||
_PyRuntime.allocators.is_debug_enabled = pydebug; | ||
break; | ||
|
||
case PYMEM_ALLOCATOR_DEBUG: | ||
(void)set_default_allocator_unlocked(PYMEM_DOMAIN_RAW, 1, NULL); | ||
(void)set_default_allocator_unlocked(PYMEM_DOMAIN_MEM, 1, NULL); | ||
(void)set_default_allocator_unlocked(PYMEM_DOMAIN_OBJ, 1, NULL); | ||
_PyRuntime.allocators.is_debug_enabled = 1; | ||
break; | ||
|
||
#ifdef WITH_PYMALLOC | ||
|
@@ -458,7 +460,9 @@ set_up_allocators_unlocked(PyMemAllocatorName allocator) | |
set_allocator_unlocked(PYMEM_DOMAIN_MEM, &pymalloc); | ||
set_allocator_unlocked(PYMEM_DOMAIN_OBJ, &pymalloc); | ||
|
||
if (allocator == PYMEM_ALLOCATOR_PYMALLOC_DEBUG) { | ||
int is_debug = (allocator == PYMEM_ALLOCATOR_PYMALLOC_DEBUG); | ||
_PyRuntime.allocators.is_debug_enabled = is_debug; | ||
if (is_debug) { | ||
set_up_debug_hooks_unlocked(); | ||
} | ||
break; | ||
|
@@ -477,7 +481,9 @@ set_up_allocators_unlocked(PyMemAllocatorName allocator) | |
PyMemAllocatorEx objmalloc = MIMALLOC_OBJALLOC; | ||
set_allocator_unlocked(PYMEM_DOMAIN_OBJ, &objmalloc); | ||
|
||
if (allocator == PYMEM_ALLOCATOR_MIMALLOC_DEBUG) { | ||
int is_debug = (allocator == PYMEM_ALLOCATOR_MIMALLOC_DEBUG); | ||
_PyRuntime.allocators.is_debug_enabled = is_debug; | ||
if (is_debug) { | ||
set_up_debug_hooks_unlocked(); | ||
} | ||
|
||
|
@@ -493,7 +499,9 @@ set_up_allocators_unlocked(PyMemAllocatorName allocator) | |
set_allocator_unlocked(PYMEM_DOMAIN_MEM, &malloc_alloc); | ||
set_allocator_unlocked(PYMEM_DOMAIN_OBJ, &malloc_alloc); | ||
|
||
if (allocator == PYMEM_ALLOCATOR_MALLOC_DEBUG) { | ||
int is_debug = (allocator == PYMEM_ALLOCATOR_MALLOC_DEBUG); | ||
_PyRuntime.allocators.is_debug_enabled = is_debug; | ||
if (is_debug) { | ||
set_up_debug_hooks_unlocked(); | ||
} | ||
break; | ||
|
@@ -604,13 +612,17 @@ _PyMem_GetCurrentAllocatorName(void) | |
} | ||
|
||
|
||
#ifdef WITH_PYMALLOC | ||
static int | ||
int | ||
_PyMem_DebugEnabled(void) | ||
{ | ||
return (_PyObject.malloc == _PyMem_DebugMalloc); | ||
#ifdef WITH_PYMALLOC | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like this ifdef isn't necessary and i should always reutnr There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that makes sense -- I'll get rid of the |
||
return _PyRuntime.allocators.is_debug_enabled; | ||
#else | ||
return 0; | ||
#endif | ||
} | ||
|
||
#ifdef WITH_PYMALLOC | ||
static int | ||
_PyMem_PymallocEnabled(void) | ||
{ | ||
|
@@ -691,6 +703,7 @@ set_up_debug_hooks_unlocked(void) | |
set_up_debug_hooks_domain_unlocked(PYMEM_DOMAIN_RAW); | ||
set_up_debug_hooks_domain_unlocked(PYMEM_DOMAIN_MEM); | ||
set_up_debug_hooks_domain_unlocked(PYMEM_DOMAIN_OBJ); | ||
_PyRuntime.allocators.is_debug_enabled = 1; | ||
} | ||
|
||
void | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these assignments necessary? It seems like this is going to get set in
set_up_debug_hooks_unlocked
anyway. I suppose there's a question if you were to change the allocator after initializing it, but it seems like that would blow up horribly anyway?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think they're not necessary - I'll remove them and make sure things still work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out they are needed. We may statically initialize
is_debug_enabled
to1
in a debug build, but then disable debug hooks via configuration (such as,PYTHONMALLOC=mimalloc
). In that case we need to clearis_debug_enabled
.