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

DCHECK_ALWAYS_ON to make D* enabled under NDEBUG #164

Merged
merged 1 commit into from
Feb 9, 2017
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
22 changes: 14 additions & 8 deletions src/glog/logging.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,15 @@ DECLARE_bool(stop_logging_if_full_disk);
#define LOG_TO_STRING_FATAL(message) @ac_google_namespace@::NullStreamFatal()
#endif

#if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
#define DCHECK_IS_ON() 0
#else
#define DCHECK_IS_ON() 1
#endif

// For DFATAL, we want to use LogMessage (as opposed to
// LogMessageFatal), to be consistent with the original behavior.
#ifdef NDEBUG
#if !DCHECK_IS_ON()
#define COMPACT_GOOGLE_LOG_DFATAL COMPACT_GOOGLE_LOG_ERROR
#elif GOOGLE_STRIP_LOG <= 3
#define COMPACT_GOOGLE_LOG_DFATAL @ac_google_namespace@::LogMessage( \
Expand Down Expand Up @@ -572,7 +578,7 @@ class LogSink; // defined below
SYSLOG_IF(FATAL, !(condition)) << "Assert failed: " #condition

// 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
// controlled by DCHECK_IS_ON(), so the check will be executed regardless of
// compilation mode. Therefore, it is safe to do things like:
// CHECK(fp->Write(x) == 4)
#define CHECK(condition) \
Expand Down Expand Up @@ -722,7 +728,7 @@ DEFINE_CHECK_OP_IMPL(Check_GT, > )
#if defined(STATIC_ANALYSIS)
// Only for static analysis tool to know that it is equivalent to assert
#define CHECK_OP_LOG(name, op, val1, val2, log) CHECK((val1) op (val2))
#elif !defined(NDEBUG)
#elif DCHECK_IS_ON()
// In debug mode, avoid constructing CheckOpStrings if possible,
// to reduce the overhead of CHECK statments by 2x.
// Real DCHECK-heavy tests have seen 1.5x speedups.
Expand Down Expand Up @@ -751,7 +757,7 @@ typedef std::string _Check_string;
@ac_google_namespace@::GetReferenceableValue(val2), \
#val1 " " #op " " #val2)) \
log(__FILE__, __LINE__, _result).stream()
#endif // STATIC_ANALYSIS, !NDEBUG
#endif // STATIC_ANALYSIS, DCHECK_IS_ON()

#if GOOGLE_STRIP_LOG <= 3
#define CHECK_OP(name, op, val1, val2) \
Expand Down Expand Up @@ -976,7 +982,7 @@ const LogSeverity GLOG_0 = GLOG_ERROR;

// Plus some debug-logging macros that get compiled to nothing for production

#ifndef NDEBUG
#if DCHECK_IS_ON()

#define DLOG(severity) LOG(severity)
#define DVLOG(verboselevel) VLOG(verboselevel)
Expand All @@ -986,7 +992,7 @@ const LogSeverity GLOG_0 = GLOG_ERROR;
LOG_IF_EVERY_N(severity, condition, n)
#define DLOG_ASSERT(condition) LOG_ASSERT(condition)

// debug-only checking. not executed in NDEBUG mode.
// debug-only checking. executed if DCHECK_IS_ON().
#define DCHECK(condition) CHECK(condition)
#define DCHECK_EQ(val1, val2) CHECK_EQ(val1, val2)
#define DCHECK_NE(val1, val2) CHECK_NE(val1, val2)
Expand All @@ -1000,7 +1006,7 @@ const LogSeverity GLOG_0 = GLOG_ERROR;
#define DCHECK_STRNE(str1, str2) CHECK_STRNE(str1, str2)
#define DCHECK_STRCASENE(str1, str2) CHECK_STRCASENE(str1, str2)

#else // NDEBUG
#else // !DCHECK_IS_ON()

#define DLOG(severity) \
true ? (void) 0 : @ac_google_namespace@::LogMessageVoidify() & LOG(severity)
Expand Down Expand Up @@ -1081,7 +1087,7 @@ const LogSeverity GLOG_0 = GLOG_ERROR;
while (false) \
GLOG_MSVC_POP_WARNING() CHECK_STRCASENE(str1, str2)

