2008-11-16 17:36:30 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* include/assert.h
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2021-09-28 11:44:33 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2021-09-28 11:44:33 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2016-06-12 14:15:48 +02:00
|
|
|
*
|
2021-09-28 11:44:33 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2008-11-16 17:36:30 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-11-16 17:36:30 +01:00
|
|
|
#ifndef __INCLUDE_ASSERT_H
|
|
|
|
#define __INCLUDE_ASSERT_H
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-11-16 17:36:30 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2008-11-16 17:36:30 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-02-12 15:37:55 +01:00
|
|
|
#include <nuttx/compiler.h>
|
2009-12-15 00:32:23 +01:00
|
|
|
#include <stdint.h>
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-11-16 17:36:30 +01:00
|
|
|
/****************************************************************************
|
2009-12-15 00:32:23 +01:00
|
|
|
* Pre-processor Definitions
|
2008-11-16 17:36:30 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-06-12 14:15:48 +02:00
|
|
|
/* Macro Name: PANIC, ASSERT, VERIFY, et al. */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-06-12 14:15:48 +02:00
|
|
|
#undef PANIC /* Unconditional abort */
|
2013-05-02 14:28:59 +02:00
|
|
|
#undef ASSERT /* Assert if the condition is not true */
|
|
|
|
#undef VERIFY /* Assert if a function returns a negative value */
|
2016-06-12 14:15:48 +02:00
|
|
|
#undef DEBUGPANIC /* Like PANIC, but only if CONFIG_DEBUG_ASSERTIONS is defined */
|
2016-06-11 20:49:21 +02:00
|
|
|
#undef DEBUGASSERT /* Like ASSERT, but only if CONFIG_DEBUG_ASSERTIONS is defined */
|
|
|
|
#undef DEBUGVERIFY /* Like VERIFY, but only if CONFIG_DEBUG_ASSERTIONS is defined */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-02-12 15:37:55 +01:00
|
|
|
#ifdef CONFIG_HAVE_FILENAME
|
2020-06-07 08:51:54 +02:00
|
|
|
# define PANIC() _assert(__FILE__, __LINE__)
|
2007-02-18 00:21:28 +01:00
|
|
|
#else
|
2020-06-07 08:51:54 +02:00
|
|
|
# define PANIC() _assert("unknown", 0)
|
2016-06-08 17:07:24 +02:00
|
|
|
#endif
|
|
|
|
|
2016-06-12 14:15:48 +02:00
|
|
|
#define ASSERT(f) do { if (!(f)) PANIC(); } while (0)
|
|
|
|
#define VERIFY(f) do { if ((f) < 0) PANIC(); } while (0)
|
2013-06-23 22:39:56 +02:00
|
|
|
|
2016-06-12 14:15:48 +02:00
|
|
|
#ifdef CONFIG_DEBUG_ASSERTIONS
|
|
|
|
# define DEBUGPANIC() PANIC()
|
2016-06-08 17:07:24 +02:00
|
|
|
# define DEBUGASSERT(f) ASSERT(f)
|
|
|
|
# define DEBUGVERIFY(f) VERIFY(f)
|
|
|
|
#else
|
2016-06-12 14:15:48 +02:00
|
|
|
# define DEBUGPANIC()
|
2021-03-29 08:00:56 +02:00
|
|
|
# define DEBUGASSERT(f) UNUSED(f)
|
2016-06-08 17:07:24 +02:00
|
|
|
# define DEBUGVERIFY(f) ((void)(f))
|
2016-06-12 14:15:48 +02:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2016-06-08 17:59:11 +02:00
|
|
|
/* 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
|
|
|
|
* does something or does not do anything.
|
|
|
|
*/
|
|
|
|
|
2016-06-08 17:07:24 +02:00
|
|
|
#ifdef NDEBUG
|
2021-03-29 08:00:56 +02:00
|
|
|
# define assert(f) UNUSED(f)
|
2016-06-08 17:07:24 +02:00
|
|
|
#else
|
|
|
|
# define assert(f) ASSERT(f)
|
2012-08-30 22:13:50 +02:00
|
|
|
#endif
|
|
|
|
|
2016-06-21 13:03:31 +02:00
|
|
|
/* Definition required for C11 compile-time assertion checking. The
|
2016-06-20 22:26:13 +02:00
|
|
|
* static_assert macro simply expands to the _Static_assert keyword.
|
|
|
|
*/
|
|
|
|
|
2016-06-21 13:03:31 +02:00
|
|
|
#ifndef __cplusplus
|
|
|
|
# define static_assert _Static_assert
|
|
|
|
#endif
|
2016-06-20 16:29:41 +02:00
|
|
|
|
2008-11-16 17:36:30 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2008-11-16 17:36:30 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-11-16 17:36:30 +01:00
|
|
|
/****************************************************************************
|
2013-02-01 00:29:34 +01:00
|
|
|
* Public Data
|
2008-11-16 17:36:30 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
#define EXTERN extern "C"
|
2013-02-01 00:29:34 +01:00
|
|
|
extern "C"
|
|
|
|
{
|
2007-02-18 00:21:28 +01:00
|
|
|
#else
|
|
|
|
#define EXTERN extern
|
|
|
|
#endif
|
|
|
|
|
2013-02-01 00:29:34 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-06-07 08:51:54 +02:00
|
|
|
void _assert(FAR const char *filename, int linenum) noreturn_function;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
#undef EXTERN
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-11-16 17:36:30 +01:00
|
|
|
#endif /* __INCLUDE_ASSERT_H */
|