]> git.saurik.com Git - apple/system_cmds.git/blame - CPPUtil/UtilAssert.hpp
system_cmds-671.10.3.tar.gz
[apple/system_cmds.git] / CPPUtil / UtilAssert.hpp
CommitLineData
bd6521f0
A
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