]>
git.saurik.com Git - apple/xnu.git/blob - EXTERNAL_HEADERS/AssertMacros.h
2 * Copyright (c) 2002-2008 by Apple Inc.. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
28 Contains: This file defines structured error handling and assertion macros for
29 programming in C. Originally used in QuickDraw GX and later enhanced.
30 These macros are used throughout Apple's software.
32 New code may not want to begin adopting these macros and instead use
33 existing language functionality.
35 See "Living In an Exceptional World" by Sean Parent
36 (develop, The Apple Technical Journal, Issue 11, August/September 1992)
37 <http://developer.apple.com/dev/techsupport/develop/issue11toc.shtml> or
38 <http://www.mactech.com/articles/develop/issue_11/Parent_final.html>
39 for the methodology behind these error handling and assertion macros.
41 Bugs?: For bug reports, consult the following page on
44 http://developer.apple.com/bugreporter/
46 #ifndef __ASSERTMACROS__
47 #define __ASSERTMACROS__
53 * In production builds, pre-processed away
54 * In debug builds, if assertion evaluates to false, calls DEBUG_ASSERT_MESSAGE
57 * In production builds, evaluates assertion and does nothing
58 * In debug builds, if assertion evaluates to false, calls DEBUG_ASSERT_MESSAGE
60 * require(assertion, exceptionLabel)
61 * In production builds, if the assertion expression evaluates to false, goto exceptionLabel
62 * In debug builds, if the assertion expression evaluates to false, calls DEBUG_ASSERT_MESSAGE
63 * and jumps to exceptionLabel
65 * In addition the following suffixes are available:
67 * _noerr Adds "!= 0" to assertion. Useful for asserting and OSStatus or OSErr is noErr (zero)
68 * _action Adds statement to be executued if assertion fails
69 * _quiet Suppress call to DEBUG_ASSERT_MESSAGE
70 * _string Allows you to add explanitory message to DEBUG_ASSERT_MESSAGE
72 * For instance, require_noerr_string(resultCode, label, msg) will do nothing if
73 * resultCode is zero, otherwise it will call DEBUG_ASSERT_MESSAGE with msg
78 * By default all macros generate "production code" (i.e non-debug). If
79 * DEBUG_ASSERT_PRODUCTION_CODE is defined to zero or DEBUG is defined to non-zero
80 * while this header is included, the macros will generated debug code.
82 * If DEBUG_ASSERT_COMPONENT_NAME_STRING is defined, all debug messages will
83 * be prefixed with it.
85 * By default, all messages write to stderr. If you would like to write a custom
86 * error message formater, defined DEBUG_ASSERT_MESSAGE to your function name.
88 * Each individual macro will only be defined if it is not already defined, so
89 * you can redefine their behavior singly by providing your own definition before
90 * this file is included.
92 * If you define __ASSERTMACROS__ before this file is included, then nothing in
93 * this file will take effect.
95 * Prior to Mac OS X 10.6 the macro names used in this file conflicted with some
96 * user code, including libraries in boost and the proposed C++ standards efforts,
97 * and there was no way for a client of this header to resolve this conflict. Because
98 * of this, most of the macros have been changed so that they are prefixed with
99 * __ and contain at least one capital letter, which should alleviate the current
100 * and future conflicts. However, to allow current sources to continue to compile,
101 * compatibility macros are defined at the end with the old names. A tops script
102 * at the end of this file will convert all of the old macro names used in a directory
103 * to the new names. Clients are recommended to migrate over to these new macros as
104 * they update their sources because a future release of Mac OS X will remove the
105 * old macro definitions ( without the double-underscore prefix ). Clients who
106 * want to compile without the old macro definitions can define the macro
107 * __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES to 0 before this file is
113 * Before including this file, #define DEBUG_ASSERT_COMPONENT_NAME_STRING to
114 * a C-string containing the name of your client. This string will be passed to
115 * the DEBUG_ASSERT_MESSAGE macro for inclusion in any assertion messages.
117 * If you do not define DEBUG_ASSERT_COMPONENT_NAME_STRING, the default
118 * DEBUG_ASSERT_COMPONENT_NAME_STRING value, an empty string, will be used by
119 * the assertion macros.
121 #ifndef DEBUG_ASSERT_COMPONENT_NAME_STRING
122 #define DEBUG_ASSERT_COMPONENT_NAME_STRING ""
127 * To activate the additional assertion code and messages for non-production builds,
128 * #define DEBUG_ASSERT_PRODUCTION_CODE to zero before including this file.
130 * If you do not define DEBUG_ASSERT_PRODUCTION_CODE, the default value 1 will be used
131 * (production code = no assertion code and no messages).
133 #ifndef DEBUG_ASSERT_PRODUCTION_CODE
134 #define DEBUG_ASSERT_PRODUCTION_CODE !DEBUG
139 * DEBUG_ASSERT_MESSAGE(component, assertion, label, error, file, line, errorCode)
142 * All assertion messages are routed through this macro. If you wish to use your
143 * own routine to display assertion messages, you can override DEBUG_ASSERT_MESSAGE
144 * by #defining DEBUG_ASSERT_MESSAGE before including this file.
148 * componentNameString:
149 * A pointer to a string constant containing the name of the
150 * component this code is part of. This must be a string constant
151 * (and not a string variable or NULL) because the preprocessor
152 * concatenates it with other string constants.
155 * A pointer to a string constant containing the assertion.
156 * This must be a string constant (and not a string variable or
157 * NULL) because the Preprocessor concatenates it with other
160 * exceptionLabelString:
161 * A pointer to a string containing the exceptionLabel, or NULL.
164 * A pointer to the error string, or NULL. DEBUG_ASSERT_MESSAGE macros
165 * must not attempt to concatenate this string with constant
169 * A pointer to the fileName or pathname (generated by the
170 * preprocessor __FILE__ identifier), or NULL.
173 * The line number in the file (generated by the preprocessor
174 * __LINE__ identifier), or 0 (zero).
177 * A value associated with the assertion, or 0.
179 * Here is an example of a DEBUG_ASSERT_MESSAGE macro and a routine which displays
180 * assertion messsages:
182 * #define DEBUG_ASSERT_COMPONENT_NAME_STRING "MyCoolProgram"
184 * #define DEBUG_ASSERT_MESSAGE(componentNameString, assertionString, \
185 * exceptionLabelString, errorString, fileName, lineNumber, errorCode) \
186 * MyProgramDebugAssert(componentNameString, assertionString, \
187 * exceptionLabelString, errorString, fileName, lineNumber, errorCode)
190 * MyProgramDebugAssert(const char *componentNameString, const char *assertionString,
191 * const char *exceptionLabelString, const char *errorString,
192 * const char *fileName, long lineNumber, int errorCode)
194 * if ( (assertionString != NULL) && (*assertionString != '\0') )
195 * fprintf(stderr, "Assertion failed: %s: %s\n", componentNameString, assertionString);
197 * fprintf(stderr, "Check failed: %s:\n", componentNameString);
198 * if ( exceptionLabelString != NULL )
199 * fprintf(stderr, " %s\n", exceptionLabelString);
200 * if ( errorString != NULL )
201 * fprintf(stderr, " %s\n", errorString);
202 * if ( fileName != NULL )
203 * fprintf(stderr, " file: %s\n", fileName);
204 * if ( lineNumber != 0 )
205 * fprintf(stderr, " line: %ld\n", lineNumber);
206 * if ( errorCode != 0 )
207 * fprintf(stderr, " error: %d\n", errorCode);
210 * If you do not define DEBUG_ASSERT_MESSAGE, a simple printf to stderr will be used.
212 #ifndef DEBUG_ASSERT_MESSAGE
214 #include <libkern/libkern.h>
215 #define DEBUG_ASSERT_MESSAGE(name, assertion, label, message, file, line, value) \
216 printf( "AssertMacros: %s, %s file: %s, line: %d\n", assertion, (message!=0) ? message : "", file, line);
219 #define DEBUG_ASSERT_MESSAGE(name, assertion, label, message, file, line, value) \
220 fprintf(stderr, "AssertMacros: %s, %s file: %s, line: %d\n", assertion, (message!=0) ? message : "", file, line);
229 * __Debug_String(message)
232 * Production builds: does nothing and produces no code.
234 * Non-production builds: call DEBUG_ASSERT_MESSAGE.
239 * The C string to display.
242 #ifndef __Debug_String
243 #if DEBUG_ASSERT_PRODUCTION_CODE
244 #define __Debug_String(message)
246 #define __Debug_String(message) \
249 DEBUG_ASSERT_MESSAGE( \
250 DEBUG_ASSERT_COMPONENT_NAME_STRING, \
265 * Production builds: does nothing and produces no code.
267 * Non-production builds: if the assertion expression evaluates to false,
268 * call DEBUG_ASSERT_MESSAGE.
273 * The assertion expression.
276 #if DEBUG_ASSERT_PRODUCTION_CODE
277 #define __Check(assertion)
279 #define __Check(assertion) \
282 if ( __builtin_expect(!(assertion), 0) ) \
284 DEBUG_ASSERT_MESSAGE( \
285 DEBUG_ASSERT_COMPONENT_NAME_STRING, \
286 #assertion, 0, 0, __FILE__, __LINE__, 0 ); \
293 #define __nCheck(assertion) __Check(!(assertion))
297 * __Check_String(assertion, message)
300 * Production builds: does nothing and produces no code.
302 * Non-production builds: if the assertion expression evaluates to false,
303 * call DEBUG_ASSERT_MESSAGE.
308 * The assertion expression.
311 * The C string to display.
313 #ifndef __Check_String
314 #if DEBUG_ASSERT_PRODUCTION_CODE
315 #define __Check_String(assertion, message)
317 #define __Check_String(assertion, message) \
320 if ( __builtin_expect(!(assertion), 0) ) \
322 DEBUG_ASSERT_MESSAGE( \
323 DEBUG_ASSERT_COMPONENT_NAME_STRING, \
324 #assertion, 0, message, __FILE__, __LINE__, 0 ); \
330 #ifndef __nCheck_String
331 #define __nCheck_String(assertion, message) __Check_String(!(assertion), message)
335 * __Check_noErr(errorCode)
338 * Production builds: does nothing and produces no code.
340 * Non-production builds: if the errorCode expression does not equal 0 (noErr),
341 * call DEBUG_ASSERT_MESSAGE.
346 * The errorCode expression to compare with 0.
348 #ifndef __Check_noErr
349 #if DEBUG_ASSERT_PRODUCTION_CODE
350 #define __Check_noErr(errorCode)
352 #define __Check_noErr(errorCode) \
355 long evalOnceErrorCode = (errorCode); \
356 if ( __builtin_expect(0 != evalOnceErrorCode, 0) ) \
358 DEBUG_ASSERT_MESSAGE( \
359 DEBUG_ASSERT_COMPONENT_NAME_STRING, \
360 #errorCode " == 0 ", 0, 0, __FILE__, __LINE__, evalOnceErrorCode ); \
367 * __Check_noErr_String(errorCode, message)
370 * Production builds: check_noerr_string() does nothing and produces
373 * Non-production builds: if the errorCode expression does not equal 0 (noErr),
374 * call DEBUG_ASSERT_MESSAGE.
379 * The errorCode expression to compare to 0.
382 * The C string to display.
384 #ifndef __Check_noErr_String
385 #if DEBUG_ASSERT_PRODUCTION_CODE
386 #define __Check_noErr_String(errorCode, message)
388 #define __Check_noErr_String(errorCode, message) \
391 long evalOnceErrorCode = (errorCode); \
392 if ( __builtin_expect(0 != evalOnceErrorCode, 0) ) \
394 DEBUG_ASSERT_MESSAGE( \
395 DEBUG_ASSERT_COMPONENT_NAME_STRING, \
396 #errorCode " == 0 ", 0, message, __FILE__, __LINE__, evalOnceErrorCode ); \
403 * __Verify(assertion)
406 * Production builds: evaluate the assertion expression, but ignore
409 * Non-production builds: if the assertion expression evaluates to false,
410 * call DEBUG_ASSERT_MESSAGE.
415 * The assertion expression.
418 #if DEBUG_ASSERT_PRODUCTION_CODE
419 #define __Verify(assertion) \
422 if ( !(assertion) ) \
427 #define __Verify(assertion) \
430 if ( __builtin_expect(!(assertion), 0) ) \
432 DEBUG_ASSERT_MESSAGE( \
433 DEBUG_ASSERT_COMPONENT_NAME_STRING, \
434 #assertion, 0, 0, __FILE__, __LINE__, 0 ); \
441 #define __nVerify(assertion) __Verify(!(assertion))
445 * __Verify_String(assertion, message)
448 * Production builds: evaluate the assertion expression, but ignore
451 * Non-production builds: if the assertion expression evaluates to false,
452 * call DEBUG_ASSERT_MESSAGE.
457 * The assertion expression.
460 * The C string to display.
462 #ifndef __Verify_String
463 #if DEBUG_ASSERT_PRODUCTION_CODE
464 #define __Verify_String(assertion, message) \
467 if ( !(assertion) ) \
472 #define __Verify_String(assertion, message) \
475 if ( __builtin_expect(!(assertion), 0) ) \
477 DEBUG_ASSERT_MESSAGE( \
478 DEBUG_ASSERT_COMPONENT_NAME_STRING, \
479 #assertion, 0, message, __FILE__, __LINE__, 0 ); \
485 #ifndef __nVerify_String
486 #define __nVerify_String(assertion, message) __Verify_String(!(assertion), message)
490 * __Verify_noErr(errorCode)
493 * Production builds: evaluate the errorCode expression, but ignore
496 * Non-production builds: if the errorCode expression does not equal 0 (noErr),
497 * call DEBUG_ASSERT_MESSAGE.
502 * The expression to compare to 0.
504 #ifndef __Verify_noErr
505 #if DEBUG_ASSERT_PRODUCTION_CODE
506 #define __Verify_noErr(errorCode) \
509 if ( 0 != (errorCode) ) \
514 #define __Verify_noErr(errorCode) \
517 long evalOnceErrorCode = (errorCode); \
518 if ( __builtin_expect(0 != evalOnceErrorCode, 0) ) \
520 DEBUG_ASSERT_MESSAGE( \
521 DEBUG_ASSERT_COMPONENT_NAME_STRING, \
522 #errorCode " == 0 ", 0, 0, __FILE__, __LINE__, evalOnceErrorCode ); \
529 * __Verify_noErr_String(errorCode, message)
532 * Production builds: evaluate the errorCode expression, but ignore
535 * Non-production builds: if the errorCode expression does not equal 0 (noErr),
536 * call DEBUG_ASSERT_MESSAGE.
541 * The expression to compare to 0.
544 * The C string to display.
546 #ifndef __Verify_noErr_String
547 #if DEBUG_ASSERT_PRODUCTION_CODE
548 #define __Verify_noErr_String(errorCode, message) \
551 if ( 0 != (errorCode) ) \
556 #define __Verify_noErr_String(errorCode, message) \
559 long evalOnceErrorCode = (errorCode); \
560 if ( __builtin_expect(0 != evalOnceErrorCode, 0) ) \
562 DEBUG_ASSERT_MESSAGE( \
563 DEBUG_ASSERT_COMPONENT_NAME_STRING, \
564 #errorCode " == 0 ", 0, message, __FILE__, __LINE__, evalOnceErrorCode ); \
571 * __Verify_noErr_Action(errorCode, action)
574 * Production builds: if the errorCode expression does not equal 0 (noErr),
575 * execute the action statement or compound statement (block).
577 * Non-production builds: if the errorCode expression does not equal 0 (noErr),
578 * call DEBUG_ASSERT_MESSAGE and then execute the action statement or compound
584 * The expression to compare to 0.
587 * The statement or compound statement (block).
589 #ifndef __Verify_noErr_Action
590 #if DEBUG_ASSERT_PRODUCTION_CODE
591 #define __Verify_noErr_Action(errorCode, action) \
592 if ( 0 != (errorCode) ) { \
597 #define __Verify_noErr_Action(errorCode, action) \
599 long evalOnceErrorCode = (errorCode); \
600 if ( __builtin_expect(0 != evalOnceErrorCode, 0) ) { \
601 DEBUG_ASSERT_MESSAGE( \
602 DEBUG_ASSERT_COMPONENT_NAME_STRING, \
603 #errorCode " == 0 ", 0, 0, __FILE__, __LINE__, evalOnceErrorCode ); \
611 * __Verify_Action(assertion, action)
614 * Production builds: if the assertion expression evaluates to false,
615 * then execute the action statement or compound statement (block).
617 * Non-production builds: if the assertion expression evaluates to false,
618 * call DEBUG_ASSERT_MESSAGE and then execute the action statement or compound
624 * The assertion expression.
627 * The statement or compound statement (block).
629 #ifndef __Verify_Action
630 #if DEBUG_ASSERT_PRODUCTION_CODE
631 #define __Verify_Action(assertion, action) \
632 if ( __builtin_expect(!(assertion), 0) ) { \
637 #define __Verify_Action(assertion, action) \
638 if ( __builtin_expect(!(assertion), 0) ) { \
639 DEBUG_ASSERT_MESSAGE( \
640 DEBUG_ASSERT_COMPONENT_NAME_STRING, \
641 #assertion, 0, 0, __FILE__, __LINE__, 0 ); \
649 * __Require(assertion, exceptionLabel)
652 * Production builds: if the assertion expression evaluates to false,
653 * goto exceptionLabel.
655 * Non-production builds: if the assertion expression evaluates to false,
656 * call DEBUG_ASSERT_MESSAGE and then goto exceptionLabel.
661 * The assertion expression.
667 #if DEBUG_ASSERT_PRODUCTION_CODE
668 #define __Require(assertion, exceptionLabel) \
671 if ( __builtin_expect(!(assertion), 0) ) \
673 goto exceptionLabel; \
677 #define __Require(assertion, exceptionLabel) \
680 if ( __builtin_expect(!(assertion), 0) ) { \
681 DEBUG_ASSERT_MESSAGE( \
682 DEBUG_ASSERT_COMPONENT_NAME_STRING, \
683 #assertion, #exceptionLabel, 0, __FILE__, __LINE__, 0); \
684 goto exceptionLabel; \
691 #define __nRequire(assertion, exceptionLabel) __Require(!(assertion), exceptionLabel)
695 * __Require_Action(assertion, exceptionLabel, action)
698 * Production builds: if the assertion expression evaluates to false,
699 * execute the action statement or compound statement (block) and then
700 * goto exceptionLabel.
702 * Non-production builds: if the assertion expression evaluates to false,
703 * call DEBUG_ASSERT_MESSAGE, execute the action statement or compound
704 * statement (block), and then goto exceptionLabel.
709 * The assertion expression.
715 * The statement or compound statement (block).
717 #ifndef __Require_Action
718 #if DEBUG_ASSERT_PRODUCTION_CODE
719 #define __Require_Action(assertion, exceptionLabel, action) \
722 if ( __builtin_expect(!(assertion), 0) ) \
727 goto exceptionLabel; \
731 #define __Require_Action(assertion, exceptionLabel, action) \
734 if ( __builtin_expect(!(assertion), 0) ) \
736 DEBUG_ASSERT_MESSAGE( \
737 DEBUG_ASSERT_COMPONENT_NAME_STRING, \
738 #assertion, #exceptionLabel, 0, __FILE__, __LINE__, 0); \
742 goto exceptionLabel; \
748 #ifndef __nRequire_Action
749 #define __nRequire_Action(assertion, exceptionLabel, action) \
750 __Require_Action(!(assertion), exceptionLabel, action)
754 * __Require_Quiet(assertion, exceptionLabel)
757 * If the assertion expression evaluates to false, goto exceptionLabel.
762 * The assertion expression.
767 #ifndef __Require_Quiet
768 #define __Require_Quiet(assertion, exceptionLabel) \
771 if ( __builtin_expect(!(assertion), 0) ) \
773 goto exceptionLabel; \
778 #ifndef __nRequire_Quiet
779 #define __nRequire_Quiet(assertion, exceptionLabel) __Require_Quiet(!(assertion), exceptionLabel)
783 * __Require_Action_Quiet(assertion, exceptionLabel, action)
786 * If the assertion expression evaluates to false, execute the action
787 * statement or compound statement (block), and goto exceptionLabel.
792 * The assertion expression.
798 * The statement or compound statement (block).
800 #ifndef __Require_Action_Quiet
801 #define __Require_Action_Quiet(assertion, exceptionLabel, action) \
804 if ( __builtin_expect(!(assertion), 0) ) \
809 goto exceptionLabel; \
814 #ifndef __nRequire_Action_Quiet
815 #define __nRequire_Action_Quiet(assertion, exceptionLabel, action) \
816 __Require_Action_Quiet(!(assertion), exceptionLabel, action)
820 * __Require_String(assertion, exceptionLabel, message)
823 * Production builds: if the assertion expression evaluates to false,
824 * goto exceptionLabel.
826 * Non-production builds: if the assertion expression evaluates to false,
827 * call DEBUG_ASSERT_MESSAGE, and then goto exceptionLabel.
832 * The assertion expression.
838 * The C string to display.
840 #ifndef __Require_String
841 #if DEBUG_ASSERT_PRODUCTION_CODE
842 #define __Require_String(assertion, exceptionLabel, message) \
845 if ( __builtin_expect(!(assertion), 0) ) \
847 goto exceptionLabel; \
851 #define __Require_String(assertion, exceptionLabel, message) \
854 if ( __builtin_expect(!(assertion), 0) ) \
856 DEBUG_ASSERT_MESSAGE( \
857 DEBUG_ASSERT_COMPONENT_NAME_STRING, \
858 #assertion, #exceptionLabel, message, __FILE__, __LINE__, 0); \
859 goto exceptionLabel; \
865 #ifndef __nRequire_String
866 #define __nRequire_String(assertion, exceptionLabel, string) \
867 __Require_String(!(assertion), exceptionLabel, string)
871 * __Require_Action_String(assertion, exceptionLabel, action, message)
874 * Production builds: if the assertion expression evaluates to false,
875 * execute the action statement or compound statement (block), and then
876 * goto exceptionLabel.
878 * Non-production builds: if the assertion expression evaluates to false,
879 * call DEBUG_ASSERT_MESSAGE, execute the action statement or compound
880 * statement (block), and then goto exceptionLabel.
885 * The assertion expression.
891 * The statement or compound statement (block).
894 * The C string to display.
896 #ifndef __Require_Action_String
897 #if DEBUG_ASSERT_PRODUCTION_CODE
898 #define __Require_Action_String(assertion, exceptionLabel, action, message) \
901 if ( __builtin_expect(!(assertion), 0) ) \
906 goto exceptionLabel; \
910 #define __Require_Action_String(assertion, exceptionLabel, action, message) \
913 if ( __builtin_expect(!(assertion), 0) ) \
915 DEBUG_ASSERT_MESSAGE( \
916 DEBUG_ASSERT_COMPONENT_NAME_STRING, \
917 #assertion, #exceptionLabel, message, __FILE__, __LINE__, 0); \
921 goto exceptionLabel; \
927 #ifndef __nRequire_Action_String
928 #define __nRequire_Action_String(assertion, exceptionLabel, action, message) \
929 __Require_Action_String(!(assertion), exceptionLabel, action, message)
933 * __Require_noErr(errorCode, exceptionLabel)
936 * Production builds: if the errorCode expression does not equal 0 (noErr),
937 * goto exceptionLabel.
939 * Non-production builds: if the errorCode expression does not equal 0 (noErr),
940 * call DEBUG_ASSERT_MESSAGE and then goto exceptionLabel.
945 * The expression to compare to 0.
950 #ifndef __Require_noErr
951 #if DEBUG_ASSERT_PRODUCTION_CODE
952 #define __Require_noErr(errorCode, exceptionLabel) \
955 if ( __builtin_expect(0 != (errorCode), 0) ) \
957 goto exceptionLabel; \
961 #define __Require_noErr(errorCode, exceptionLabel) \
964 long evalOnceErrorCode = (errorCode); \
965 if ( __builtin_expect(0 != evalOnceErrorCode, 0) ) \
967 DEBUG_ASSERT_MESSAGE( \
968 DEBUG_ASSERT_COMPONENT_NAME_STRING, \
969 #errorCode " == 0 ", #exceptionLabel, 0, __FILE__, __LINE__, evalOnceErrorCode); \
970 goto exceptionLabel; \
977 * __Require_noErr_Action(errorCode, exceptionLabel, action)
980 * Production builds: if the errorCode expression does not equal 0 (noErr),
981 * execute the action statement or compound statement (block) and
982 * goto exceptionLabel.
984 * Non-production builds: if the errorCode expression does not equal 0 (noErr),
985 * call DEBUG_ASSERT_MESSAGE, execute the action statement or
986 * compound statement (block), and then goto exceptionLabel.
991 * The expression to compare to 0.
997 * The statement or compound statement (block).
999 #ifndef __Require_noErr_Action
1000 #if DEBUG_ASSERT_PRODUCTION_CODE
1001 #define __Require_noErr_Action(errorCode, exceptionLabel, action) \
1004 if ( __builtin_expect(0 != (errorCode), 0) ) \
1009 goto exceptionLabel; \
1013 #define __Require_noErr_Action(errorCode, exceptionLabel, action) \
1016 long evalOnceErrorCode = (errorCode); \
1017 if ( __builtin_expect(0 != evalOnceErrorCode, 0) ) \
1019 DEBUG_ASSERT_MESSAGE( \
1020 DEBUG_ASSERT_COMPONENT_NAME_STRING, \
1021 #errorCode " == 0 ", #exceptionLabel, 0, __FILE__, __LINE__, evalOnceErrorCode); \
1025 goto exceptionLabel; \
1032 * __Require_noErr_Quiet(errorCode, exceptionLabel)
1035 * If the errorCode expression does not equal 0 (noErr),
1036 * goto exceptionLabel.
1041 * The expression to compare to 0.
1046 #ifndef __Require_noErr_Quiet
1047 #define __Require_noErr_Quiet(errorCode, exceptionLabel) \
1050 if ( __builtin_expect(0 != (errorCode), 0) ) \
1052 goto exceptionLabel; \
1058 * __Require_noErr_Action_Quiet(errorCode, exceptionLabel, action)
1061 * If the errorCode expression does not equal 0 (noErr),
1062 * execute the action statement or compound statement (block) and
1063 * goto exceptionLabel.
1068 * The expression to compare to 0.
1074 * The statement or compound statement (block).
1076 #ifndef __Require_noErr_Action_Quiet
1077 #define __Require_noErr_Action_Quiet(errorCode, exceptionLabel, action) \
1080 if ( __builtin_expect(0 != (errorCode), 0) ) \
1085 goto exceptionLabel; \
1091 * __Require_noErr_String(errorCode, exceptionLabel, message)
1094 * Production builds: if the errorCode expression does not equal 0 (noErr),
1095 * goto exceptionLabel.
1097 * Non-production builds: if the errorCode expression does not equal 0 (noErr),
1098 * call DEBUG_ASSERT_MESSAGE, and then goto exceptionLabel.
1103 * The expression to compare to 0.
1109 * The C string to display.
1111 #ifndef __Require_noErr_String
1112 #if DEBUG_ASSERT_PRODUCTION_CODE
1113 #define __Require_noErr_String(errorCode, exceptionLabel, message) \
1116 if ( __builtin_expect(0 != (errorCode), 0) ) \
1118 goto exceptionLabel; \
1122 #define __Require_noErr_String(errorCode, exceptionLabel, message) \
1125 long evalOnceErrorCode = (errorCode); \
1126 if ( __builtin_expect(0 != evalOnceErrorCode, 0) ) \
1128 DEBUG_ASSERT_MESSAGE( \
1129 DEBUG_ASSERT_COMPONENT_NAME_STRING, \
1130 #errorCode " == 0 ", #exceptionLabel, message, __FILE__, __LINE__, evalOnceErrorCode); \
1131 goto exceptionLabel; \
1138 * __Require_noErr_Action_String(errorCode, exceptionLabel, action, message)
1141 * Production builds: if the errorCode expression does not equal 0 (noErr),
1142 * execute the action statement or compound statement (block) and
1143 * goto exceptionLabel.
1145 * Non-production builds: if the errorCode expression does not equal 0 (noErr),
1146 * call DEBUG_ASSERT_MESSAGE, execute the action statement or compound
1147 * statement (block), and then goto exceptionLabel.
1152 * The expression to compare to 0.
1158 * The statement or compound statement (block).
1161 * The C string to display.
1163 #ifndef __Require_noErr_Action_String
1164 #if DEBUG_ASSERT_PRODUCTION_CODE
1165 #define __Require_noErr_Action_String(errorCode, exceptionLabel, action, message) \
1168 if ( __builtin_expect(0 != (errorCode), 0) ) \
1173 goto exceptionLabel; \
1177 #define __Require_noErr_Action_String(errorCode, exceptionLabel, action, message) \
1180 long evalOnceErrorCode = (errorCode); \
1181 if ( __builtin_expect(0 != evalOnceErrorCode, 0) ) \
1183 DEBUG_ASSERT_MESSAGE( \
1184 DEBUG_ASSERT_COMPONENT_NAME_STRING, \
1185 #errorCode " == 0 ", #exceptionLabel, message, __FILE__, __LINE__, evalOnceErrorCode); \
1189 goto exceptionLabel; \
1196 * __Check_Compile_Time(expr)
1199 * any build: if the expression is not true, generated a compile time error.
1204 * The compile time expression that should evaluate to non-zero.
1207 * This declares an array with a size that is determined by a compile-time expression.
1208 * If false, it declares a negatively sized array, which generates a compile-time error.
1211 * __Check_Compile_Time( sizeof( int ) == 4 );
1212 * __Check_Compile_Time( offsetof( MyStruct, myField ) == 4 );
1213 * __Check_Compile_Time( ( kMyBufferSize % 512 ) == 0 );
1215 * Note: This only works with compile-time expressions.
1216 * Note: This only works in places where extern declarations are allowed (e.g. global scope).
1218 #ifndef __Check_Compile_Time
1220 #define __Check_Compile_Time( expr ) \
1221 extern int compile_time_assert_failed[ ( expr ) ? 1 : -1 ] __attribute__( ( unused ) )
1223 #define __Check_Compile_Time( expr ) \
1224 extern int compile_time_assert_failed[ ( expr ) ? 1 : -1 ]
1229 * For time immemorial, Mac OS X has defined version of most of these macros without the __ prefix, which
1230 * could collide with similarly named functions or macros in user code, including new functionality in
1231 * Boost and the C++ standard library.
1233 * A future release of Mac OS X will no longer do this, and will require that clients move to the
1234 * new macros as defined above. However, in the interim both the new and old macros will work, unless
1235 * clients define a macro __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES before this file is included
1236 * in their compilations. Clients who do not want the older macros defined can accomplish this by adding
1237 * #define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0
1238 * at the top of their sources, or my adding -D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES=0 to the
1239 * gcc compilation options.
1241 * To aid users of these macros in converting their sources, the following tops script will convert usages
1242 * of the old macros into the new equivalents. To do so, in Terminal go into the directory containing the
1243 * sources to be converted and run this command.
1245 find . -name '*.[c|cc|cp|cpp|m|mm|h]' -print0 | xargs -0 tops -verbose \
1246 replace "check(<b args>)" with "__Check(<args>)" \
1247 replace "check_noerr(<b args>)" with "__Check_noErr(<args>)" \
1248 replace "check_noerr_string(<b args>)" with "__Check_noErr_String(<args>)" \
1249 replace "check_string(<b args>)" with "__Check_String(<args>)" \
1250 replace "require(<b args>)" with "__Require(<args>)" \
1251 replace "require_action(<b args>)" with "__Require_Action(<args>)" \
1252 replace "require_action_string(<b args>)" with "__Require_Action_String(<args>)" \
1253 replace "require_noerr(<b args>)" with "__Require_noErr(<args>)" \
1254 replace "require_noerr_action(<b args>)" with "__Require_noErr_Action(<args>)" \
1255 replace "require_noerr_action_string(<b args>)" with "__Require_noErr_Action_String(<args>)" \
1256 replace "require_noerr_string(<b args>)" with "__Require_noErr_String(<args>)" \
1257 replace "require_string(<b args>)" with "__Require_String(<args>)" \
1258 replace "verify(<b args>)" with "__Verify(<args>)" \
1259 replace "verify_action(<b args>)" with "__Verify_Action(<args>)" \
1260 replace "verify_noerr(<b args>)" with "__Verify_noErr(<args>)" \
1261 replace "verify_noerr_action(<b args>)" with "__Verify_noErr_Action(<args>)" \
1262 replace "verify_noerr_string(<b args>)" with "__Verify_noErr_String(<args>)" \
1263 replace "verify_string(<b args>)" with "__Verify_String(<args>)" \
1264 replace "ncheck(<b args>)" with "__nCheck(<args>)" \
1265 replace "ncheck_string(<b args>)" with "__nCheck_String(<args>)" \
1266 replace "nrequire(<b args>)" with "__nRequire(<args>)" \
1267 replace "nrequire_action(<b args>)" with "__nRequire_Action(<args>)" \
1268 replace "nrequire_action_quiet(<b args>)" with "__nRequire_Action_Quiet(<args>)" \
1269 replace "nrequire_action_string(<b args>)" with "__nRequire_Action_String(<args>)" \
1270 replace "nrequire_quiet(<b args>)" with "__nRequire_Quiet(<args>)" \
1271 replace "nrequire_string(<b args>)" with "__nRequire_String(<args>)" \
1272 replace "nverify(<b args>)" with "__nVerify(<args>)" \
1273 replace "nverify_string(<b args>)" with "__nVerify_String(<args>)" \
1274 replace "require_action_quiet(<b args>)" with "__Require_Action_Quiet(<args>)" \
1275 replace "require_noerr_action_quiet(<b args>)" with "__Require_noErr_Action_Quiet(<args>)" \
1276 replace "require_noerr_quiet(<b args>)" with "__Require_noErr_Quiet(<args>)" \
1277 replace "require_quiet(<b args>)" with "__Require_Quiet(<args>)" \
1278 replace "check_compile_time(<b args>)" with "__Check_Compile_Time(<args>)" \
1279 replace "debug_string(<b args>)" with "__Debug_String(<args>)"
1283 #ifndef __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES
1284 /* If we haven't set this yet, it defaults to on. In the next release, this will default to off. */
1285 #define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 1
1288 #if __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES
1291 #define check(assertion) __Check(assertion)
1295 #define check_noerr(errorCode) __Check_noErr(errorCode)
1298 #ifndef check_noerr_string
1299 #define check_noerr_string(errorCode, message) __Check_noErr_String(errorCode, message)
1302 #ifndef check_string
1303 #define check_string(assertion, message) __Check_String(assertion, message)
1307 #define require(assertion, exceptionLabel) __Require(assertion, exceptionLabel)
1310 #ifndef require_action
1311 #define require_action(assertion, exceptionLabel, action) __Require_Action(assertion, exceptionLabel, action)
1314 #ifndef require_action_string
1315 #define require_action_string(assertion, exceptionLabel, action, message) __Require_Action_String(assertion, exceptionLabel, action, message)
1318 #ifndef require_noerr
1319 #define require_noerr(errorCode, exceptionLabel) __Require_noErr(errorCode, exceptionLabel)
1322 #ifndef require_noerr_action
1323 #define require_noerr_action(errorCode, exceptionLabel, action) __Require_noErr_Action(errorCode, exceptionLabel, action)
1326 #ifndef require_noerr_action_string
1327 #define require_noerr_action_string(errorCode, exceptionLabel, action, message) __Require_noErr_Action_String(errorCode, exceptionLabel, action, message)
1330 #ifndef require_noerr_string
1331 #define require_noerr_string(errorCode, exceptionLabel, message) __Require_noErr_String(errorCode, exceptionLabel, message)
1334 #ifndef require_string
1335 #define require_string(assertion, exceptionLabel, message) __Require_String(assertion, exceptionLabel, message)
1339 #define verify(assertion) __Verify(assertion)
1342 #ifndef verify_action
1343 #define verify_action(assertion, action) __Verify_Action(assertion, action)
1346 #ifndef verify_noerr
1347 #define verify_noerr(errorCode) __Verify_noErr(errorCode)
1350 #ifndef verify_noerr_action
1351 #define verify_noerr_action(errorCode, action) __Verify_noErr_Action(errorCode, action)
1354 #ifndef verify_noerr_string
1355 #define verify_noerr_string(errorCode, message) __Verify_noErr_String(errorCode, message)
1358 #ifndef verify_string
1359 #define verify_string(assertion, message) __Verify_String(assertion, message)
1363 #define ncheck(assertion) __nCheck(assertion)
1366 #ifndef ncheck_string
1367 #define ncheck_string(assertion, message) __nCheck_String(assertion, message)
1371 #define nrequire(assertion, exceptionLabel) __nRequire(assertion, exceptionLabel)
1374 #ifndef nrequire_action
1375 #define nrequire_action(assertion, exceptionLabel, action) __nRequire_Action(assertion, exceptionLabel, action)
1378 #ifndef nrequire_action_quiet
1379 #define nrequire_action_quiet(assertion, exceptionLabel, action) __nRequire_Action_Quiet(assertion, exceptionLabel, action)
1382 #ifndef nrequire_action_string
1383 #define nrequire_action_string(assertion, exceptionLabel, action, message) __nRequire_Action_String(assertion, exceptionLabel, action, message)
1386 #ifndef nrequire_quiet
1387 #define nrequire_quiet(assertion, exceptionLabel) __nRequire_Quiet(assertion, exceptionLabel)
1390 #ifndef nrequire_string
1391 #define nrequire_string(assertion, exceptionLabel, string) __nRequire_String(assertion, exceptionLabel, string)
1395 #define nverify(assertion) __nVerify(assertion)
1398 #ifndef nverify_string
1399 #define nverify_string(assertion, message) __nVerify_String(assertion, message)
1402 #ifndef require_action_quiet
1403 #define require_action_quiet(assertion, exceptionLabel, action) __Require_Action_Quiet(assertion, exceptionLabel, action)
1406 #ifndef require_noerr_action_quiet
1407 #define require_noerr_action_quiet(errorCode, exceptionLabel, action) __Require_noErr_Action_Quiet(errorCode, exceptionLabel, action)
1410 #ifndef require_noerr_quiet
1411 #define require_noerr_quiet(errorCode, exceptionLabel) __Require_noErr_Quiet(errorCode, exceptionLabel)
1414 #ifndef require_quiet
1415 #define require_quiet(assertion, exceptionLabel) __Require_Quiet(assertion, exceptionLabel)
1418 #ifndef check_compile_time
1419 #define check_compile_time( expr ) __Check_Compile_Time( expr )
1422 #ifndef debug_string
1423 #define debug_string(message) __Debug_String(message)
1426 #endif /* ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES */
1429 #endif /* __ASSERTMACROS__ */