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

83 lines
2.0 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
//------------------------------------------//
// Useful macros //
//------------------------------------------//
#ifndef noreturn
#define noreturn __attribute__((noreturn))
#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);
//
// Aliases
//
#ifndef Assert
#define Assert assert
#endif
#ifndef DosAssert
#define DosAssert assert
#endif
#ifndef KalAssert
#define KalAssert assert
#endif
//------------------------------------------//
// When not debugging //
//------------------------------------------//
#else
#if !defined(NDEBUG)
# define NDEBUG 1
#endif
#if !defined(_NO_DEBUG)
# define _NO_DEBUG 1
#endif
#ifndef assert
#define assert(x)
#endif
#endif
//------------------------------------------//
// End of <kalassrt.h> //
//------------------------------------------//
#endif