2020-03-09 02:12:24 +01:00
|
|
|
#ifndef __PANIC_H__
|
|
|
|
#define __PANIC_H__
|
|
|
|
|
2020-04-24 08:36:29 +02:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
# define __attribute__(x)
|
|
|
|
#endif
|
|
|
|
|
2021-02-07 15:39:03 +01:00
|
|
|
#ifndef __cplusplus // C doesn't know bool
|
|
|
|
#define bool unsigned char
|
|
|
|
#endif
|
|
|
|
|
2020-03-11 15:23:58 +01:00
|
|
|
extern bool stop_at_panic;
|
|
|
|
extern bool i_have_panicked;
|
|
|
|
|
2020-10-12 16:49:43 +02:00
|
|
|
#ifdef __cplusplus // C cannot accept 2 functions with same name and different parameters.
|
2020-11-02 21:26:41 +01:00
|
|
|
#if !defined(PANIC_CAN_RETURN) && defined(_MSC_VER)
|
|
|
|
__declspec(noreturn)
|
|
|
|
#endif
|
2020-08-15 22:39:25 +02:00
|
|
|
void panic(void)
|
|
|
|
#ifndef PANIC_CAN_RETURN
|
2020-10-12 16:49:43 +02:00
|
|
|
__attribute__ ((noreturn))
|
2020-08-15 22:39:25 +02:00
|
|
|
#endif
|
|
|
|
;
|
2020-10-12 16:49:43 +02:00
|
|
|
#endif
|
2020-08-15 22:39:25 +02:00
|
|
|
|
2020-11-02 21:26:41 +01:00
|
|
|
#if !defined(PANIC_CAN_RETURN) && defined(_MSC_VER)
|
|
|
|
__declspec(noreturn)
|
|
|
|
#endif
|
2020-08-15 22:39:25 +02:00
|
|
|
void panic(const char* format, ...) __attribute__((__format__(__printf__, 1, 2)))
|
|
|
|
#ifndef PANIC_CAN_RETURN
|
2020-10-12 16:49:43 +02:00
|
|
|
__attribute__ ((noreturn))
|
2020-08-15 22:39:25 +02:00
|
|
|
#endif
|
|
|
|
;
|
2020-04-24 08:36:29 +02:00
|
|
|
|
2020-11-02 20:36:36 +01:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
# define assert(expr) _assert(expr, "Expression \"%s\" failed in %s", #expr, __FUNCSIG__)
|
|
|
|
#else
|
|
|
|
# define assert(expr) _assert(expr, "Expression \"%s\" failed in %s", #expr, __PRETTY_FUNCTION__)
|
|
|
|
#endif
|
2020-10-17 15:01:33 +02:00
|
|
|
#define assertf(...) _assert(__VA_ARGS__)
|
|
|
|
|
|
|
|
void _assert(bool b, const char* format, ...) __attribute__((__format__(__printf__, 2, 3)));
|
|
|
|
|
2020-10-12 16:49:43 +02:00
|
|
|
#ifdef __cplusplus
|
2020-04-08 12:49:00 +02:00
|
|
|
class DontStopAtPanic
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DontStopAtPanic() { stop_at_panic = false; i_have_panicked = false; }
|
|
|
|
~DontStopAtPanic() { stop_at_panic = true; i_have_panicked = false; }
|
|
|
|
};
|
2020-10-12 16:49:43 +02:00
|
|
|
#endif
|
2020-04-08 12:49:00 +02:00
|
|
|
|
2020-03-09 02:12:24 +01:00
|
|
|
#endif
|