os-k/src/kaleid/include/kalassrt.h

79 lines
2.1 KiB
C
Raw Normal View History

2019-01-01 13:09:57 +01:00
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Authors: spectral` //
// NeoX //
// //
// Desc: Kaleid assert() support //
//----------------------------------------------------------------------------//
#ifndef _KALASSRT_H
#define _KALASSRT_H
//------------------------------------------//
2019-01-01 17:11:30 +01:00
// Macros //
2019-01-01 13:09:57 +01:00
//------------------------------------------//
#ifndef noreturn
2019-01-01 17:11:30 +01:00
#define noreturn __attribute__((__noreturn__))
2019-01-01 13:09:57 +01:00
#endif
#ifndef unlikely(x)
#define unlikely(x) (__builtin_expect((x), 0))
#endif
//------------------------------------------//
// When debugging //
//------------------------------------------//
#if !defined(_NO_DEBUG) && !defined(NDEBUG) && !defined(assert)
//
// Failed assert handler
//
noreturn void _assert_handler(const char *, const char *, int, const char *);
#define assert(x) \
do { \
if unlikely(!(x)) \
_assert_handler(#x, __FILE__, __LINE__, __func__); \
} while (0);
//------------------------------------------//
// When not debugging //
//------------------------------------------//
#else
2019-01-01 17:37:58 +01:00
#ifndef NDEBUG
#define NDEBUG 1
2019-01-01 13:09:57 +01:00
#endif
2019-01-01 17:37:58 +01:00
#ifndef _NO_DEBUG
#define _NO_DEBUG 1
2019-01-01 13:09:57 +01:00
#endif
#ifndef assert
#define assert(x)
#endif
#endif
2019-01-01 17:11:30 +01:00
//------------------------------------------//
// Aliases for assert() //
//------------------------------------------//
#ifndef Assert
#define Assert assert
#endif
#ifndef KalAssert
#define KalAssert assert
#endif
2019-01-01 13:09:57 +01:00
//------------------------------------------//
// End of <kalassrt.h> //
//------------------------------------------//
#endif