Commit | Line | Data |
---|---|---|
eb31c5e6 | 1 | /* |
0235b0db | 2 | * SPDX-License-Identifier: MIT |
eb31c5e6 | 3 | * |
0235b0db | 4 | * Copyright 2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
eb31c5e6 | 5 | */ |
fd3c708f | 6 | |
0235b0db MJ |
7 | #ifndef _BABELTRACE_INTERNAL_H |
8 | #define _BABELTRACE_INTERNAL_H | |
70bd0a12 | 9 | |
91d81473 | 10 | #define bt_max_t(type, a, b) \ |
f3e4505b | 11 | ((type) (a) > (type) (b) ? (type) (a) : (type) (b)) |
f3e4505b | 12 | |
5d6c80a5 JD |
13 | /* |
14 | * BT_HIDDEN: set the hidden attribute for internal functions | |
675860f4 MJ |
15 | * On Windows, symbols are local unless explicitly exported, |
16 | * see https://gcc.gnu.org/wiki/Visibility | |
5d6c80a5 | 17 | */ |
675860f4 MJ |
18 | #if defined(_WIN32) || defined(__CYGWIN__) |
19 | #define BT_HIDDEN | |
20 | #else | |
5d6c80a5 | 21 | #define BT_HIDDEN __attribute__((visibility("hidden"))) |
675860f4 | 22 | #endif |
5d6c80a5 | 23 | |
55b71f05 SM |
24 | /* |
25 | * Yield `ref`'s value while setting `ref` to NULL. | |
26 | * | |
27 | * This can be used to give a strong reference to a callee: | |
28 | * | |
29 | * add_foo_to_list(list, BT_MOVE_REF(foo)); | |
30 | * | |
31 | * or in a simple assignment: | |
32 | * | |
33 | * my_struct->foo = BT_MOVE_REF(foo); | |
34 | * | |
35 | * When moving a reference in a function call, the reference is given to the | |
36 | * callee even if that function call fails, so make sure the called function | |
37 | * is written accordingly. | |
38 | */ | |
39 | ||
40 | #define BT_MOVE_REF(ref) \ | |
41 | ({ \ | |
e3d110d6 | 42 | typeof(ref) _ref = ref; \ |
55b71f05 SM |
43 | ref = NULL; \ |
44 | _ref; \ | |
45 | }) | |
46 | ||
70bd0a12 | 47 | #endif |