Skip to content

Commit

Permalink
refactor(check): don't throw, print to stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
Curve committed Oct 11, 2023
1 parent 1c8f804 commit 5dd02e7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 22 deletions.
6 changes: 0 additions & 6 deletions include/rohrkabel/utils/assert.hpp

This file was deleted.

7 changes: 7 additions & 0 deletions include/rohrkabel/utils/check.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once
#include <source_location>

namespace pipewire
{
void check(bool, const char *, const std::source_location = std::source_location::current());
}
16 changes: 0 additions & 16 deletions src/assert.cpp

This file was deleted.

26 changes: 26 additions & 0 deletions src/check.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "utils/check.hpp"

#include <format>
#include <cstring>
#include <iostream>

namespace pipewire
{
#ifdef NDEBUG
void check(bool, const char *, const std::source_location) {}
#else
void check(bool condition, const char *message, const std::source_location loc)
{
if (condition)
{
return;
}

const auto *error = strerror(errno); // NOLINT(*-mt-unsafe)
auto [file, line, col, func] = std::make_tuple(loc.file_name(), loc.line(), loc.column(), loc.function_name());

std::cerr << std::format("{} ({}:{}) [{}]: check failed \"{}\", error is \"{}\"\n", file, line, col, func,
message, error);
}
#endif
} // namespace pipewire

0 comments on commit 5dd02e7

Please sign in to comment.