1 #ifndef __ZZIP_INTERNAL_HINTS_H 2 #define __ZZIP_INTERNAL_HINTS_H 3 #include <zzip/conf.h> 4 5 #ifndef ZZIP_GNUC_ATLEAST 6 # if defined __GNUC__ && defined __GNUC_MINOR__ 7 # define ZZIP_GNUC_ATLEAST(_M_,_N_) \ 8 ((__GNUC__ << 10) + __GNUC_MINOR__ >= ((_M_) << 10) + (_N_)) 9 # elif defined __GNUC__ 10 # define ZZIP_GNUC_ATLEAST(_M_,_N_) \ 11 ((__GNUC__ << 10) >= ((_M_) << 10)) 12 # else 13 # define ZZIP_GNUC_ATLEAST(_M_, _N_) 0 14 # endif 15 #endif 16 17 #ifndef ZZIP_GNUC_EXTENSION 18 # if ZZIP_GNUC_ATLEAST(2,8) 19 # define ZZIP_GNUC_EXTENSION __extension__ 20 # else 21 # define ZZIP_GNUC_EXTENSION 22 # endif 23 #endif 24 25 /* func has no side effects, return value depends only on params and globals */ 26 #ifndef ZZIP_GNUC_PURE 27 # if ZZIP_GNUC_ATLEAST(2,8) 28 # define ZZIP_GNUC_PURE __attribute__((__pure__)) 29 # else 30 # define ZZIP_GNUC_PURE 31 # endif 32 #endif 33 34 /* func has no side effects, return value depends only on params */ 35 #ifndef ZZIP_GNUC_CONST 36 # if ZZIP_GNUC_ATLEAST(2,4) 37 # define ZZIP_GNUC_CONST __attribute__((__const__)) 38 # else 39 # define ZZIP_GNUC_CONST 40 # endif 41 #endif 42 43 /* typename / variable / function possibly unused */ 44 #ifndef ZZIP_GNUC_UNUSED 45 # if ZZIP_GNUC_ATLEAST(2,4) 46 # define ZZIP_GNUC_UNUSED __attribute__((__unused__)) 47 # else 48 # define ZZIP_GNUC_UNUSED 49 # endif 50 #endif 51 52 /* obvious. btw, a noreturn-func should return void */ 53 #ifndef ZZIP_GNUC_NORETURN 54 # if ZZIP_GNUC_ATLEAST(2,5) 55 # define ZZIP_GNUC_NORETURN __attribute__((__noreturn__)) 56 # else 57 # define ZZIP_GNUC_NORETURN 58 # endif 59 #endif 60 61 /* omit function from profiling with -finstrument-functions */ 62 #ifndef ZZIP_GNUC_NO_INSTRUMENT 63 # if ZZIP_GNUC_ATLEAST(2,4) 64 # define ZZIP_GNUC_NO_INSTRUMENT __attribute__((__no_instrument_function__)) 65 # else 66 # define ZZIP_GNUC_NO_INSTRUMENT 67 # endif 68 #endif 69 70 /* all pointer args must not be null, and allow optimiztons based on the fact*/ 71 #ifndef ZZIP_GNUC_NONNULL 72 # if ZZIP_GNUC_ATLEAST(3,1) 73 # define ZZIP_GNUC_NONNULL __attribute__((nonnull)) 74 # else 75 # define ZZIP_GNUC_NONNULL 76 # endif 77 #endif 78 79 /* the function can not throw - the libc function are usually nothrow */ 80 #ifndef ZZIP_GNUC_NOTHROW 81 # if ZZIP_GNUC_ATLEAST(3,2) 82 # define ZZIP_GNUC_NOTHROW __attribute__((nothrow)) 83 # else 84 # define ZZIP_GNUC_NOTHROW 85 # endif 86 #endif 87 88 /* typename / function / variable is obsolete but still listed in headers */ 89 #ifndef ZZIP_GNUC_DEPRECATED 90 # if ZZIP_GNUC_ATLEAST(3,1) 91 # define ZZIP_GNUC_DEPRECATED __attribute__((deprecated)) 92 # else 93 # define ZZIP_GNUC_DEPRECATED 94 # endif 95 #endif 96 97 /* resolve references to this function during pre-linking the library */ 98 #ifndef ZZIP_GNUC_LIB_PROTECTED 99 # if ZZIP_GNUC_ATLEAST(3,1) 100 # define ZZIP_GNUC_LIB_PROTECTED __attribute__((visiblity("protected"))) 101 # else 102 # define ZZIP_GNUC_LIB_PROTECTED 103 # endif 104 #endif 105 106 /* func shall only be usable within the same lib (so, no entry in lib symtab)*/ 107 #ifndef ZZIP_GNUC_LIB_PRIVATE 108 # if ZZIP_GNUC_ATLEAST(3,1) 109 # define ZZIP_GNUC_LIB_PRIVATE __attribute__((visiblity("hidden"))) 110 # else 111 # define ZZIP_GNUC_LIB_PRIVATE 112 # endif 113 #endif 114 115 /* ... and not even passed as a function pointer reference to outside the lib*/ 116 #ifndef ZZIP_GNUC_LIB_INTERNAL 117 # if ZZIP_GNUC_ATLEAST(3,1) 118 # define ZZIP_GNUC_LIB_INTERNAL __attribute__((visiblity("internal"))) 119 # else 120 # define ZZIP_GNUC_LIB_INTERNAL 121 # endif 122 #endif 123 124 125 #ifndef ZZIP_GNUC_FORMAT 126 # if ZZIP_GNUC_ATLEAST(2,4) 127 # define ZZIP_GNUC_FORMAT(_X_) __attribute__((__format_arg__(_X_))) 128 # else 129 # define ZZIP_GNUC_FORMAT(_X_) 130 # endif 131 #endif 132 133 #ifndef ZZIP_GNUC_SCANF 134 # if ZZIP_GNUC_ATLEAST(2,4) 135 # define ZZIP_GNUC_SCANF(_S_,_X_) __attribute__((__scanf__(_S_,_X_))) 136 # else 137 # define ZZIP_GNUC_SCANF(_S_,_X_) 138 # endif 139 #endif 140 141 #ifndef ZZIP_GNUC_PRINTF 142 # if ZZIP_GNUC_ATLEAST(2,4) 143 # define ZZIP_GNUC_PRINTF(_S_,_X_) __attribute__((__printf__(_S_,_X_))) 144 # else 145 # define ZZIP_GNUC_PRINTF(_S_,_X_) 146 # endif 147 #endif 148 149 #ifdef __GNUC__ 150 #define ZZIP_GNUC_PACKED __attribute__((packed)) 151 #else 152 #define ZZIP_GNUC_PACKED 153 #endif 154 155 #ifndef ZZIP_FUNCTION 156 # if ZZIP_GNUC_ATLEAST(2,6) 157 # define ZZIP_FUNC __FUNCTION__ 158 # define ZZIP_FUNCTION __FUNCTION__ 159 # elif defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L 160 # define ZZIP_FUNC __func__ 161 # define ZZIP_FUNCTION "" 162 # else 163 # define ZZIP_FUNC 0 164 # define ZZIP_FUNCTION "" 165 # endif 166 #endif 167 168 #ifndef ZZIP_STRING 169 #define ZZIP_STRING(_X_) ZZIP_STRING_(_X_) 170 #define ZZIP_STRING_(_Y_) #_Y_ 171 #endif 172 173 #ifndef ZZIP_DIM 174 #define ZZIP_DIM(_A_) (sizeof(_A_) / sizeof ((_A_)[0])) 175 #endif 176 177 #if !(defined ZZIP_FOR1 && defined ZZIP_END1) 178 # if defined sun || defined __sun__ 179 # define ZZIP_FOR1 if (1) 180 # define ZZIP_END1 else (void)0 181 # else 182 # define ZZIP_FOR1 do 183 # define ZZIP_END1 while (0) 184 # endif 185 #endif 186 187 #ifndef ZZIP_BRANCH_OVER 188 # if ZZIP_GNUC_ATLEAST(2,96) 189 # define ZZIP_BRANCH_OVER(_X_) __builtin_expect((_X_),0) 190 # else 191 # define ZZIP_BRANCH_OVER(_X_) (_X_) 192 # endif 193 #endif 194 195 #endif 196