X-Git-Url: https://git.saurik.com/apple/system_cmds.git/blobdiff_plain/1a7e3f61d38d679bba59130891c2031b5a0092b6..bd6521f0fc816ab056bc71376f9706a69b3b52c1:/CPPUtil/UtilAssert.hpp diff --git a/CPPUtil/UtilAssert.hpp b/CPPUtil/UtilAssert.hpp new file mode 100644 index 0000000..f7a0d57 --- /dev/null +++ b/CPPUtil/UtilAssert.hpp @@ -0,0 +1,50 @@ +// +// Assert.hpp +// CPPUtil +// +// Created by James McIlree on 4/7/13. +// Copyright (c) 2013 Apple. All rights reserved. +// + +#ifndef CPPUtil_Assert_hpp +#define CPPUtil_Assert_hpp + +#if !defined(NDEBUG) && !defined(NS_BLOCK_ASSERTIONS) + + #define DEBUG_ONLY( statement ) statement + + #define ASSERT(e, d) \ + { \ + if (__builtin_expect(!(e), 0)) { \ + ::printf("ASSERT(%s) %s %d, %s\n", #e, util::Path::basename((char*)__FILE__).c_str(), __LINE__, d); \ + std::abort(); \ + } \ + } + + #define SHOULD_NOT_REACH_HERE(d) \ + { \ + ::printf("SHOULD_NOT_REACH_HERE %s %d, %s\n", util::Path::basename((char*)__FILE__).c_str(), __LINE__, d); \ + std::abort(); \ + } + + #define TrueInDebug true + +#else + + #define DEBUG_ONLY( statement ) + #define ASSERT(e, d) + #define SHOULD_NOT_REACH_HERE(d) + + #define TrueInDebug false + +#endif + +#define GUARANTEE(e) \ +{ \ + if (__builtin_expect(!(e), 0)) { \ + ::printf("ASSERT(%s) %s %d\n", #e, util::Path::basename((char*)__FILE__).c_str(), __LINE__); \ + std::abort(); \ + } \ +} + +#endif