1 #ifndef foopulsegccmacrohfoo
2 #define foopulsegccmacrohfoo
5 This file is part of PulseAudio.
7 Copyright 2004-2006 Lennart Poettering
9 PulseAudio is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published
11 by the Free Software Foundation; either version 2.1 of the License,
12 or (at your option) any later version.
14 PulseAudio is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public License
20 along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
24 * GCC attribute macros */
29 #define PA_GCC_PRINTF_ATTR(a,b) __attribute__ ((format (__MINGW_PRINTF_FORMAT, a, b)))
31 #define PA_GCC_PRINTF_ATTR(a,b) __attribute__ ((format (printf, a, b)))
34 /** If we're in GNU C, use some magic for detecting invalid format strings */
35 #define PA_GCC_PRINTF_ATTR(a,b)
38 #if defined(__GNUC__) && (__GNUC__ >= 4)
39 #define PA_GCC_SENTINEL __attribute__ ((sentinel))
41 /** Macro for usage of GCC's sentinel compilation warnings */
42 #define PA_GCC_SENTINEL
46 #define PA_GCC_NORETURN __attribute__((noreturn))
48 /** Macro for no-return functions */
49 #define PA_GCC_NORETURN
53 #define PA_GCC_UNUSED __attribute__ ((unused))
55 /** Macro for not used function, variable or parameter */
60 #define PA_GCC_DESTRUCTOR __attribute__ ((destructor))
62 /** Call this function when process terminates */
63 #define PA_GCC_DESTRUCTOR
68 #define PA_GCC_PURE __attribute__ ((pure))
70 /** This function's return value depends only the arguments list and global state **/
77 #define PA_GCC_CONST __attribute__ ((const))
79 /** This function's return value depends only the arguments list (stricter version of PA_GCC_PURE) **/
84 #ifndef PA_GCC_DEPRECATED
86 #define PA_GCC_DEPRECATED __attribute__ ((deprecated))
88 /** This function is deprecated **/
89 #define PA_GCC_DEPRECATED
95 #define PA_GCC_PACKED __attribute__ ((packed))
97 /** Structure shall be packed in memory **/
102 #ifndef PA_GCC_ALLOC_SIZE
103 #if defined(__GNUC__) && (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 3)
104 #define PA_GCC_ALLOC_SIZE(x) __attribute__ ((__alloc_size__(x)))
105 #define PA_GCC_ALLOC_SIZE2(x,y) __attribute__ ((__alloc_size__(x,y)))
107 /** Macro for usage of GCC's alloc_size attribute */
108 #define PA_GCC_ALLOC_SIZE(x)
109 /** Macro for usage of GCC's alloc_size attribute */
110 #define PA_GCC_ALLOC_SIZE2(x,y)
114 #ifndef PA_GCC_MALLOC
116 #define PA_GCC_MALLOC __attribute__ ((malloc))
118 /** Macro for usage of GCC's malloc attribute */
119 #define PA_GCC_MALLOC
123 #ifndef PA_GCC_WEAKREF
124 #if defined(__GNUC__) && defined(__ELF__) && (((__GNUC__ == 4) && (__GNUC_MINOR__ > 1)) || (__GNUC__ > 4))
125 /** Macro for usage of GCC's weakref attribute */
126 #define PA_GCC_WEAKREF(x) __attribute__((weakref(#x)))
132 #define PA_LIKELY(x) (__builtin_expect(!!(x),1))
133 #define PA_UNLIKELY(x) (__builtin_expect(!!(x),0))
135 #define PA_LIKELY(x) (x)
136 #define PA_UNLIKELY(x) (x)
141 #define PA_CLAMP(x, low, high) \
143 typeof(x) _x = (x); \
144 typeof(low) _low = (low); \
145 typeof(high) _high = (high); \
146 ((_x > _high) ? _high : ((_x < _low) ? _low : _x)); \
149 #define PA_CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
153 #define PA_CLAMP_UNLIKELY(x, low, high) \
155 typeof(x) _x = (x); \
156 typeof(low) _low = (low); \
157 typeof(high) _high = (high); \
158 (PA_UNLIKELY(_x > _high) ? _high : (PA_UNLIKELY(_x < _low) ? _low : _x)); \
161 #define PA_CLAMP_UNLIKELY(x, low, high) (PA_UNLIKELY((x) > (high)) ? (high) : (PA_UNLIKELY((x) < (low)) ? (low) : (x)))
164 /* We don't define a PA_CLAMP_LIKELY here, because it doesn't really
165 * make sense: we cannot know if it is more likely that the value is
166 * lower or greater than the boundaries. */