|
42 | 42 | #undef DEBUGASSERT /* Like ASSERT, but only if CONFIG_DEBUG_ASSERTIONS is defined */
|
43 | 43 | #undef DEBUGVERIFY /* Like VERIFY, but only if CONFIG_DEBUG_ASSERTIONS is defined */
|
44 | 44 |
|
45 |
| -#if !defined(CONFIG_HAVE_FILENAME) || !defined(CONFIG_DEBUG_ASSERTIONS_FILENAME) |
| 45 | +/* Macro to define the assertions file name and file line |
| 46 | + * | Function |CONFIG | Show name/line | |
| 47 | + * | --- | --- | --- | |
| 48 | + * |assert(), ASSERT()|CONFIG_ASSERTIONS_FILENAME=y | Yes | |
| 49 | + * |assert(), ASSERT()|CONFIG_ASSERTIONS_FILENAME=n | No | |
| 50 | + * |DEBUGASSERT() |CONFIG_DEBUG_ASSERTIONS_FILENAME=y| Yes | |
| 51 | + * |DEBUGASSERT() |CONFIG_DEBUG_ASSERTIONS_FILENAME=n| No | |
| 52 | + */ |
| 53 | + |
| 54 | +#ifdef CONFIG_HAVE_FILENAME |
| 55 | +# ifdef CONFIG_DEBUG_ASSERTIONS_FILENAME |
| 56 | +# define __DEBUG_ASSERT_FILE__ __FILE__ |
| 57 | +# define __DEBUG_ASSERT_LINE__ __LINE__ |
| 58 | +# endif |
| 59 | +# ifdef CONFIG_ASSERTIONS_FILENAME |
| 60 | +# define __ASSERT_FILE__ __FILE__ |
| 61 | +# define __ASSERT_LINE__ __LINE__ |
| 62 | +# endif |
| 63 | +#endif |
| 64 | + |
| 65 | +#ifndef __DEBUG_ASSERT_FILE__ |
| 66 | +# define __DEBUG_ASSERT_FILE__ 0 |
| 67 | +# define __DEBUG_ASSERT_LINE__ 0 |
| 68 | +#endif |
| 69 | + |
| 70 | +#ifndef __ASSERT_FILE__ |
46 | 71 | # define __ASSERT_FILE__ 0
|
47 | 72 | # define __ASSERT_LINE__ 0
|
48 |
| -#else |
49 |
| -# define __ASSERT_FILE__ __FILE__ |
50 |
| -# define __ASSERT_LINE__ __LINE__ |
51 | 73 | #endif
|
52 | 74 |
|
53 | 75 | #define PANIC() __assert(__ASSERT_FILE__, __ASSERT_LINE__, "panic")
|
54 | 76 | #define PANIC_WITH_REGS(msg, regs) _assert(__ASSERT_FILE__, \
|
55 | 77 | __ASSERT_LINE__, msg, regs)
|
56 | 78 |
|
57 |
| -#ifdef CONFIG_DEBUG_ASSERTIONS_EXPRESSION |
58 |
| -# define ASSERT(f) \ |
59 |
| - do \ |
60 |
| - { \ |
61 |
| - if (predict_false(!(f))) \ |
62 |
| - __assert(__ASSERT_FILE__, \ |
63 |
| - __ASSERT_LINE__, #f); \ |
64 |
| - } \ |
| 79 | +#define __ASSERT(f, file, line, _f) \ |
| 80 | + do \ |
| 81 | + { \ |
| 82 | + if (predict_false(!(f))) \ |
| 83 | + __assert(file, line, _f); \ |
| 84 | + } \ |
65 | 85 | while (0)
|
66 | 86 |
|
67 |
| -# define VERIFY(f) \ |
68 |
| - do \ |
69 |
| - { \ |
70 |
| - if (predict_false((f) < 0)) \ |
71 |
| - __assert(__ASSERT_FILE__, \ |
72 |
| - __ASSERT_LINE__, #f); \ |
73 |
| - } \ |
74 |
| - while (0) |
75 |
| -#else |
76 |
| -# define ASSERT(f) \ |
77 |
| - do \ |
78 |
| - { \ |
79 |
| - if (predict_false(!(f))) \ |
80 |
| - __assert(__ASSERT_FILE__, \ |
81 |
| - __ASSERT_LINE__, 0); \ |
82 |
| - } \ |
| 87 | +#define __VERIFY(f, file, line, _f) \ |
| 88 | + do \ |
| 89 | + { \ |
| 90 | + if (predict_false((f) < 0)) \ |
| 91 | + __assert(file, line, _f); \ |
| 92 | + } \ |
83 | 93 | while (0)
|
84 | 94 |
|
85 |
| -# define VERIFY(f) \ |
86 |
| - do \ |
87 |
| - { \ |
88 |
| - if (predict_false((f) < 0)) \ |
89 |
| - __assert(__ASSERT_FILE__, \ |
90 |
| - __ASSERT_LINE__, 0); \ |
91 |
| - } \ |
92 |
| - while (0) |
| 95 | +#ifdef CONFIG_DEBUG_ASSERTIONS_EXPRESSION |
| 96 | +# define _ASSERT(f,file,line) __ASSERT(f, file, line, #f) |
| 97 | +# define _VERIFY(f,file,line) __VERIFY(f, file, line, #f) |
| 98 | +#else |
| 99 | +# define _ASSERT(f,file,line) __ASSERT(f, file, line, NULL) |
| 100 | +# define _VERIFY(f,file,line) __VERIFY(f, file, line, NULL) |
93 | 101 | #endif
|
94 | 102 |
|
95 | 103 | #ifdef CONFIG_DEBUG_ASSERTIONS
|
96 |
| -# define DEBUGPANIC() PANIC() |
97 |
| -# define DEBUGASSERT(f) ASSERT(f) |
98 |
| -# define DEBUGVERIFY(f) VERIFY(f) |
| 104 | +# define DEBUGPANIC() __assert(__DEBUG_ASSERT_FILE__, __DEBUG_ASSERT_LINE__, "panic") |
| 105 | +# define DEBUGASSERT(f) _ASSERT(f, __DEBUG_ASSERT_FILE__, __DEBUG_ASSERT_LINE__) |
| 106 | +# define DEBUGVERIFY(f) _VERIFY(f, __DEBUG_ASSERT_FILE__, __DEBUG_ASSERT_LINE__) |
99 | 107 | #else
|
100 | 108 | # define DEBUGPANIC()
|
101 | 109 | # define DEBUGASSERT(f) ((void)(1 || (f)))
|
|
109 | 117 |
|
110 | 118 | #ifdef NDEBUG
|
111 | 119 | # define assert(f) ((void)(1 || (f)))
|
| 120 | +# define VERIFY(f) assert(f) |
112 | 121 | #else
|
113 |
| -# define assert(f) ASSERT(f) |
| 122 | +# define assert(f) _ASSERT(f, __ASSERT_FILE__, __ASSERT_LINE__) |
| 123 | +# define VERIFY(f) _VERIFY(f, __ASSERT_FILE__, __ASSERT_LINE__) |
114 | 124 | #endif
|
115 | 125 |
|
| 126 | +#define ASSERT(f) assert(f) |
| 127 | + |
116 | 128 | /* Suppress 3rd party library redefine _assert/__assert */
|
117 | 129 |
|
118 | 130 | #define _assert _assert
|
|
0 commit comments