-
Notifications
You must be signed in to change notification settings - Fork 0
/
assert.h
58 lines (41 loc) · 1.09 KB
/
assert.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef ASSERT_H
#define ASSERT_H
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include "macros.h"
#define STRINGIFY(x) #x
#if defined(BNS_DEBUG)
#define ASSERT(cond) if (!(cond)){\
assertFrom(#cond, __FUNCTION__, __FILE__, __LINE__, nullptr);\
}
#define ASSERT_MSG(cond, str, ...) if(!(cond)){\
char assertMsg[4096];\
snprintf(assertMsg, 4096, str, ## __VA_ARGS__);\
assertFrom(#cond, __FUNCTION__, __FILE__, __LINE__, assertMsg);\
}
#define ASSERT_WARN(str, ...) {\
char assertMsg[4096];\
snprintf(assertMsg, 4096, str, __VA_ARGS__);\
assertFrom(nullptr, __FUNCTION__, __FILE__, __LINE__, assertMsg);\
}
#else
#define DEBUG_BREAK()
#define ASSERT(cond)
#define ASSERT_MSG(cond, str, ...)
#define ASSERT_WARN(str, ...)
#endif
#if defined(BNS_DEBUG)
#if defined(_MSC_VER)
#define DEBUG_BREAK() __debugbreak()
#else
#include <signal.h>
#if defined(_WIN32) || defined(_WIN64)
#define DEBUG_BREAK() __builtin_trap()
#else
#define DEBUG_BREAK() raise(SIGTRAP);
#endif
#endif
void assertFrom(const char* cond, const char* function, const char* file, int line, const char* msg);
#endif
#endif