Introduce RTC_CHECK_NOTREACHED(), an always-checking RTC_NOTREACHED()

And use it in a few places that were using RTC_CHECK(false) or FATAL()
to do the exact same job. There should be no change in behavior.

Bug: none
Change-Id: I36d5e6bcf35fd41534e08a8c879fa0811b4f1967
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/191963
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32567}
This commit is contained in:
Karl Wiberg 2020-11-08 00:49:37 +01:00 committed by Commit Bot
parent 9dfe2fce9a
commit c95b939667
42 changed files with 168 additions and 177 deletions

View file

@ -21,7 +21,7 @@ const char* ResourceUsageStateToString(ResourceUsageState usage_state) {
case ResourceUsageState::kUnderuse:
return "kUnderuse";
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
ResourceListener::~ResourceListener() {}

View file

@ -32,7 +32,7 @@ int GetIlbcBitrate(int ptime) {
// 50 bytes per frame of 30 ms => (approx) 13333 bits/s.
return 13333;
default:
FATAL();
RTC_CHECK_NOTREACHED();
}
}
} // namespace

View file

@ -31,7 +31,7 @@ std::string MediaTypeToString(MediaType type) {
RTC_NOTREACHED();
return "";
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
} // namespace cricket

View file

@ -30,7 +30,7 @@ const char* DegradationPreferenceToString(
case DegradationPreference::BALANCED:
return "balanced";
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
const double kDefaultBitratePriority = 1.0;

View file

@ -36,7 +36,7 @@ class DummyPeerConnection : public PeerConnectionInterface {
bool AddStream(MediaStreamInterface* stream) override { return false; }
void RemoveStream(MediaStreamInterface* stream) override {
FATAL() << "Not implemented";
RTC_CHECK_NOTREACHED();
}
RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> AddTrack(
@ -100,17 +100,17 @@ class DummyPeerConnection : public PeerConnectionInterface {
}
void GetStats(RTCStatsCollectorCallback* callback) override {
FATAL() << "Not implemented";
RTC_CHECK_NOTREACHED();
}
void GetStats(
rtc::scoped_refptr<RtpSenderInterface> selector,
rtc::scoped_refptr<RTCStatsCollectorCallback> callback) override {
FATAL() << "Not implemented";
RTC_CHECK_NOTREACHED();
}
void GetStats(
rtc::scoped_refptr<RtpReceiverInterface> selector,
rtc::scoped_refptr<RTCStatsCollectorCallback> callback) override {
FATAL() << "Not implemented";
RTC_CHECK_NOTREACHED();
}
void ClearStatsCache() override {}
@ -145,33 +145,33 @@ class DummyPeerConnection : public PeerConnectionInterface {
return nullptr;
}
void RestartIce() override { FATAL() << "Not implemented"; }
void RestartIce() override { RTC_CHECK_NOTREACHED(); }
// Create a new offer.
// The CreateSessionDescriptionObserver callback will be called when done.
void CreateOffer(CreateSessionDescriptionObserver* observer,
const RTCOfferAnswerOptions& options) override {
FATAL() << "Not implemented";
RTC_CHECK_NOTREACHED();
}
void CreateAnswer(CreateSessionDescriptionObserver* observer,
const RTCOfferAnswerOptions& options) override {
FATAL() << "Not implemented";
RTC_CHECK_NOTREACHED();
}
void SetLocalDescription(SetSessionDescriptionObserver* observer,
SessionDescriptionInterface* desc) override {
FATAL() << "Not implemented";
RTC_CHECK_NOTREACHED();
}
void SetRemoteDescription(SetSessionDescriptionObserver* observer,
SessionDescriptionInterface* desc) override {
FATAL() << "Not implemented";
RTC_CHECK_NOTREACHED();
}
void SetRemoteDescription(
std::unique_ptr<SessionDescriptionInterface> desc,
rtc::scoped_refptr<SetRemoteDescriptionObserverInterface> observer)
override {
FATAL() << "Not implemented";
RTC_CHECK_NOTREACHED();
}
PeerConnectionInterface::RTCConfiguration GetConfiguration() override {
@ -194,10 +194,8 @@ class DummyPeerConnection : public PeerConnectionInterface {
return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented");
}
void SetAudioPlayout(bool playout) override { FATAL() << "Not implemented"; }
void SetAudioRecording(bool recording) override {
FATAL() << "Not implemented";
}
void SetAudioPlayout(bool playout) override { RTC_CHECK_NOTREACHED(); }
void SetAudioRecording(bool recording) override { RTC_CHECK_NOTREACHED(); }
rtc::scoped_refptr<DtlsTransportInterface> LookupDtlsTransportByMid(
const std::string& mid) override {
@ -235,7 +233,7 @@ class DummyPeerConnection : public PeerConnectionInterface {
return false;
}
void StopRtcEventLog() { FATAL() << "Not implemented"; }
void StopRtcEventLog() { RTC_CHECK_NOTREACHED(); }
void Close() override {}

View file

@ -120,7 +120,7 @@ const char* CodecTypeToPayloadString(VideoCodecType type) {
case kVideoCodecGeneric:
return kPayloadNameGeneric;
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
VideoCodecType PayloadStringToCodecType(const std::string& name) {

View file

@ -162,7 +162,7 @@ class VideoEncoderSoftwareFallbackWrapper final : public VideoEncoder {
case EncoderState::kForcedFallback:
return fallback_encoder_.get();
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
// Updates encoder with last observed parameters, such as callbacks, rates,
@ -346,7 +346,7 @@ int32_t VideoEncoderSoftwareFallbackWrapper::Encode(
case EncoderState::kForcedFallback:
return fallback_encoder_->Encode(frame, frame_types);
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
int32_t VideoEncoderSoftwareFallbackWrapper::EncodeWithMainEncoder(

View file

@ -162,7 +162,7 @@ const char* Adaptation::StatusToString(Adaptation::Status status) {
case Status::kRejectedByConstraint:
return "kRejectedByConstraint";
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
Adaptation::Adaptation(int validation_id,
@ -382,7 +382,7 @@ VideoStreamAdapter::RestrictionsOrState VideoStreamAdapter::GetAdaptationUpStep(
case DegradationPreference::DISABLED:
return Adaptation::Status::kAdaptationDisabled;
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
Adaptation VideoStreamAdapter::GetAdaptationDown() {
@ -462,7 +462,7 @@ VideoStreamAdapter::GetAdaptationDownStep(
case DegradationPreference::DISABLED:
return Adaptation::Status::kAdaptationDisabled;
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
VideoStreamAdapter::RestrictionsOrState VideoStreamAdapter::DecreaseResolution(
@ -601,7 +601,7 @@ Adaptation VideoStreamAdapter::GetAdaptDownResolution() {
GetAdaptDownResolutionStepForBalanced(input_state), input_state);
}
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
VideoStreamAdapter::RestrictionsOrState

View file

@ -77,7 +77,7 @@ bool CoDelSimulation::DropDequeuedPacket(Timestamp now,
}
return false;
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
SimulatedNetwork::SimulatedNetwork(Config config, uint64_t random_seed)

View file

@ -28,7 +28,7 @@ const char* StreamTypeToString(VideoSendStream::StreamStats::StreamType type) {
case VideoSendStream::StreamStats::StreamType::kFlexfec:
return "flexfec";
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
} // namespace

View file

@ -132,7 +132,7 @@ uint16_t MapWavFormatToHeaderField(WavFormat format) {
case WavFormat::kWavFormatMuLaw:
return 7;
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
WavFormat MapHeaderFieldToWavFormat(uint16_t format_header_value) {
@ -278,10 +278,8 @@ size_t GetFormatBytesPerSample(WavFormat format) {
return 1;
case WavFormat::kWavFormatIeeeFloat:
return 4;
default:
RTC_CHECK(false);
return 2;
}
RTC_CHECK_NOTREACHED();
}
bool CheckWavParameters(size_t num_channels,

View file

@ -323,7 +323,7 @@ absl::string_view RtpPacketTypeToString(RtpPacketType packet_type) {
case RtpPacketType::kUnknown:
return "Unknown";
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
RtpPacketType InferRtpPacketType(rtc::ArrayView<const char> packet) {

View file

@ -34,7 +34,7 @@ int GetIlbcBitrate(int ptime) {
// 50 bytes per frame of 30 ms => (approx) 13333 bits/s.
return 13333;
default:
FATAL();
RTC_CHECK_NOTREACHED();
}
}
@ -144,7 +144,7 @@ size_t AudioEncoderIlbcImpl::RequiredOutputSizeBytes() const {
case 6:
return 2 * 50;
default:
FATAL();
RTC_CHECK_NOTREACHED();
}
}

View file

@ -103,15 +103,13 @@ class AudioDeviceTemplate : public AudioDeviceGeneric {
int32_t PlayoutDeviceName(uint16_t index,
char name[kAdmMaxDeviceNameSize],
char guid[kAdmMaxGuidSize]) override {
FATAL() << "Should never be called";
return -1;
RTC_CHECK_NOTREACHED();
}
int32_t RecordingDeviceName(uint16_t index,
char name[kAdmMaxDeviceNameSize],
char guid[kAdmMaxGuidSize]) override {
FATAL() << "Should never be called";
return -1;
RTC_CHECK_NOTREACHED();
}
int32_t SetPlayoutDevice(uint16_t index) override {
@ -123,8 +121,7 @@ class AudioDeviceTemplate : public AudioDeviceGeneric {
int32_t SetPlayoutDevice(
AudioDeviceModule::WindowsDeviceType device) override {
FATAL() << "Should never be called";
return -1;
RTC_CHECK_NOTREACHED();
}
int32_t SetRecordingDevice(uint16_t index) override {
@ -136,8 +133,7 @@ class AudioDeviceTemplate : public AudioDeviceGeneric {
int32_t SetRecordingDevice(
AudioDeviceModule::WindowsDeviceType device) override {
FATAL() << "Should never be called";
return -1;
RTC_CHECK_NOTREACHED();
}
int32_t PlayoutIsAvailable(bool& available) override {
@ -266,53 +262,38 @@ class AudioDeviceTemplate : public AudioDeviceGeneric {
}
int32_t SetMicrophoneVolume(uint32_t volume) override {
FATAL() << "Should never be called";
return -1;
RTC_CHECK_NOTREACHED();
}
int32_t MicrophoneVolume(uint32_t& volume) const override {
FATAL() << "Should never be called";
RTC_CHECK_NOTREACHED();
return -1;
}
int32_t MaxMicrophoneVolume(uint32_t& maxVolume) const override {
FATAL() << "Should never be called";
return -1;
RTC_CHECK_NOTREACHED();
}
int32_t MinMicrophoneVolume(uint32_t& minVolume) const override {
FATAL() << "Should never be called";
return -1;
RTC_CHECK_NOTREACHED();
}
int32_t SpeakerMuteIsAvailable(bool& available) override {
FATAL() << "Should never be called";
return -1;
RTC_CHECK_NOTREACHED();
}
int32_t SetSpeakerMute(bool enable) override {
FATAL() << "Should never be called";
return -1;
}
int32_t SetSpeakerMute(bool enable) override { RTC_CHECK_NOTREACHED(); }
int32_t SpeakerMute(bool& enabled) const override {
FATAL() << "Should never be called";
return -1;
}
int32_t SpeakerMute(bool& enabled) const override { RTC_CHECK_NOTREACHED(); }
int32_t MicrophoneMuteIsAvailable(bool& available) override {
FATAL() << "Not implemented";
return -1;
RTC_CHECK_NOTREACHED();
}
int32_t SetMicrophoneMute(bool enable) override {
FATAL() << "Not implemented";
return -1;
}
int32_t SetMicrophoneMute(bool enable) override { RTC_CHECK_NOTREACHED(); }
int32_t MicrophoneMute(bool& enabled) const override {
FATAL() << "Not implemented";
return -1;
RTC_CHECK_NOTREACHED();
}
// Returns true if the audio manager has been configured to support stereo

View file

@ -219,8 +219,7 @@ int32_t AudioRecordJni::EnableBuiltInAEC(bool enable) {
int32_t AudioRecordJni::EnableBuiltInAGC(bool enable) {
// TODO(henrika): possibly remove when no longer used by any client.
FATAL() << "Should never be called";
return -1;
RTC_CHECK_NOTREACHED();
}
int32_t AudioRecordJni::EnableBuiltInNS(bool enable) {

View file

@ -42,7 +42,7 @@ float GetLevel(const VadLevelAnalyzer::Result& vad_level,
return vad_level.peak_dbfs;
break;
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
} // namespace

View file

@ -114,7 +114,7 @@ GainControl::Mode Agc1ConfigModeToInterfaceMode(
case Agc1Config::kFixedDigital:
return GainControl::kFixedDigital;
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
// Maximum lengths that frame of samples being passed from the render side to
@ -1830,7 +1830,7 @@ void AudioProcessingImpl::InitializeNoiseSuppressor() {
case NoiseSuppresionConfig::kVeryHigh:
return NsConfig::SuppressionLevel::k21dB;
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
};
NsConfig cfg;

View file

@ -31,7 +31,7 @@ std::string NoiseSuppressionLevelToString(
case AudioProcessing::Config::NoiseSuppression::Level::kVeryHigh:
return "VeryHigh";
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
std::string GainController1ModeToString(const Agc1Config::Mode& mode) {
@ -43,7 +43,7 @@ std::string GainController1ModeToString(const Agc1Config::Mode& mode) {
case Agc1Config::Mode::kFixedDigital:
return "FixedDigital";
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
std::string GainController2LevelEstimatorToString(
@ -54,7 +54,7 @@ std::string GainController2LevelEstimatorToString(
case Agc2Config::LevelEstimator::kPeak:
return "Peak";
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
int GetDefaultMaxInternalRate() {

View file

@ -269,8 +269,7 @@ void AecDumpBasedSimulator::HandleEvent(
HandleMessage(event_msg.runtime_setting());
break;
case webrtc::audioproc::Event::UNKNOWN_EVENT:
RTC_CHECK(false);
break;
RTC_CHECK_NOTREACHED();
}
}

View file

@ -40,7 +40,7 @@ EchoCanceller3Config ReadAec3ConfigFromJsonFile(const std::string& filename) {
std::ifstream f(filename.c_str());
if (f.fail()) {
std::cout << "Failed to open the file " << filename << std::endl;
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
while (std::getline(f, s)) {
json_string += s;
@ -52,7 +52,7 @@ EchoCanceller3Config ReadAec3ConfigFromJsonFile(const std::string& filename) {
if (!parsing_successful) {
std::cout << "Parsing of json string failed: " << std::endl
<< json_string << std::endl;
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
RTC_CHECK(EchoCanceller3Config::Validate(&cfg));

View file

@ -80,8 +80,7 @@ bool DebugDumpReplayer::RunNextEvent() {
break;
case audioproc::Event::UNKNOWN_EVENT:
// We do not expect to receive UNKNOWN event.
RTC_CHECK(false);
return false;
RTC_CHECK_NOTREACHED();
}
LoadNextMessage();
return true;

View file

@ -146,8 +146,7 @@ AudioProcessing::ChannelLayout LayoutFromChannels(size_t num_channels) {
case 2:
return AudioProcessing::kStereo;
default:
RTC_CHECK(false);
return AudioProcessing::kMono;
RTC_CHECK_NOTREACHED();
}
}

View file

@ -118,7 +118,7 @@ void WavBasedSimulator::Process() {
}
break;
default:
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
call_chain_index = (call_chain_index + 1) % call_chain_.size();

View file

@ -84,7 +84,7 @@ int GetPriorityForType(RtpPacketMediaType type) {
// BWE high.
return kFirstPriority + 4;
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
} // namespace

View file

@ -37,7 +37,7 @@ std::unique_ptr<VideoRtpDepacketizer> CreateVideoRtpDepacketizer(
case kVideoCodecMultiplex:
return std::make_unique<VideoRtpDepacketizerGeneric>();
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
} // namespace webrtc

View file

@ -128,7 +128,7 @@ bool IsNonVolatile(RTPExtensionType type) {
RTC_NOTREACHED();
return false;
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
bool HasBweExtension(const RtpHeaderExtensionMap& extensions_map) {

View file

@ -46,7 +46,7 @@ const char* FrameTypeToString(AudioFrameType frame_type) {
case AudioFrameType::kAudioFrameCN:
return "audio_cn";
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
#endif

View file

@ -29,7 +29,7 @@ TemporalLayersChecker::CreateTemporalLayersChecker(Vp8TemporalLayersType type,
// Conference mode temporal layering for screen content in base stream.
return std::make_unique<TemporalLayersChecker>(num_temporal_layers);
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
TemporalLayersChecker::TemporalLayersChecker(int num_temporal_layers)

View file

@ -31,7 +31,7 @@ DtlsTransportState TranslateState(cricket::DtlsTransportState internal_state) {
case cricket::DTLS_TRANSPORT_FAILED:
return DtlsTransportState::kFailed;
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
} // namespace

View file

@ -1818,7 +1818,7 @@ const AudioCodecs& MediaSessionDescriptionFactory::GetAudioCodecsForOffer(
case RtpTransceiverDirection::kRecvOnly:
return audio_recv_codecs_;
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
const AudioCodecs& MediaSessionDescriptionFactory::GetAudioCodecsForAnswer(
@ -1837,7 +1837,7 @@ const AudioCodecs& MediaSessionDescriptionFactory::GetAudioCodecsForAnswer(
case RtpTransceiverDirection::kRecvOnly:
return audio_recv_codecs_;
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
const VideoCodecs& MediaSessionDescriptionFactory::GetVideoCodecsForOffer(
@ -1853,7 +1853,7 @@ const VideoCodecs& MediaSessionDescriptionFactory::GetVideoCodecsForOffer(
case RtpTransceiverDirection::kRecvOnly:
return video_recv_codecs_;
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
const VideoCodecs& MediaSessionDescriptionFactory::GetVideoCodecsForAnswer(
@ -1872,7 +1872,7 @@ const VideoCodecs& MediaSessionDescriptionFactory::GetVideoCodecsForAnswer(
case RtpTransceiverDirection::kRecvOnly:
return video_recv_codecs_;
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
void MergeCodecsFromDescription(

View file

@ -2408,7 +2408,7 @@ void PeerConnection::ReportBestConnectionState(
GetIceCandidatePairCounter(local, remote),
kIceCandidatePairMax);
} else {
RTC_CHECK(0);
RTC_CHECK_NOTREACHED();
}
// Increment the counter for IP type.

View file

@ -141,7 +141,7 @@ RtpCapabilities PeerConnectionFactory::GetRtpSenderCapabilities(
case cricket::MEDIA_TYPE_UNSUPPORTED:
return RtpCapabilities();
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
RtpCapabilities PeerConnectionFactory::GetRtpReceiverCapabilities(
@ -167,7 +167,7 @@ RtpCapabilities PeerConnectionFactory::GetRtpReceiverCapabilities(
case cricket::MEDIA_TYPE_UNSUPPORTED:
return RtpCapabilities();
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
rtc::scoped_refptr<AudioSourceInterface>

View file

@ -216,7 +216,7 @@ const char* QualityLimitationReasonToRTCQualityLimitationReason(
case QualityLimitationReason::kOther:
return RTCQualityLimitationReason::kOther;
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
double DoubleAudioLevelFromIntAudioLevel(int audio_level) {

View file

@ -76,7 +76,7 @@ RTCErrorOr<cricket::FeedbackParam> ToCricketFeedbackParam(
}
return cricket::FeedbackParam(cricket::kRtcpFbParamTransportCc);
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
template <typename C>

View file

@ -36,6 +36,21 @@
#include "rtc_base/checks.h"
namespace {
RTC_NORETURN void WriteFatalLogAndAbort(const std::string& output) {
const char* output_c = output.c_str();
#if defined(WEBRTC_ANDROID)
__android_log_print(ANDROID_LOG_ERROR, RTC_LOG_TAG_ANDROID, "%s\n", output_c);
#endif
fflush(stdout);
fprintf(stderr, "%s", output_c);
fflush(stderr);
#if defined(WEBRTC_WIN)
DebugBreak();
#endif
abort();
}
#if defined(__GNUC__)
__attribute__((__format__(__printf__, 2, 3)))
#endif
@ -149,19 +164,7 @@ RTC_NORETURN void FatalLog(const char* file,
va_end(args);
const char* output = s.c_str();
#if defined(WEBRTC_ANDROID)
__android_log_print(ANDROID_LOG_ERROR, RTC_LOG_TAG_ANDROID, "%s\n", output);
#endif
fflush(stdout);
fprintf(stderr, "%s", output);
fflush(stderr);
#if defined(WEBRTC_WIN)
DebugBreak();
#endif
abort();
WriteFatalLogAndAbort(s);
}
#else // RTC_CHECK_MSG_ENABLED
RTC_NORETURN void FatalLog(const char* file, int line) {
@ -174,22 +177,40 @@ RTC_NORETURN void FatalLog(const char* file, int line) {
"# Check failed.\n"
"# ",
file, line, LAST_SYSTEM_ERROR);
const char* output = s.c_str();
#if defined(WEBRTC_ANDROID)
__android_log_print(ANDROID_LOG_ERROR, RTC_LOG_TAG_ANDROID, "%s\n", output);
#endif
fflush(stdout);
fprintf(stderr, "%s", output);
fflush(stderr);
#if defined(WEBRTC_WIN)
DebugBreak();
#endif
abort();
WriteFatalLogAndAbort(s);
}
#endif // RTC_CHECK_MSG_ENABLED
#if RTC_DCHECK_IS_ON
RTC_NORETURN void UnreachableCodeReached(const char* file, int line) {
std::string s;
AppendFormat(&s,
"\n\n"
"#\n"
"# Unreachable code reached: %s, line %d\n"
"# last system error: %u\n"
"# ",
file, line, LAST_SYSTEM_ERROR);
WriteFatalLogAndAbort(s);
}
#else // !RTC_DCHECK_IS_ON
RTC_NORETURN void UnreachableCodeReached() {
std::string s;
AppendFormat(&s,
"\n\n"
"#\n"
"# Unreachable code reached (file and line unknown)\n"
"# last system error: %u\n"
"# ",
LAST_SYSTEM_ERROR);
WriteFatalLogAndAbort(s);
}
#endif // !RTC_DCHECK_IS_ON
} // namespace webrtc_checks_impl
} // namespace rtc

View file

@ -338,6 +338,22 @@ class FatalLogCall final {
const char* message_;
};
#if RTC_DCHECK_IS_ON
// Be helpful, and include file and line in the RTC_CHECK_NOTREACHED error
// message.
#define RTC_UNREACHABLE_FILE_AND_LINE_CALL_ARGS __FILE__, __LINE__
RTC_NORETURN RTC_EXPORT void UnreachableCodeReached(const char* file, int line);
#else
// Be mindful of binary size, and don't include file and line in the
// RTC_CHECK_NOTREACHED error message.
#define RTC_UNREACHABLE_FILE_AND_LINE_CALL_ARGS
RTC_NORETURN RTC_EXPORT void UnreachableCodeReached();
#endif
} // namespace webrtc_checks_impl
// The actual stream used isn't important. We reference |ignored| in the code
@ -430,6 +446,14 @@ class FatalLogCall final {
#define RTC_UNREACHABLE_CODE_HIT false
#define RTC_NOTREACHED() RTC_DCHECK(RTC_UNREACHABLE_CODE_HIT)
// Kills the process with an error message. Never returns. Use when you wish to
// assert that a point in the code is never reached.
#define RTC_CHECK_NOTREACHED() \
do { \
::rtc::webrtc_checks_impl::UnreachableCodeReached( \
RTC_UNREACHABLE_FILE_AND_LINE_CALL_ARGS); \
} while (0)
// TODO(bugs.webrtc.org/8454): Add an RTC_ prefix or rename differently.
#define FATAL() \
::rtc::webrtc_checks_impl::FatalLogCall<false>(__FILE__, __LINE__, \

View file

@ -21,7 +21,7 @@ const char* NetworkPreferenceToString(NetworkPreference preference) {
case NetworkPreference::NOT_PREFERRED:
return "NOT_PREFERRED";
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
NetworkMonitorInterface::NetworkMonitorInterface() {}

View file

@ -63,12 +63,10 @@ inline constexpr Dst saturated_cast(Src value) {
// Should fail only on attempting to assign NaN to a saturated integer.
case internal::TYPE_INVALID:
FATAL();
return std::numeric_limits<Dst>::max();
RTC_CHECK_NOTREACHED();
}
FATAL();
return static_cast<Dst>(value);
RTC_CHECK_NOTREACHED();
}
} // namespace rtc

View file

@ -244,13 +244,8 @@ std::unique_ptr<SSLCertificate> OpenSSLCertificate::Clone() const {
std::string OpenSSLCertificate::ToPEMString() const {
BIO* bio = BIO_new(BIO_s_mem());
if (!bio) {
FATAL() << "Unreachable code.";
}
if (!PEM_write_bio_X509(bio, x509_)) {
BIO_free(bio);
FATAL() << "Unreachable code.";
}
RTC_CHECK(bio);
RTC_CHECK(PEM_write_bio_X509(bio, x509_));
BIO_write(bio, "\0", 1);
char* buffer;
BIO_get_mem_data(bio, &buffer);
@ -264,13 +259,8 @@ void OpenSSLCertificate::ToDER(Buffer* der_buffer) const {
der_buffer->SetSize(0);
// Calculates the DER representation of the certificate, from scratch.
BIO* bio = BIO_new(BIO_s_mem());
if (!bio) {
FATAL() << "Unreachable code.";
}
if (!i2d_X509_bio(bio, x509_)) {
BIO_free(bio);
FATAL() << "Unreachable code.";
}
RTC_CHECK(bio);
RTC_CHECK(i2d_X509_bio(bio, x509_));
char* data = nullptr;
size_t length = BIO_get_mem_data(bio, &data);
der_buffer->SetData(data, length);

View file

@ -110,7 +110,7 @@ void DataRace() {
thread2.Join();
// TSan seems to mess with gtest's death detection.
// Fail intentionally, and rely on detecting the error message.
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
TEST(SanitizersDeathTest, ThreadSanitizer) {

View file

@ -151,15 +151,13 @@ class AndroidAudioDeviceModule : public AudioDeviceModule {
int32_t PlayoutDeviceName(uint16_t index,
char name[kAdmMaxDeviceNameSize],
char guid[kAdmMaxGuidSize]) override {
FATAL() << "Should never be called";
return -1;
RTC_CHECK_NOTREACHED();
}
int32_t RecordingDeviceName(uint16_t index,
char name[kAdmMaxDeviceNameSize],
char guid[kAdmMaxGuidSize]) override {
FATAL() << "Should never be called";
return -1;
RTC_CHECK_NOTREACHED();
}
int32_t SetPlayoutDevice(uint16_t index) override {
@ -171,8 +169,7 @@ class AndroidAudioDeviceModule : public AudioDeviceModule {
int32_t SetPlayoutDevice(
AudioDeviceModule::WindowsDeviceType device) override {
FATAL() << "Should never be called";
return -1;
RTC_CHECK_NOTREACHED();
}
int32_t SetRecordingDevice(uint16_t index) override {
@ -184,8 +181,7 @@ class AndroidAudioDeviceModule : public AudioDeviceModule {
int32_t SetRecordingDevice(
AudioDeviceModule::WindowsDeviceType device) override {
FATAL() << "Should never be called";
return -1;
RTC_CHECK_NOTREACHED();
}
int32_t PlayoutIsAvailable(bool* available) override {
@ -396,62 +392,52 @@ class AndroidAudioDeviceModule : public AudioDeviceModule {
int32_t SetMicrophoneVolume(uint32_t volume) override {
RTC_LOG(INFO) << __FUNCTION__ << "(" << volume << ")";
FATAL() << "Should never be called";
return -1;
RTC_CHECK_NOTREACHED();
}
int32_t MicrophoneVolume(uint32_t* volume) const override {
RTC_LOG(INFO) << __FUNCTION__;
FATAL() << "Should never be called";
return -1;
RTC_CHECK_NOTREACHED();
}
int32_t MaxMicrophoneVolume(uint32_t* maxVolume) const override {
RTC_LOG(INFO) << __FUNCTION__;
FATAL() << "Should never be called";
return -1;
RTC_CHECK_NOTREACHED();
}
int32_t MinMicrophoneVolume(uint32_t* minVolume) const override {
RTC_LOG(INFO) << __FUNCTION__;
FATAL() << "Should never be called";
return -1;
RTC_CHECK_NOTREACHED();
}
int32_t SpeakerMuteIsAvailable(bool* available) override {
RTC_LOG(INFO) << __FUNCTION__;
FATAL() << "Should never be called";
return -1;
RTC_CHECK_NOTREACHED();
}
int32_t SetSpeakerMute(bool enable) override {
RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
FATAL() << "Should never be called";
return -1;
RTC_CHECK_NOTREACHED();
}
int32_t SpeakerMute(bool* enabled) const override {
RTC_LOG(INFO) << __FUNCTION__;
FATAL() << "Should never be called";
return -1;
RTC_CHECK_NOTREACHED();
}
int32_t MicrophoneMuteIsAvailable(bool* available) override {
RTC_LOG(INFO) << __FUNCTION__;
FATAL() << "Not implemented";
return -1;
RTC_CHECK_NOTREACHED();
}
int32_t SetMicrophoneMute(bool enable) override {
RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
FATAL() << "Not implemented";
return -1;
RTC_CHECK_NOTREACHED();
}
int32_t MicrophoneMute(bool* enabled) const override {
RTC_LOG(INFO) << __FUNCTION__;
FATAL() << "Not implemented";
return -1;
RTC_CHECK_NOTREACHED();
}
int32_t StereoPlayoutIsAvailable(bool* available) const override {
@ -569,8 +555,7 @@ class AndroidAudioDeviceModule : public AudioDeviceModule {
int32_t EnableBuiltInAGC(bool enable) override {
RTC_LOG(INFO) << __FUNCTION__ << "(" << enable << ")";
FATAL() << "HW AGC is not available";
return -1;
RTC_CHECK_NOTREACHED();
}
// TODO(henrika): add implementation for OpenSL ES based audio as well.

View file

@ -55,7 +55,7 @@ std::string ToString(VideoAdaptationReason reason) {
case VideoAdaptationReason::kCpu:
return "cpu";
}
RTC_CHECK(false);
RTC_CHECK_NOTREACHED();
}
} // namespace