From 967f1f203313364b3591c7e7fd6781a42be7e5f9 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Tue, 10 May 2022 11:33:12 +0100 Subject: [PATCH] Allow check_client messages to have parameters Make the check_client macro use the new "pretty" format. --- src/snmalloc/ds_core/defines.h | 75 ++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/src/snmalloc/ds_core/defines.h b/src/snmalloc/ds_core/defines.h index 869310d..98fbf39 100644 --- a/src/snmalloc/ds_core/defines.h +++ b/src/snmalloc/ds_core/defines.h @@ -166,39 +166,6 @@ namespace snmalloc namespace snmalloc { - template - SNMALLOC_FAST_PATH_INLINE void UNUSED(Args&&...) - {} - - inline SNMALLOC_FAST_PATH void check_client_error(const char* const str) - { - //[[clang::musttail]] - return snmalloc::error(str); - } - - inline SNMALLOC_FAST_PATH void - check_client_impl(bool test, const char* const str) - { - if (SNMALLOC_UNLIKELY(!test)) - { - if constexpr (DEBUG) - { - UNUSED(str); - SNMALLOC_FAST_FAIL(); - } - else - { - check_client_error(str); - } - } - } - -#ifdef SNMALLOC_CHECK_CLIENT - static constexpr bool CHECK_CLIENT = true; -#else - static constexpr bool CHECK_CLIENT = false; -#endif - /** * Forward declaration so that this can be called before the pal header is * included. @@ -212,11 +179,47 @@ namespace snmalloc */ template inline void message(Args... args); + + template + SNMALLOC_FAST_PATH_INLINE void UNUSED(Args&&...) + {} + + template + inline SNMALLOC_FAST_PATH void + check_client_error(const char* const str, Args... args) + { + //[[clang::musttail]] + return snmalloc::report_fatal_error(str, args...); + } + + template + inline SNMALLOC_FAST_PATH void + check_client_impl(bool test, const char* const str, Args... args) + { + if (SNMALLOC_UNLIKELY(!test)) + { + if constexpr (!DEBUG) + { + UNUSED(str, args...); + SNMALLOC_FAST_FAIL(); + } + else + { + check_client_error(str, args...); + } + } + } + +#ifdef SNMALLOC_CHECK_CLIENT + static constexpr bool CHECK_CLIENT = true; +#else + static constexpr bool CHECK_CLIENT = false; +#endif } // namespace snmalloc #ifdef SNMALLOC_CHECK_CLIENT -# define snmalloc_check_client(test, str) \ - snmalloc::check_client_impl(test, str) +# define snmalloc_check_client(test, str, ...) \ + snmalloc::check_client_impl(test, str, ##__VA_ARGS__) #else -# define snmalloc_check_client(test, str) +# define snmalloc_check_client(test, str, ...) #endif