Port: win32 DLLs don't support hidden symbols
[babeltrace.git] / include / babeltrace / babeltrace-internal.h
CommitLineData
70bd0a12
JD
1#ifndef _BABELTRACE_INTERNAL_H
2#define _BABELTRACE_INTERNAL_H
3
eb31c5e6
MD
4/*
5 * babeltrace/babeltrace-internal.h
6 *
7 * Copyright 2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
c462e188
MD
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
eb31c5e6 26 */
70bd0a12
JD
27#include <stdio.h>
28#include <glib.h>
11ac6674 29#include <stdint.h>
f3e4505b
JG
30#include <stdlib.h>
31#include <errno.h>
3d9990ac 32#include <babeltrace/compat/string-internal.h>
c55a9f58 33#include <babeltrace/types.h>
fd3c708f
MD
34
35#define PERROR_BUFLEN 200
70bd0a12 36
c55a9f58 37extern bt_bool babeltrace_verbose, babeltrace_debug;
70bd0a12 38
3394d22e
MD
39#define printf_verbose(fmt, args...) \
40 do { \
41 if (babeltrace_verbose) \
42 fprintf(stdout, "[verbose] " fmt, ## args); \
70bd0a12
JD
43 } while (0)
44
3394d22e
MD
45#define printf_debug(fmt, args...) \
46 do { \
47 if (babeltrace_debug) \
48 fprintf(stdout, "[debug] " fmt, ## args); \
70bd0a12
JD
49 } while (0)
50
b8c621ad
EB
51#define _bt_printf(fp, kindstr, fmt, args...) \
52 fprintf(fp, "[%s]%s%s%s: " fmt "\n", \
53 kindstr, \
fd3c708f
MD
54 babeltrace_debug ? " \"" : "", \
55 babeltrace_debug ? __func__ : "", \
56 babeltrace_debug ? "\"" : "", \
b8c621ad
EB
57 ## args)
58
59#define _bt_printfl(fp, kindstr, lineno, fmt, args...) \
60 fprintf(fp, "[%s]%s%s%s at line %u: " fmt "\n", \
61 kindstr, \
fd3c708f
MD
62 babeltrace_debug ? " \"" : "", \
63 babeltrace_debug ? __func__ : "", \
64 babeltrace_debug ? "\"" : "", \
65 lineno, \
66 ## args)
67
68#define _bt_printfe(fp, kindstr, perrorstr, fmt, args...) \
69 fprintf(fp, "[%s]%s%s%s: %s: " fmt "\n", \
70 kindstr, \
71 babeltrace_debug ? " \"" : "", \
72 babeltrace_debug ? __func__ : "", \
73 babeltrace_debug ? "\"" : "", \
74 perrorstr, \
75 ## args)
76
77#define _bt_printfle(fp, kindstr, lineno, perrorstr, fmt, args...) \
78 fprintf(fp, "[%s]%s%s%s at line %u: %s: " fmt "\n", \
79 kindstr, \
80 babeltrace_debug ? " \"" : "", \
81 babeltrace_debug ? __func__ : "", \
82 babeltrace_debug ? "\"" : "", \
b8c621ad 83 lineno, \
fd3c708f 84 perrorstr, \
b8c621ad
EB
85 ## args)
86
fd3c708f
MD
87#define _bt_printf_perror(fp, fmt, args...) \
88 ({ \
89 char buf[PERROR_BUFLEN] = "Error in strerror_r()"; \
695f152d 90 bt_strerror_r(errno, buf, sizeof(buf)); \
fd3c708f
MD
91 _bt_printfe(fp, "error", buf, fmt, ## args); \
92 })
93
94#define _bt_printfl_perror(fp, lineno, fmt, args...) \
95 ({ \
96 char buf[PERROR_BUFLEN] = "Error in strerror_r()"; \
695f152d 97 bt_strerror_r(errno, buf, sizeof(buf)); \
fd3c708f
MD
98 _bt_printfle(fp, "error", lineno, buf, fmt, ## args); \
99 })
100
b8c621ad
EB
101/* printf without lineno information */
102#define printf_fatal(fmt, args...) \
103 _bt_printf(stderr, "fatal", fmt, ## args)
104#define printf_error(fmt, args...) \
105 _bt_printf(stderr, "error", fmt, ## args)
106#define printf_warning(fmt, args...) \
107 _bt_printf(stderr, "warning", fmt, ## args)
fd3c708f
MD
108#define printf_perror(fmt, args...) \
109 _bt_printf_perror(stderr, fmt, ## args)
b8c621ad
EB
110
111/* printf with lineno information */
112#define printfl_fatal(lineno, fmt, args...) \
113 _bt_printfl(stderr, "fatal", lineno, fmt, ## args)
114#define printfl_error(lineno, fmt, args...) \
115 _bt_printfl(stderr, "error", lineno, fmt, ## args)
116#define printfl_warning(lineno, fmt, args...) \
117 _bt_printfl(stderr, "warning", lineno, fmt, ## args)
fd3c708f
MD
118#define printfl_perror(lineno, fmt, args...) \
119 _bt_printfl_perror(stderr, lineno, fmt, ## args)
b8c621ad
EB
120
121/* printf with node lineno information */
122#define printfn_fatal(node, fmt, args...) \
123 _bt_printfl(stderr, "fatal", (node)->lineno, fmt, ## args)
124#define printfn_error(node, fmt, args...) \
125 _bt_printfl(stderr, "error", (node)->lineno, fmt, ## args)
126#define printfn_warning(node, fmt, args...) \
127 _bt_printfl(stderr, "warning", (node)->lineno, fmt, ## args)
fd3c708f
MD
128#define printfn_perror(node, fmt, args...) \
129 _bt_printfl_perror(stderr, (node)->lineno, fmt, ## args)
b8c621ad
EB
130
131/* fprintf with Node lineno information */
132#define fprintfn_fatal(fp, node, fmt, args...) \
133 _bt_printfl(fp, "fatal", (node)->lineno, fmt, ## args)
134#define fprintfn_error(fp, node, fmt, args...) \
135 _bt_printfl(fp, "error", (node)->lineno, fmt, ## args)
136#define fprintfn_warning(fp, node, fmt, args...) \
137 _bt_printfl(fp, "warning", (node)->lineno, fmt, ## args)
fd3c708f
MD
138#define fprintfn_perror(fp, node, fmt, args...) \
139 _bt_printfl_perror(fp, (node)->lineno, fmt, ## args)
b8c621ad 140
196409fe
EB
141#ifndef likely
142# ifdef __GNUC__
143# define likely(x) __builtin_expect(!!(x), 1)
144# else
145# define likely(x) (!!(x))
146# endif
147#endif
148
149#ifndef unlikely
150# ifdef __GNUC__
151# define unlikely(x) __builtin_expect(!!(x), 0)
152# else
153# define unlikely(x) (!!(x))
154# endif
155#endif
90bf3cef 156
40af9f9f
JG
157#ifndef min
158#define min(a, b) (((a) < (b)) ? (a) : (b))
159#endif
160
161#ifndef max
162#define max(a, b) (((a) > (b)) ? (a) : (b))
163#endif
164
f3e4505b
JG
165#ifndef max_t
166#define max_t(type, a, b) \
167 ((type) (a) > (type) (b) ? (type) (a) : (type) (b))
168#endif
169
170/*
171 * Memory allocation zeroed
172 */
173#define zmalloc(x) calloc(1, x)
174
5d6c80a5
JD
175/*
176 * BT_HIDDEN: set the hidden attribute for internal functions
675860f4
MJ
177 * On Windows, symbols are local unless explicitly exported,
178 * see https://gcc.gnu.org/wiki/Visibility
5d6c80a5 179 */
675860f4
MJ
180#if defined(_WIN32) || defined(__CYGWIN__)
181#define BT_HIDDEN
182#else
5d6c80a5 183#define BT_HIDDEN __attribute__((visibility("hidden")))
675860f4 184#endif
5d6c80a5 185
6fbd4105
PP
186#define __STRINGIFY(x) #x
187#define TOSTRING(x) __STRINGIFY(x)
188
70bd0a12 189#endif
This page took 0.048627 seconds and 4 git commands to generate.