From f39f69d390efad3df9674a6ad28dab45cabb15c2 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 28 Aug 2013 08:18:58 +0200 Subject: [PATCH] Refactor ASSERT macro. --- components/livestatus/query.cpp | 2 +- lib/base/Makefile.am | 1 + lib/base/application.cpp | 1 + lib/base/array.cpp | 2 +- lib/base/debug.h | 40 ++++++++++++++++++++++++++++++++ lib/base/dictionary.cpp | 2 +- lib/base/dynamicobject.cpp | 2 +- lib/base/dynamictype.cpp | 2 +- lib/base/dynamictype.h | 2 +- lib/base/netstring.cpp | 2 +- lib/base/objectlock.cpp | 2 +- lib/base/script.cpp | 4 ++-- lib/base/threadpool.cpp | 1 + lib/base/timer.cpp | 1 + lib/base/tlsstream.cpp | 1 + lib/base/utility.h | 7 ------ lib/config/configitem.cpp | 2 +- lib/config/expression.cpp | 2 +- lib/icinga/compatutility.cpp | 2 +- lib/icinga/host.cpp | 2 +- lib/icinga/icingaapplication.cpp | 2 ++ lib/icinga/legacytimeperiod.cpp | 2 +- lib/ido/dbtype.cpp | 2 +- 23 files changed, 63 insertions(+), 23 deletions(-) create mode 100644 lib/base/debug.h diff --git a/components/livestatus/query.cpp b/components/livestatus/query.cpp index a1043891e..d250b5618 100644 --- a/components/livestatus/query.cpp +++ b/components/livestatus/query.cpp @@ -31,7 +31,7 @@ #include "livestatus/orfilter.h" #include "livestatus/andfilter.h" #include "icinga/externalcommandprocessor.h" -#include "base/utility.h" +#include "base/debug.h" #include "base/convert.h" #include "base/objectlock.h" #include "base/logger_fwd.h" diff --git a/lib/base/Makefile.am b/lib/base/Makefile.am index 38806031e..e5faae376 100644 --- a/lib/base/Makefile.am +++ b/lib/base/Makefile.am @@ -15,6 +15,7 @@ libbase_la_SOURCES = \ consolelogger.h \ convert.cpp \ convert.h \ + debug.h \ dictionary.cpp \ dictionary.h \ dynamicobject.cpp \ diff --git a/lib/base/application.cpp b/lib/base/application.cpp index e822895ae..0b46d6b58 100644 --- a/lib/base/application.cpp +++ b/lib/base/application.cpp @@ -24,6 +24,7 @@ #include "base/exception.h" #include "base/objectlock.h" #include "base/utility.h" +#include "base/debug.h" #include #include #include diff --git a/lib/base/array.cpp b/lib/base/array.cpp index 043f89ba1..474622518 100644 --- a/lib/base/array.cpp +++ b/lib/base/array.cpp @@ -19,7 +19,7 @@ #include "base/array.h" #include "base/objectlock.h" -#include "base/utility.h" +#include "base/debug.h" #include #include #include diff --git a/lib/base/debug.h b/lib/base/debug.h new file mode 100644 index 000000000..88d1d87dc --- /dev/null +++ b/lib/base/debug.h @@ -0,0 +1,40 @@ +/****************************************************************************** + * Icinga 2 * + * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software Foundation * + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * + ******************************************************************************/ + +#ifndef DEBUG_H +#define DEBUG_H + +#include +#include + +#ifdef NDEBUG +# define ASSERT(expr) ((void)0) +#else /* NDEBUG */ +# define ASSERT(expr) define ASSERT(expr) ((expr) ? 0 : icinga_assert_fail(#expr, __FILE__, __LINE__)) +#endif /* NDEBUG */ + +#define VERIFY(expr) ((expr) ? 0 : icinga_assert_fail(#expr, __FILE__, __LINE__)) + +inline void icinga_assert_fail(const char *expr, const char *file, int line) +{ + fprintf(stderr, "%s:%d: assertion failed: %s\n", file, line, expr); + abort(); +} + +#endif /* DEBUG_H */ diff --git a/lib/base/dictionary.cpp b/lib/base/dictionary.cpp index 1c8773d2d..1c31693a9 100644 --- a/lib/base/dictionary.cpp +++ b/lib/base/dictionary.cpp @@ -19,7 +19,7 @@ #include "base/dictionary.h" #include "base/objectlock.h" -#include "base/utility.h" +#include "base/debug.h" #include #include #include diff --git a/lib/base/dynamicobject.cpp b/lib/base/dynamicobject.cpp index 485cb2fe7..87aa47604 100644 --- a/lib/base/dynamicobject.cpp +++ b/lib/base/dynamicobject.cpp @@ -22,7 +22,7 @@ #include "base/netstring.h" #include "base/registry.h" #include "base/stdiostream.h" -#include "base/utility.h" +#include "base/debug.h" #include "base/objectlock.h" #include "base/logger_fwd.h" #include "base/exception.h" diff --git a/lib/base/dynamictype.cpp b/lib/base/dynamictype.cpp index 4f25a1961..8a607ef42 100644 --- a/lib/base/dynamictype.cpp +++ b/lib/base/dynamictype.cpp @@ -18,7 +18,7 @@ ******************************************************************************/ #include "base/dynamictype.h" -#include "base/utility.h" +#include "base/debug.h" #include "base/objectlock.h" using namespace icinga; diff --git a/lib/base/dynamictype.h b/lib/base/dynamictype.h index 9e574d444..ddc038d72 100644 --- a/lib/base/dynamictype.h +++ b/lib/base/dynamictype.h @@ -23,7 +23,7 @@ #include "base/i2-base.h" #include "base/registry.h" #include "base/dynamicobject.h" -#include "base/utility.h" +#include "base/debug.h" #include #include #include diff --git a/lib/base/netstring.cpp b/lib/base/netstring.cpp index ba6eab5f9..0be349e7b 100644 --- a/lib/base/netstring.cpp +++ b/lib/base/netstring.cpp @@ -18,7 +18,7 @@ ******************************************************************************/ #include "base/netstring.h" -#include "base/utility.h" +#include "base/debug.h" #include using namespace icinga; diff --git a/lib/base/objectlock.cpp b/lib/base/objectlock.cpp index 727585644..ea4c6a785 100644 --- a/lib/base/objectlock.cpp +++ b/lib/base/objectlock.cpp @@ -18,7 +18,7 @@ ******************************************************************************/ #include "base/objectlock.h" -#include "base/utility.h" +#include "base/debug.h" using namespace icinga; diff --git a/lib/base/script.cpp b/lib/base/script.cpp index 1cf5d0fba..9f82c555e 100644 --- a/lib/base/script.cpp +++ b/lib/base/script.cpp @@ -22,7 +22,7 @@ #include "base/dynamictype.h" #include "base/logger_fwd.h" #include "base/objectlock.h" -#include "base/utility.h" +#include "base/debug.h" using namespace icinga; @@ -74,4 +74,4 @@ void Script::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes) m_Language = bag->Get("language"); m_Code = bag->Get("code"); -} \ No newline at end of file +} diff --git a/lib/base/threadpool.cpp b/lib/base/threadpool.cpp index 4ef83f9ea..6adfc8242 100644 --- a/lib/base/threadpool.cpp +++ b/lib/base/threadpool.cpp @@ -20,6 +20,7 @@ #include "base/threadpool.h" #include "base/logger_fwd.h" #include "base/convert.h" +#include "base/debug.h" #include "base/utility.h" #include #include diff --git a/lib/base/timer.cpp b/lib/base/timer.cpp index 4f644a030..e72b03d9c 100644 --- a/lib/base/timer.cpp +++ b/lib/base/timer.cpp @@ -19,6 +19,7 @@ #include "base/timer.h" #include "base/application.h" +#include "base/debug.h" #include "base/utility.h" #include "base/logger_fwd.h" #include diff --git a/lib/base/tlsstream.cpp b/lib/base/tlsstream.cpp index ea20871df..3db044d7e 100644 --- a/lib/base/tlsstream.cpp +++ b/lib/base/tlsstream.cpp @@ -20,6 +20,7 @@ #include "base/tlsstream.h" #include "base/stream_bio.h" #include "base/objectlock.h" +#include "base/debug.h" #include "base/utility.h" #include "base/exception.h" #include diff --git a/lib/base/utility.h b/lib/base/utility.h index b3f7d8e0b..128f8ea2e 100644 --- a/lib/base/utility.h +++ b/lib/base/utility.h @@ -89,11 +89,4 @@ private: } -#ifdef _DEBUG -# include -# define ASSERT(expr) assert(expr) -#else /* _DEBUG */ -# define ASSERT(expr) __builtin_unreachable() -#endif /* _DEBUG */ - #endif /* UTILITY_H */ diff --git a/lib/config/configitem.cpp b/lib/config/configitem.cpp index 4f5381a4f..052e7b855 100644 --- a/lib/config/configitem.cpp +++ b/lib/config/configitem.cpp @@ -22,7 +22,7 @@ #include "base/dynamictype.h" #include "base/objectlock.h" #include "base/logger_fwd.h" -#include "base/utility.h" +#include "base/debug.h" #include #include #include diff --git a/lib/config/expression.cpp b/lib/config/expression.cpp index e29397474..1e42fbcd2 100644 --- a/lib/config/expression.cpp +++ b/lib/config/expression.cpp @@ -20,7 +20,7 @@ #include "config/expression.h" #include "config/expressionlist.h" #include "base/objectlock.h" -#include "base/utility.h" +#include "base/debug.h" #include "base/array.h" #include #include diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index e158f6067..728a52009 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -23,7 +23,7 @@ #include "icinga/eventcommand.h" #include "base/dynamictype.h" #include "base/objectlock.h" -#include "base/utility.h" +#include "base/debug.h" #include #include #include diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index f59e4e1b4..e5bd63295 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -27,7 +27,7 @@ #include "base/timer.h" #include "base/convert.h" #include "base/scriptfunction.h" -#include "base/utility.h" +#include "base/debug.h" #include "config/configitembuilder.h" #include "config/configcompilercontext.h" #include diff --git a/lib/icinga/icingaapplication.cpp b/lib/icinga/icingaapplication.cpp index 6166d574a..fe0df2178 100644 --- a/lib/icinga/icingaapplication.cpp +++ b/lib/icinga/icingaapplication.cpp @@ -22,6 +22,8 @@ #include "base/logger_fwd.h" #include "base/objectlock.h" #include "base/convert.h" +#include "base/debug.h" +#include "base/utility.h" #include "base/timer.h" #include diff --git a/lib/icinga/legacytimeperiod.cpp b/lib/icinga/legacytimeperiod.cpp index 6237023d2..b24f961ef 100644 --- a/lib/icinga/legacytimeperiod.cpp +++ b/lib/icinga/legacytimeperiod.cpp @@ -23,7 +23,7 @@ #include "base/exception.h" #include "base/objectlock.h" #include "base/logger_fwd.h" -#include "base/utility.h" +#include "base/debug.h" #include #include #include diff --git a/lib/ido/dbtype.cpp b/lib/ido/dbtype.cpp index 835b048dd..3fec66868 100644 --- a/lib/ido/dbtype.cpp +++ b/lib/ido/dbtype.cpp @@ -20,7 +20,7 @@ #include "ido/dbtype.h" #include "ido/dbconnection.h" #include "base/objectlock.h" -#include "base/utility.h" +#include "base/debug.h" #include #include #include