Work around changes in newer versions of glibc
[model-checker.git] / common.h
1 /** @file common.h
2  *  @brief General purpose macros.
3  */
4
5 #ifndef __COMMON_H__
6 #define __COMMON_H__
7
8 #include <stdio.h>
9 #include "config.h"
10
11 extern int model_out;
12 extern int switch_alloc;
13
14 #define model_print(fmt, ...) do { switch_alloc = 1; dprintf(model_out, fmt, ##__VA_ARGS__); switch_alloc = 0; } while (0)
15
16 #ifdef CONFIG_DEBUG
17 #define DEBUG(fmt, ...) do { model_print("*** %15s:%-4d %25s() *** " fmt, __FILE__, __LINE__, __func__, ##__VA_ARGS__); } while (0)
18 #define DBG() DEBUG("\n")
19 #define DBG_ENABLED() (1)
20 #else
21 #define DEBUG(fmt, ...)
22 #define DBG()
23 #define DBG_ENABLED() (0)
24 #endif
25
26 void assert_hook(void);
27
28 #ifdef CONFIG_ASSERT
29 #define ASSERT(expr) \
30 do { \
31         if (!(expr)) { \
32                 fprintf(stderr, "Error: assertion failed in %s at line %d\n", __FILE__, __LINE__); \
33                 /* print_trace(); // Trace printing may cause dynamic memory allocation */ \
34                 assert_hook();                           \
35                 exit(EXIT_FAILURE); \
36         } \
37 } while (0)
38 #else
39 #define ASSERT(expr) \
40         do { } while (0)
41 #endif /* CONFIG_ASSERT */
42
43 #define error_msg(...) fprintf(stderr, "Error: " __VA_ARGS__)
44
45 void print_trace(void);
46 #endif /* __COMMON_H__ */