1 // Copyright 2020 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/check.h"
7 // check.h is a widely included header and its size has significant impact on
8 // build time. Try not to raise this limit unless absolutely necessary. See
9 // https://chromium.googlesource.com/chromium/src/+/HEAD/docs/wmax_tokens.md
11 #pragma clang max_tokens_here 17000
14 #include "base/check_op.h"
15 #include "base/logging.h"
16 #include "build/build_config.h"
20 CheckError CheckError::Check(const char* file,
22 const char* condition) {
23 CheckError check_error(new LogMessage(file, line, LOG_FATAL));
24 check_error.stream() << "Check failed: " << condition << ". ";
28 CheckError CheckError::CheckOp(const char* file,
30 CheckOpResult* check_op_result) {
31 CheckError check_error(new LogMessage(file, line, LOG_FATAL));
32 check_error.stream() << "Check failed: " << check_op_result->message_;
33 free(check_op_result->message_);
34 check_op_result->message_ = nullptr;
38 CheckError CheckError::DCheck(const char* file,
40 const char* condition) {
41 CheckError check_error(new LogMessage(file, line, LOG_DCHECK));
42 check_error.stream() << "Check failed: " << condition << ". ";
46 CheckError CheckError::DCheckOp(const char* file,
48 CheckOpResult* check_op_result) {
49 CheckError check_error(new LogMessage(file, line, LOG_DCHECK));
50 check_error.stream() << "Check failed: " << check_op_result->message_;
51 free(check_op_result->message_);
52 check_op_result->message_ = nullptr;
56 CheckError CheckError::PCheck(const char* file,
58 const char* condition) {
59 SystemErrorCode err_code = logging::GetLastSystemErrorCode();
61 CheckError check_error(
62 new Win32ErrorLogMessage(file, line, LOG_FATAL, err_code));
63 #elif defined(OS_POSIX) || defined(OS_FUCHSIA)
64 CheckError check_error(new ErrnoLogMessage(file, line, LOG_FATAL, err_code));
66 check_error.stream() << "Check failed: " << condition << ". ";
70 CheckError CheckError::PCheck(const char* file, int line) {
71 return PCheck(file, line, "");
74 CheckError CheckError::DPCheck(const char* file,
76 const char* condition) {
77 SystemErrorCode err_code = logging::GetLastSystemErrorCode();
79 CheckError check_error(
80 new Win32ErrorLogMessage(file, line, LOG_DCHECK, err_code));
81 #elif defined(OS_POSIX) || defined(OS_FUCHSIA)
82 CheckError check_error(new ErrnoLogMessage(file, line, LOG_DCHECK, err_code));
84 check_error.stream() << "Check failed: " << condition << ". ";
88 CheckError CheckError::NotImplemented(const char* file,
90 const char* function) {
91 CheckError check_error(new LogMessage(file, line, LOG_ERROR));
92 check_error.stream() << "Not implemented reached in " << function;
96 std::ostream& CheckError::stream() {
97 return log_message_->stream();
100 CheckError::~CheckError() {
101 // Note: This function ends up in crash stack traces. If its full name
102 // changes, the crash server's magic signature logic needs to be updated.
107 CheckError::CheckError(LogMessage* log_message) : log_message_(log_message) {}
109 void RawCheck(const char* message) {
110 RawLog(LOG_FATAL, message);
113 } // namespace logging