]> granicus.if.org Git - icinga2/blob - lib/base/debug.hpp
Update copyright headers for 2016
[icinga2] / lib / base / debug.hpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2016 Icinga Development Team (https://www.icinga.org/)  *
4  *                                                                            *
5  * This program is free software; you can redistribute it and/or              *
6  * modify it under the terms of the GNU General Public License                *
7  * as published by the Free Software Foundation; either version 2             *
8  * of the License, or (at your option) any later version.                     *
9  *                                                                            *
10  * This program is distributed in the hope that it will be useful,            *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
13  * GNU General Public License for more details.                               *
14  *                                                                            *
15  * You should have received a copy of the GNU General Public License          *
16  * along with this program; if not, write to the Free Software Foundation     *
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
18  ******************************************************************************/
19
20 #ifndef DEBUG_H
21 #define DEBUG_H
22
23 #include "i2-base.hpp"
24
25 #ifndef I2_DEBUG
26 #       define ASSERT(expr) ((void)0)
27 #else /* I2_DEBUG */
28 #       define ASSERT(expr) ((expr) ? 0 : icinga_assert_fail(#expr, __FILE__, __LINE__))
29 #endif /* I2_DEBUG */
30
31 #define VERIFY(expr) ((expr) ? 0 : icinga_assert_fail(#expr, __FILE__, __LINE__))
32
33 #ifdef _MSC_VER
34 #       define NORETURNPRE __declspec(noreturn)
35 #else /* _MSC_VER */
36 #       define NORETURNPRE
37 #endif /* _MSC_VER */
38
39 #ifdef __GNUC__
40 #       define NORETURNPOST __attribute__((noreturn))
41 #else /* __GNUC__ */
42 #       define NORETURNPOST
43 #endif /* __GNUC__ */
44
45 NORETURNPRE int icinga_assert_fail(const char *expr, const char *file, int line) NORETURNPOST;
46
47 #ifdef _MSC_VER
48 #       pragma warning( push )
49 #       pragma warning( disable : 4646 ) /* function declared with __declspec(noreturn) has non-void return type */
50 #endif /* _MSC_VER */
51
52 inline int icinga_assert_fail(const char *expr, const char *file, int line)
53 {
54         fprintf(stderr, "%s:%d: assertion failed: %s\n", file, line, expr);
55         std::abort();
56
57 #if !defined(__GNUC__) && !defined(_MSC_VER)
58         return 0;
59 #endif /* !defined(__GNUC__) && !defined(_MSC_VER) */
60 }
61
62 #ifdef _MSC_VER
63 #       pragma warning( pop )
64 #endif /* _MSC_VER */
65
66 #endif /* DEBUG_H */