Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add macro semicolons #120

Merged
merged 3 commits into from
Oct 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions resource/logging_macros.h.em
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ extern "C"
#endif

// TODO(dhood): optimise severity check via notifyLoggerLevelsChanged concept or similar.
// The RCUTILS_LOG_COND_NAMED macro is surrounded by do { .. } while (0) to implement
// the standard C macro idiom to make the macro safe in all contexts; see
// http://c-faq.com/cpp/multistmt.html for more information.
/**
* \def RCUTILS_LOG_COND_NAMED
* The logging macro all other logging macros call directly or indirectly.
Expand All @@ -61,15 +64,15 @@ extern "C"
* \param ... The format string, followed by the variable arguments for the format string
*/
#define RCUTILS_LOG_COND_NAMED(severity, condition_before, condition_after, name, ...) \
{ \
do { \
RCUTILS_LOGGING_AUTOINIT \
static rcutils_log_location_t __rcutils_logging_location = {__func__, __FILE__, __LINE__}; \
if (rcutils_logging_logger_is_enabled_for(name, severity)) { \
condition_before \
rcutils_log(&__rcutils_logging_location, severity, name, __VA_ARGS__); \
condition_after \
} \
}
} while (0)

///@@{
/**
Expand Down
4 changes: 2 additions & 2 deletions test/test_logging_macros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ TEST_F(TestLoggingMacros, test_logging_skipfirst) {

TEST_F(TestLoggingMacros, test_logging_throttle) {
for (int i : {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}) {
RCUTILS_LOG_ERROR_THROTTLE(RCUTILS_STEADY_TIME, 50 /* ms */, "throttled message %d", i)
RCUTILS_LOG_ERROR_THROTTLE(RCUTILS_STEADY_TIME, 50 /* ms */, "throttled message %d", i);
using namespace std::chrono_literals;
std::this_thread::sleep_for(30ms);
}
Expand All @@ -161,7 +161,7 @@ TEST_F(TestLoggingMacros, test_logging_throttle) {
TEST_F(TestLoggingMacros, test_logging_skipfirst_throttle) {
for (int i : {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}) {
RCUTILS_LOG_FATAL_SKIPFIRST_THROTTLE(
RCUTILS_STEADY_TIME, 50 /* ms */, "throttled message %d", i)
RCUTILS_STEADY_TIME, 50 /* ms */, "throttled message %d", i);
using namespace std::chrono_literals;
std::this_thread::sleep_for(30ms);
}
Expand Down