| 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 | #include <stdio.h> |
| 29 | #define PA_GCC_PRINTF_ATTR(a,b) __attribute__ ((format (__MINGW_PRINTF_FORMAT, a, b))) |
| 30 | #else |
| 31 | #define PA_GCC_PRINTF_ATTR(a,b) __attribute__ ((format (printf, a, b))) |
| 32 | #endif |
| 33 | #else |
| 34 | /** If we're in GNU C, use some magic for detecting invalid format strings */ |
| 35 | #define PA_GCC_PRINTF_ATTR(a,b) |
| 36 | #endif |
| 37 | |
| 38 | #if defined(__GNUC__) && (__GNUC__ >= 4) |
| 39 | #define PA_GCC_SENTINEL __attribute__ ((sentinel)) |
| 40 | #else |
| 41 | /** Macro for usage of GCC's sentinel compilation warnings */ |
| 42 | #define PA_GCC_SENTINEL |
| 43 | #endif |
| 44 | |
| 45 | #ifdef __GNUC__ |
| 46 | #define PA_GCC_NORETURN __attribute__((noreturn)) |
| 47 | #else |
| 48 | /** Macro for no-return functions */ |
| 49 | #define PA_GCC_NORETURN |
| 50 | #endif |
| 51 | |
| 52 | #ifdef __GNUC__ |
| 53 | #define PA_GCC_UNUSED __attribute__ ((unused)) |
| 54 | #else |
| 55 | /** Macro for not used function, variable or parameter */ |
| 56 | #define PA_GCC_UNUSED |
| 57 | #endif |
| 58 | |
| 59 | #ifdef __GNUC__ |
| 60 | #define PA_GCC_DESTRUCTOR __attribute__ ((destructor)) |
| 61 | #else |
| 62 | /** Call this function when process terminates */ |
| 63 | #define PA_GCC_DESTRUCTOR |
| 64 | #endif |
| 65 | |
| 66 | #ifndef PA_GCC_PURE |
| 67 | #ifdef __GNUC__ |
| 68 | #define PA_GCC_PURE __attribute__ ((pure)) |
| 69 | #else |
| 70 | /** This function's return value depends only the arguments list and global state **/ |
| 71 | #define PA_GCC_PURE |
| 72 | #endif |
| 73 | #endif |
| 74 | |
| 75 | #ifndef PA_GCC_CONST |
| 76 | #ifdef __GNUC__ |
| 77 | #define PA_GCC_CONST __attribute__ ((const)) |
| 78 | #else |
| 79 | /** This function's return value depends only the arguments list (stricter version of PA_GCC_PURE) **/ |
| 80 | #define PA_GCC_CONST |
| 81 | #endif |
| 82 | #endif |
| 83 | |
| 84 | #ifndef PA_GCC_DEPRECATED |
| 85 | #ifdef __GNUC__ |
| 86 | #define PA_GCC_DEPRECATED __attribute__ ((deprecated)) |
| 87 | #else |
| 88 | /** This function is deprecated **/ |
| 89 | #define PA_GCC_DEPRECATED |
| 90 | #endif |
| 91 | #endif |
| 92 | |
| 93 | #ifndef PA_GCC_PACKED |
| 94 | #ifdef __GNUC__ |
| 95 | #define PA_GCC_PACKED __attribute__ ((packed)) |
| 96 | #else |
| 97 | /** Structure shall be packed in memory **/ |
| 98 | #define PA_GCC_PACKED |
| 99 | #endif |
| 100 | #endif |
| 101 | |
| 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))) |
| 106 | #else |
| 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) |
| 111 | #endif |
| 112 | #endif |
| 113 | |
| 114 | #ifndef PA_GCC_MALLOC |
| 115 | #ifdef __GNUC__ |
| 116 | #define PA_GCC_MALLOC __attribute__ ((malloc)) |
| 117 | #else |
| 118 | /** Macro for usage of GCC's malloc attribute */ |
| 119 | #define PA_GCC_MALLOC |
| 120 | #endif |
| 121 | #endif |
| 122 | |
| 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))) |
| 127 | #endif |
| 128 | #endif |
| 129 | |
| 130 | #ifndef PA_LIKELY |
| 131 | #ifdef __GNUC__ |
| 132 | #define PA_LIKELY(x) (__builtin_expect(!!(x),1)) |
| 133 | #define PA_UNLIKELY(x) (__builtin_expect(!!(x),0)) |
| 134 | #else |
| 135 | #define PA_LIKELY(x) (x) |
| 136 | #define PA_UNLIKELY(x) (x) |
| 137 | #endif |
| 138 | #endif |
| 139 | |
| 140 | #ifdef __GNUC__ |
| 141 | #define PA_CLAMP(x, low, high) \ |
| 142 | __extension__ ({ \ |
| 143 | typeof(x) _x = (x); \ |
| 144 | typeof(low) _low = (low); \ |
| 145 | typeof(high) _high = (high); \ |
| 146 | ((_x > _high) ? _high : ((_x < _low) ? _low : _x)); \ |
| 147 | }) |
| 148 | #else |
| 149 | #define PA_CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x))) |
| 150 | #endif |
| 151 | |
| 152 | #ifdef __GNUC__ |
| 153 | #define PA_CLAMP_UNLIKELY(x, low, high) \ |
| 154 | __extension__ ({ \ |
| 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)); \ |
| 159 | }) |
| 160 | #else |
| 161 | #define PA_CLAMP_UNLIKELY(x, low, high) (PA_UNLIKELY((x) > (high)) ? (high) : (PA_UNLIKELY((x) < (low)) ? (low) : (x))) |
| 162 | #endif |
| 163 | |
| 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. */ |
| 167 | |
| 168 | #endif |
| 169 | |