hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
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
/* SPDX-License-Identifier: BSD-2-Clause */
/*
 * Copyright (c) 2014, STMicroelectronics International N.V.
 */
#ifndef ASSERT_H
#define ASSERT_H
 
#include <compiler.h>
#include <trace.h>
 
void __noreturn _assert_break(void);
void _assert_log(const char *expr, const char *file, const int line,
           const char *func);
 
/* assert() specs: generates a log but does not panic if NDEBUG is defined */
#ifdef NDEBUG
#define assert(expr)    do { } while (0)
#define __assert_func(f, l, n1, n2) do { } while (0)
#else
#define assert(expr) \
   do { \
       if (!(expr)) { \
           _assert_log(#expr, __FILE__, __LINE__, __func__); \
           _assert_break(); \
       } \
   } while (0)
 
#define __assert_func(f, l, n1, n2) \
   do { \
       _assert_log(n2, __FILE__, __LINE__, __func__); \
       _assert_break(); \
   } while (0);
#endif
 
#define COMPILE_TIME_ASSERT(x) \
   do { \
       switch (0) { case 0: case ((x) ? 1: 0): default : break; } \
   } while (0)
 
/* Unconditional assert */
#define ASSERT(expr) assert(expr)
 
#endif