From f7a72b03ca9db9dd0ab15090557f42c0e36fe5e0 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Wed, 27 Dec 2023 09:17:03 +0100 Subject: [PATCH 1/2] Fix LF_ASSERT --- include/core/utils/util.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/core/utils/util.h b/include/core/utils/util.h index d93f5de24..958cb6b6c 100644 --- a/include/core/utils/util.h +++ b/include/core/utils/util.h @@ -272,8 +272,7 @@ void lf_register_print_function(print_message_function_t* function, int log_leve * By definng `LF_NOASSERT` this check is not performed. */ #if defined(LF_NOASSERT) -#define LF_ASSERT(condition, format, ...) \ - while(0) { } +#define LF_ASSERT(condition, format, ...) (condition) #else #define LF_ASSERT(condition, format, ...) \ do { \ From 6b3513175aeab2747d6c57d026f88a9dc9d948c5 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Wed, 27 Dec 2023 16:17:19 +0100 Subject: [PATCH 2/2] Just use NDEBUG flag to decide if LF_ASSERT is expanded or not --- core/CMakeLists.txt | 1 - include/core/utils/util.h | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 888e583d4..78edea140 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -133,4 +133,3 @@ define(LF_PACKAGE_DIRECTORY) define(LF_FILE_SEPARATOR) define(WORKERS_NEEDED_FOR_FEDERATE) define(LF_ENCLAVES) -define(LF_NOASSERT) diff --git a/include/core/utils/util.h b/include/core/utils/util.h index 958cb6b6c..ddb821a6f 100644 --- a/include/core/utils/util.h +++ b/include/core/utils/util.h @@ -269,9 +269,9 @@ void lf_register_print_function(print_message_function_t* function, int log_leve /** * Assertion handling. LF_ASSERT can be used as a short hand for verifying * a condition and calling `lf_print_error_and_exit` if it is not true. - * By definng `LF_NOASSERT` this check is not performed. + * This is optimized away if the NDEBUG flag is defined. */ -#if defined(LF_NOASSERT) +#if defined(NDEBUG) #define LF_ASSERT(condition, format, ...) (condition) #else #define LF_ASSERT(condition, format, ...) \ @@ -280,5 +280,5 @@ void lf_register_print_function(print_message_function_t* function, int log_leve lf_print_error_and_exit(format, ##__VA_ARGS__); \ } \ } while(0) -#endif // LF_NOASSERT +#endif // NDEBUG #endif /* UTIL_H */