]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * cc_macros.h | |
3 | * corecrypto | |
4 | * | |
5 | * Created on 01/11/2012 | |
6 | * | |
7 | * Copyright (c) 2012,2015 Apple Inc. All rights reserved. | |
8 | * | |
9 | */ | |
10 | ||
11 | #ifndef _CORECRYPTO_CC_MACROS_H_ | |
12 | #define _CORECRYPTO_CC_MACROS_H_ | |
13 | ||
14 | #include <corecrypto/cc_config.h> | |
15 | ||
16 | #ifndef __CC_DEBUG_ASSERT_COMPONENT_NAME_STRING | |
17 | #define __CC_DEBUG_ASSERT_COMPONENT_NAME_STRING "" | |
18 | #endif | |
19 | ||
20 | #ifndef __CC_DEBUG_ASSERT_PRODUCTION_CODE | |
21 | #define __CC_DEBUG_ASSERT_PRODUCTION_CODE !CORECRYPTO_DEBUG | |
22 | #endif | |
23 | ||
24 | #ifndef __CC_DEBUG_ASSERT_MESSAGE | |
25 | #define __CC_DEBUG_ASSERT_MESSAGE(name, assertion, label, message, file, line, value) \ | |
26 | cc_printf( "CCAssertMacros: %s, %s file: %s, line: %d\n", assertion, (message!=0) ? message : "", file, line); | |
27 | #endif | |
28 | ||
29 | #ifndef cc_require | |
30 | #if __CC_DEBUG_ASSERT_PRODUCTION_CODE | |
31 | #define cc_require(assertion, exceptionLabel) \ | |
32 | do { \ | |
33 | if ( __builtin_expect(!(assertion), 0) ) { \ | |
34 | goto exceptionLabel; \ | |
35 | } \ | |
36 | } while ( 0 ) | |
37 | #else | |
38 | #define cc_require(assertion, exceptionLabel) \ | |
39 | do { \ | |
40 | if ( __builtin_expect(!(assertion), 0) ) { \ | |
41 | __CC_DEBUG_ASSERT_MESSAGE(__CC_DEBUG_ASSERT_COMPONENT_NAME_STRING, \ | |
42 | #assertion, #exceptionLabel, 0, __FILE__, __LINE__, 0); \ | |
43 | goto exceptionLabel; \ | |
44 | } \ | |
45 | } while ( 0 ) | |
46 | #endif | |
47 | #endif | |
48 | ||
49 | #ifndef cc_require_action | |
50 | #if __CC_DEBUG_ASSERT_PRODUCTION_CODE | |
51 | #define cc_require_action(assertion, exceptionLabel, action) \ | |
52 | do \ | |
53 | { \ | |
54 | if ( __builtin_expect(!(assertion), 0) ) \ | |
55 | { \ | |
56 | { \ | |
57 | action; \ | |
58 | } \ | |
59 | goto exceptionLabel; \ | |
60 | } \ | |
61 | } while ( 0 ) | |
62 | #else | |
63 | #define cc_require_action(assertion, exceptionLabel, action) \ | |
64 | do \ | |
65 | { \ | |
66 | if ( __builtin_expect(!(assertion), 0) ) \ | |
67 | { \ | |
68 | __CC_DEBUG_ASSERT_MESSAGE( \ | |
69 | __CC_DEBUG_ASSERT_COMPONENT_NAME_STRING, \ | |
70 | #assertion, #exceptionLabel, 0, __FILE__, __LINE__, 0); \ | |
71 | { \ | |
72 | action; \ | |
73 | } \ | |
74 | goto exceptionLabel; \ | |
75 | } \ | |
76 | } while ( 0 ) | |
77 | #endif | |
78 | #endif | |
79 | ||
80 | #endif /* _CORECRYPTO_CC_MACROS_H_ */ |