From cfa996692f8fd610d00d94c0f9ef2512c2f2793e Mon Sep 17 00:00:00 2001 From: Nathaniel Filardo Date: Tue, 6 Apr 2021 22:56:09 +0100 Subject: [PATCH] Correct PAL Concept The test for NoAllocation/AlignedAllocation/neither was broken and this was undetected until the sandbox demo came into being with its NoAllocation PAL instance. (Sadly, this remained undetected for so long because we can't routinely build with C++20 because std::atomic_t<>'s initialization rules changed in ways that make us require oodles and oodles of RAM at compile time. This patch has been validated with -j1 on a machine with lots of RAM.) Separately, it's possible that we end up here without `using namespace std`, which seems like overkill. So just use `std::size_t` ourselves within the PAL Concept definition. --- src/pal/pal_concept.h | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/pal/pal_concept.h b/src/pal/pal_concept.h index ee926c2..62cdc07 100644 --- a/src/pal/pal_concept.h +++ b/src/pal/pal_concept.h @@ -19,7 +19,7 @@ namespace snmalloc concept ConceptPAL_static_members = requires() { typename std::integral_constant; - typename std::integral_constant; + typename std::integral_constant; }; /** @@ -35,7 +35,7 @@ namespace snmalloc * PALs expose a basic library of memory operations. */ template - concept ConceptPAL_memops = requires(void* vp, size_t sz) + concept ConceptPAL_memops = requires(void* vp, std::size_t sz) { { PAL::notify_not_using(vp, sz) } noexcept -> ConceptSame; @@ -52,17 +52,18 @@ namespace snmalloc * Absent any feature flags, the PAL must support a crude primitive allocator */ template - concept ConceptPAL_reserve_at_least = requires(PAL p, void* vp, size_t sz) + concept ConceptPAL_reserve_at_least = + requires(PAL p, void* vp, std::size_t sz) { { PAL::reserve_at_least(sz) } noexcept - -> ConceptSame>; + -> ConceptSame>; }; /** * Some PALs expose a richer allocator which understands aligned allocations */ template - concept ConceptPAL_reserve_aligned = requires(size_t sz) + concept ConceptPAL_reserve_aligned = requires(std::size_t sz) { { PAL::template reserve_aligned(sz) } noexcept -> ConceptSame; { PAL::template reserve_aligned(sz) } noexcept @@ -90,13 +91,13 @@ namespace snmalloc ConceptPAL_static_members && ConceptPAL_error && ConceptPAL_memops && - (!(PAL::pal_features & LowMemoryNotification) || + (!pal_supports || ConceptPAL_mem_low_notify) && - (!(PAL::pal_features & NoAllocation) && ( - (!!(PAL::pal_features & AlignedAllocation) || - ConceptPAL_reserve_at_least) && - (!(PAL::pal_features & AlignedAllocation) || - ConceptPAL_reserve_aligned))); + (pal_supports || + (pal_supports && + ConceptPAL_reserve_aligned) || + (!pal_supports && + ConceptPAL_reserve_at_least)); } // namespace snmalloc #endif