mirror of
https://gitlab.os-k.eu/os-k-team/os-k.git
synced 2023-08-25 14:03:10 +02:00
109 lines
2.8 KiB
C
109 lines
2.8 KiB
C
//----------------------------------------------------------------------------//
|
|
// GNU GPL OS/K //
|
|
// //
|
|
// Authors: spectral` //
|
|
// NeoX //
|
|
// //
|
|
// Desc: Kaleid assert() support //
|
|
//----------------------------------------------------------------------------//
|
|
|
|
#ifndef _KALASSRT_H
|
|
#define _KALASSRT_H
|
|
|
|
//------------------------------------------//
|
|
// Macros //
|
|
//------------------------------------------//
|
|
|
|
#ifndef noreturn
|
|
#define noreturn __attribute__((__noreturn__))
|
|
#endif
|
|
|
|
#ifndef unlikely
|
|
#define unlikely(x) (__builtin_expect((x), 0))
|
|
#endif
|
|
|
|
#ifndef static_assert
|
|
#define static_assert _Static_assert
|
|
#endif
|
|
|
|
//------------------------------------------//
|
|
// API compatibility checks //
|
|
//------------------------------------------//
|
|
|
|
#define _SA_MSG "Incompatible type sizes"
|
|
static_assert(sizeof(char) == 1, _SA_MSG);
|
|
static_assert(sizeof(short) == 2, _SA_MSG);
|
|
static_assert(sizeof(int) == 4, _SA_MSG);
|
|
static_assert(sizeof(long) == 8, _SA_MSG);
|
|
static_assert(sizeof(void *) == 8, _SA_MSG);
|
|
#undef _SA_MSG
|
|
|
|
//------------------------------------------//
|
|
// When debugging //
|
|
//------------------------------------------//
|
|
|
|
#if !defined(_NO_DEBUG) && !defined(NDEBUG) && !defined(assert)
|
|
|
|
#ifdef _OSK_SOURCE
|
|
|
|
//
|
|
// Failed assert handler
|
|
//
|
|
noreturn void _assert_handler(const char *, const char *, int, const char *);
|
|
|
|
//
|
|
// Checks whether (x) holds, if not call _assert_handler
|
|
//
|
|
#define assert(x) \
|
|
do { \
|
|
if unlikely (!(x)) \
|
|
_assert_handler(#x, __FILE__, __LINE__, __func__); \
|
|
} while (0);
|
|
|
|
#else
|
|
|
|
//
|
|
// When not building for OS/K, use the system's assert
|
|
//
|
|
#include <assert.h>
|
|
|
|
#endif
|
|
|
|
//------------------------------------------//
|
|
// When not debugging //
|
|
//------------------------------------------//
|
|
|
|
#else
|
|
|
|
#ifndef NDEBUG
|
|
#define NDEBUG 1
|
|
#endif
|
|
|
|
#ifndef _NO_DEBUG
|
|
#define _NO_DEBUG 1
|
|
#endif
|
|
|
|
#ifndef assert
|
|
#define assert(x) ((void)0)
|
|
#endif
|
|
|
|
#endif
|
|
|
|
//------------------------------------------//
|
|
// Aliases for assert() //
|
|
//------------------------------------------//
|
|
|
|
#ifndef Assert
|
|
#define Assert assert
|
|
#endif
|
|
|
|
#ifndef KalAssert
|
|
#define KalAssert assert
|
|
#endif
|
|
|
|
//------------------------------------------//
|
|
// End of header //
|
|
//------------------------------------------//
|
|
|
|
#endif
|