00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef __G_MACROS_H__
00032 #define __G_MACROS_H__
00033
00034
00035
00036 #include <stddef.h>
00037
00038
00039
00040
00041
00042 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
00043 # define G_GNUC_EXTENSION __extension__
00044 #else
00045 # define G_GNUC_EXTENSION
00046 #endif
00047
00048
00049
00050 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
00051 #define G_GNUC_PURE \
00052 __attribute__((__pure__))
00053 #define G_GNUC_MALLOC \
00054 __attribute__((__malloc__))
00055 #else
00056 #define G_GNUC_PURE
00057 #define G_GNUC_MALLOC
00058 #endif
00059
00060 #if __GNUC__ >= 4
00061 #define G_GNUC_NULL_TERMINATED __attribute__((__sentinel__))
00062 #else
00063 #define G_GNUC_NULL_TERMINATED
00064 #endif
00065
00066 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
00067 #define G_GNUC_PRINTF( format_idx, arg_idx ) \
00068 __attribute__((__format__ (__printf__, format_idx, arg_idx)))
00069 #define G_GNUC_SCANF( format_idx, arg_idx ) \
00070 __attribute__((__format__ (__scanf__, format_idx, arg_idx)))
00071 #define G_GNUC_FORMAT( arg_idx ) \
00072 __attribute__((__format_arg__ (arg_idx)))
00073 #define G_GNUC_NORETURN \
00074 __attribute__((__noreturn__))
00075 #define G_GNUC_CONST \
00076 __attribute__((__const__))
00077 #define G_GNUC_UNUSED \
00078 __attribute__((__unused__))
00079 #define G_GNUC_NO_INSTRUMENT \
00080 __attribute__((__no_instrument_function__))
00081 #else
00082 #define G_GNUC_PRINTF( format_idx, arg_idx )
00083 #define G_GNUC_SCANF( format_idx, arg_idx )
00084 #define G_GNUC_FORMAT( arg_idx )
00085 #define G_GNUC_NORETURN
00086 #define G_GNUC_CONST
00087 #define G_GNUC_UNUSED
00088 #define G_GNUC_NO_INSTRUMENT
00089 #endif
00090
00091 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
00092 #define G_GNUC_DEPRECATED \
00093 __attribute__((__deprecated__))
00094 #else
00095 #define G_GNUC_DEPRECATED
00096 #endif
00097
00098 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
00099 #define G_GNUC_WARN_UNUSED_RESULT \
00100 __attribute__((warn_unused_result))
00101 #else
00102 #define G_GNUC_WARN_UNUSED_RESULT
00103 #endif
00104
00105
00106
00107
00108
00109 #if defined (__GNUC__) && (__GNUC__ < 3)
00110 #define G_GNUC_FUNCTION __FUNCTION__
00111 #define G_GNUC_PRETTY_FUNCTION __PRETTY_FUNCTION__
00112 #else
00113 #define G_GNUC_FUNCTION ""
00114 #define G_GNUC_PRETTY_FUNCTION ""
00115 #endif
00116
00117 #define G_STRINGIFY(macro_or_string) G_STRINGIFY_ARG (macro_or_string)
00118 #define G_STRINGIFY_ARG(contents) #contents
00119
00120
00121 #if defined(__GNUC__) && (__GNUC__ < 3) && !defined(__cplusplus)
00122 # define G_STRLOC __FILE__ ":" G_STRINGIFY (__LINE__) ":" __PRETTY_FUNCTION__ "()"
00123 #else
00124 # define G_STRLOC __FILE__ ":" G_STRINGIFY (__LINE__)
00125 #endif
00126
00127
00128 #if defined (__GNUC__)
00129 # define G_STRFUNC ((const char*) (__PRETTY_FUNCTION__))
00130 #elif defined (G_HAVE_ISO_VARARGS)
00131 # define G_STRFUNC ((const char*) (__func__))
00132 #else
00133 # define G_STRFUNC ((const char*) ("???"))
00134 #endif
00135
00136
00137 #ifdef __cplusplus
00138 # define G_BEGIN_DECLS extern "C" {
00139 # define G_END_DECLS }
00140 #else
00141 # define G_BEGIN_DECLS
00142 # define G_END_DECLS
00143 #endif
00144
00145
00146
00147
00148
00149
00150 #ifndef NULL
00151 # ifdef __cplusplus
00152 # define NULL (0L)
00153 # else
00154 # define NULL ((void*) 0)
00155 # endif
00156 #endif
00157
00158 #ifndef FALSE
00159 #define FALSE (0)
00160 #endif
00161
00162 #ifndef TRUE
00163 #define TRUE (!FALSE)
00164 #endif
00165
00166 #undef MAX
00167 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
00168
00169 #undef MIN
00170 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
00171
00172 #undef ABS
00173 #define ABS(a) (((a) < 0) ? -(a) : (a))
00174
00175 #undef CLAMP
00176 #define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
00177
00178
00179
00180
00181
00182 #define G_N_ELEMENTS(arr) (sizeof (arr) / sizeof ((arr)[0]))
00183
00184
00185
00186 #define GPOINTER_TO_SIZE(p) ((gsize) (p))
00187 #define GSIZE_TO_POINTER(s) ((gpointer) (gsize) (s))
00188
00189
00190
00191
00192 #define G_STRUCT_OFFSET(struct_type, member) \
00193 ((glong) ((guint8*) &((struct_type*) 0)->member))
00194 #define G_STRUCT_MEMBER_P(struct_p, struct_offset) \
00195 ((gpointer) ((guint8*) (struct_p) + (glong) (struct_offset)))
00196 #define G_STRUCT_MEMBER(member_type, struct_p, struct_offset) \
00197 (*(member_type*) G_STRUCT_MEMBER_P ((struct_p), (struct_offset)))
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211 #if !(defined (G_STMT_START) && defined (G_STMT_END))
00212 # if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
00213 # define G_STMT_START (void) __extension__ (
00214 # define G_STMT_END )
00215 # else
00216 # if defined (HAVE_DOWHILE_MACROS)
00217 # define G_STMT_START do
00218 # define G_STMT_END while (0)
00219 # else
00220 # define G_STMT_START if (1)
00221 # define G_STMT_END else (void) 0
00222 # endif
00223 # endif
00224 #endif
00225
00226
00227
00228
00229
00230 #ifdef G_DISABLE_CONST_RETURNS
00231 #define G_CONST_RETURN
00232 #else
00233 #define G_CONST_RETURN const
00234 #endif
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244 #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
00245 #define _G_BOOLEAN_EXPR(expr) \
00246 __extension__ ({ \
00247 int _g_boolean_var_; \
00248 if (expr) \
00249 _g_boolean_var_ = 1; \
00250 else \
00251 _g_boolean_var_ = 0; \
00252 _g_boolean_var_; \
00253 })
00254 #define G_LIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR(expr), 1))
00255 #define G_UNLIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR(expr), 0))
00256 #else
00257 #define G_LIKELY(expr) (expr)
00258 #define G_UNLIKELY(expr) (expr)
00259 #endif
00260
00261 #endif