1 #ifndef _BABELTRACE_INTERNAL_H
2 #define _BABELTRACE_INTERNAL_H
5 * Copyright 2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 #include "compat/string.h"
32 #include <babeltrace2/types.h>
34 #define PERROR_BUFLEN 200
38 # define likely(x) __builtin_expect(!!(x), 1)
40 # define likely(x) (!!(x))
46 # define unlikely(x) __builtin_expect(!!(x), 0)
48 # define unlikely(x) (!!(x))
53 #define min(a, b) (((a) < (b)) ? (a) : (b))
57 #define max(a, b) (((a) > (b)) ? (a) : (b))
61 #define max_t(type, a, b) \
62 ((type) (a) > (type) (b) ? (type) (a) : (type) (b))
66 bool bt_safe_to_mul_int64(int64_t a
, int64_t b
)
68 if (a
== 0 || b
== 0) {
72 return a
< INT64_MAX
/ b
;
76 bool bt_safe_to_mul_uint64(uint64_t a
, uint64_t b
)
78 if (a
== 0 || b
== 0) {
82 return a
< UINT64_MAX
/ b
;
86 bool bt_safe_to_add_int64(int64_t a
, int64_t b
)
88 return a
<= INT64_MAX
- b
;
92 bool bt_safe_to_add_uint64(uint64_t a
, uint64_t b
)
94 return a
<= UINT64_MAX
- b
;
98 * Memory allocation zeroed
100 #define zmalloc(x) calloc(1, x)
103 * BT_HIDDEN: set the hidden attribute for internal functions
104 * On Windows, symbols are local unless explicitly exported,
105 * see https://gcc.gnu.org/wiki/Visibility
107 #if defined(_WIN32) || defined(__CYGWIN__)
110 #define BT_HIDDEN __attribute__((visibility("hidden")))
114 #define __STRINGIFY(x) #x
117 #define TOSTRING(x) __STRINGIFY(x)
119 #define BT_UNUSED __attribute__((unused))
This page took 0.03648 seconds and 4 git commands to generate.