Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions impeller/base/validation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,30 @@ ScopedValidationFatal::~ScopedValidationFatal() {
sValidationLogsAreFatal--;
}

ValidationLog::ValidationLog() = default;
ValidationLog::ValidationLog(const char* file, int line)
: file_(file), line_(line) {}

ValidationLog::~ValidationLog() {
if (sValidationLogsDisabledCount <= 0) {
ImpellerValidationBreak(stream_.str().c_str());
ImpellerValidationBreak(stream_.str().c_str(), file_, line_);
}
}

std::ostream& ValidationLog::GetStream() {
return stream_;
}

void ImpellerValidationBreak(const char* message) {
std::stringstream stream;
void ImpellerValidationBreak(const char* message, const char* file, int line) {
const auto severity =
ImpellerValidationErrorsAreFatal() ? fml::LOG_FATAL : fml::LOG_ERROR;
auto fml_log = fml::LogMessage{severity, file, line, nullptr};
fml_log.stream() <<
#if FLUTTER_RELEASE
stream << "Impeller validation: " << message;
#else
stream << "Break on '" << __FUNCTION__
<< "' to inspect point of failure: " << message;
#endif
if (sValidationLogsAreFatal > 0) {
FML_LOG(FATAL) << stream.str();
} else {
FML_LOG(ERROR) << stream.str();
}
"Impeller validation: " << message;
#else // FLUTTER_RELEASE
"Break on '" << __FUNCTION__
<< "' to inspect point of failure: " << message;
#endif // FLUTTER_RELEASE
}

bool ImpellerValidationErrorsAreFatal() {
Expand Down
8 changes: 5 additions & 3 deletions impeller/base/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ namespace impeller {

class ValidationLog {
public:
ValidationLog();
ValidationLog(const char* file, int line);

~ValidationLog();

std::ostream& GetStream();

private:
const char* file_ = nullptr;
int line_ = 0;
std::ostringstream stream_;

ValidationLog(const ValidationLog&) = delete;
Expand All @@ -29,7 +31,7 @@ class ValidationLog {
ValidationLog& operator=(ValidationLog&&) = delete;
};

void ImpellerValidationBreak(const char* message);
void ImpellerValidationBreak(const char* message, const char* file, int line);

void ImpellerValidationErrorsSetFatal(bool fatal);

Expand Down Expand Up @@ -70,6 +72,6 @@ struct ScopedValidationFatal {
/// are fatal. The runtime-mode restriction still applies. This usually
/// happens in test environments.
///
#define VALIDATION_LOG ::impeller::ValidationLog{}.GetStream()
#define VALIDATION_LOG ::impeller::ValidationLog{__FILE__, __LINE__}.GetStream()

#endif // FLUTTER_IMPELLER_BASE_VALIDATION_H_