assert: Simplify
This commit is contained in:
parent
e18e2b351b
commit
f995f3c7bf
@ -4,6 +4,9 @@
|
|||||||
* Copyright (C) 2007-2009, 2011-2013, 2015-2016 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2009, 2011-2013, 2015-2016 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
|
* Copyright (C) 2016 Omni Hoverboards Inc. All rights reserved.
|
||||||
|
* Author: Paul Alexander Patience <paul-a.patience@polymtl.ca>
|
||||||
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
* are met:
|
* are met:
|
||||||
@ -47,61 +50,33 @@
|
|||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* Macro Name: ASSERT, VERIFY, et al. */
|
/* Macro Name: PANIC, ASSERT, VERIFY, et al. */
|
||||||
|
|
||||||
|
#undef PANIC /* Unconditional abort */
|
||||||
#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 DEBUGPANIC /* Like PANIC, but only if CONFIG_DEBUG_ASSERTIONS is defined */
|
||||||
#undef DEBUGASSERT /* Like ASSERT, but only if CONFIG_DEBUG_ASSERTIONS is defined */
|
#undef DEBUGASSERT /* Like ASSERT, but only if CONFIG_DEBUG_ASSERTIONS is defined */
|
||||||
#undef DEBUGVERIFY /* Like VERIFY, but only if CONFIG_DEBUG_ASSERTIONS is defined */
|
#undef DEBUGVERIFY /* Like VERIFY, but only if CONFIG_DEBUG_ASSERTIONS is defined */
|
||||||
#undef DEBUGPANIC /* Like PANIC, but only if CONFIG_DEBUG_ASSERTIONS is defined */
|
|
||||||
|
|
||||||
#ifdef CONFIG_HAVE_FILENAME
|
#ifdef CONFIG_HAVE_FILENAME
|
||||||
|
# define PANIC() up_assert((const uint8_t *)__FILE__, (int)__LINE__)
|
||||||
# define ASSERT(f) \
|
|
||||||
do \
|
|
||||||
{ \
|
|
||||||
if (!(f)) \
|
|
||||||
{ \
|
|
||||||
up_assert((const uint8_t *)__FILE__, (int)__LINE__); \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
while (0)
|
|
||||||
|
|
||||||
# define VERIFY(f) \
|
|
||||||
do \
|
|
||||||
{ \
|
|
||||||
if ((f) < 0) \
|
|
||||||
{ \
|
|
||||||
up_assert((const uint8_t *)__FILE__, (int)__LINE__); \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
while (0)
|
|
||||||
|
|
||||||
# define PANIC() \
|
|
||||||
up_assert((const uint8_t *)__FILE__, (int)__LINE__)
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
# define PANIC() up_assert()
|
||||||
# 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()
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_DEBUG_ASSERTIONS
|
#define ASSERT(f) do { if (!(f)) PANIC(); } while (0)
|
||||||
|
#define VERIFY(f) do { if ((f) < 0) PANIC(); } while (0)
|
||||||
|
|
||||||
|
#ifdef CONFIG_DEBUG_ASSERTIONS
|
||||||
|
# define DEBUGPANIC() PANIC()
|
||||||
# define DEBUGASSERT(f) ASSERT(f)
|
# define DEBUGASSERT(f) ASSERT(f)
|
||||||
# define DEBUGVERIFY(f) VERIFY(f)
|
# define DEBUGVERIFY(f) VERIFY(f)
|
||||||
# define DEBUGPANIC() PANIC()
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
# define DEBUGPANIC()
|
||||||
# define DEBUGASSERT(f)
|
# define DEBUGASSERT(f)
|
||||||
# define DEBUGVERIFY(f) ((void)(f))
|
# define DEBUGVERIFY(f) ((void)(f))
|
||||||
# define DEBUGPANIC()
|
#endif
|
||||||
|
|
||||||
# endif /* CONFIG_DEBUG_ASSERTIONS */
|
|
||||||
|
|
||||||
/* The C standard states that if NDEBUG is defined, assert will do nothing.
|
/* The C standard states that if NDEBUG is defined, assert will do nothing.
|
||||||
* Users can define and undefine NDEBUG as they see fit to choose when assert
|
* Users can define and undefine NDEBUG as they see fit to choose when assert
|
||||||
|
Loading…
Reference in New Issue
Block a user