77c35e2e14700547de416270a8d37f43739d9a58
[babeltrace.git] / src / common / assert.h
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright (c) 2018-2019 EfficiOS Inc. and Linux Foundation
5 * Copyright (c) 2018-2019 Philippe Proulx <pproulx@efficios.com>
6 */
7
8 #ifndef BABELTRACE_ASSERT_INTERNAL_H
9 #define BABELTRACE_ASSERT_INTERNAL_H
10
11 #include <assert.h>
12 #include <glib.h>
13
14 #include "common/macros.h"
15
16 BT_HIDDEN
17 extern void bt_common_assert_failed(const char *file, int line,
18 const char *func, const char *assertion)
19 __attribute__((noreturn));
20
21 /*
22 * Internal assertion (to detect logic errors on which the library user
23 * has no influence). Use BT_ASSERT_PRE*() or BT_ASSERT_POST*() to check
24 * preconditions or postconditions which must be directly or indirectly
25 * satisfied by the library user.
26 *
27 * BT_ASSERT() is enabled in both debug and non-debug modes.
28 */
29 #define BT_ASSERT(_cond) \
30 do { \
31 if (!(_cond)) { \
32 bt_common_assert_failed(__FILE__, __LINE__, __func__, \
33 G_STRINGIFY(_cond)); \
34 } \
35 } while (0)
36
37 /*
38 * Marks a function as being only used within a BT_ASSERT() context.
39 */
40 #define BT_ASSERT_FUNC
41
42 #ifdef BT_DEBUG_MODE
43
44 /*
45 * Debug mode internal assertion.
46 */
47 #define BT_ASSERT_DBG(_cond) BT_ASSERT(_cond)
48
49 /*
50 * Marks a function as being only used within a BT_ASSERT_DBG() context.
51 */
52 #define BT_ASSERT_DBG_FUNC
53
54 #else /* BT_DEBUG_MODE */
55 # define BT_ASSERT_DBG(_cond) BT_USE_EXPR(_cond)
56 # define BT_ASSERT_DBG_FUNC __attribute__((unused))
57 #endif /* BT_DEBUG_MODE */
58
59 #endif /* BABELTRACE_ASSERT_INTERNAL_H */
This page took 0.029375 seconds and 3 git commands to generate.