From 34a6764981a656c62daed0d962f01374a08f9bac Mon Sep 17 00:00:00 2001 From: "andrew@webrtc.org" Date: Tue, 2 Sep 2014 19:00:45 +0000 Subject: [PATCH] Remove the checks.h dependence on logging.h in a standalone build. logging.h apparently drags in a lot of undesirable dependencies. It was only required for the trivial LogMessageVoidify; simply add an identical FatalMessageVoidify instead. Keep the include in a Chromium build to still have the override mechanism use Chromium's macros. Bonus: Add the missing DCHECK_GT (noticed by bercic). R=kwiberg@webrtc.org Review URL: https://webrtc-codereview.appspot.com/17259004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7031 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/base/checks.cc | 9 +++------ webrtc/base/checks.h | 40 +++++++++++++++++++++++++++------------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/webrtc/base/checks.cc b/webrtc/base/checks.cc index 5de1a8044c..9694b93d88 100644 --- a/webrtc/base/checks.cc +++ b/webrtc/base/checks.cc @@ -13,22 +13,19 @@ // Use the C++ version to provide __GLIBCXX__. #include +#include #if defined(__GLIBCXX__) && !defined(__UCLIBC__) #include #include #endif -#if defined(ANDROID) +#if defined(WEBRTC_ANDROID) #define LOG_TAG "rtc" #include // NOLINT #endif -#include - #include "webrtc/base/checks.h" -#include "webrtc/base/common.h" -#include "webrtc/base/logging.h" #if defined(_MSC_VER) // Warning C4722: destructor never returns, potential memory leak. @@ -59,7 +56,7 @@ void PrintError(const char* format, ...) { void DumpBacktrace() { #if defined(__GLIBCXX__) && !defined(__UCLIBC__) void* trace[100]; - int size = backtrace(trace, ARRAY_SIZE(trace)); + int size = backtrace(trace, sizeof(trace) / sizeof(*trace)); char** symbols = backtrace_symbols(trace, size); PrintError("\n==== C stack trace ===============================\n\n"); if (size == 0) { diff --git a/webrtc/base/checks.h b/webrtc/base/checks.h index b3917bb559..d8be3ad594 100644 --- a/webrtc/base/checks.h +++ b/webrtc/base/checks.h @@ -11,12 +11,16 @@ #ifndef WEBRTC_BASE_CHECKS_H_ #define WEBRTC_BASE_CHECKS_H_ -#include -#include - #include +#include +#ifdef WEBRTC_CHROMIUM_BUILD +// Include logging.h in a Chromium build to enable the overrides mechanism for +// using Chromium's macros. Otherwise, don't depend on logging.h. +// TODO(ajm): Ideally, checks.h would be combined with logging.h, but +// consolidation with system_wrappers/logging.h should happen first. #include "webrtc/base/logging.h" +#endif #include "webrtc/typedefs.h" // The macros here print a message to stderr and abort under various @@ -47,8 +51,6 @@ // doesn't hold. Prefer them to raw CHECK and DCHECK. // // - FATAL() aborts unconditionally. -// -// TODO(ajm): Ideally, this would be combined with webrtc/base/logging.h. namespace rtc { @@ -59,12 +61,13 @@ namespace rtc { // Helper macro which avoids evaluating the arguments to a stream if // the condition doesn't hold. -#define LAZY_STREAM(stream, condition) \ - !(condition) ? (void) 0 : rtc::LogMessageVoidify() & (stream) +#define LAZY_STREAM(stream, condition) \ + !(condition) ? static_cast(0) : rtc::FatalMessageVoidify() & (stream) // The actual stream used isn't important. -#define EAT_STREAM_PARAMETERS \ - true ? (void) 0 : rtc::LogMessageVoidify() & rtc::FatalMessage("", 0).stream() +#define EAT_STREAM_PARAMETERS \ + true ? static_cast(0) \ + : rtc::FatalMessageVoidify() & rtc::FatalMessage("", 0).stream() // CHECK dies with a fatal error if condition is not true. It is *not* // controlled by NDEBUG, so the check will be executed regardless of @@ -155,18 +158,29 @@ DEFINE_CHECK_OP_IMPL(GT, > ) #define DCHECK(condition) CHECK(condition) #define DCHECK_EQ(v1, v2) CHECK_EQ(v1, v2) #define DCHECK_NE(v1, v2) CHECK_NE(v1, v2) -#define DCHECK_GE(v1, v2) CHECK_GE(v1, v2) -#define DCHECK_LT(v1, v2) CHECK_LT(v1, v2) #define DCHECK_LE(v1, v2) CHECK_LE(v1, v2) +#define DCHECK_LT(v1, v2) CHECK_LT(v1, v2) +#define DCHECK_GE(v1, v2) CHECK_GE(v1, v2) +#define DCHECK_GT(v1, v2) CHECK_GT(v1, v2) #else #define DCHECK(condition) EAT_STREAM_PARAMETERS #define DCHECK_EQ(v1, v2) EAT_STREAM_PARAMETERS #define DCHECK_NE(v1, v2) EAT_STREAM_PARAMETERS -#define DCHECK_GE(v1, v2) EAT_STREAM_PARAMETERS -#define DCHECK_LT(v1, v2) EAT_STREAM_PARAMETERS #define DCHECK_LE(v1, v2) EAT_STREAM_PARAMETERS +#define DCHECK_LT(v1, v2) EAT_STREAM_PARAMETERS +#define DCHECK_GE(v1, v2) EAT_STREAM_PARAMETERS +#define DCHECK_GT(v1, v2) EAT_STREAM_PARAMETERS #endif +// This is identical to LogMessageVoidify but in name. +class FatalMessageVoidify { + public: + FatalMessageVoidify() { } + // This has to be an operator with a precedence lower than << but + // higher than ?: + void operator&(std::ostream&) { } +}; + #endif // WEBRTC_CHROMIUM_BUILD #define FATAL() rtc::FatalMessage(__FILE__, __LINE__).stream()