diff --git a/src/snmalloc/ds_core/concept.h b/src/snmalloc/ds_core/concept.h index 2e48244..996af5f 100644 --- a/src/snmalloc/ds_core/concept.h +++ b/src/snmalloc/ds_core/concept.h @@ -71,6 +71,7 @@ namespace snmalloc */ template constexpr bool is_type_complete_v = false; + template constexpr bool is_type_complete_v> = true; diff --git a/src/snmalloc/ds_core/helpers.h b/src/snmalloc/ds_core/helpers.h index 73a8729..2dd1e7c 100644 --- a/src/snmalloc/ds_core/helpers.h +++ b/src/snmalloc/ds_core/helpers.h @@ -4,7 +4,7 @@ #include #include -#include +#include #include #include @@ -192,11 +192,12 @@ namespace snmalloc /** * Append a string to the buffer. */ - void append(std::string_view sv) + template + void append(const char (&s)[N]) { - for (auto c : sv) + for (size_t i = 0; i < N - 1; i++) { - append_char(c); + append_char(s[i]); } } @@ -224,15 +225,45 @@ namespace snmalloc } #endif + /** + * Append a nullptr + */ + void append(std::nullptr_t) + { + append("(nullptr)"); + } + /** * Append a raw pointer to the buffer as a hex string. */ void append(void* ptr) { + if (ptr == nullptr) + { + append(nullptr); + return; + } append(static_cast(reinterpret_cast(ptr))); // TODO: CHERI bits. } + /** + * Append a literal pointer. + */ + void append(const char* ptr) + { + if (ptr == nullptr) + { + append(nullptr); + return; + } + + while (char data = *ptr++) + { + append_char(data); + } + } + /** * Append a signed integer to the buffer, as a decimal string. */ diff --git a/src/snmalloc/pal/pal.h b/src/snmalloc/pal/pal.h index 47dde5e..cc7ca1b 100644 --- a/src/snmalloc/pal/pal.h +++ b/src/snmalloc/pal/pal.h @@ -159,9 +159,7 @@ namespace snmalloc * The following are supported as arguments: * * - Characters (`char`), printed verbatim. - * - Strings (anything convertible to `std::string_view`), typically string - * literals because nothing on this path should be performing heap - * allocations. Printed verbatim. + * - Strings Literals (`const char*` or `const char[]`), printed verbatim. * - Raw pointers (void*), printed as hex strings. * - Integers (convertible to `size_t`), printed as hex strings. * diff --git a/src/test/func/malloc/malloc.cc b/src/test/func/malloc/malloc.cc index 6549e58..1444018 100644 --- a/src/test/func/malloc/malloc.cc +++ b/src/test/func/malloc/malloc.cc @@ -232,7 +232,8 @@ int main(int argc, char** argv) 1234567}; if ( strcmp( - "testing pointer 0x42 size_t 0x2a message, hello world, null is 0x0, " + "testing pointer 0x42 size_t 0x2a message, hello world, null is " + "(nullptr), " "-123456 is -123456, 1234567 is 1234567", b.get_message()) != 0) {