1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-20 18:18:51 +03:00
mal/cpp/Debug.h
Stephen Thirlwall 0997015d97 Split ASSERT into ASSERT and MAL_CHECK/MAL_FAIL
* ASSERT is to check for internal errors
* MAL_CHECK / MAL_FAIL is to check mal code errors
2015-03-28 22:54:26 +11:00

46 lines
956 B
C

#ifndef INCLUDE_DEBUG_H
#define INCLUDE_DEBUG_H
#include <stdio.h>
#include <stdlib.h>
#define DEBUG_TRACE 1
//#define DEBUG_OBJECT_LIFETIMES 1
//#define DEBUG_ENV_LIFETIMES 1
#define DEBUG_TRACE_FILE stderr
#define NOOP do { } while (false)
#define NOTRACE(...) NOOP
#if DEBUG_TRACE
#define TRACE(...) fprintf(DEBUG_TRACE_FILE, __VA_ARGS__)
#else
#define TRACE NOTRACE
#endif
#if DEBUG_OBJECT_LIFETIMES
#define TRACE_OBJECT TRACE
#else
#define TRACE_OBJECT NOTRACE
#endif
#if DEBUG_ENV_LIFETIMES
#define TRACE_ENV TRACE
#else
#define TRACE_ENV NOTRACE
#endif
#define _ASSERT(file, line, condition, ...) \
if (!(condition)) { \
printf("Assertion failed at %s(%d): ", file, line); \
printf(__VA_ARGS__); \
exit(1); \
} else { }
#define ASSERT(condition, ...) \
_ASSERT(__FILE__, __LINE__, condition, __VA_ARGS__)
#endif // INCLUDE_DEBUG_H