2011-04-27 23:42:16 +02:00
|
|
|
/** @file
|
2011-08-04 20:13:02 +02:00
|
|
|
Provides a definition of the assert macro used to insert diagnostic messages
|
|
|
|
into code.
|
2011-04-27 23:42:16 +02:00
|
|
|
|
|
|
|
This header file defines the assert macro and refers to the NDEBUG macro,
|
|
|
|
which is NOT defined in this file.
|
|
|
|
|
|
|
|
Unlike other header files, assert.h is designed to be included multiple
|
|
|
|
times, with potentially different behavior on each inclusion.
|
|
|
|
|
|
|
|
If the NDEBUG macro is defined at the point where assert.h
|
|
|
|
is included, the assert macro is defined so as to not produce code.
|
2011-08-04 20:13:02 +02:00
|
|
|
Otherwise, the assertion is tested and if the assertion is FALSE
|
|
|
|
(e.g. evaluates to 0) a diagnostic message of the form<BR>
|
|
|
|
"Assertion failed: (EXPR), file FILE, function FUNC, line LINE.\n"<BR>
|
|
|
|
is produced.
|
|
|
|
A FALSE evaluation will also result in the application being aborted.
|
2011-04-27 23:42:16 +02:00
|
|
|
|
2011-08-04 20:13:02 +02:00
|
|
|
Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
|
|
|
|
This program and the accompanying materials are licensed and made available under
|
|
|
|
the terms and conditions of the BSD License that accompanies this distribution.
|
|
|
|
The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
2011-04-27 23:42:16 +02:00
|
|
|
**/
|
|
|
|
#include <sys/EfiCdefs.h>
|
|
|
|
|
|
|
|
#undef assert ///< Remove any existing definition for assert.
|
|
|
|
|
2011-08-04 20:13:02 +02:00
|
|
|
/** Internal helper function for the assert macro.
|
|
|
|
The __assert function prints a diagnostic message then exits the
|
|
|
|
currently running application.
|
|
|
|
|
|
|
|
This function should NEVER be called directly.
|
|
|
|
|
|
|
|
Some pre-processors do not provide the __func__ identifier. When that is
|
|
|
|
the case, __func__ will be NULL. This function accounts for this and
|
|
|
|
will modify the diagnostic message appropriately.
|
|
|
|
|
|
|
|
|
|
|
|
@param[in] file The name of the file containing the assert.
|
|
|
|
@param[in] func The name of the function containing the assert.
|
|
|
|
@param[in] line The line number the assert is located on.
|
|
|
|
@param[in] failedexpr A literal representation of the assert's expression.
|
|
|
|
|
|
|
|
@return The __assert function will never return. It aborts the
|
|
|
|
current application and returns to the environment that
|
|
|
|
the application was launched from.
|
|
|
|
**/
|
2011-04-27 23:42:16 +02:00
|
|
|
extern void
|
2011-08-04 20:13:02 +02:00
|
|
|
__assert(const char *file, const char *func, int line, const char *failedexpr);
|
2011-04-27 23:42:16 +02:00
|
|
|
|
|
|
|
/** The assert macro puts diagnostic tests into programs; it expands to a
|
|
|
|
void expression.
|
|
|
|
|
2011-08-04 20:13:02 +02:00
|
|
|
When it is executed, if expression (which must have a scalar type) is
|
|
|
|
FALSE (that is, compares equal to 0), the assert macro writes information
|
2011-04-27 23:42:16 +02:00
|
|
|
about the particular call that failed (including the text of the argument,
|
|
|
|
the name of the source file, the source line number, and the name of the
|
|
|
|
enclosing function - the latter are respectively the values of the
|
|
|
|
preprocessing macros __FILE__ and __LINE__ and of the identifier __func__)
|
|
|
|
on the standard error stream. It then calls the abort function.
|
|
|
|
|
2011-08-04 20:13:02 +02:00
|
|
|
If NDEBUG is not defined, Expression is evaluated. If Expression evaluates to FALSE,
|
|
|
|
then __assert is called passing in the source filename, source function, source
|
|
|
|
line number, and the Expression.
|
2011-04-27 23:42:16 +02:00
|
|
|
|
|
|
|
@param Expression Boolean expression.
|
|
|
|
|
|
|
|
@{
|
|
|
|
**/
|
|
|
|
#ifdef NDEBUG
|
|
|
|
#define assert(Expression) /* ignored */
|
|
|
|
|
|
|
|
#else
|
|
|
|
#define assert(Expression) ((Expression) ? (void)0 :\
|
2011-08-04 20:13:02 +02:00
|
|
|
__assert(__FILE__, __func__, __LINE__, #Expression) )
|
2011-04-27 23:42:16 +02:00
|
|
|
#endif
|
|
|
|
/// @}
|
|
|
|
/* END of file assert.h */
|