forked from apache/nuttx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassert.h
148 lines (121 loc) · 5.05 KB
/
assert.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/****************************************************************************
* include/assert.h
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*
****************************************************************************/
#ifndef __INCLUDE_ASSERT_H
#define __INCLUDE_ASSERT_H
#ifndef __ASSEMBLY__
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/compiler.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Macro Name: PANIC, ASSERT, VERIFY, et al. */
#undef PANIC /* Unconditional abort */
#undef ASSERT /* Assert if the condition is not true */
#undef VERIFY /* Assert if a function returns a negative value */
#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 DEBUGVERIFY /* Like VERIFY, but only if CONFIG_DEBUG_ASSERTIONS is defined */
#ifndef CONFIG_HAVE_FILENAME
# define __FILE__ NULL
# define __LINE__ 0
#endif
#define PANIC() __assert(__FILE__, __LINE__, "panic")
#ifdef CONFIG_DEBUG_ASSERTIONS_EXPRESSION
#define ASSERT(f) do { if (unlikely(!(f))) __assert(__FILE__, __LINE__, #f); } while (0)
#define VERIFY(f) do { if (unlikely((f) < 0)) __assert(__FILE__, __LINE__, #f); } while (0)
#else
#define ASSERT(f) do { if (unlikely(!(f))) __assert(__FILE__, __LINE__, NULL); } while (0)
#define VERIFY(f) do { if (unlikely((f) < 0)) __assert(__FILE__, __LINE__, NULL); } while (0)
#endif
#ifdef CONFIG_DEBUG_ASSERTIONS
# define DEBUGPANIC() PANIC()
# define DEBUGASSERT(f) ASSERT(f)
# define DEBUGVERIFY(f) VERIFY(f)
#else
# define DEBUGPANIC()
# define DEBUGASSERT(f) ((void)(1 || (f)))
# define DEBUGVERIFY(f) ((void)(f))
#endif
/* 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.
*/
#ifdef NDEBUG
# define assert(f) ((void)(1 || (f)))
#else
# define assert(f) ASSERT(f)
#endif
/* Suppress 3rd party library redefine _assert/__assert */
#define _assert _assert
#define __assert __assert
/* Definition required for C11 compile-time assertion checking. The
* static_assert macro simply expands to the _Static_assert keyword.
*/
#ifndef __cplusplus
# if defined(__STDC_VERSION__) && __STDC_VERSION__ > 199901L
# define static_assert _Static_assert
# else
# define static_assert(cond, msg) \
extern int (*__static_assert_function (void)) \
[!!sizeof (struct { int __error_if_negative: (cond) ? 2 : -1; })]
# endif
#endif
/****************************************************************************
* Included Files
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: _assert
*
* Description:
* This is the assert system call that performs the core dump etc. Function
* might not return if it is not safe to do so (in IRQ or in IDLE task).
*
****************************************************************************/
void _assert(FAR const char *filename, int linenum, FAR const char *msg);
/****************************************************************************
* Name: __assert
*
* Description:
* This is the user space assert procedure.
*
****************************************************************************/
void __assert(FAR const char *filename, int linenum,
FAR const char *msg) noreturn_function;
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* __INCLUDE_ASSERT_H */