platform/base layer
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
/* - | Copyright | ------------------------------------------------------------
|
||||
Copyright (c) 2026 Randy Jordan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
* --------------------------------------------------------------------------*/
|
||||
#ifndef CI2_ASSERT_H
|
||||
#define CI2_ASSERT_H
|
||||
|
||||
#include "../base/ci2_debug_trap.h"
|
||||
#include "../base/ci2_func.h"
|
||||
#include "../base/ci2_inline.h"
|
||||
#include <stdio.h>
|
||||
|
||||
/* Assert Fail */
|
||||
static CI2_INLINE void
|
||||
ci2_assert_fail(const char* expr,
|
||||
const char* msg, /* may be NULL */
|
||||
const char* file,
|
||||
int line,
|
||||
const char* func)
|
||||
{
|
||||
if (msg)
|
||||
fprintf(stderr,
|
||||
"\n[ASSERT FAILED]\n"
|
||||
" Expression : %s\n"
|
||||
" Message : %s\n"
|
||||
" Location : %s:%d\n"
|
||||
" Function : %s\n\n",
|
||||
expr,
|
||||
msg,
|
||||
file,
|
||||
line,
|
||||
func);
|
||||
else
|
||||
fprintf(stderr,
|
||||
"\n[ASSERT FAILED]\n"
|
||||
" Expression : %s\n"
|
||||
" Location : %s:%d\n"
|
||||
" Function : %s\n\n",
|
||||
expr,
|
||||
file,
|
||||
line,
|
||||
func);
|
||||
|
||||
/* Flush so the message is visible before we halt */
|
||||
fflush(stderr);
|
||||
|
||||
CI2_DEBUG_TRAP();
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define CI2_ASSERT(expr) \
|
||||
do { \
|
||||
if (!(expr)) { \
|
||||
ci2_assert_fail(#expr, NULL, __FILE__, __LINE__, CI2_FUNC); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CI2_ASSERT_MSG(expr, msg) \
|
||||
do { \
|
||||
if (!(expr)) { \
|
||||
ci2_assert_fail(#expr, (msg), __FILE__, __LINE__, CI2_FUNC); \
|
||||
} \
|
||||
} while (0)
|
||||
#else /* NDEBUG — strip all runtime checks */
|
||||
|
||||
#define CI2_ASSERT(expr) ((void)(expr))
|
||||
#define CI2_ASSERT_MSG(expr, msg) ((void)(expr))
|
||||
#endif /* NDEBUG */
|
||||
|
||||
#endif // ci2_assert.h
|
||||
Reference in New Issue
Block a user