#endif // NDEBUG
#endif // DCHECK_IS_ON()

// Log only in verbose mode.

Expand Down
22 changes: 14 additions & 8 deletions src/windows/glog/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,15 @@ DECLARE_bool(stop_logging_if_full_disk);
#define LOG_TO_STRING_FATAL(message) google::NullStreamFatal()
#endif

#if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
#define DCHECK_IS_ON() 0
#else
#define DCHECK_IS_ON() 1
#endif

// For DFATAL, we want to use LogMessage (as opposed to
// LogMessageFatal), to be consistent with the original behavior.
#ifdef NDEBUG
#if !DCHECK_IS_ON()
#define COMPACT_GOOGLE_LOG_DFATAL COMPACT_GOOGLE_LOG_ERROR
#elif GOOGLE_STRIP_LOG <= 3
#define COMPACT_GOOGLE_LOG_DFATAL google::LogMessage( \
Expand Down Expand Up @@ -576,7 +582,7 @@ class LogSink; // defined below
SYSLOG_IF(FATAL, !(condition)) << "Assert failed: " #condition

// 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
// controlled by DCHECK_IS_ON(), so the check will be executed regardless of
// compilation mode. Therefore, it is safe to do things like:
// CHECK(fp->Write(x) == 4)
#define CHECK(condition) \
Expand Down Expand Up @@ -726,7 +732,7 @@ DEFINE_CHECK_OP_IMPL(Check_GT, > )
#if defined(STATIC_ANALYSIS)
// Only for static analysis tool to know that it is equivalent to assert
#define CHECK_OP_LOG(name, op, val1, val2, log) CHECK((val1) op (val2))
#elif !defined(NDEBUG)
#elif DCHECK_IS_ON()
// In debug mode, avoid constructing CheckOpStrings if possible,
// to reduce the overhead of CHECK statments by 2x.
// Real DCHECK-heavy tests have seen 1.5x speedups.
Expand Down Expand Up @@ -755,7 +761,7 @@ typedef std::string _Check_string;
google::GetReferenceableValue(val2), \
#val1 " " #op " " #val2)) \
log(__FILE__, __LINE__, _result).stream()
#endif // STATIC_ANALYSIS, !NDEBUG
#endif // STATIC_ANALYSIS, DCHECK_IS_ON()

#if GOOGLE_STRIP_LOG <= 3
#define CHECK_OP(name, op, val1, val2) \
Expand Down Expand Up @@ -980,7 +986,7 @@ const LogSeverity GLOG_0 = GLOG_ERROR;

// Plus some debug-logging macros that get compiled to nothing for production

#ifndef NDEBUG
#if DCHECK_IS_ON()

#define DLOG(severity) LOG(severity)
#define DVLOG(verboselevel) VLOG(verboselevel)
Expand All @@ -990,7 +996,7 @@ const LogSeverity GLOG_0 = GLOG_ERROR;
LOG_IF_EVERY_N(severity, condition, n)
#define DLOG_ASSERT(condition) LOG_ASSERT(condition)

// debug-only checking. not executed in NDEBUG mode.
// debug-only checking. executed if DCHECK_IS_ON().
#define DCHECK(condition) CHECK(condition)
#define DCHECK_EQ(val1, val2) CHECK_EQ(val1, val2)
#define DCHECK_NE(val1, val2) CHECK_NE(val1, val2)
Expand All @@ -1004,7 +1010,7 @@ const LogSeverity GLOG_0 = GLOG_ERROR;
#define DCHECK_STRNE(str1, str2) CHECK_STRNE(str1, str2)
#define DCHECK_STRCASENE(str1, str2) CHECK_STRCASENE(str1, str2)

#else // NDEBUG
#else // !DCHECK_IS_ON()

#define DLOG(severity) \
true ? (void) 0 : google::LogMessageVoidify() & LOG(severity)
Expand Down Expand Up @@ -1085,7 +1091,7 @@ const LogSeverity GLOG_0 = GLOG_ERROR;
while (false) \
GLOG_MSVC_POP_WARNING() CHECK_STRCASENE(str1, str2)

#endif // NDEBUG
#endif // DCHECK_IS_ON()

// Log only in verbose mode.

Expand Down