assert: Check if NDEBUG is defined

This commit is contained in:
Paul A. Patience 2016-06-08 11:07:24 -04:00
parent 4a4f407175
commit 79a157cc9d

View File

@ -51,9 +51,10 @@
#undef ASSERT /* Assert if the condition is not true */ #undef ASSERT /* Assert if the condition is not true */
#undef VERIFY /* Assert if a function returns a negative value */ #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 DEBUGASSERT /* Like ASSERT, but only if CONFIG_DEBUG is defined */
#undef DEBUGVERIFY /* Like VERIFY, 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 #ifdef CONFIG_HAVE_FILENAME
@ -80,62 +81,32 @@
# define PANIC() \ # define PANIC() \
up_assert((const uint8_t *)__FILE__, (int)__LINE__) up_assert((const uint8_t *)__FILE__, (int)__LINE__)
# ifdef CONFIG_DEBUG #else
# define DEBUGASSERT(f) \ # define ASSERT(f) do { if (!(f)) up_assert(); } while (0)
do \ # define VERIFY(f) do { if ((f) < 0) up_assert(); } while (0)
{ \ # define PANIC() up_assert()
if (!(f)) \
{ \
up_assert((const uint8_t *)__FILE__, (int)__LINE__); \
} \
} \
while (0)
# define DEBUGVERIFY(f) \ #endif
do \
{ \
if ((f) < 0) \
{ \
up_assert((const uint8_t *)__FILE__, (int)__LINE__); \
} \
} \
while (0)
# define DEBUGPANIC() \ #ifdef CONFIG_DEBUG
up_assert((const uint8_t *)__FILE__, (int)__LINE__)
# else # define DEBUGASSERT(f) ASSERT(f)
# define DEBUGVERIFY(f) VERIFY(f)
# define DEBUGASSERT(f) # define DEBUGPANIC() PANIC()
# define DEBUGVERIFY(f) ((void)(f))
# define DEBUGPANIC()
# endif /* CONFIG_DEBUG */
#else #else
# define ASSERT(f) { if (!(f)) up_assert(); } # define DEBUGASSERT(f)
# define VERIFY(f) { if ((f) < 0) up_assert(); } # define DEBUGVERIFY(f) ((void)(f))
# define PANIC() up_assert() # define DEBUGPANIC()
# 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()
# endif /* CONFIG_DEBUG */ # endif /* CONFIG_DEBUG */
#endif
#ifndef assert #ifdef NDEBUG
# define assert ASSERT # define assert(f)
#else
# define assert(f) ASSERT(f)
#endif #endif
/**************************************************************************** /****************************************************************************