]>
git.saurik.com Git - apple/xnu.git/blob - EXTERNAL_HEADERS/corecrypto/cc_macros.h
5 * Created on 01/11/2012
7 * Copyright (c) 2012,2015 Apple Inc. All rights reserved.
11 #ifndef _CORECRYPTO_CC_MACROS_H_
12 #define _CORECRYPTO_CC_MACROS_H_
14 #include <corecrypto/cc_config.h>
16 #ifndef __CC_DEBUG_ASSERT_COMPONENT_NAME_STRING
17 #define __CC_DEBUG_ASSERT_COMPONENT_NAME_STRING ""
20 #ifndef __CC_DEBUG_ASSERT_PRODUCTION_CODE
21 #define __CC_DEBUG_ASSERT_PRODUCTION_CODE !CORECRYPTO_DEBUG
24 #if CORECRYPTO_DEBUG_ENABLE_CC_REQUIRE_PRINTS
27 #include <string.h> // for strstr
30 CC_UNUSED
static char *cc_strstr(const char *file
) {
34 const char cc_char
[]="corecrypto";
35 char *p
=strstr(file
, cc_char
);
36 if (p
) return (p
+strlen(cc_char
)+1);
41 #define __CC_DEBUG_REQUIRE_MESSAGE(name, assertion, label, message, file, line, value) \
42 {char *___t = cc_strstr(file); cc_printf( "require: %s, %s%s:%d\n", assertion, (message!=0) ? message : "", ___t==NULL?file:___t, line);}
44 #endif // CORECRYPTO_DEBUG_ENABLE_CC_REQUIRE_PRINTS
47 #if (__CC_DEBUG_ASSERT_PRODUCTION_CODE) || (!CORECRYPTO_DEBUG_ENABLE_CC_REQUIRE_PRINTS)
48 #if defined(_WIN32) && defined (__clang__)
49 #define cc_require(assertion, exceptionLabel) \
51 if (!(assertion) ) { \
52 goto exceptionLabel; \
56 #define cc_require(assertion, exceptionLabel) \
58 if ( __builtin_expect(!(assertion), 0) ) { \
59 goto exceptionLabel; \
64 #define cc_require(assertion, exceptionLabel) \
66 if ( __builtin_expect(!(assertion), 0) ) { \
67 __CC_DEBUG_REQUIRE_MESSAGE(__CC_DEBUG_ASSERT_COMPONENT_NAME_STRING, \
68 #assertion, #exceptionLabel, 0, __FILE__, __LINE__, 0); \
69 goto exceptionLabel; \
75 #ifndef cc_require_action
76 #if __CC_DEBUG_ASSERT_PRODUCTION_CODE || (!CORECRYPTO_DEBUG_ENABLE_CC_REQUIRE_PRINTS)
77 #if defined(_WIN32) && defined(__clang__)
78 #define cc_require_action(assertion, exceptionLabel, action) \
86 goto exceptionLabel; \
90 #define cc_require_action(assertion, exceptionLabel, action) \
93 if ( __builtin_expect(!(assertion), 0) ) \
98 goto exceptionLabel; \
103 #define cc_require_action(assertion, exceptionLabel, action) \
106 if ( __builtin_expect(!(assertion), 0) ) \
108 __CC_DEBUG_REQUIRE_MESSAGE( \
109 __CC_DEBUG_ASSERT_COMPONENT_NAME_STRING, \
110 #assertion, #exceptionLabel, 0, __FILE__, __LINE__, 0); \
114 goto exceptionLabel; \
120 #endif /* _CORECRYPTO_CC_MACROS_H_ */