From 79a157cc9d42f56cdd1c1670fdb67f4e1c028d3c Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Wed, 8 Jun 2016 11:07:24 -0400 Subject: [PATCH] assert: Check if NDEBUG is defined --- include/assert.h | 65 ++++++++++++++---------------------------------- 1 file changed, 18 insertions(+), 47 deletions(-) diff --git a/include/assert.h b/include/assert.h index bb6948ab53..2302a7b8eb 100644 --- a/include/assert.h +++ b/include/assert.h @@ -51,9 +51,10 @@ #undef ASSERT /* Assert if the condition is not true */ #undef VERIFY /* Assert if a function returns a negative value */ +#undef PANIC /* Unconditional abort */ #undef DEBUGASSERT /* Like ASSERT, but only if CONFIG_DEBUG is defined */ #undef DEBUGVERIFY /* Like VERIFY, but only if CONFIG_DEBUG is defined */ -#undef PANIC /* Unconditional abort */ +#undef DEBUGPANIC /* Like PANIC, but only if CONFIG_DEBUG is defined */ #ifdef CONFIG_HAVE_FILENAME @@ -80,62 +81,32 @@ # define PANIC() \ up_assert((const uint8_t *)__FILE__, (int)__LINE__) -# ifdef CONFIG_DEBUG +#else -# define DEBUGASSERT(f) \ - do \ - { \ - if (!(f)) \ - { \ - up_assert((const uint8_t *)__FILE__, (int)__LINE__); \ - } \ - } \ - while (0) +# define ASSERT(f) do { if (!(f)) up_assert(); } while (0) +# define VERIFY(f) do { if ((f) < 0) up_assert(); } while (0) +# define PANIC() up_assert() -# define DEBUGVERIFY(f) \ - do \ - { \ - if ((f) < 0) \ - { \ - up_assert((const uint8_t *)__FILE__, (int)__LINE__); \ - } \ - } \ - while (0) +#endif -# define DEBUGPANIC() \ - up_assert((const uint8_t *)__FILE__, (int)__LINE__) +#ifdef CONFIG_DEBUG -# else - -# define DEBUGASSERT(f) -# define DEBUGVERIFY(f) ((void)(f)) -# define DEBUGPANIC() - -# endif /* CONFIG_DEBUG */ +# define DEBUGASSERT(f) ASSERT(f) +# define DEBUGVERIFY(f) VERIFY(f) +# define DEBUGPANIC() PANIC() #else -# define ASSERT(f) { if (!(f)) up_assert(); } -# define VERIFY(f) { if ((f) < 0) up_assert(); } -# define PANIC() up_assert() - -# ifdef CONFIG_DEBUG - -# define DEBUGASSERT(f) { if (!(f)) up_assert(); } -# define DEBUGVERIFY(f) { if ((f) < 0) up_assert(); } -# define DEBUGPANIC() up_assert() - -# else - -# define DEBUGASSERT(f) -# define DEBUGVERIFY(f) ((void)(f)) -# define DEBUGPANIC() +# define DEBUGASSERT(f) +# define DEBUGVERIFY(f) ((void)(f)) +# define DEBUGPANIC() # endif /* CONFIG_DEBUG */ -#endif -#ifndef assert -# define assert ASSERT +#ifdef NDEBUG +# define assert(f) +#else +# define assert(f) ASSERT(f) #endif /****************************************************************************