Add DEBUG constexpr

Enable checking use of a constexpr rather than ifdef for checking if in
DEBUG.
This commit is contained in:
Matthew Parkinson
2022-02-01 09:11:35 +00:00
committed by Matthew Parkinson
parent f1be609cdb
commit 3d1b973480
9 changed files with 83 additions and 87 deletions

View File

@@ -113,9 +113,8 @@ namespace snmalloc
{
SNMALLOC_ASSERT(is_aligned_block<page_size>(p, size));
# if !defined(NDEBUG)
memset(p, 0x5a, size);
# endif
if constexpr (DEBUG)
memset(p, 0x5a, size);
// `MADV_FREE_REUSABLE` can only be applied to writable pages,
// otherwise it's an error.

View File

@@ -35,9 +35,9 @@ namespace snmalloc
{
SNMALLOC_ASSERT(is_aligned_block<OS::page_size>(p, size));
#if !defined(NDEBUG)
memset(p, 0x5a, size);
#endif
if constexpr (DEBUG)
memset(p, 0x5a, size);
madvise(p, size, MADV_FREE);
if constexpr (PalEnforceAccess)

View File

@@ -70,11 +70,11 @@ namespace snmalloc
if constexpr (PalEnforceAccess)
{
# if !defined(NDEBUG)
// Fill memory so that when we switch the pages back on we don't make
// assumptions on the content.
memset(p, 0x5a, size);
# endif
if constexpr (DEBUG)
memset(p, 0x5a, size);
madvise(p, size, MADV_FREE);
mprotect(p, size, PROT_NONE);
}

View File

@@ -189,11 +189,11 @@ namespace snmalloc
if constexpr (PalEnforceAccess)
{
#if !defined(NDEBUG)
// Fill memory so that when we switch the pages back on we don't make
// assumptions on the content.
memset(p, 0x5a, size);
#endif
if constexpr (DEBUG)
memset(p, 0x5a, size);
mprotect(p, size, PROT_NONE);
}
else