From 14e5f0b2cb035abf2b62fd77cf27e0b72a8162fc Mon Sep 17 00:00:00 2001 From: Jiawei Ou Date: Wed, 4 Mar 2020 13:38:02 -0800 Subject: [PATCH] Update RTC_CHECK and RTC_LOG macros so they work when called from xxxxx::rtc namespaces Adding :: before rtc allow us to use the macro in nested rtc namespace for external components like namespace xxxxxxx { namespace rtc { RTC_CHECK(true); } } Bug: webrtc:11400 Change-Id: I79349b847c3fce8197c82aec31b672a1a16e5388 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/169683 Commit-Queue: Jiawei Ou Reviewed-by: Tommi Cr-Commit-Position: refs/heads/master@{#30684} --- rtc_base/checks.h | 74 +++++++++++++++++++++++----------------------- rtc_base/logging.h | 38 ++++++++++++------------ 2 files changed, 56 insertions(+), 56 deletions(-) diff --git a/rtc_base/checks.h b/rtc_base/checks.h index 0b461c8984..2fde3f6640 100644 --- a/rtc_base/checks.h +++ b/rtc_base/checks.h @@ -345,17 +345,17 @@ class FatalLogCall final { // in a particularly convoluted way with an extra ?: because that appears to be // the simplest construct that keeps Visual Studio from complaining about // condition being unused). -#define RTC_EAT_STREAM_PARAMETERS(ignored) \ - (true ? true : ((void)(ignored), true)) \ - ? static_cast(0) \ - : rtc::webrtc_checks_impl::FatalLogCall("", 0, "") & \ - rtc::webrtc_checks_impl::LogStreamer<>() +#define RTC_EAT_STREAM_PARAMETERS(ignored) \ + (true ? true : ((void)(ignored), true)) \ + ? static_cast(0) \ + : ::rtc::webrtc_checks_impl::FatalLogCall("", 0, "") & \ + ::rtc::webrtc_checks_impl::LogStreamer<>() // Call RTC_EAT_STREAM_PARAMETERS with an argument that fails to compile if // values of the same types as |a| and |b| can't be compared with the given // operation, and that would evaluate |a| and |b| if evaluated. #define RTC_EAT_STREAM_PARAMETERS_OP(op, a, b) \ - RTC_EAT_STREAM_PARAMETERS(((void)rtc::Safe##op(a, b))) + RTC_EAT_STREAM_PARAMETERS(((void)::rtc::Safe##op(a, b))) // RTC_CHECK dies with a fatal error if condition is not true. It is *not* // controlled by NDEBUG or anything else, so the check will be executed @@ -367,36 +367,36 @@ class FatalLogCall final { // RTC_CHECK_OP is a helper macro for binary operators. // Don't use this macro directly in your code, use RTC_CHECK_EQ et al below. #if RTC_CHECK_MSG_ENABLED -#define RTC_CHECK(condition) \ - (condition) ? static_cast(0) \ - : rtc::webrtc_checks_impl::FatalLogCall( \ - __FILE__, __LINE__, #condition) & \ - rtc::webrtc_checks_impl::LogStreamer<>() +#define RTC_CHECK(condition) \ + (condition) ? static_cast(0) \ + : ::rtc::webrtc_checks_impl::FatalLogCall( \ + __FILE__, __LINE__, #condition) & \ + ::rtc::webrtc_checks_impl::LogStreamer<>() -#define RTC_CHECK_OP(name, op, val1, val2) \ - rtc::Safe##name((val1), (val2)) \ - ? static_cast(0) \ - : rtc::webrtc_checks_impl::FatalLogCall(__FILE__, __LINE__, \ - #val1 " " #op " " #val2) & \ - rtc::webrtc_checks_impl::LogStreamer<>() << (val1) << (val2) +#define RTC_CHECK_OP(name, op, val1, val2) \ + ::rtc::Safe##name((val1), (val2)) \ + ? static_cast(0) \ + : ::rtc::webrtc_checks_impl::FatalLogCall( \ + __FILE__, __LINE__, #val1 " " #op " " #val2) & \ + ::rtc::webrtc_checks_impl::LogStreamer<>() << (val1) << (val2) #else -#define RTC_CHECK(condition) \ - (condition) \ - ? static_cast(0) \ - : true ? rtc::webrtc_checks_impl::FatalLogCall(__FILE__, \ - __LINE__, "") & \ - rtc::webrtc_checks_impl::LogStreamer<>() \ - : rtc::webrtc_checks_impl::FatalLogCall("", 0, "") & \ - rtc::webrtc_checks_impl::LogStreamer<>() +#define RTC_CHECK(condition) \ + (condition) \ + ? static_cast(0) \ + : true ? ::rtc::webrtc_checks_impl::FatalLogCall(__FILE__, \ + __LINE__, "") & \ + ::rtc::webrtc_checks_impl::LogStreamer<>() \ + : ::rtc::webrtc_checks_impl::FatalLogCall("", 0, "") & \ + ::rtc::webrtc_checks_impl::LogStreamer<>() -#define RTC_CHECK_OP(name, op, val1, val2) \ - rtc::Safe##name((val1), (val2)) \ - ? static_cast(0) \ - : true ? rtc::webrtc_checks_impl::FatalLogCall(__FILE__, __LINE__, \ - "") & \ - rtc::webrtc_checks_impl::LogStreamer<>() \ - : rtc::webrtc_checks_impl::FatalLogCall("", 0, "") & \ - rtc::webrtc_checks_impl::LogStreamer<>() +#define RTC_CHECK_OP(name, op, val1, val2) \ + ::rtc::Safe##name((val1), (val2)) \ + ? static_cast(0) \ + : true ? ::rtc::webrtc_checks_impl::FatalLogCall(__FILE__, \ + __LINE__, "") & \ + ::rtc::webrtc_checks_impl::LogStreamer<>() \ + : ::rtc::webrtc_checks_impl::FatalLogCall("", 0, "") & \ + ::rtc::webrtc_checks_impl::LogStreamer<>() #endif #define RTC_CHECK_EQ(val1, val2) RTC_CHECK_OP(Eq, ==, val1, val2) @@ -431,10 +431,10 @@ class FatalLogCall final { #define RTC_NOTREACHED() RTC_DCHECK(RTC_UNREACHABLE_CODE_HIT) // TODO(bugs.webrtc.org/8454): Add an RTC_ prefix or rename differently. -#define FATAL() \ - rtc::webrtc_checks_impl::FatalLogCall(__FILE__, __LINE__, \ - "FATAL()") & \ - rtc::webrtc_checks_impl::LogStreamer<>() +#define FATAL() \ + ::rtc::webrtc_checks_impl::FatalLogCall(__FILE__, __LINE__, \ + "FATAL()") & \ + ::rtc::webrtc_checks_impl::LogStreamer<>() // Performs the integer division a/b and returns the result. CHECKs that the // remainder is zero. diff --git a/rtc_base/logging.h b/rtc_base/logging.h index fe12068fa6..3c237df0d3 100644 --- a/rtc_base/logging.h +++ b/rtc_base/logging.h @@ -574,13 +574,13 @@ class LogMessage { // Logging Helpers ////////////////////////////////////////////////////////////////////// -#define RTC_LOG_FILE_LINE(sev, file, line) \ - RTC_LOG_ENABLED() && \ - rtc::webrtc_logging_impl::LogCall() & \ - rtc::webrtc_logging_impl::LogStreamer<>() \ - << rtc::webrtc_logging_impl::LogMetadata(file, line, sev) +#define RTC_LOG_FILE_LINE(sev, file, line) \ + RTC_LOG_ENABLED() && \ + ::rtc::webrtc_logging_impl::LogCall() & \ + ::rtc::webrtc_logging_impl::LogStreamer<>() \ + << ::rtc::webrtc_logging_impl::LogMetadata(file, line, sev) -#define RTC_LOG(sev) RTC_LOG_FILE_LINE(rtc::sev, __FILE__, __LINE__) +#define RTC_LOG(sev) RTC_LOG_FILE_LINE(::rtc::sev, __FILE__, __LINE__) // The _V version is for when a variable is passed in. #define RTC_LOG_V(sev) RTC_LOG_FILE_LINE(sev, __FILE__, __LINE__) @@ -595,18 +595,18 @@ class LogMessage { #define RTC_LOG_T_F(sev) RTC_LOG(sev) << this << ": " << __FUNCTION__ << ": " #endif -#define RTC_LOG_CHECK_LEVEL(sev) rtc::LogCheckLevel(rtc::sev) -#define RTC_LOG_CHECK_LEVEL_V(sev) rtc::LogCheckLevel(sev) +#define RTC_LOG_CHECK_LEVEL(sev) ::rtc::LogCheckLevel(::rtc::sev) +#define RTC_LOG_CHECK_LEVEL_V(sev) ::rtc::LogCheckLevel(sev) inline bool LogCheckLevel(LoggingSeverity sev) { return (LogMessage::GetMinLogSeverity() <= sev); } -#define RTC_LOG_E(sev, ctx, err) \ - RTC_LOG_ENABLED() && rtc::webrtc_logging_impl::LogCall() & \ - rtc::webrtc_logging_impl::LogStreamer<>() \ - << rtc::webrtc_logging_impl::LogMetadataErr { \ - {__FILE__, __LINE__, rtc::sev}, rtc::ERRCTX_##ctx, (err) \ +#define RTC_LOG_E(sev, ctx, err) \ + RTC_LOG_ENABLED() && ::rtc::webrtc_logging_impl::LogCall() & \ + ::rtc::webrtc_logging_impl::LogStreamer<>() \ + << ::rtc::webrtc_logging_impl::LogMetadataErr { \ + {__FILE__, __LINE__, ::rtc::sev}, ::rtc::ERRCTX_##ctx, (err) \ } #define RTC_LOG_T(sev) RTC_LOG(sev) << this << ": " @@ -639,11 +639,11 @@ inline const char* AdaptString(const std::string& str) { } } // namespace webrtc_logging_impl -#define RTC_LOG_TAG(sev, tag) \ - RTC_LOG_ENABLED() && rtc::webrtc_logging_impl::LogCall() & \ - rtc::webrtc_logging_impl::LogStreamer<>() \ - << rtc::webrtc_logging_impl::LogMetadataTag { \ - sev, rtc::webrtc_logging_impl::AdaptString(tag) \ +#define RTC_LOG_TAG(sev, tag) \ + RTC_LOG_ENABLED() && ::rtc::webrtc_logging_impl::LogCall() & \ + ::rtc::webrtc_logging_impl::LogStreamer<>() \ + << ::rtc::webrtc_logging_impl::LogMetadataTag { \ + sev, ::rtc::webrtc_logging_impl::AdaptString(tag) \ } #else @@ -662,7 +662,7 @@ inline const char* AdaptString(const std::string& str) { #else #define RTC_DLOG_EAT_STREAM_PARAMS() \ while (false) \ - rtc::webrtc_logging_impl::LogStreamer<>() + ::rtc::webrtc_logging_impl::LogStreamer<>() #define RTC_DLOG(sev) RTC_DLOG_EAT_STREAM_PARAMS() #define RTC_DLOG_V(sev) RTC_DLOG_EAT_STREAM_PARAMS() #define RTC_DLOG_F(sev) RTC_DLOG_EAT_STREAM_PARAMS()