pw_log: Remove uses of PW_COMMA_ARGS - Remove uses of PW_COMMA_ARGS on macro-macro boundaries. PW_COMMA_ARGS doesn't expand as expected when invoking one macro from another. - Expand comment for PW_COMMA_ARGS to indicate that it should not be used when invoking a macro from another macro. It should only be used when the macro expands to C code (e.g. a function call). Bug: 117 Change-Id: I201197f0b4727304cc2dedad40ed2f5b6d02b27e
diff --git a/pw_log/BUILD.gn b/pw_log/BUILD.gn index 9216bf4..1dbe783 100644 --- a/pw_log/BUILD.gn +++ b/pw_log/BUILD.gn
@@ -27,7 +27,6 @@ "public/pw_log/levels.h", "public/pw_log/log.h", ] - public_deps = [ dir_pw_preprocessor ] } pw_test_group("tests") { @@ -42,6 +41,7 @@ deps = [ ":pw_log", dir_pw_log_backend, + dir_pw_preprocessor, ] sources = [
diff --git a/pw_log/public/pw_log/log.h b/pw_log/public/pw_log/log.h index 97db527..66203a8 100644 --- a/pw_log/public/pw_log/log.h +++ b/pw_log/public/pw_log/log.h
@@ -26,7 +26,6 @@ #pragma once #include "pw_log/levels.h" -#include "pw_preprocessor/macro_arg_count.h" // PW_COMMA_ARGS // log_backend.h must ultimately resolve to a header that implements the macros // required by the logging facade, as described below. @@ -76,31 +75,27 @@ // of the general PW_LOG(). #ifndef PW_LOG_DEBUG #define PW_LOG_DEBUG(message, ...) \ - PW_LOG( \ - PW_LOG_LEVEL_DEBUG, PW_LOG_NO_FLAGS, message PW_COMMA_ARGS(__VA_ARGS__)) + PW_LOG(PW_LOG_LEVEL_DEBUG, PW_LOG_NO_FLAGS, message, __VA_ARGS__) #endif // PW_LOG_DEBUG #ifndef PW_LOG_INFO #define PW_LOG_INFO(message, ...) \ - PW_LOG(PW_LOG_LEVEL_INFO, PW_LOG_NO_FLAGS, message PW_COMMA_ARGS(__VA_ARGS__)) + PW_LOG(PW_LOG_LEVEL_INFO, PW_LOG_NO_FLAGS, message, __VA_ARGS__) #endif // PW_LOG_INFO #ifndef PW_LOG_WARN #define PW_LOG_WARN(message, ...) \ - PW_LOG(PW_LOG_LEVEL_WARN, PW_LOG_NO_FLAGS, message PW_COMMA_ARGS(__VA_ARGS__)) + PW_LOG(PW_LOG_LEVEL_WARN, PW_LOG_NO_FLAGS, message, __VA_ARGS__) #endif // PW_LOG_WARN #ifndef PW_LOG_ERROR #define PW_LOG_ERROR(message, ...) \ - PW_LOG( \ - PW_LOG_LEVEL_ERROR, PW_LOG_NO_FLAGS, message PW_COMMA_ARGS(__VA_ARGS__)) + PW_LOG(PW_LOG_LEVEL_ERROR, PW_LOG_NO_FLAGS, message, __VA_ARGS__) #endif // PW_LOG_ERROR #ifndef PW_LOG_CRITICAL #define PW_LOG_CRITICAL(message, ...) \ - PW_LOG(PW_LOG_LEVEL_CRITICAL, \ - PW_LOG_NO_FLAGS, \ - message PW_COMMA_ARGS(__VA_ARGS__)) + PW_LOG(PW_LOG_LEVEL_CRITICAL, PW_LOG_NO_FLAGS, message, __VA_ARGS__) #endif // PW_LOG_CRITICAL // Define short, usable names if requested.
diff --git a/pw_log_basic/BUILD.gn b/pw_log_basic/BUILD.gn index d5a9dd8..f5b8758 100644 --- a/pw_log_basic/BUILD.gn +++ b/pw_log_basic/BUILD.gn
@@ -30,7 +30,6 @@ ] deps = [ ":pw_log_basic_core" ] public = [ "public_overrides/pw_log_backend/log_backend.h" ] - sources = public } } @@ -43,6 +42,7 @@ "$dir_pw_sys_io", ] public = [ "public/pw_log_basic/log_basic.h" ] + public_deps = [ dir_pw_preprocessor ] # Use emoji log levels if they've been enabled. _use_emoji = getenv("PW_EMOJI") @@ -51,7 +51,7 @@ defines += [ "PW_EMOJI=1" ] } - sources = public + [ "log_basic.cc" ] + sources = [ "log_basic.cc" ] } pw_doc_group("docs") {
diff --git a/pw_log_basic/public/pw_log_basic/log_basic.h b/pw_log_basic/public/pw_log_basic/log_basic.h index e820921..305b786 100644 --- a/pw_log_basic/public/pw_log_basic/log_basic.h +++ b/pw_log_basic/public/pw_log_basic/log_basic.h
@@ -14,6 +14,7 @@ #pragma once #include "pw_preprocessor/compiler.h" +#include "pw_preprocessor/macro_arg_count.h" #include "pw_preprocessor/util.h" PW_EXTERN_C_START
diff --git a/pw_preprocessor/public/pw_preprocessor/macro_arg_count.h b/pw_preprocessor/public/pw_preprocessor/macro_arg_count.h index 8525577..4d704de 100644 --- a/pw_preprocessor/public/pw_preprocessor/macro_arg_count.h +++ b/pw_preprocessor/public/pw_preprocessor/macro_arg_count.h
@@ -103,13 +103,18 @@ // Expands to a comma followed by __VA_ARGS__, if __VA_ARGS__ is non-empty. // Otherwise, expands to nothing. This is useful when calling a function with // __VA_ARGS__, since it removes the extra comma when no arguments are -// provided. +// provided. It must NOT be used when invoking a macro from another macro. // // This is a more flexible, standard-compliant version of ##__VA_ARGS__. Unlike // ##__VA_ARGS__, this can be used to eliminate an unwanted comma when // __VA_ARGS__ expands to an empty argument because an outer macro was called // with __VA_ARGS__ instead of ##__VA_ARGS__. // +// PW_COMMA_ARGS must NOT be used to conditionally include a comma when invoking +// a macro from another macro. PW_COMMA_ARGS only functions correctly when the +// macro expands to C or C++ code! When invoking one macro from another, simply +// pass __VA_ARGS__. +// // This can be used to call variadic functions or provide variadic template // parameters from a macro. For example: //