1 #ifndef foopulsegccmacrohfoo 2 #define foopulsegccmacrohfoo 3 4 /*** 5 This file is part of PulseAudio. 6 7 Copyright 2004-2006 Lennart Poettering 8 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. 13 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. 18 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/>. 21 ***/ 22 23 /** \file 24 * GCC attribute macros */ 25 26 #if defined(__GNUC__) 27 #ifdef __MINGW32__ 28 /* libintl overrides printf with a #define. As this breaks this attribute, 29 * it has a workaround. However the workaround isn't enabled for MINGW 30 * builds (only cygwin) */ 31 #define PA_GCC_PRINTF_ATTR(a,b) __attribute__ ((format (__printf__, a, b))) 32 #else 33 #define PA_GCC_PRINTF_ATTR(a,b) __attribute__ ((format (printf, a, b))) 34 #endif 35 #else 36 /** If we're in GNU C, use some magic for detecting invalid format strings */ 37 #define PA_GCC_PRINTF_ATTR(a,b) 38 #endif 39 40 #if defined(__GNUC__) && (__GNUC__ >= 4) 41 #define PA_GCC_SENTINEL __attribute__ ((sentinel)) 42 #else 43 /** Macro for usage of GCC's sentinel compilation warnings */ 44 #define PA_GCC_SENTINEL 45 #endif 46 47 #ifdef __GNUC__ 48 #define PA_GCC_NORETURN __attribute__((noreturn)) 49 #else 50 /** Macro for no-return functions */ 51 #define PA_GCC_NORETURN 52 #endif 53 54 #ifdef __GNUC__ 55 #define PA_GCC_UNUSED __attribute__ ((unused)) 56 #else 57 /** Macro for not used function, variable or parameter */ 58 #define PA_GCC_UNUSED 59 #endif 60 61 #ifdef __GNUC__ 62 #define PA_GCC_DESTRUCTOR __attribute__ ((destructor)) 63 #else 64 /** Call this function when process terminates */ 65 #define PA_GCC_DESTRUCTOR 66 #endif 67 68 #ifndef PA_GCC_PURE 69 #ifdef __GNUC__ 70 #define PA_GCC_PURE __attribute__ ((pure)) 71 #else 72 /** This function's return value depends only the arguments list and global state **/ 73 #define PA_GCC_PURE 74 #endif 75 #endif 76 77 #ifndef PA_GCC_CONST 78 #ifdef __GNUC__ 79 #define PA_GCC_CONST __attribute__ ((const)) 80 #else 81 /** This function's return value depends only the arguments list (stricter version of PA_GCC_PURE) **/ 82 #define PA_GCC_CONST 83 #endif 84 #endif 85 86 #ifndef PA_GCC_DEPRECATED 87 #ifdef __GNUC__ 88 #define PA_GCC_DEPRECATED __attribute__ ((deprecated)) 89 #else 90 /** This function is deprecated **/ 91 #define PA_GCC_DEPRECATED 92 #endif 93 #endif 94 95 #ifndef PA_GCC_PACKED 96 #ifdef __GNUC__ 97 #define PA_GCC_PACKED __attribute__ ((packed)) 98 #else 99 /** Structure shall be packed in memory **/ 100 #define PA_GCC_PACKED 101 #endif 102 #endif 103 104 #ifndef PA_GCC_ALLOC_SIZE 105 #if defined(__GNUC__) && (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 3) 106 #define PA_GCC_ALLOC_SIZE(x) __attribute__ ((__alloc_size__(x))) 107 #define PA_GCC_ALLOC_SIZE2(x,y) __attribute__ ((__alloc_size__(x,y))) 108 #else 109 /** Macro for usage of GCC's alloc_size attribute */ 110 #define PA_GCC_ALLOC_SIZE(x) 111 /** Macro for usage of GCC's alloc_size attribute */ 112 #define PA_GCC_ALLOC_SIZE2(x,y) 113 #endif 114 #endif 115 116 #ifndef PA_GCC_MALLOC 117 #ifdef __GNUC__ 118 #define PA_GCC_MALLOC __attribute__ ((malloc)) 119 #else 120 /** Macro for usage of GCC's malloc attribute */ 121 #define PA_GCC_MALLOC 122 #endif 123 #endif 124 125 #ifndef PA_GCC_WEAKREF 126 #if defined(__GNUC__) && defined(__ELF__) && (((__GNUC__ == 4) && (__GNUC_MINOR__ > 1)) || (__GNUC__ > 4)) 127 /** Macro for usage of GCC's weakref attribute */ 128 #define PA_GCC_WEAKREF(x) __attribute__((weakref(#x))) 129 #endif 130 #endif 131 132 #ifndef PA_LIKELY 133 #ifdef __GNUC__ 134 #define PA_LIKELY(x) (__builtin_expect(!!(x),1)) 135 #define PA_UNLIKELY(x) (__builtin_expect(!!(x),0)) 136 #else 137 #define PA_LIKELY(x) (x) 138 #define PA_UNLIKELY(x) (x) 139 #endif 140 #endif 141 142 #ifdef __GNUC__ 143 #define PA_CLAMP(x, low, high) \ 144 __extension__ ({ \ 145 typeof(x) _x = (x); \ 146 typeof(low) _low = (low); \ 147 typeof(high) _high = (high); \ 148 ((_x > _high) ? _high : ((_x < _low) ? _low : _x)); \ 149 }) 150 #else 151 #define PA_CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x))) 152 #endif 153 154 #ifdef __GNUC__ 155 #define PA_CLAMP_UNLIKELY(x, low, high) \ 156 __extension__ ({ \ 157 typeof(x) _x = (x); \ 158 typeof(low) _low = (low); \ 159 typeof(high) _high = (high); \ 160 (PA_UNLIKELY(_x > _high) ? _high : (PA_UNLIKELY(_x < _low) ? _low : _x)); \ 161 }) 162 #else 163 #define PA_CLAMP_UNLIKELY(x, low, high) (PA_UNLIKELY((x) > (high)) ? (high) : (PA_UNLIKELY((x) < (low)) ? (low) : (x))) 164 #endif 165 166 /* We don't define a PA_CLAMP_LIKELY here, because it doesn't really 167 * make sense: we cannot know if it is more likely that the value is 168 * lower or greater than the boundaries. */ 169 170 #endif 171