diff options
author | andrew@webrtc.org <andrew@webrtc.org> | 2014-08-28 16:28:26 +0000 |
---|---|---|
committer | andrew@webrtc.org <andrew@webrtc.org> | 2014-08-28 16:28:26 +0000 |
commit | 54ade8bbee7cea004418c02de3658ffc870fc968 (patch) | |
tree | b3d16cb9bc096df8103e4f342bdf2901aa6ec3df /common_audio | |
parent | 84bd5249d97dcd38f37ef10b565986808f74abce (diff) | |
download | webrtc-54ade8bbee7cea004418c02de3658ffc870fc968.tar.gz |
Add CHECK and friends from Chromium.
Replace FATAL_ERROR_IF with the more familiar (to Chromium developers)
CHECK and DCHECK. The full Chromium implementation is fairly elaborate
but I copied enough to get us most of the benefits. I believe the main
missing component is a more advanced stack dump. For this bit I relied
on the V8 implementation.
There are a few minor modifications from the Chromium original:
- The FatalMessage class is specialized for logging fatal error
messages and aborting. Chromium uses the general LogMessage class,
which we could consider moving towards in the future.
- NOTIMPLEMENTED() and NOTREACHED() have been removed, partly because
I don't want to rely on our logging.h until base/ and system_wrappers/
are consolidated.
- FATAL() replaces LOG(FATAL).
Minor modifications from V8's stack dump:
- If parsing of a stack trace symbol fails, just print the unparsed
symbol. (I noticed this happened on Mac.)
- Use __GLIBCXX__ and __UCLIBC__. This is from examining the backtrace
use in Chromium.
UNREACHABLE() has been removed because its behavior is different than
Chromium's NOTREACHED(), which is bound to cause confusion. The few uses
were replaced with FATAL(), matching the previous behavior.
Add a NO_RETURN macro, allowing us to remove unreachable return
statements following a CHECK/FATAL.
TESTED=the addition of dummy CHECK, DCHECK, CHECK_EQ and FATAL did the
did the right things. Stack traces work on Mac, but I don't get symbols
on Linux.
R=henrik.lundin@webrtc.org, kwiberg@webrtc.org, tommi@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/22449004
git-svn-id: http://webrtc.googlecode.com/svn/trunk/webrtc@7003 4adac7df-926f-26a2-2b94-8c16560cd09d
Diffstat (limited to 'common_audio')
-rw-r--r-- | common_audio/wav_writer.cc | 36 | ||||
-rw-r--r-- | common_audio/wav_writer.h | 2 |
2 files changed, 19 insertions, 19 deletions
diff --git a/common_audio/wav_writer.cc b/common_audio/wav_writer.cc index f3b8118c..30a220c2 100644 --- a/common_audio/wav_writer.cc +++ b/common_audio/wav_writer.cc @@ -29,17 +29,17 @@ WavFile::WavFile(const std::string& filename, int sample_rate, int num_channels) num_channels_(num_channels), num_samples_(0), file_handle_(fopen(filename.c_str(), "wb")) { - FATAL_ERROR_IF(!CheckWavParameters(num_channels_, - sample_rate_, - kWavFormat, - kBytesPerSample, - num_samples_)); - FATAL_ERROR_IF(!file_handle_); + CHECK(file_handle_); + CHECK(CheckWavParameters(num_channels_, + sample_rate_, + kWavFormat, + kBytesPerSample, + num_samples_)); // Write a blank placeholder header, since we need to know the total number // of samples before we can fill in the real data. static const uint8_t blank_header[kWavHeaderSize] = {0}; - FATAL_ERROR_IF(fwrite(blank_header, kWavHeaderSize, 1, file_handle_) != 1); + CHECK_EQ(1u, fwrite(blank_header, kWavHeaderSize, 1, file_handle_)); } WavFile::~WavFile() { @@ -52,15 +52,15 @@ void WavFile::WriteSamples(const int16_t* samples, size_t num_samples) { #endif const size_t written = fwrite(samples, sizeof(*samples), num_samples, file_handle_); - FATAL_ERROR_IF(written != num_samples); + CHECK_EQ(num_samples, written); num_samples_ += static_cast<uint32_t>(written); - FATAL_ERROR_IF(written > std::numeric_limits<uint32_t>::max() || - num_samples_ < written); // detect uint32_t overflow - FATAL_ERROR_IF(!CheckWavParameters(num_channels_, - sample_rate_, - kWavFormat, - kBytesPerSample, - num_samples_)); + CHECK(written <= std::numeric_limits<uint32_t>::max() || + num_samples_ >= written); // detect uint32_t overflow + CHECK(CheckWavParameters(num_channels_, + sample_rate_, + kWavFormat, + kBytesPerSample, + num_samples_)); } void WavFile::WriteSamples(const float* samples, size_t num_samples) { @@ -74,12 +74,12 @@ void WavFile::WriteSamples(const float* samples, size_t num_samples) { } void WavFile::Close() { - FATAL_ERROR_IF(fseek(file_handle_, 0, SEEK_SET) != 0); + CHECK_EQ(0, fseek(file_handle_, 0, SEEK_SET)); uint8_t header[kWavHeaderSize]; WriteWavHeader(header, num_channels_, sample_rate_, kWavFormat, kBytesPerSample, num_samples_); - FATAL_ERROR_IF(fwrite(header, kWavHeaderSize, 1, file_handle_) != 1); - FATAL_ERROR_IF(fclose(file_handle_) != 0); + CHECK_EQ(1u, fwrite(header, kWavHeaderSize, 1, file_handle_)); + CHECK_EQ(0, fclose(file_handle_)); file_handle_ = NULL; } diff --git a/common_audio/wav_writer.h b/common_audio/wav_writer.h index e0582657..45bcbac5 100644 --- a/common_audio/wav_writer.h +++ b/common_audio/wav_writer.h @@ -20,7 +20,7 @@ namespace webrtc { // Simple C++ class for writing 16-bit PCM WAV files. All error handling is -// by calls to FATAL_ERROR(), making it unsuitable for anything but debug code. +// by calls to CHECK(), making it unsuitable for anything but debug code. class WavFile { public: // Open a new WAV file for writing. |