1 /* EINA - EFL data type library
2 * Copyright (C) 2007-2008 Carsten Haitzler, Vincent Torri, Jorge Luis Zapata Muga
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
23 * @addtogroup Eina_Core_Group Core
29 * @defgroup Eina_Types_Group Types
39 # ifdef EFL_EINA_BUILD
41 # define EAPI __declspec(dllexport)
44 # endif /* ! DLL_EXPORT */
46 # define EAPI __declspec(dllimport)
47 # endif /* ! EFL_EINA_BUILD */
51 # define EAPI __attribute__ ((visibility("default")))
58 * @brief Used to export functions(by changing visibility).
64 #include "eina_config.h"
66 #ifdef EINA_WARN_UNUSED_RESULT
67 # undef EINA_WARN_UNUSED_RESULT
69 #ifdef EINA_ARG_NONNULL
70 # undef EINA_ARG_NONNULL
72 #ifdef EINA_DEPRECATED
73 # undef EINA_DEPRECATED
93 #ifdef EINA_NOINSTRUMENT
94 # undef EINA_NOINSTRUMENT
103 # undef EINA_SENTINEL
107 # if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
108 # define EINA_WARN_UNUSED_RESULT __attribute__ ((__warn_unused_result__))
110 # define EINA_WARN_UNUSED_RESULT
113 # if (!defined(EINA_SAFETY_CHECKS)) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))
114 # define EINA_ARG_NONNULL(...) __attribute__ ((__nonnull__(__VA_ARGS__)))
116 # define EINA_ARG_NONNULL(...)
119 # if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
120 # define EINA_DEPRECATED __attribute__ ((__deprecated__))
122 # define EINA_DEPRECATED
125 # if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
126 # define EINA_MALLOC __attribute__ ((__malloc__))
127 # define EINA_PURE __attribute__ ((__pure__))
133 # if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
134 # if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 3)
135 # define EINA_PRINTF(fmt, arg) __attribute__((__format__ (__gnu_printf__, fmt, arg)))
137 # define EINA_PRINTF(fmt, arg) __attribute__((__format__ (__printf__, fmt, arg)))
139 # define EINA_SCANF(fmt, arg) __attribute__((__format__ (__scanf__, fmt, arg)))
140 # define EINA_FORMAT(fmt) __attribute__((__format_arg__(fmt)))
141 # define EINA_CONST __attribute__((__const__))
142 # define EINA_NOINSTRUMENT __attribute__((__no_instrument_function__))
143 # define EINA_UNLIKELY(exp) __builtin_expect((exp), 0)
144 # define EINA_LIKELY(exp) __builtin_expect((exp), 1)
145 # define EINA_SENTINEL __attribute__((__sentinel__))
147 # define EINA_PRINTF(fmt, arg)
148 # define EINA_SCANF(fmt, arg)
149 # define EINA_FORMAT(fmt)
151 # define EINA_NOINSTRUMENT
152 # define EINA_UNLIKELY(exp) exp
153 # define EINA_LIKELY(exp) exp
154 # define EINA_SENTINEL
157 #elif defined(_WIN32)
158 # define EINA_WARN_UNUSED_RESULT
159 # define EINA_ARG_NONNULL(...)
160 # if defined(_MSC_VER) && _MSC_VER >= 1300
161 # define EINA_DEPRECATED __declspec(deprecated)
163 # define EINA_DEPRECATED
167 # define EINA_PRINTF(fmt, arg)
168 # define EINA_SCANF(fmt, arg)
169 # define EINA_FORMAT(fmt)
171 # define EINA_NOINSTRUMENT
172 # define EINA_UNLIKELY(exp) exp
173 # define EINA_LIKELY(exp) exp
174 # define EINA_SENTINEL
176 #elif defined(__SUNPRO_C)
177 # define EINA_WARN_UNUSED_RESULT
178 # define EINA_ARG_NONNULL(...)
179 # define EINA_DEPRECATED
180 # if __SUNPRO_C >= 0x590
181 # define EINA_MALLOC __attribute__ ((malloc))
182 # define EINA_PURE __attribute__ ((pure))
187 # define EINA_PRINTF(fmt, arg)
188 # define EINA_SCANF(fmt, arg)
189 # define EINA_FORMAT(fmt)
190 # if __SUNPRO_C >= 0x590
191 # define EINA_CONST __attribute__ ((const))
195 # define EINA_NOINSTRUMENT
196 # define EINA_UNLIKELY(exp) exp
197 # define EINA_LIKELY(exp) exp
198 # define EINA_SENTINEL
200 #else /* ! __GNUC__ && ! _WIN32 && ! __SUNPRO_C */
203 * @def EINA_WARN_UNUSED_RESULT
204 * Used to warn when the returned value of the function is not used.
206 # define EINA_WARN_UNUSED_RESULT
209 * @def EINA_ARG_NONNULL
210 * Used to warn when the specified arguments of the function are @c NULL.
212 # define EINA_ARG_NONNULL(...)
215 * @def EINA_DEPRECATED
216 * Used to warn when the function is considered as deprecated.
218 # define EINA_DEPRECATED
221 * @brief EINA_MALLOC is used to tell the compiler that a function may be treated
222 * as if any non-NULL pointer it returns cannot alias any other pointer valid when
223 * the function returns and that the memory has undefined content.
228 * @brief EINA_PURE is used to tell the compiler this functions has no effects
229 * except the return value and their return value depends only on the parameters
230 * and/or global variables.
235 * @param fmt The format to be used.
236 * @param arg The argument to be used.
238 # define EINA_PRINTF(fmt, arg)
241 * @param fmt The format to be used.
242 * @param arg The argument to be used.
244 # define EINA_SCANF(fmt, arg)
247 * @param fmt The format to be used.
249 # define EINA_FORMAT(fmt)
252 * @brief Attribute from gcc to prevent the function to read/modify any global memory.
256 * @def EINA_NOINSTRUMENT
257 * @brief Attribute from gcc to disable instrumentation for a specific function.
259 # define EINA_NOINSTRUMENT
262 * @param exp The expression to be used.
264 # define EINA_UNLIKELY(exp) exp
267 * @param exp The expression to be used.
269 # define EINA_LIKELY(exp) exp
272 * @brief Attribute from gcc to prevent calls without the necessary NULL
273 * sentinel in certain variadic functions
276 # define EINA_SENTINEL
277 #endif /* ! __GNUC__ && ! _WIN32 && ! __SUNPRO_C */
281 * Type to mimic a boolean.
283 * @note it differs from stdbool.h as this is defined as an unsigned
284 * char to make it usable by bitfields (Eina_Bool name:1) and
285 * also take as few bytes as possible.
287 typedef unsigned char Eina_Bool;
291 * boolean value FALSE (numerical value 0)
293 #define EINA_FALSE ((Eina_Bool)0)
297 * boolean value TRUE (numerical value 1)
299 #define EINA_TRUE ((Eina_Bool)1)
301 EAPI extern const unsigned int eina_prime_table[];
304 * @typedef Eina_Compare_Cb
305 * Function used in functions using sorting. It compares @p data1 and
306 * @p data2. If @p data1 is 'less' than @p data2, -1 must be returned,
307 * if it is 'greater', 1 must be returned, and if they are equal, 0
310 typedef int (*Eina_Compare_Cb)(const void *data1, const void *data2);
313 * @def EINA_COMPARE_CB
314 * Macro to cast to Eina_Compare_Cb.
316 #define EINA_COMPARE_CB(function) ((Eina_Compare_Cb)function)
319 * @typedef Eina_Each_Cb
320 * A callback type used when iterating over a container.
322 typedef Eina_Bool (*Eina_Each_Cb)(const void *container, void *data, void *fdata);
326 * Macro to cast to Eina_Each.
328 #define EINA_EACH_CB(Function) ((Eina_Each_Cb)Function)
331 * @typedef Eina_Free_Cb
332 * A callback type used to free data when iterating over a container.
334 typedef void (*Eina_Free_Cb)(void *data);
338 * Macro to cast to Eina_Free_Cb.
340 #define EINA_FREE_CB(Function) ((Eina_Free_Cb)Function)
343 * @def EINA_C_ARRAY_LENGTH
344 * Macro to return the array length of a standard c array.
346 * int foo[] = { 0, 1, 2, 3 };
347 * would return 4 and not 4 * sizeof(int).
350 #define EINA_C_ARRAY_LENGTH(arr) (sizeof(arr) / sizeof((arr)[0]))
360 #endif /* EINA_TYPES_H_ */