2 * SPDX-License-Identifier: MIT
4 * Copyright 2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 #ifndef _BABELTRACE_INTERNAL_H
8 #define _BABELTRACE_INTERNAL_H
15 #define BT_EXTERN_C extern "C"
20 #define bt_max_t(type, a, b) \
21 ((type) (a) > (type) (b) ? (type) (a) : (type) (b))
24 * BT_EXPORT: set the visibility for exported functions.
26 #if defined(_WIN32) || defined(__CYGWIN__)
29 #define BT_EXPORT __attribute__((visibility("default")))
32 /* Enable `txt` if developer mode is enabled. */
34 #define BT_IF_DEV_MODE(txt) txt
36 #define BT_IF_DEV_MODE(txt)
40 * Yield `ref`'s value while setting `ref` to NULL.
42 * This can be used to give a strong reference to a callee:
44 * add_foo_to_list(list, BT_MOVE_REF(foo));
46 * or in a simple assignment:
48 * my_struct->foo = BT_MOVE_REF(foo);
50 * When moving a reference in a function call, the reference is given to the
51 * callee even if that function call fails, so make sure the called function
52 * is written accordingly.
55 #define BT_MOVE_REF(ref) \
57 __typeof__(ref) _ref = ref; \
62 /* Wrapper for g_array_index that adds bound checking. */
63 #define bt_g_array_index(a, t, i) \
64 g_array_index((a), t, ({ BT_ASSERT_DBG((i) < (a)->len); (i); }))
68 * <https://stackoverflow.com/questions/37411809/how-to-elegantly-fix-this-unused-variable-warning/37412551#37412551>:
70 * * sizeof() ensures that the expression is not evaluated at all, so
71 * its side-effects don't happen. That is to be consistent with the
72 * usual behaviour of debug-only constructs, such as assert().
74 * * `((_expr), 0)` uses the comma operator to swallow the actual type
75 * of `(_expr)`. This is to prevent VLAs from triggering evaluation.
77 * * `(void)` explicitly ignores the result of `(_expr)` and sizeof() so
78 * no "unused value" warning appears.
81 #define BT_USE_EXPR(_expr) ((void) sizeof((void) (_expr), 0))
82 #define BT_USE_EXPR2(_expr1, _expr2) \
83 ((void) sizeof((void) (_expr1), (void) (_expr2), 0))
84 #define BT_USE_EXPR3(_expr1, _expr2, _expr3) \
85 ((void) sizeof((void) (_expr1), (void) (_expr2), (void) (_expr3), 0))
86 #define BT_USE_EXPR4(_expr1, _expr2, _expr3, _expr4) \
87 ((void) sizeof((void) (_expr1), (void) (_expr2), \
88 (void) (_expr3), (void) (_expr4), 0))
89 #define BT_USE_EXPR5(_expr1, _expr2, _expr3, _expr4, _expr5) \
90 ((void) sizeof((void) (_expr1), (void) (_expr2), \
91 (void) (_expr3), (void) (_expr4), (void) (_expr5), 0))
94 # if __has_warning("-Wunused-but-set-variable")
95 # define BT_DIAG_IGNORE_UNUSED_BUT_SET_VARIABLE \
96 _Pragma("GCC diagnostic ignored \"-Wunused-but-set-variable\"")
100 #if !defined BT_DIAG_IGNORE_UNUSED_BUT_SET_VARIABLE
101 # define BT_DIAG_IGNORE_UNUSED_BUT_SET_VARIABLE
This page took 0.032336 seconds and 4 git commands to generate.