Test RTC_DCHECK_IS_ON instead of checking DCHECK_ALWAYS_ON everywhere
The former is always defined (by webrtc/base/checks.h) to either 0 or
1, whereas the latter isn't necessarily defined.
NOTRY=true
BUG=webrtc:6451
Review-Url: https://codereview.webrtc.org/2384693002
Cr-Commit-Position: refs/heads/master@{#14474}
diff --git a/webrtc/api/statscollector.cc b/webrtc/api/statscollector.cc
index 4dd5305..766e949 100644
--- a/webrtc/api/statscollector.cc
+++ b/webrtc/api/statscollector.cc
@@ -398,7 +398,7 @@
uint32_t ssrc) {
RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent());
RTC_DCHECK(audio_track != NULL);
-#if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
+#if RTC_DCHECK_IS_ON
for (const auto& track : local_audio_tracks_)
RTC_DCHECK(track.first != audio_track || track.second != ssrc);
#endif
diff --git a/webrtc/api/statstypes.cc b/webrtc/api/statstypes.cc
index eb6b30c..339d5bb 100644
--- a/webrtc/api/statstypes.cc
+++ b/webrtc/api/statstypes.cc
@@ -276,7 +276,7 @@
case kFloat:
return value_.float_ == other.value_.float_;
case kStaticString: {
-#if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
+#if RTC_DCHECK_IS_ON
if (value_.static_string_ != other.value_.static_string_) {
RTC_DCHECK(strcmp(value_.static_string_, other.value_.static_string_) !=
0)
@@ -306,7 +306,7 @@
return value_.string_->compare(value) == 0;
if (type_ != kStaticString)
return false;
-#if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
+#if RTC_DCHECK_IS_ON
if (value_.static_string_ != value)
RTC_DCHECK(strcmp(value_.static_string_, value) != 0)
<< "Duplicate global?";
diff --git a/webrtc/base/buffer.h b/webrtc/base/buffer.h
index 6ae49f7..44f941e 100644
--- a/webrtc/base/buffer.h
+++ b/webrtc/base/buffer.h
@@ -349,7 +349,7 @@
// Called when *this has been moved from. Conceptually it's a no-op, but we
// can mutate the state slightly to help subsequent sanity checks catch bugs.
void OnMovedFrom() {
-#ifdef NDEBUG
+#if RTC_DCHECK_IS_ON
// Make *this consistent and empty. Shouldn't be necessary, but better safe
// than sorry.
size_ = 0;
diff --git a/webrtc/base/checks.h b/webrtc/base/checks.h
index a48971f..2d0e8af 100644
--- a/webrtc/base/checks.h
+++ b/webrtc/base/checks.h
@@ -13,7 +13,10 @@
#include "webrtc/typedefs.h"
-#if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
+// If you for some reson need to know if DCHECKs are on, test the value of
+// RTC_DCHECK_IS_ON. (Test its value, not if it's defined; it'll always be
+// defined, to either a true or a false value.)
+#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
#define RTC_DCHECK_IS_ON 1
#else
#define RTC_DCHECK_IS_ON 0
@@ -90,9 +93,9 @@
? static_cast<void>(0) \
: rtc::FatalMessageVoidify() & rtc::FatalMessage("", 0).stream()
-// RTC_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
-// compilation mode.
+// 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
+// regardless of compilation mode.
//
// We make sure RTC_CHECK et al. always evaluates their arguments, as
// doing RTC_CHECK(FunctionWithSideEffect()) is a common idiom.
diff --git a/webrtc/base/criticalsection.h b/webrtc/base/criticalsection.h
index bf77e2b..a0f9a6b 100644
--- a/webrtc/base/criticalsection.h
+++ b/webrtc/base/criticalsection.h
@@ -12,6 +12,7 @@
#define WEBRTC_BASE_CRITICALSECTION_H_
#include "webrtc/base/atomicops.h"
+#include "webrtc/base/checks.h"
#include "webrtc/base/constructormagic.h"
#include "webrtc/base/thread_annotations.h"
#include "webrtc/base/platform_thread_types.h"
@@ -37,11 +38,7 @@
#include <dispatch/dispatch.h>
#endif
-#if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
-#define CS_DEBUG_CHECKS 1
-#else
-#define CS_DEBUG_CHECKS 0
-#endif
+#define CS_DEBUG_CHECKS RTC_DCHECK_IS_ON
#if CS_DEBUG_CHECKS
#define CS_DEBUG_CODE(x) x
diff --git a/webrtc/base/sequenced_task_checker.h b/webrtc/base/sequenced_task_checker.h
index 9fc3b4a..4df5b54 100644
--- a/webrtc/base/sequenced_task_checker.h
+++ b/webrtc/base/sequenced_task_checker.h
@@ -12,18 +12,9 @@
#define WEBRTC_BASE_SEQUENCED_TASK_CHECKER_H_
// Apart from debug builds, we also enable the sequence checker in
-// builds with DCHECK_ALWAYS_ON so that trybots and waterfall bots
+// builds with RTC_DCHECK_IS_ON so that trybots and waterfall bots
// with this define will get the same level of checking as debug bots.
-//
-// Note that this does not perfectly match situations where RTC_DCHECK is
-// enabled. For example a non-official release build may have
-// DCHECK_ALWAYS_ON undefined (and therefore SequencedTaskChecker would be
-// disabled) but have RTC_DCHECKs enabled at runtime.
-#if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
-#define ENABLE_SEQUENCED_TASK_CHECKER 1
-#else
-#define ENABLE_SEQUENCED_TASK_CHECKER 0
-#endif
+#define ENABLE_SEQUENCED_TASK_CHECKER RTC_DCHECK_IS_ON
#include "webrtc/base/checks.h"
#include "webrtc/base/constructormagic.h"
diff --git a/webrtc/base/sequenced_task_checker_unittest.cc b/webrtc/base/sequenced_task_checker_unittest.cc
index 20a4c0f..8588648 100644
--- a/webrtc/base/sequenced_task_checker_unittest.cc
+++ b/webrtc/base/sequenced_task_checker_unittest.cc
@@ -198,7 +198,7 @@
EXPECT_TRUE(done_event.Wait(1000));
}
-#if !defined(NDEBUG) || DCHECK_ALWAYS_ON
+#if RTC_DCHECK_IS_ON
TEST(SequencedTaskCheckerTest, MethodNotAllowedOnDifferentThreadInDebug) {
RunMethodOnDifferentThread(false);
}
@@ -208,7 +208,7 @@
}
#endif
-#if !defined(NDEBUG) || DCHECK_ALWAYS_ON
+#if RTC_DCHECK_IS_ON
TEST(SequencedTaskCheckerTest, MethodNotAllowedOnDifferentTaskQueueInDebug) {
RunMethodOnDifferentTaskQueue(false);
}
@@ -218,7 +218,7 @@
}
#endif
-#if !defined(NDEBUG) || DCHECK_ALWAYS_ON
+#if RTC_DCHECK_IS_ON
TEST(SequencedTaskCheckerTest, DetachFromTaskQueueInDebug) {
DetachThenCallFromDifferentTaskQueue(false);
}
diff --git a/webrtc/base/stringutils.cc b/webrtc/base/stringutils.cc
index 9580253..48830e4 100644
--- a/webrtc/base/stringutils.cc
+++ b/webrtc/base/stringutils.cc
@@ -77,7 +77,7 @@
} else if (srclen >= buflen) {
srclen = buflen - 1;
}
-#if !defined(NDEBUG)
+#if RTC_DCHECK_IS_ON
// Double check that characters are not UTF-8
for (size_t pos = 0; pos < srclen; ++pos)
RTC_DCHECK_LT(static_cast<unsigned char>(source[pos]), 128);
diff --git a/webrtc/base/thread_checker.h b/webrtc/base/thread_checker.h
index 3ae6e2c..5914282 100644
--- a/webrtc/base/thread_checker.h
+++ b/webrtc/base/thread_checker.h
@@ -14,19 +14,10 @@
#define WEBRTC_BASE_THREAD_CHECKER_H_
// Apart from debug builds, we also enable the thread checker in
-// builds with DCHECK_ALWAYS_ON so that trybots and waterfall bots
+// builds with RTC_DCHECK_IS_ON so that trybots and waterfall bots
// with this define will get the same level of thread checking as
// debug bots.
-//
-// Note that this does not perfectly match situations where RTC_DCHECK is
-// enabled. For example a non-official release build may have
-// DCHECK_ALWAYS_ON undefined (and therefore ThreadChecker would be
-// disabled) but have RTC_DCHECKs enabled at runtime.
-#if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
-#define ENABLE_THREAD_CHECKER 1
-#else
-#define ENABLE_THREAD_CHECKER 0
-#endif
+#define ENABLE_THREAD_CHECKER RTC_DCHECK_IS_ON
#include "webrtc/base/checks.h"
#include "webrtc/base/constructormagic.h"
diff --git a/webrtc/base/thread_checker_unittest.cc b/webrtc/base/thread_checker_unittest.cc
index 76462fd..dee1653 100644
--- a/webrtc/base/thread_checker_unittest.cc
+++ b/webrtc/base/thread_checker_unittest.cc
@@ -21,11 +21,7 @@
// Duplicated from base/threading/thread_checker.h so that we can be
// good citizens there and undef the macro.
-#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
-#define ENABLE_THREAD_CHECKER 1
-#else
-#define ENABLE_THREAD_CHECKER 0
-#endif
+#define ENABLE_THREAD_CHECKER RTC_DCHECK_IS_ON
namespace rtc {
diff --git a/webrtc/common_audio/resampler/push_resampler.cc b/webrtc/common_audio/resampler/push_resampler.cc
index b26774d..9f329c4 100644
--- a/webrtc/common_audio/resampler/push_resampler.cc
+++ b/webrtc/common_audio/resampler/push_resampler.cc
@@ -29,7 +29,7 @@
size_t num_channels) {
// The below checks are temporarily disabled on WEBRTC_WIN due to problems
// with clang debug builds.
-#if !defined(WEBRTC_WIN) && defined(__clang__) && !defined(NDEBUG)
+#if !defined(WEBRTC_WIN) && defined(__clang__)
RTC_DCHECK_GT(src_sample_rate_hz, 0);
RTC_DCHECK_GT(dst_sample_rate_hz, 0);
RTC_DCHECK_GT(num_channels, 0u);
@@ -46,11 +46,11 @@
// with clang debug builds.
// TODO(tommi): Re-enable when we've figured out what the problem is.
// http://crbug.com/615050
-#if !defined(WEBRTC_WIN) && defined(__clang__) && !defined(NDEBUG)
+#if !defined(WEBRTC_WIN) && defined(__clang__)
const size_t src_size_10ms = src_sample_rate * num_channels / 100;
const size_t dst_size_10ms = dst_sample_rate * num_channels / 100;
- RTC_CHECK_EQ(src_length, src_size_10ms);
- RTC_CHECK_GE(dst_capacity, dst_size_10ms);
+ RTC_DCHECK_EQ(src_length, src_size_10ms);
+ RTC_DCHECK_GE(dst_capacity, dst_size_10ms);
#endif
}
}
diff --git a/webrtc/media/sctp/sctpdataengine.cc b/webrtc/media/sctp/sctpdataengine.cc
index a724b2a..0804fed 100644
--- a/webrtc/media/sctp/sctpdataengine.cc
+++ b/webrtc/media/sctp/sctpdataengine.cc
@@ -118,7 +118,7 @@
// Helper for logging SCTP messages.
void DebugSctpPrintf(const char* format, ...) {
-#if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
+#if RTC_DCHECK_IS_ON
char s[255];
va_list ap;
va_start(ap, format);
diff --git a/webrtc/modules/audio_coding/acm2/audio_coding_module_unittest_oldapi.cc b/webrtc/modules/audio_coding/acm2/audio_coding_module_unittest_oldapi.cc
index 60e90f7..344bc3b 100644
--- a/webrtc/modules/audio_coding/acm2/audio_coding_module_unittest_oldapi.cc
+++ b/webrtc/modules/audio_coding/acm2/audio_coding_module_unittest_oldapi.cc
@@ -317,8 +317,8 @@
// with clang debug builds.
// TODO(tommi): Re-enable when we've figured out what the problem is.
// http://crbug.com/615050
-#if !defined(WEBRTC_WIN) && defined(__clang__) && !defined(NDEBUG)
-#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
+#if !defined(WEBRTC_WIN) && defined(__clang__) && RTC_DCHECK_IS_ON && \
+ GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
TEST_F(AudioCodingModuleTestOldApi, FailOnZeroDesiredFrequency) {
AudioFrame audio_frame;
bool muted;
@@ -326,7 +326,6 @@
"dst_sample_rate_hz");
}
#endif
-#endif
// Checks that the transport callback is invoked once for each speech packet.
// Also checks that the frame type is kAudioFrameSpeech.
diff --git a/webrtc/modules/audio_device/android/opensles_player.cc b/webrtc/modules/audio_device/android/opensles_player.cc
index a63b8c1..9850d00 100644
--- a/webrtc/modules/audio_device/android/opensles_player.cc
+++ b/webrtc/modules/audio_device/android/opensles_player.cc
@@ -141,7 +141,7 @@
RETURN_ON_ERROR((*player_)->SetPlayState(player_, SL_PLAYSTATE_STOPPED), -1);
// Clear the buffer queue to flush out any remaining data.
RETURN_ON_ERROR((*simple_buffer_queue_)->Clear(simple_buffer_queue_), -1);
-#ifndef NDEBUG
+#if RTC_DCHECK_IS_ON
// Verify that the buffer queue is in fact cleared as it should.
SLAndroidSimpleBufferQueueState buffer_queue_state;
(*simple_buffer_queue_)->GetState(simple_buffer_queue_, &buffer_queue_state);
diff --git a/webrtc/modules/utility/source/process_thread_impl.cc b/webrtc/modules/utility/source/process_thread_impl.cc
index 66534de..3332cd6 100644
--- a/webrtc/modules/utility/source/process_thread_impl.cc
+++ b/webrtc/modules/utility/source/process_thread_impl.cc
@@ -133,7 +133,7 @@
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(module);
-#if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
+#if RTC_DCHECK_IS_ON
{
// Catch programmer error.
rtc::CritScope lock(&lock_);