From d1f292f352ffedd8c1d04319e1a65b9969e62c9d Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Sun, 3 Mar 2024 19:17:24 -0500 Subject: [PATCH] Updates for uncrustify 0.78. (#454) Shorten some unnecessary macros, and add INDENT-OFF around the logging macros. Signed-off-by: Chris Lalancette --- .../stdatomic_helper/win32/stdatomic.h | 4 +- resource/logging_macros.h.em | 38 ++++++++++--------- test/test_find.cpp | 13 +------ test/test_split.cpp | 9 +---- 4 files changed, 24 insertions(+), 40 deletions(-) diff --git a/include/rcutils/stdatomic_helper/win32/stdatomic.h b/include/rcutils/stdatomic_helper/win32/stdatomic.h index 7000fb21..7c9318da 100644 --- a/include/rcutils/stdatomic_helper/win32/stdatomic.h +++ b/include/rcutils/stdatomic_helper/win32/stdatomic.h @@ -91,9 +91,7 @@ */ #define ATOMIC_VAR_INIT(value) {.__val = (value)} -#define atomic_init(obj, value) do { \ - (obj)->__val = (value); \ -} while (0) +#define atomic_init(obj, value) do {(obj)->__val = (value);} while (0) /* * Clang and recent GCC both provide predefined macros for the memory diff --git a/resource/logging_macros.h.em b/resource/logging_macros.h.em index 1b87e496..82eb7130 100644 --- a/resource/logging_macros.h.em +++ b/resource/logging_macros.h.em @@ -19,6 +19,8 @@ #ifndef RCUTILS__LOGGING_MACROS_H_ #define RCUTILS__LOGGING_MACROS_H_ +// *INDENT-OFF* + #include "rcutils/logging.h" #include @@ -108,7 +110,7 @@ extern "C" * A macro finalizing the `once` condition. */ #define RCUTILS_LOG_CONDITION_ONCE_AFTER } \ -} + } ///@@} /** @@name Macros for the `expression` condition which ignores the log calls @@ -169,7 +171,7 @@ typedef bool (* RclLogFilter)(); * A macro finalizing the `skipfirst` condition. */ #define RCUTILS_LOG_CONDITION_SKIPFIRST_AFTER } \ -} + } ///@@} /** @@name Macros for the `throttle` condition which ignores log calls if the @@ -181,28 +183,28 @@ typedef bool (* RclLogFilter)(); * A macro initializing and checking the `throttle` condition. */ #define RCUTILS_LOG_CONDITION_THROTTLE_BEFORE(get_time_point_value, duration) { \ - static rcutils_duration_value_t __rcutils_logging_duration = RCUTILS_MS_TO_NS(RCUTILS_CAST_DURATION(duration)); \ - static rcutils_time_point_value_t __rcutils_logging_last_logged = 0; \ - rcutils_time_point_value_t __rcutils_logging_now = 0; \ - bool __rcutils_logging_condition = true; \ - if (get_time_point_value(&__rcutils_logging_now) != RCUTILS_RET_OK) { \ - rcutils_log( \ - &__rcutils_logging_location, RCUTILS_LOG_SEVERITY_ERROR, "", \ - "%s() at %s:%d getting current steady time failed\n", \ - __func__, __FILE__, __LINE__); \ - } else { \ - __rcutils_logging_condition = __rcutils_logging_now >= __rcutils_logging_last_logged + __rcutils_logging_duration; \ - } \ + static rcutils_duration_value_t __rcutils_logging_duration = RCUTILS_MS_TO_NS(RCUTILS_CAST_DURATION(duration)); \ + static rcutils_time_point_value_t __rcutils_logging_last_logged = 0; \ + rcutils_time_point_value_t __rcutils_logging_now = 0; \ + bool __rcutils_logging_condition = true; \ + if (get_time_point_value(&__rcutils_logging_now) != RCUTILS_RET_OK) { \ + rcutils_log( \ + &__rcutils_logging_location, RCUTILS_LOG_SEVERITY_ERROR, "", \ + "%s() at %s:%d getting current steady time failed\n", \ + __func__, __FILE__, __LINE__); \ + } else { \ + __rcutils_logging_condition = __rcutils_logging_now >= __rcutils_logging_last_logged + __rcutils_logging_duration; \ + } \ \ - if (RCUTILS_LIKELY(__rcutils_logging_condition)) { \ - __rcutils_logging_last_logged = __rcutils_logging_now; + if (RCUTILS_LIKELY(__rcutils_logging_condition)) { \ + __rcutils_logging_last_logged = __rcutils_logging_now; /** * \def RCUTILS_LOG_CONDITION_THROTTLE_AFTER * A macro finalizing the `throttle` condition. */ #define RCUTILS_LOG_CONDITION_THROTTLE_AFTER } \ -} + } ///@@} @{ @@ -257,6 +259,8 @@ from rcutils.logging import severities #endif ///@@} +// *INDENT-ON* + @[end for]@ #ifdef __cplusplus } diff --git a/test/test_find.cpp b/test/test_find.cpp index aa6726c0..46f7cb82 100644 --- a/test/test_find.cpp +++ b/test/test_find.cpp @@ -18,18 +18,7 @@ #include "rcutils/find.h" -#define ENABLE_LOGGING 1 - -#if ENABLE_LOGGING -#define LOG(expected, actual) do { \ - printf("Expected: %zu Actual: %zu\n", expected, actual); \ -} while (0) -#else -#define LOG(X, arg) do { \ - (void)(X); \ - (void)(arg); \ -} while (0) -#endif +#define LOG(expected, actual) printf("Expected: %zu Actual: %zu\n", expected, actual); size_t test_find(const char * str, char delimiter, size_t expected_pos) { diff --git a/test/test_split.cpp b/test/test_split.cpp index 6a11ef66..0d3b65e3 100644 --- a/test/test_split.cpp +++ b/test/test_split.cpp @@ -20,14 +20,7 @@ #include "rcutils/split.h" #include "rcutils/types/string_array.h" -#define ENABLE_LOGGING 1 - -#if ENABLE_LOGGING -#define LOG(expected, actual) { \ - printf("Expected: %s Actual: %s\n", expected, actual);} -#else -#define LOG(X, arg) {} -#endif +#define LOG(expected, actual) printf("Expected: %s Actual: %s\n", expected, actual); rcutils_string_array_t test_split(const char * str, char delimiter, size_t expected_token_size) {