spew.h
1 /*
2  shm-arena shared memory arena
3  Copyright (C) 2006-2008 Lance Arsenault (LGPL v3)
4 
5 
6  This file is part of shm-arena.
7 
8  shm-arena is free software; you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as
10  published by the Free Software Foundation; either version 3 of the
11  License, or (at your option) any later version.
12 
13  shm-arena is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this program. If not, see
20  <http://www.gnu.org/licenses/>.
21 */
22 
32 #ifdef WITH_SPEW
33 
34 #define _SILENT 0
35 #define _WARN 1
36 #define _INFO 2
37 #define _DEBUG 3
38 
39 #ifdef __GNUC__
40  #if __GNUC__ >= 4
41  /* Don't let the library expose symbols that it does not
42  * have to. Works for newer gcc. */
43  #define DLL_LOCAL __attribute__ ((visibility("hidden")))
44  #else
45  #define DLL_LOCAL
46  #endif
47 #else
48  #define DLL_LOCAL
49 #endif
50 
51 
52 extern void _shm_spew(int level, const char *fmt, ...)
53  __attribute__ ((format(printf, 2, 3)));
54 
55 extern const char *_shm_spew_levels[];
56 
57 extern void _shm_spew_init(void);
58 
76 #ifdef TTY_COLOR
77 /* from spew.c */
78 extern const
79 char *_shm_tty_color[4];
80 /* from spew.c */
81 extern
82 int _shm_with_tty_color;
83 
84 # define COLOR_ON(level) ((_shm_with_tty_color)?(_shm_tty_color[(level)]):"")
85 # define COLOR_OFF ((_shm_with_tty_color)?(_shm_tty_color[0]):"")
86 #else /* #ifdef TTY_COLOR */
87 # define COLOR_ON(level) ""
88 # define COLOR_OFF ""
89 #endif /* #ifdef TTY_COLOR */
90 
91 
92 #define SPEW(level, fmt, ...) \
93  (_shm_spew_init(), \
94  _shm_spew((level), "%sSHM %s " __FILE__ ":%d %u %lu " fmt "%s\n", \
95  COLOR_ON((level)), \
96  _shm_spew_levels[(level)], \
97  __LINE__, (getpid()) , pthread_self(), ##__VA_ARGS__ , \
98  COLOR_OFF))
99 
100 
102 #define SPEW_SYS(level, fmt, ...) \
103  SPEW(level, fmt ": sys err %d: \"%s\"", ##__VA_ARGS__ , \
104  errno, strerror(errno))
105 
107 #define SPEW_RET(x, level, fmt, ...) \
108  (SPEW(level, fmt , ##__VA_ARGS__) , (x))
109 
111 #define SPEW_SYS_RET(x, level, fmt, ...) \
112  (SPEW_SYS(level, fmt , ##__VA_ARGS__) , (x))
113 
115 #define SPEW_SYS_ERR_RET(x, level, err_x, fmt, ...) \
116  (errno=(err_x), SPEW_SYS(level, fmt , ##__VA_ARGS__), \
117  errno=(err_x), (x))
118 
120 #define SPEW_SYS_ERR(level, err_x, fmt, ...) \
121  (errno=(err_x), SPEW_SYS(level, fmt , ##__VA_ARGS__), \
122  errno=(err_x))
123 
124 #else
125 
126 #define SPEW(level, fmt, ...) /* empty macro function */
127 #define SPEW_SYS(level, fmt, ...) /* empty macro function */
128 #define SPEW_RET(x, level, fmt, ...) (x)
129 #define SPEW_SYS_RET(x, level, fmt, ...) (x)
130 #define SPEW_SYS_ERR_RET(x, level, err_x, fmt, ...) (errno=(err_x), (x))
131 #define SPEW_SYS_ERR(level, err_x, fmt, ...) (errno=(err_x))
132 
133 #endif

Shared Memory Arena version RC-0.0.25