iuno
This commit is contained in:
124
src/assert/assert.c
Normal file
124
src/assert/assert.c
Normal file
@@ -0,0 +1,124 @@
|
||||
/**
|
||||
* Copyright (c) 2023 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "assert.h"
|
||||
|
||||
void assertTrueImpl(
|
||||
const char *file,
|
||||
const int32_t line,
|
||||
const bool x,
|
||||
const char *message
|
||||
) {
|
||||
if(x != true) {
|
||||
fprintf(
|
||||
stderr,
|
||||
"Assertion Failed in %s:%i\n\n%s\n",
|
||||
file,
|
||||
line,
|
||||
message
|
||||
);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
void assertFalseImpl(
|
||||
const char *file,
|
||||
const int32_t line,
|
||||
bool x,
|
||||
const char *message
|
||||
) {
|
||||
assertTrueImpl(file, line, !x, message);
|
||||
}
|
||||
|
||||
void assertUnreachableImpl(
|
||||
const char *file,
|
||||
const int32_t line,
|
||||
const char *message
|
||||
) {
|
||||
assertTrueImpl(file, line, false, message);
|
||||
}
|
||||
|
||||
void assertNotNullImpl(
|
||||
const char *file,
|
||||
const int32_t line,
|
||||
const void *pointer,
|
||||
const char *message
|
||||
) {
|
||||
assertTrueImpl(
|
||||
file,
|
||||
line,
|
||||
pointer != NULL,
|
||||
message
|
||||
);
|
||||
|
||||
// Ensure we can touch it
|
||||
volatile char temp;
|
||||
temp = *((char*)pointer);
|
||||
}
|
||||
|
||||
void assertNullImpl(
|
||||
const char *file,
|
||||
const int32_t line,
|
||||
const void *pointer,
|
||||
const char *message
|
||||
) {
|
||||
assertTrueImpl(
|
||||
file,
|
||||
line,
|
||||
pointer == NULL,
|
||||
message
|
||||
);
|
||||
}
|
||||
|
||||
void assertDeprecatedImpl(
|
||||
const char *file,
|
||||
const int32_t line,
|
||||
const char *message
|
||||
) {
|
||||
assertUnreachableImpl(file, line, message);
|
||||
}
|
||||
|
||||
// void assertMemoryRangeMatchesImpl(
|
||||
// const char *file,
|
||||
// const int32_t line,
|
||||
// const void *start,
|
||||
// const void *end,
|
||||
// const size_t size,
|
||||
// const char *message
|
||||
// ) {
|
||||
// assertTrueImpl(
|
||||
// file,
|
||||
// line,
|
||||
// start != NULL,
|
||||
// "Start pointer is NULL"
|
||||
// );
|
||||
// assertTrueImpl(
|
||||
// file,
|
||||
// line,
|
||||
// end != NULL,
|
||||
// "End pointer is NULL"
|
||||
// );
|
||||
// assertTrueImpl(
|
||||
// file,
|
||||
// line,
|
||||
// size > 0,
|
||||
// "Size is 0"
|
||||
// );
|
||||
// assertTrueImpl(
|
||||
// file,
|
||||
// line,
|
||||
// start < end,
|
||||
// "Start pointer is not before end pointer"
|
||||
// );
|
||||
|
||||
// assertTrueImpl(
|
||||
// file,
|
||||
// line,
|
||||
// ((uintptr_t)end - (uintptr_t)start) == size,
|
||||
// message
|
||||
// );
|
||||
// }
|
Reference in New Issue
Block a user