]> git.saurik.com Git - apple/system_cmds.git/blob - CPPUtil/UtilAssert.hpp
f7a0d5749c1bc84f5d10a47762e0593cb91fa61e
[apple/system_cmds.git] / CPPUtil / UtilAssert.hpp
1 //
2 // Assert.hpp
3 // CPPUtil
4 //
5 // Created by James McIlree on 4/7/13.
6 // Copyright (c) 2013 Apple. All rights reserved.
7 //
8
9 #ifndef CPPUtil_Assert_hpp
10 #define CPPUtil_Assert_hpp
11
12 #if !defined(NDEBUG) && !defined(NS_BLOCK_ASSERTIONS)
13
14 #define DEBUG_ONLY( statement ) statement
15
16 #define ASSERT(e, d) \
17 { \
18 if (__builtin_expect(!(e), 0)) { \
19 ::printf("ASSERT(%s) %s %d, %s\n", #e, util::Path::basename((char*)__FILE__).c_str(), __LINE__, d); \
20 std::abort(); \
21 } \
22 }
23
24 #define SHOULD_NOT_REACH_HERE(d) \
25 { \
26 ::printf("SHOULD_NOT_REACH_HERE %s %d, %s\n", util::Path::basename((char*)__FILE__).c_str(), __LINE__, d); \
27 std::abort(); \
28 }
29
30 #define TrueInDebug true
31
32 #else
33
34 #define DEBUG_ONLY( statement )
35 #define ASSERT(e, d)
36 #define SHOULD_NOT_REACH_HERE(d)
37
38 #define TrueInDebug false
39
40 #endif
41
42 #define GUARANTEE(e) \
43 { \
44 if (__builtin_expect(!(e), 0)) { \
45 ::printf("ASSERT(%s) %s %d\n", #e, util::Path::basename((char*)__FILE__).c_str(), __LINE__); \
46 std::abort(); \
47 } \
48 }
49
50 #endif