1 | /** @file
|
---|
2 | Provides a definition of the assert macro used to insert diagnostic messages
|
---|
3 | into code.
|
---|
4 |
|
---|
5 | This header file defines the assert macro and refers to the NDEBUG macro,
|
---|
6 | which is NOT defined in this file.
|
---|
7 |
|
---|
8 | Unlike other header files, assert.h is designed to be included multiple
|
---|
9 | times, with potentially different behavior on each inclusion.
|
---|
10 |
|
---|
11 | If the NDEBUG macro is defined at the point where assert.h
|
---|
12 | is included, the assert macro is defined so as to not produce code.
|
---|
13 | Otherwise, the assertion is tested and if the assertion is FALSE
|
---|
14 | (e.g. evaluates to 0) a diagnostic message of the form<BR>
|
---|
15 | "Assertion failed: (EXPR), file FILE, function FUNC, line LINE.\n"<BR>
|
---|
16 | is produced.
|
---|
17 | A FALSE evaluation will also result in the application being aborted.
|
---|
18 |
|
---|
19 | Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
|
---|
20 | This program and the accompanying materials are licensed and made available under
|
---|
21 | the terms and conditions of the BSD License that accompanies this distribution.
|
---|
22 | The full text of the license may be found at
|
---|
23 | http://opensource.org/licenses/bsd-license.
|
---|
24 |
|
---|
25 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
---|
26 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
---|
27 | **/
|
---|
28 | #include <sys/EfiCdefs.h>
|
---|
29 |
|
---|
30 | #undef assert ///< Remove any existing definition for assert.
|
---|
31 |
|
---|
32 | /** Internal helper function for the assert macro.
|
---|
33 | The __assert function prints a diagnostic message then exits the
|
---|
34 | currently running application.
|
---|
35 |
|
---|
36 | This function should NEVER be called directly.
|
---|
37 |
|
---|
38 | Some pre-processors do not provide the __func__ identifier. When that is
|
---|
39 | the case, __func__ will be NULL. This function accounts for this and
|
---|
40 | will modify the diagnostic message appropriately.
|
---|
41 |
|
---|
42 |
|
---|
43 | @param[in] file The name of the file containing the assert.
|
---|
44 | @param[in] func The name of the function containing the assert.
|
---|
45 | @param[in] line The line number the assert is located on.
|
---|
46 | @param[in] failedexpr A literal representation of the assert's expression.
|
---|
47 |
|
---|
48 | @return The __assert function will never return. It aborts the
|
---|
49 | current application and returns to the environment that
|
---|
50 | the application was launched from.
|
---|
51 | **/
|
---|
52 | extern void
|
---|
53 | __assert(const char *file, const char *func, int line, const char *failedexpr);
|
---|
54 |
|
---|
55 | /** The assert macro puts diagnostic tests into programs; it expands to a
|
---|
56 | void expression.
|
---|
57 |
|
---|
58 | When it is executed, if expression (which must have a scalar type) is
|
---|
59 | FALSE (that is, compares equal to 0), the assert macro writes information
|
---|
60 | about the particular call that failed (including the text of the argument,
|
---|
61 | the name of the source file, the source line number, and the name of the
|
---|
62 | enclosing function - the latter are respectively the values of the
|
---|
63 | preprocessing macros __FILE__ and __LINE__ and of the identifier __func__)
|
---|
64 | on the standard error stream. It then calls the abort function.
|
---|
65 |
|
---|
66 | If NDEBUG is not defined, Expression is evaluated. If Expression evaluates to FALSE,
|
---|
67 | then __assert is called passing in the source filename, source function, source
|
---|
68 | line number, and the Expression.
|
---|
69 |
|
---|
70 | @param Expression Boolean expression.
|
---|
71 |
|
---|
72 | @{
|
---|
73 | **/
|
---|
74 | #ifdef NDEBUG
|
---|
75 | #define assert(Expression) /* ignored */
|
---|
76 |
|
---|
77 | #else
|
---|
78 | #define assert(Expression) ((Expression) ? (void)0 :\
|
---|
79 | __assert(__FILE__, __func__, __LINE__, #Expression) )
|
---|
80 | #endif
|
---|
81 | /// @}
|
---|
82 | /* END of file assert.h */
|
---|