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