os-k/src/kaleid/common/assert.h

45 lines
1.4 KiB
C
Raw Normal View History

//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Authors: spectral` //
// NeoX //
// //
// Desc: Assertions //
//----------------------------------------------------------------------------//
2018-12-24 18:13:58 +01:00
#ifndef _KALCOMM_ASSERT_H
#define _KALCOMM_ASSERT_H
2018-12-24 22:38:14 +01:00
#if !defined(_NO_DEBUG) && !defined(NDEBUG)
2018-12-24 22:38:14 +01:00
// uses panic() in kernel, abort() in system
noreturn void ___assert_handler(const char *, const char *, int, const char *);
2018-12-24 18:13:58 +01:00
2018-12-24 22:38:14 +01:00
#define assert(x) do{if(!(x))___assert_handler(#x, __FILE__, __LINE__, __func__);}while(0);
2018-12-24 22:38:14 +01:00
/*
2018-12-24 18:13:58 +01:00
#define assert_never_used(x) do{static bool __##x##_init = FALSE; \
assert(__##x##_init == FALSE); __##x##_init = TRUE;}while(0);
2018-12-24 18:13:58 +01:00
#define assert_used_once(x) do{static bool __##x##_init; assert(__##x##_init == TRUE);} while(0);
2018-12-24 22:38:14 +01:00
*/
2018-12-24 18:13:58 +01:00
#else // not debugging
#if !defined(NDEBUG)
#define NDEBUG 1
#endif
2018-12-24 22:38:14 +01:00
#if !defined(_NO_DEBUG)
#define _NO_DEBUG 1
#endif
#define assert(x)
#define assert_used_once(x)
2018-12-24 22:38:14 +01:00
#define assert_never_used(x)
2018-12-24 18:13:58 +01:00
#endif
#endif