|
Packit |
6c4009 |
/* Copyright (C) 1991-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/*
|
|
Packit |
6c4009 |
* ISO C99 Standard: 7.2 Diagnostics <assert.h>
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef _ASSERT_H
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# undef _ASSERT_H
|
|
Packit |
6c4009 |
# undef assert
|
|
Packit |
6c4009 |
# undef __ASSERT_VOID_CAST
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# ifdef __USE_GNU
|
|
Packit |
6c4009 |
# undef assert_perror
|
|
Packit |
6c4009 |
# endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#endif /* assert.h */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define _ASSERT_H 1
|
|
Packit |
6c4009 |
#include <features.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#if defined __cplusplus && __GNUC_PREREQ (2,95)
|
|
Packit |
6c4009 |
# define __ASSERT_VOID_CAST static_cast<void>
|
|
Packit |
6c4009 |
#else
|
|
Packit |
6c4009 |
# define __ASSERT_VOID_CAST (void)
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* void assert (int expression);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
If NDEBUG is defined, do nothing.
|
|
Packit |
6c4009 |
If not, and EXPRESSION is zero, print an error message and abort. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef NDEBUG
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# define assert(expr) (__ASSERT_VOID_CAST (0))
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* void assert_perror (int errnum);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
If NDEBUG is defined, do nothing. If not, and ERRNUM is not zero, print an
|
|
Packit |
6c4009 |
error message with the error text for ERRNUM and abort.
|
|
Packit |
6c4009 |
(This is a GNU extension.) */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# ifdef __USE_GNU
|
|
Packit |
6c4009 |
# define assert_perror(errnum) (__ASSERT_VOID_CAST (0))
|
|
Packit |
6c4009 |
# endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#else /* Not NDEBUG. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
__BEGIN_DECLS
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* This prints an "Assertion failed" message and aborts. */
|
|
Packit |
6c4009 |
extern void __assert_fail (const char *__assertion, const char *__file,
|
|
Packit |
6c4009 |
unsigned int __line, const char *__function)
|
|
Packit |
6c4009 |
__THROW __attribute__ ((__noreturn__));
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Likewise, but prints the error text for ERRNUM. */
|
|
Packit |
6c4009 |
extern void __assert_perror_fail (int __errnum, const char *__file,
|
|
Packit |
6c4009 |
unsigned int __line, const char *__function)
|
|
Packit |
6c4009 |
__THROW __attribute__ ((__noreturn__));
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* The following is not at all used here but needed for standard
|
|
Packit |
6c4009 |
compliance. */
|
|
Packit |
6c4009 |
extern void __assert (const char *__assertion, const char *__file, int __line)
|
|
Packit |
6c4009 |
__THROW __attribute__ ((__noreturn__));
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
__END_DECLS
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* When possible, define assert so that it does not add extra
|
|
Packit |
6c4009 |
parentheses around EXPR. Otherwise, those added parentheses would
|
|
Packit |
6c4009 |
suppress warnings we'd expect to be detected by gcc's -Wparentheses. */
|
|
Packit |
6c4009 |
# if defined __cplusplus
|
|
Packit |
6c4009 |
# define assert(expr) \
|
|
Packit |
6c4009 |
(static_cast <bool> (expr) \
|
|
Packit |
6c4009 |
? void (0) \
|
|
Packit |
6c4009 |
: __assert_fail (#expr, __FILE__, __LINE__, __ASSERT_FUNCTION))
|
|
Packit |
6c4009 |
# elif !defined __GNUC__ || defined __STRICT_ANSI__
|
|
Packit |
6c4009 |
# define assert(expr) \
|
|
Packit |
6c4009 |
((expr) \
|
|
Packit |
6c4009 |
? __ASSERT_VOID_CAST (0) \
|
|
Packit |
6c4009 |
: __assert_fail (#expr, __FILE__, __LINE__, __ASSERT_FUNCTION))
|
|
Packit |
6c4009 |
# else
|
|
Packit |
6c4009 |
/* The first occurrence of EXPR is not evaluated due to the sizeof,
|
|
Packit |
6c4009 |
but will trigger any pedantic warnings masked by the __extension__
|
|
Packit |
6c4009 |
for the second occurrence. The ternary operator is required to
|
|
Packit |
6c4009 |
support function pointers and bit fields in this context, and to
|
|
Packit |
6c4009 |
suppress the evaluation of variable length arrays. */
|
|
Packit |
6c4009 |
# define assert(expr) \
|
|
Packit |
6c4009 |
((void) sizeof ((expr) ? 1 : 0), __extension__ ({ \
|
|
Packit |
6c4009 |
if (expr) \
|
|
Packit |
6c4009 |
; /* empty */ \
|
|
Packit |
6c4009 |
else \
|
|
Packit |
6c4009 |
__assert_fail (#expr, __FILE__, __LINE__, __ASSERT_FUNCTION); \
|
|
Packit |
6c4009 |
}))
|
|
Packit |
6c4009 |
# endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# ifdef __USE_GNU
|
|
Packit |
6c4009 |
# define assert_perror(errnum) \
|
|
Packit |
6c4009 |
(!(errnum) \
|
|
Packit |
6c4009 |
? __ASSERT_VOID_CAST (0) \
|
|
Packit |
6c4009 |
: __assert_perror_fail ((errnum), __FILE__, __LINE__, __ASSERT_FUNCTION))
|
|
Packit |
6c4009 |
# endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Version 2.4 and later of GCC define a magical variable `__PRETTY_FUNCTION__'
|
|
Packit |
6c4009 |
which contains the name of the function currently being defined.
|
|
Packit |
6c4009 |
This is broken in G++ before version 2.6.
|
|
Packit |
6c4009 |
C9x has a similar variable called __func__, but prefer the GCC one since
|
|
Packit |
6c4009 |
it demangles C++ function names. */
|
|
Packit |
6c4009 |
# if defined __cplusplus ? __GNUC_PREREQ (2, 6) : __GNUC_PREREQ (2, 4)
|
|
Packit |
6c4009 |
# define __ASSERT_FUNCTION __extension__ __PRETTY_FUNCTION__
|
|
Packit |
6c4009 |
# else
|
|
Packit |
6c4009 |
# if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
|
|
Packit |
6c4009 |
# define __ASSERT_FUNCTION __func__
|
|
Packit |
6c4009 |
# else
|
|
Packit |
6c4009 |
# define __ASSERT_FUNCTION ((const char *) 0)
|
|
Packit |
6c4009 |
# endif
|
|
Packit |
6c4009 |
# endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#endif /* NDEBUG. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#if defined __USE_ISOC11 && !defined __cplusplus
|
|
Packit |
6c4009 |
# undef static_assert
|
|
Packit |
6c4009 |
# define static_assert _Static_assert
|
|
Packit |
6c4009 |
#endif
|