1 /* Copyright (c) (2012,2015,2016,2017,2019) Apple Inc. All rights reserved.
3 * corecrypto is licensed under Apple Inc.’s Internal Use License Agreement (which
4 * is contained in the License.txt file distributed with corecrypto) and only to
5 * people who accept that license. IMPORTANT: Any license rights granted to you by
6 * Apple Inc. (if any) are limited to internal use within your organization only on
7 * devices and computers you own or control, for the sole purpose of verifying the
8 * security characteristics and correct functioning of the Apple Software. You may
9 * not, directly or indirectly, redistribute the Apple Software or any portions thereof.
12 #ifndef _CORECRYPTO_CC_MACROS_H_
13 #define _CORECRYPTO_CC_MACROS_H_
15 #include <corecrypto/cc_config.h>
17 #ifndef __CC_DEBUG_ASSERT_COMPONENT_NAME_STRING
18 #define __CC_DEBUG_ASSERT_COMPONENT_NAME_STRING ""
21 #ifndef __CC_DEBUG_ASSERT_PRODUCTION_CODE
22 #define __CC_DEBUG_ASSERT_PRODUCTION_CODE !CORECRYPTO_DEBUG
25 #if CORECRYPTO_DEBUG_ENABLE_CC_REQUIRE_PRINTS
28 #include <string.h> // for strstr
31 CC_UNUSED
static char *cc_strstr(const char *file
) {
35 const char cc_char
[]="corecrypto";
36 char *p
=strstr(file
, cc_char
);
37 if (p
) return (p
+strlen(cc_char
)+1);
42 #define __CC_DEBUG_REQUIRE_MESSAGE(name, assertion, label, message, file, line, value) \
43 {char *___t = cc_strstr(file); cc_printf( "require: %s, %s%s:%d\n", assertion, (message!=0) ? message : "", ___t==NULL?file:___t, line);}
45 #endif // CORECRYPTO_DEBUG_ENABLE_CC_REQUIRE_PRINTS
48 #if (__CC_DEBUG_ASSERT_PRODUCTION_CODE) || (!CORECRYPTO_DEBUG_ENABLE_CC_REQUIRE_PRINTS)
49 #if defined(_WIN32) && defined (__clang__)
50 #define cc_require(assertion, exceptionLabel) \
52 if (!(assertion) ) { \
53 goto exceptionLabel; \
57 #define cc_require(assertion, exceptionLabel) \
59 if ( __builtin_expect(!(assertion), 0) ) { \
60 goto exceptionLabel; \
65 #define cc_require(assertion, exceptionLabel) \
67 if ( __builtin_expect(!(assertion), 0) ) { \
68 __CC_DEBUG_REQUIRE_MESSAGE(__CC_DEBUG_ASSERT_COMPONENT_NAME_STRING, \
69 #assertion, #exceptionLabel, 0, __FILE__, __LINE__, 0); \
70 goto exceptionLabel; \
76 #ifndef cc_require_action
77 #if __CC_DEBUG_ASSERT_PRODUCTION_CODE || (!CORECRYPTO_DEBUG_ENABLE_CC_REQUIRE_PRINTS)
78 #if defined(_WIN32) && defined(__clang__)
79 #define cc_require_action(assertion, exceptionLabel, action) \
87 goto exceptionLabel; \
91 #define cc_require_action(assertion, exceptionLabel, action) \
94 if ( __builtin_expect(!(assertion), 0) ) \
99 goto exceptionLabel; \
104 #define cc_require_action(assertion, exceptionLabel, action) \
107 if ( __builtin_expect(!(assertion), 0) ) \
109 __CC_DEBUG_REQUIRE_MESSAGE( \
110 __CC_DEBUG_ASSERT_COMPONENT_NAME_STRING, \
111 #assertion, #exceptionLabel, 0, __FILE__, __LINE__, 0); \
115 goto exceptionLabel; \
121 #ifndef cc_require_or_return
122 #if (__CC_DEBUG_ASSERT_PRODUCTION_CODE) || (!CORECRYPTO_DEBUG_ENABLE_CC_REQUIRE_PRINTS)
123 #if defined(_WIN32) && defined (__clang__)
124 #define cc_require_or_return(assertion, value) \
126 if (!(assertion) ) { \
131 #define cc_require_or_return(assertion, value) \
133 if ( __builtin_expect(!(assertion), 0) ) { \
139 #define cc_require_or_return(assertion, value) \
141 if ( __builtin_expect(!(assertion), 0) ) { \
142 __CC_DEBUG_REQUIRE_MESSAGE(__CC_DEBUG_ASSERT_COMPONENT_NAME_STRING, \
143 #assertion, #exceptionLabel, 0, __FILE__, __LINE__, 0); \
150 #endif /* _CORECRYPTO_CC_MACROS_H_ */