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")))
33 * BT_NOEXCEPT: defined to `noexcept` if compiling as C++, else empty.
35 #if defined(__cplusplus)
36 #define BT_NOEXCEPT noexcept
41 /* Enable `txt` if developer mode is enabled. */
43 #define BT_IF_DEV_MODE(txt) txt
45 #define BT_IF_DEV_MODE(txt)
48 /* Wrapper for g_array_index that adds bound checking. */
49 #define bt_g_array_index(a, t, i) \
50 g_array_index((a), t, ({ BT_ASSERT_DBG((i) < (a)->len); (i); }))
54 * <https://stackoverflow.com/questions/37411809/how-to-elegantly-fix-this-unused-variable-warning/37412551#37412551>:
56 * * sizeof() ensures that the expression is not evaluated at all, so
57 * its side-effects don't happen. That is to be consistent with the
58 * usual behaviour of debug-only constructs, such as assert().
60 * * `((_expr), 0)` uses the comma operator to swallow the actual type
61 * of `(_expr)`. This is to prevent VLAs from triggering evaluation.
63 * * `(void)` explicitly ignores the result of `(_expr)` and sizeof() so
64 * no "unused value" warning appears.
67 #define BT_USE_EXPR(_expr) ((void) sizeof((void) (_expr), 0))
68 #define BT_USE_EXPR2(_expr1, _expr2) \
69 ((void) sizeof((void) (_expr1), (void) (_expr2), 0))
70 #define BT_USE_EXPR3(_expr1, _expr2, _expr3) \
71 ((void) sizeof((void) (_expr1), (void) (_expr2), (void) (_expr3), 0))
72 #define BT_USE_EXPR4(_expr1, _expr2, _expr3, _expr4) \
73 ((void) sizeof((void) (_expr1), (void) (_expr2), \
74 (void) (_expr3), (void) (_expr4), 0))
75 #define BT_USE_EXPR5(_expr1, _expr2, _expr3, _expr4, _expr5) \
76 ((void) sizeof((void) (_expr1), (void) (_expr2), \
77 (void) (_expr3), (void) (_expr4), (void) (_expr5), 0))
79 #define BT_DIAG_PUSH _Pragma ("GCC diagnostic push")
80 #define BT_DIAG_POP _Pragma ("GCC diagnostic push")
82 #define BT_DIAG_IGNORE_SHADOW _Pragma("GCC diagnostic ignored \"-Wshadow\"")
85 # if __has_warning("-Wunused-but-set-variable")
86 # define BT_DIAG_IGNORE_UNUSED_BUT_SET_VARIABLE \
87 _Pragma("GCC diagnostic ignored \"-Wunused-but-set-variable\"")
91 #if !defined BT_DIAG_IGNORE_UNUSED_BUT_SET_VARIABLE
92 # define BT_DIAG_IGNORE_UNUSED_BUT_SET_VARIABLE
This page took 0.075434 seconds and 5 git commands to generate.