#ifdef NDEBUG
#define KWQ_ASSERTIONS_DISABLED_DEFAULT 1
#else
#define KWQ_ASSERTIONS_DISABLED_DEFAULT 0
#endif
#ifndef ASSERT_DISABLED
#define ASSERT_DISABLED KWQ_ASSERTIONS_DISABLED_DEFAULT
#endif
#ifndef ASSERT_ARG_DISABLED
#define ASSERT_ARG_DISABLED KWQ_ASSERTIONS_DISABLED_DEFAULT
#endif
#ifndef FATAL_DISABLED
#define FATAL_DISABLED KWQ_ASSERTIONS_DISABLED_DEFAULT
#endif
#ifndef ERROR_DISABLED
#define ERROR_DISABLED KWQ_ASSERTIONS_DISABLED_DEFAULT
#endif
#ifndef LOG_DISABLED
#define LOG_DISABLED KWQ_ASSERTIONS_DISABLED_DEFAULT
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
unsigned mask;
const char *defaultName;
enum { KWQLogChannelUninitialized, KWQLogChannelOff, KWQLogChannelOn } state;
} KWQLogChannel;
void KWQReportAssertionFailure(const char *file, int line, const char *function, const char *assertion);
void KWQReportAssertionFailureWithMessage(const char *file, int line, const char *function, const char *assertion, const char *format, ...);
void KWQReportArgumentAssertionFailure(const char *file, int line, const char *function, const char *argName, const char *assertion);
void KWQReportFatalError(const char *file, int line, const char *function, const char *format, ...) ;
void KWQReportError(const char *file, int line, const char *function, const char *format, ...);
void KWQLog(const char *file, int line, const char *function, KWQLogChannel *channel, const char *format, ...);
#ifdef __cplusplus
}
#endif
#define CRASH() *(int *)0xbbadbeef = 0
#if ASSERT_DISABLED
#define ASSERT(assertion) ((void)0)
#define ASSERT_WITH_MESSAGE(assertion, formatAndArgs...) ((void)0)
#define ASSERT_NOT_REACHED() ((void)0)
#else
#define ASSERT(assertion) do \
if (!(assertion)) { \
KWQReportAssertionFailure(__FILE__, __LINE__, __PRETTY_FUNCTION__, #assertion); \
CRASH(); \
} \
while (0)
#define ASSERT_WITH_MESSAGE(assertion, formatAndArgs...) do \
if (!(assertion)) { \
KWQReportAssertionFailureWithMessage(__FILE__, __LINE__, __PRETTY_FUNCTION__, #assertion, formatAndArgs); \
CRASH(); \
} \
while (0)
#define ASSERT_NOT_REACHED() do { \
KWQReportAssertionFailure(__FILE__, __LINE__, __PRETTY_FUNCTION__, 0); \
CRASH(); \
} while (0)
#endif
#if ASSERT_ARG_DISABLED
#define ASSERT_ARG(argName, assertion) ((void)0)
#else
#define ASSERT_ARG(argName, assertion) do \
if (!(assertion)) { \
KWQReportArgumentAssertionFailure(__FILE__, __LINE__, __PRETTY_FUNCTION__, #argName, #assertion); \
CRASH(); \
} \
while (0)
#endif
#if FATAL_DISABLED
#define FATAL(formatAndArgs...) ((void)0)
#else
#define FATAL(formatAndArgs...) do { \
KWQReportFatalError(__FILE__, __LINE__, __PRETTY_FUNCTION__, formatAndArgs); \
CRASH(); \
} while (0)
#endif
#if ERROR_DISABLED
#define ERROR(formatAndArgs...) ((void)0)
#else
#define ERROR(formatAndArgs...) KWQReportError(__FILE__, __LINE__, __PRETTY_FUNCTION__, formatAndArgs)
#endif
#if LOG_DISABLED
#define LOG(channel, formatAndArgs...) ((void)0)
#else
#define LOG(channel, formatAndArgs...) KWQLog(__FILE__, __LINE__, __PRETTY_FUNCTION__, &JOIN_LOG_CHANNEL_WITH_PREFIX(LOG_CHANNEL_PREFIX, channel), formatAndArgs)
#define JOIN_LOG_CHANNEL_WITH_PREFIX(prefix, channel) JOIN_LOG_CHANNEL_WITH_PREFIX_LEVEL_2(prefix, channel)
#define JOIN_LOG_CHANNEL_WITH_PREFIX_LEVEL_2(prefix, channel) prefix ## channel
#endif