summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2024-10-15 12:34:59 -0500
committerDominick Allen <djallen@librehumanitas.org>2024-10-15 12:34:59 -0500
commit93d8e7d066ec89a235630907164b07ada6ee5c3c (patch)
tree59d8a8012075cb6337bb932f7568eb246de93dfa /source
parent2eaa2875f0f2523439beb623fc63146ef295c8cc (diff)
Change asssertions to abort.
Diffstat (limited to 'source')
-rw-r--r--source/fud_assert.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/source/fud_assert.cpp b/source/fud_assert.cpp
index 9c2ec77..749aa6b 100644
--- a/source/fud_assert.cpp
+++ b/source/fud_assert.cpp
@@ -10,16 +10,16 @@
namespace fud {
-void assertFail(const char* assertion, const char* file, unsigned int line, const char* function) noexcept(false)
+[[noreturn]] void assertFail(const char* assertion, const std::source_location sourceLocation)
{
constexpr size_t MAX_FILE_CHARS = 256;
constexpr size_t MAX_FUNCTION_CHARS = 256;
constexpr size_t BITS_PER_OCTAL = 3;
- constexpr auto MAX_LINE_CHARS = BITS_PER_OCTAL * sizeof(decltype(line)) + 3;
+ constexpr auto MAX_LINE_CHARS = BITS_PER_OCTAL * sizeof(decltype(sourceLocation.line())) + 3;
constexpr size_t MAX_ASSERT_CHARS = 512 - MAX_LINE_CHARS;
constexpr size_t ASSERT_MSG_SIZE = MAX_FILE_CHARS + MAX_LINE_CHARS + MAX_FUNCTION_CHARS + MAX_ASSERT_CHARS;
- auto lengthResult = cStringLength(file);
+ auto lengthResult = cStringLength(sourceLocation.file_name());
size_t filenameLength = 0;
auto badLength = lengthResult < 1 || lengthResult > SSIZE_MAX;
if (!badLength) {
@@ -32,7 +32,7 @@ void assertFail(const char* assertion, const char* file, unsigned int line, cons
filenameLength = sizeof(invalidFile);
filename = invalidFile;
} else if (filenameLength > MAX_LINE_CHARS) {
- filename = file + filenameLength - MAX_LINE_CHARS;
+ filename = sourceLocation.file_name() + filenameLength - MAX_LINE_CHARS;
filenameLength = MAX_FILE_CHARS;
}
@@ -40,14 +40,15 @@ void assertFail(const char* assertion, const char* file, unsigned int line, cons
// clang-format off
static_cast<void>(std::format_to_n(
buffer.data(), buffer.size() - 1U,
- "{:.{}s}:{}: {:.{}s}: Assertion `{:.{}s}` failed",
+ "{:.{}s}:{}: {:.{}s}: Assertion `{:.{}s}` failed\n",
filename, filenameLength,
- line,
- function, MAX_FUNCTION_CHARS,
+ sourceLocation.line(),
+ sourceLocation.function_name(), MAX_FUNCTION_CHARS,
assertion, MAX_ASSERT_CHARS));
// clang-format on
-
- throw std::runtime_error(buffer.data());
+ buffer[buffer.size() - 1] = '\0';
+ fputs(buffer.data(), stderr);
+ std::abort();
}
} // namespace fud