Replace calls to assert() with RTC_DCHECK_*() in .c code
We have RTC_CHECK and RTC_DCHECK for C now, so we should use it. It's
one fewer difference between our C and C++ code.
NOPRESUBMIT=true
Review-Url: https://codereview.webrtc.org/2274083002
Cr-Commit-Position: refs/heads/master@{#13930}
diff --git a/webrtc/common_audio/signal_processing/auto_correlation.c b/webrtc/common_audio/signal_processing/auto_correlation.c
index fda4fff..58e6d6e 100644
--- a/webrtc/common_audio/signal_processing/auto_correlation.c
+++ b/webrtc/common_audio/signal_processing/auto_correlation.c
@@ -10,7 +10,7 @@
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
-#include <assert.h>
+#include "webrtc/base/checks.h"
size_t WebRtcSpl_AutoCorrelation(const int16_t* in_vector,
size_t in_vector_length,
@@ -22,7 +22,7 @@
int16_t smax = 0;
int scaling = 0;
- assert(order <= in_vector_length);
+ RTC_DCHECK_LE(order, in_vector_length);
// Find the maximum absolute value of the samples.
smax = WebRtcSpl_MaxAbsValueW16(in_vector, in_vector_length);
diff --git a/webrtc/common_audio/signal_processing/filter_ar_fast_q12.c b/webrtc/common_audio/signal_processing/filter_ar_fast_q12.c
index 70001a0..53e800b 100644
--- a/webrtc/common_audio/signal_processing/filter_ar_fast_q12.c
+++ b/webrtc/common_audio/signal_processing/filter_ar_fast_q12.c
@@ -7,8 +7,8 @@
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
-#include <assert.h>
+#include "webrtc/base/checks.h"
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
// TODO(bjornv): Change the return type to report errors.
@@ -21,8 +21,8 @@
size_t i = 0;
size_t j = 0;
- assert(data_length > 0);
- assert(coefficients_length > 1);
+ RTC_DCHECK_GT(data_length, 0);
+ RTC_DCHECK_GT(coefficients_length, 1);
for (i = 0; i < data_length; i++) {
int32_t output = 0;
diff --git a/webrtc/common_audio/signal_processing/filter_ar_fast_q12_mips.c b/webrtc/common_audio/signal_processing/filter_ar_fast_q12_mips.c
index 0384701..02fa80b 100644
--- a/webrtc/common_audio/signal_processing/filter_ar_fast_q12_mips.c
+++ b/webrtc/common_audio/signal_processing/filter_ar_fast_q12_mips.c
@@ -7,8 +7,8 @@
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
-#include <assert.h>
+#include "webrtc/base/checks.h"
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
void WebRtcSpl_FilterARFastQ12(const int16_t* data_in,
@@ -25,8 +25,8 @@
int min16 = 0xFFFF8000;
#endif // #if !defined(MIPS_DSP_R1_LE)
- assert(data_length > 0);
- assert(coefficients_length > 1);
+ RTC_DCHECK_GT(data_length, 0);
+ RTC_DCHECK_GT(coefficients_length, 1);
__asm __volatile (
".set push \n\t"
diff --git a/webrtc/common_audio/signal_processing/min_max_operations.c b/webrtc/common_audio/signal_processing/min_max_operations.c
index 4a962f8..bc23a9c 100644
--- a/webrtc/common_audio/signal_processing/min_max_operations.c
+++ b/webrtc/common_audio/signal_processing/min_max_operations.c
@@ -24,9 +24,9 @@
*
*/
-#include <assert.h>
#include <stdlib.h>
+#include "webrtc/base/checks.h"
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
// TODO(bjorn/kma): Consolidate function pairs (e.g. combine
@@ -38,7 +38,7 @@
size_t i = 0;
int absolute = 0, maximum = 0;
- assert(length > 0);
+ RTC_DCHECK_GT(length, 0);
for (i = 0; i < length; i++) {
absolute = abs((int)vector[i]);
@@ -64,7 +64,7 @@
uint32_t absolute = 0, maximum = 0;
size_t i = 0;
- assert(length > 0);
+ RTC_DCHECK_GT(length, 0);
for (i = 0; i < length; i++) {
absolute = abs((int)vector[i]);
@@ -83,7 +83,7 @@
int16_t maximum = WEBRTC_SPL_WORD16_MIN;
size_t i = 0;
- assert(length > 0);
+ RTC_DCHECK_GT(length, 0);
for (i = 0; i < length; i++) {
if (vector[i] > maximum)
@@ -97,7 +97,7 @@
int32_t maximum = WEBRTC_SPL_WORD32_MIN;
size_t i = 0;
- assert(length > 0);
+ RTC_DCHECK_GT(length, 0);
for (i = 0; i < length; i++) {
if (vector[i] > maximum)
@@ -111,7 +111,7 @@
int16_t minimum = WEBRTC_SPL_WORD16_MAX;
size_t i = 0;
- assert(length > 0);
+ RTC_DCHECK_GT(length, 0);
for (i = 0; i < length; i++) {
if (vector[i] < minimum)
@@ -125,7 +125,7 @@
int32_t minimum = WEBRTC_SPL_WORD32_MAX;
size_t i = 0;
- assert(length > 0);
+ RTC_DCHECK_GT(length, 0);
for (i = 0; i < length; i++) {
if (vector[i] < minimum)
@@ -141,7 +141,7 @@
size_t i = 0, index = 0;
int absolute = 0, maximum = 0;
- assert(length > 0);
+ RTC_DCHECK_GT(length, 0);
for (i = 0; i < length; i++) {
absolute = abs((int)vector[i]);
@@ -160,7 +160,7 @@
size_t i = 0, index = 0;
int16_t maximum = WEBRTC_SPL_WORD16_MIN;
- assert(length > 0);
+ RTC_DCHECK_GT(length, 0);
for (i = 0; i < length; i++) {
if (vector[i] > maximum) {
@@ -177,7 +177,7 @@
size_t i = 0, index = 0;
int32_t maximum = WEBRTC_SPL_WORD32_MIN;
- assert(length > 0);
+ RTC_DCHECK_GT(length, 0);
for (i = 0; i < length; i++) {
if (vector[i] > maximum) {
@@ -194,7 +194,7 @@
size_t i = 0, index = 0;
int16_t minimum = WEBRTC_SPL_WORD16_MAX;
- assert(length > 0);
+ RTC_DCHECK_GT(length, 0);
for (i = 0; i < length; i++) {
if (vector[i] < minimum) {
@@ -211,7 +211,7 @@
size_t i = 0, index = 0;
int32_t minimum = WEBRTC_SPL_WORD32_MAX;
- assert(length > 0);
+ RTC_DCHECK_GT(length, 0);
for (i = 0; i < length; i++) {
if (vector[i] < minimum) {
diff --git a/webrtc/common_audio/signal_processing/min_max_operations_mips.c b/webrtc/common_audio/signal_processing/min_max_operations_mips.c
index 28de45b..c769e6a 100644
--- a/webrtc/common_audio/signal_processing/min_max_operations_mips.c
+++ b/webrtc/common_audio/signal_processing/min_max_operations_mips.c
@@ -16,8 +16,7 @@
*
*/
-#include <assert.h>
-
+#include "webrtc/base/checks.h"
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
// Maximum absolute value of word16 vector.
@@ -26,7 +25,7 @@
int32_t tmp32_0, tmp32_1, tmp32_2, tmp32_3;
size_t i, loop_size;
- assert(length > 0);
+ RTC_DCHECK_GT(length, 0);
#if defined(MIPS_DSP_R1)
const int32_t* tmpvec32 = (int32_t*)vector;
@@ -230,7 +229,7 @@
uint32_t absolute = 0, maximum = 0;
int tmp1 = 0, max_value = 0x7fffffff;
- assert(length > 0);
+ RTC_DCHECK_GT(length, 0);
__asm__ volatile (
".set push \n\t"
@@ -264,7 +263,7 @@
int tmp1;
int16_t value;
- assert(length > 0);
+ RTC_DCHECK_GT(length, 0);
__asm__ volatile (
".set push \n\t"
@@ -292,7 +291,7 @@
int32_t maximum = WEBRTC_SPL_WORD32_MIN;
int tmp1, value;
- assert(length > 0);
+ RTC_DCHECK_GT(length, 0);
__asm__ volatile (
".set push \n\t"
@@ -322,7 +321,7 @@
int tmp1;
int16_t value;
- assert(length > 0);
+ RTC_DCHECK_GT(length, 0);
__asm__ volatile (
".set push \n\t"
@@ -351,7 +350,7 @@
int32_t minimum = WEBRTC_SPL_WORD32_MAX;
int tmp1, value;
- assert(length > 0);
+ RTC_DCHECK_GT(length, 0);
__asm__ volatile (
".set push \n\t"
diff --git a/webrtc/common_audio/signal_processing/min_max_operations_neon.c b/webrtc/common_audio/signal_processing/min_max_operations_neon.c
index 6fbbf94..d5aad76 100644
--- a/webrtc/common_audio/signal_processing/min_max_operations_neon.c
+++ b/webrtc/common_audio/signal_processing/min_max_operations_neon.c
@@ -9,16 +9,16 @@
*/
#include <arm_neon.h>
-#include <assert.h>
#include <stdlib.h>
+#include "webrtc/base/checks.h"
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
// Maximum absolute value of word16 vector. C version for generic platforms.
int16_t WebRtcSpl_MaxAbsValueW16Neon(const int16_t* vector, size_t length) {
int absolute = 0, maximum = 0;
- assert(length > 0);
+ RTC_DCHECK_GT(length, 0);
const int16_t* p_start = vector;
size_t rest = length & 7;
@@ -76,7 +76,7 @@
size_t i = 0;
size_t residual = length & 0x7;
- assert(length > 0);
+ RTC_DCHECK_GT(length, 0);
const int32_t* p_start = vector;
uint32x4_t max32x4_0 = vdupq_n_u32(0);
@@ -128,7 +128,7 @@
size_t i = 0;
size_t residual = length & 0x7;
- assert(length > 0);
+ RTC_DCHECK_GT(length, 0);
const int16_t* p_start = vector;
int16x8_t max16x8 = vdupq_n_s16(WEBRTC_SPL_WORD16_MIN);
@@ -166,7 +166,7 @@
size_t i = 0;
size_t residual = length & 0x7;
- assert(length > 0);
+ RTC_DCHECK_GT(length, 0);
const int32_t* p_start = vector;
int32x4_t max32x4_0 = vdupq_n_s32(WEBRTC_SPL_WORD32_MIN);
@@ -208,7 +208,7 @@
size_t i = 0;
size_t residual = length & 0x7;
- assert(length > 0);
+ RTC_DCHECK_GT(length, 0);
const int16_t* p_start = vector;
int16x8_t min16x8 = vdupq_n_s16(WEBRTC_SPL_WORD16_MAX);
@@ -246,7 +246,7 @@
size_t i = 0;
size_t residual = length & 0x7;
- assert(length > 0);
+ RTC_DCHECK_GT(length, 0);
const int32_t* p_start = vector;
int32x4_t min32x4_0 = vdupq_n_s32(WEBRTC_SPL_WORD32_MAX);
diff --git a/webrtc/common_audio/signal_processing/spl_sqrt.c b/webrtc/common_audio/signal_processing/spl_sqrt.c
index 579e714..511039b 100644
--- a/webrtc/common_audio/signal_processing/spl_sqrt.c
+++ b/webrtc/common_audio/signal_processing/spl_sqrt.c
@@ -15,10 +15,9 @@
*
*/
+#include "webrtc/base/checks.h"
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
-#include <assert.h>
-
int32_t WebRtcSpl_SqrtLocal(int32_t in);
int32_t WebRtcSpl_SqrtLocal(int32_t in)
@@ -166,7 +165,7 @@
x_norm = (int16_t)(A >> 16); // x_norm = AH
nshift = (sh / 2);
- assert(nshift >= 0);
+ RTC_DCHECK_GE(nshift, 0);
A = (int32_t)WEBRTC_SPL_LSHIFT_W32((int32_t)x_norm, 16);
A = WEBRTC_SPL_ABS_W32(A); // A = abs(x_norm<<16)
diff --git a/webrtc/common_audio/signal_processing/splitting_filter.c b/webrtc/common_audio/signal_processing/splitting_filter.c
index ba6e77d..1400623 100644
--- a/webrtc/common_audio/signal_processing/splitting_filter.c
+++ b/webrtc/common_audio/signal_processing/splitting_filter.c
@@ -13,10 +13,9 @@
*
*/
+#include "webrtc/base/checks.h"
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
-#include <assert.h>
-
// Maximum number of samples in a low/high-band frame.
enum
{
@@ -136,8 +135,8 @@
int32_t filter1[kMaxBandFrameLength];
int32_t filter2[kMaxBandFrameLength];
const size_t band_length = in_data_length / 2;
- assert(in_data_length % 2 == 0);
- assert(band_length <= kMaxBandFrameLength);
+ RTC_DCHECK_EQ(0, in_data_length % 2);
+ RTC_DCHECK_LE(band_length, kMaxBandFrameLength);
// Split even and odd samples. Also shift them to Q10.
for (i = 0, k = 0; i < band_length; i++, k += 2)
@@ -175,7 +174,7 @@
int32_t filter2[kMaxBandFrameLength];
size_t i;
int16_t k;
- assert(band_length <= kMaxBandFrameLength);
+ RTC_DCHECK_LE(band_length, kMaxBandFrameLength);
// Obtain the sum and difference channels out of upper and lower-band channels.
// Also shift to Q10 domain.
diff --git a/webrtc/common_audio/vad/vad_filterbank.c b/webrtc/common_audio/vad/vad_filterbank.c
index 8b9df93..5e15696 100644
--- a/webrtc/common_audio/vad/vad_filterbank.c
+++ b/webrtc/common_audio/vad/vad_filterbank.c
@@ -10,8 +10,7 @@
#include "webrtc/common_audio/vad/vad_filterbank.h"
-#include <assert.h>
-
+#include "webrtc/base/checks.h"
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
#include "webrtc/typedefs.h"
@@ -160,8 +159,8 @@
// we eventually will mask out the fractional part.
uint32_t energy = 0;
- assert(data_in != NULL);
- assert(data_length > 0);
+ RTC_DCHECK(data_in);
+ RTC_DCHECK_GT(data_length, 0);
energy = (uint32_t) WebRtcSpl_Energy((int16_t*) data_in, data_length,
&tot_rshifts);
@@ -261,8 +260,8 @@
int16_t* hp_out_ptr = hp_120; // [2000 - 4000] Hz.
int16_t* lp_out_ptr = lp_120; // [0 - 2000] Hz.
- assert(data_length <= 240);
- assert(4 < kNumChannels - 1); // Checking maximum |frequency_band|.
+ RTC_DCHECK_LE(data_length, 240);
+ RTC_DCHECK_LT(4, kNumChannels - 1); // Checking maximum |frequency_band|.
// Split at 2000 Hz and downsample.
SplitFilter(in_ptr, data_length, &self->upper_state[frequency_band],
diff --git a/webrtc/common_audio/vad/vad_sp.c b/webrtc/common_audio/vad/vad_sp.c
index a54be17..4a1cebb 100644
--- a/webrtc/common_audio/vad/vad_sp.c
+++ b/webrtc/common_audio/vad/vad_sp.c
@@ -10,8 +10,7 @@
#include "webrtc/common_audio/vad/vad_sp.h"
-#include <assert.h>
-
+#include "webrtc/base/checks.h"
#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
#include "webrtc/common_audio/vad/vad_core.h"
#include "webrtc/typedefs.h"
@@ -72,7 +71,7 @@
int16_t* age = &self->index_vector[offset];
int16_t* smallest_values = &self->low_value_vector[offset];
- assert(channel < kNumChannels);
+ RTC_DCHECK_LT(channel, kNumChannels);
// Each value in |smallest_values| is getting 1 loop older. Update |age|, and
// remove old values.