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 #ifndef __G_MESSAGES_H__
00029 #define __G_MESSAGES_H__
00030
00031 #include <_ansi.h>
00032 #include <stdarg.h>
00033 #include <glib/gtypes.h>
00034 #include <glib/gmacros.h>
00035
00036
00037
00038 #if (__GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96))
00039 #pragma GCC system_header
00040 #endif
00041
00042 G_BEGIN_DECLS
00043
00044
00045
00046 IMPORT_C gsize g_printf_string_upper_bound (const gchar* format,
00047 va_list args);
00048
00049
00050
00051
00052 #define G_LOG_LEVEL_USER_SHIFT (8)
00053
00054
00055
00056 typedef enum
00057 {
00058
00059 G_LOG_FLAG_RECURSION = 1 << 0,
00060 G_LOG_FLAG_FATAL = 1 << 1,
00061
00062
00063 G_LOG_LEVEL_ERROR = 1 << 2,
00064 G_LOG_LEVEL_CRITICAL = 1 << 3,
00065 G_LOG_LEVEL_WARNING = 1 << 4,
00066 G_LOG_LEVEL_MESSAGE = 1 << 5,
00067 G_LOG_LEVEL_INFO = 1 << 6,
00068 G_LOG_LEVEL_DEBUG = 1 << 7,
00069
00070 G_LOG_LEVEL_MASK = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)
00071 } GLogLevelFlags;
00072
00073
00074 #define G_LOG_FATAL_MASK (G_LOG_FLAG_RECURSION | G_LOG_LEVEL_ERROR)
00075
00076 typedef void (*GLogFunc) (const gchar *log_domain,
00077 GLogLevelFlags log_level,
00078 const gchar *message,
00079 gpointer user_data);
00080
00081
00082
00083 IMPORT_C guint g_log_set_handler (const gchar *log_domain,
00084 GLogLevelFlags log_levels,
00085 GLogFunc log_func,
00086 gpointer user_data);
00087 IMPORT_C void g_log_remove_handler (const gchar *log_domain,
00088 guint handler_id);
00089 IMPORT_C void g_log_default_handler (const gchar *log_domain,
00090 GLogLevelFlags log_level,
00091 const gchar *message,
00092 gpointer unused_data);
00093 IMPORT_C GLogFunc g_log_set_default_handler (GLogFunc log_func,
00094 gpointer user_data);
00095 IMPORT_C void g_log (const gchar *log_domain,
00096 GLogLevelFlags log_level,
00097 const gchar *format,
00098 ...) G_GNUC_PRINTF (3, 4);
00099 IMPORT_C void g_logv (const gchar *log_domain,
00100 GLogLevelFlags log_level,
00101 const gchar *format,
00102 va_list args);
00103 IMPORT_C GLogLevelFlags g_log_set_fatal_mask (const gchar *log_domain,
00104 GLogLevelFlags fatal_mask);
00105 IMPORT_C GLogLevelFlags g_log_set_always_fatal (GLogLevelFlags fatal_mask);
00106
00107
00108 void _g_log_fallback_handler (const gchar *log_domain,
00109 GLogLevelFlags log_level,
00110 const gchar *message,
00111 gpointer unused_data) G_GNUC_INTERNAL;
00112
00113
00114 IMPORT_C void g_return_if_fail_warning (const char *log_domain,
00115 const char *pretty_function,
00116 const char *expression);
00117 IMPORT_C void g_assert_warning (const char *log_domain,
00118 const char *file,
00119 const int line,
00120 const char *pretty_function,
00121 const char *expression) G_GNUC_NORETURN;
00122
00123
00124 #ifndef G_LOG_DOMAIN
00125 #define G_LOG_DOMAIN ((gchar*) 0)
00126 #endif
00127 #ifdef G_HAVE_ISO_VARARGS
00128 #define g_error(...) g_log (G_LOG_DOMAIN, \
00129 G_LOG_LEVEL_ERROR, \
00130 __VA_ARGS__)
00131 #define g_message(...) g_log (G_LOG_DOMAIN, \
00132 G_LOG_LEVEL_MESSAGE, \
00133 __VA_ARGS__)
00134 #define g_critical(...) g_log (G_LOG_DOMAIN, \
00135 G_LOG_LEVEL_CRITICAL, \
00136 __VA_ARGS__)
00137 #define g_warning(...) g_log (G_LOG_DOMAIN, \
00138 G_LOG_LEVEL_WARNING, \
00139 __VA_ARGS__)
00140 #define g_debug(...) g_log (G_LOG_DOMAIN, \
00141 G_LOG_LEVEL_DEBUG, \
00142 __VA_ARGS__)
00143 #elif defined(G_HAVE_GNUC_VARARGS)
00144 #define g_error(format...) g_log (G_LOG_DOMAIN, \
00145 G_LOG_LEVEL_ERROR, \
00146 format)
00147 #define g_message(format...) g_log (G_LOG_DOMAIN, \
00148 G_LOG_LEVEL_MESSAGE, \
00149 format)
00150 #define g_critical(format...) g_log (G_LOG_DOMAIN, \
00151 G_LOG_LEVEL_CRITICAL, \
00152 format)
00153 #define g_warning(format...) g_log (G_LOG_DOMAIN, \
00154 G_LOG_LEVEL_WARNING, \
00155 format)
00156 #define g_debug(format...) g_log (G_LOG_DOMAIN, \
00157 G_LOG_LEVEL_DEBUG, \
00158 format)
00159 #else
00160 static void
00161 g_error (const gchar *format,
00162 ...)
00163 {
00164 va_list args;
00165 va_start (args, format);
00166 g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, args);
00167 va_end (args);
00168 }
00169 static void
00170 g_message (const gchar *format,
00171 ...)
00172 {
00173 va_list args;
00174 va_start (args, format);
00175 g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, args);
00176 va_end (args);
00177 }
00178 static void
00179 g_critical (const gchar *format,
00180 ...)
00181 {
00182 va_list args;
00183 va_start (args, format);
00184 g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, format, args);
00185 va_end (args);
00186 }
00187 static void
00188 g_warning (const gchar *format,
00189 ...)
00190 {
00191 va_list args;
00192 va_start (args, format);
00193 g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, args);
00194 va_end (args);
00195 }
00196 static void
00197 g_debug (const gchar *format,
00198 ...)
00199 {
00200 va_list args;
00201 va_start (args, format);
00202 g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format, args);
00203 va_end (args);
00204 }
00205 #endif
00206
00207 typedef void (*GPrintFunc) (const gchar *string);
00208 IMPORT_C void g_print (const gchar *format,
00209 ...) G_GNUC_PRINTF (1, 2);
00210 IMPORT_C GPrintFunc g_set_print_handler (GPrintFunc func);
00211 IMPORT_C void g_printerr (const gchar *format,
00212 ...) G_GNUC_PRINTF (1, 2);
00213 IMPORT_C GPrintFunc g_set_printerr_handler (GPrintFunc func);
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 #ifdef G_DISABLE_ASSERT
00224
00225 #define g_assert(expr) G_STMT_START{ (void)0; }G_STMT_END
00226 #define g_assert_not_reached() G_STMT_START{ (void)0; }G_STMT_END
00227
00228 #else
00229
00230 #ifdef __GNUC__
00231
00232 #define g_assert(expr) G_STMT_START{ \
00233 if G_LIKELY(expr) { } else \
00234 g_assert_warning (G_LOG_DOMAIN, \
00235 __FILE__, \
00236 __LINE__, \
00237 __PRETTY_FUNCTION__, \
00238 #expr); }G_STMT_END
00239
00240 #define g_assert_not_reached() G_STMT_START{ \
00241 g_assert_warning (G_LOG_DOMAIN, \
00242 __FILE__, \
00243 __LINE__, \
00244 __PRETTY_FUNCTION__, \
00245 NULL); }G_STMT_END
00246
00247 #else
00248
00249 #define g_assert(expr) G_STMT_START{ \
00250 if (expr) { } else \
00251 g_log (G_LOG_DOMAIN, \
00252 G_LOG_LEVEL_ERROR, \
00253 "file %s: line %d: assertion failed: (%s)", \
00254 __FILE__, \
00255 __LINE__, \
00256 #expr); }G_STMT_END
00257
00258 #define g_assert_not_reached() G_STMT_START{ \
00259 g_log (G_LOG_DOMAIN, \
00260 G_LOG_LEVEL_ERROR, \
00261 "file %s: line %d: should not be reached", \
00262 __FILE__, \
00263 __LINE__); }G_STMT_END
00264
00265 #endif
00266
00267 #endif
00268
00269
00270 #ifdef G_DISABLE_CHECKS
00271
00272 #define g_return_if_fail(expr) G_STMT_START{ (void)0; }G_STMT_END
00273 #define g_return_val_if_fail(expr,val) G_STMT_START{ (void)0; }G_STMT_END
00274 #define g_return_if_reached() G_STMT_START{ return; }G_STMT_END
00275 #define g_return_val_if_reached(val) G_STMT_START{ return (val); }G_STMT_END
00276
00277 #else
00278
00279 #ifdef __GNUC__
00280
00281 #define g_return_if_fail(expr) G_STMT_START{ \
00282 if G_LIKELY(expr) { } else \
00283 { \
00284 g_return_if_fail_warning (G_LOG_DOMAIN, \
00285 __PRETTY_FUNCTION__, \
00286 #expr); \
00287 return; \
00288 }; }G_STMT_END
00289
00290 #define g_return_val_if_fail(expr,val) G_STMT_START{ \
00291 if G_LIKELY(expr) { } else \
00292 { \
00293 g_return_if_fail_warning (G_LOG_DOMAIN, \
00294 __PRETTY_FUNCTION__, \
00295 #expr); \
00296 return (val); \
00297 }; }G_STMT_END
00298
00299 #define g_return_if_reached() G_STMT_START{ \
00300 g_log (G_LOG_DOMAIN, \
00301 G_LOG_LEVEL_CRITICAL, \
00302 "file %s: line %d (%s): should not be reached", \
00303 __FILE__, \
00304 __LINE__, \
00305 __PRETTY_FUNCTION__); \
00306 return; }G_STMT_END
00307
00308 #define g_return_val_if_reached(val) G_STMT_START{ \
00309 g_log (G_LOG_DOMAIN, \
00310 G_LOG_LEVEL_CRITICAL, \
00311 "file %s: line %d (%s): should not be reached", \
00312 __FILE__, \
00313 __LINE__, \
00314 __PRETTY_FUNCTION__); \
00315 return (val); }G_STMT_END
00316
00317 #else
00318
00319 #define g_return_if_fail(expr) G_STMT_START{ \
00320 if (expr) { } else \
00321 { \
00322 g_log (G_LOG_DOMAIN, \
00323 G_LOG_LEVEL_CRITICAL, \
00324 "file %s: line %d: assertion `%s' failed", \
00325 __FILE__, \
00326 __LINE__, \
00327 #expr); \
00328 return; \
00329 }; }G_STMT_END
00330
00331 #define g_return_val_if_fail(expr, val) G_STMT_START{ \
00332 if (expr) { } else \
00333 { \
00334 g_log (G_LOG_DOMAIN, \
00335 G_LOG_LEVEL_CRITICAL, \
00336 "file %s: line %d: assertion `%s' failed", \
00337 __FILE__, \
00338 __LINE__, \
00339 #expr); \
00340 return (val); \
00341 }; }G_STMT_END
00342
00343 #define g_return_if_reached() G_STMT_START{ \
00344 g_log (G_LOG_DOMAIN, \
00345 G_LOG_LEVEL_CRITICAL, \
00346 "file %s: line %d: should not be reached", \
00347 __FILE__, \
00348 __LINE__); \
00349 return; }G_STMT_END
00350
00351 #define g_return_val_if_reached(val) G_STMT_START{ \
00352 g_log (G_LOG_DOMAIN, \
00353 G_LOG_LEVEL_CRITICAL, \
00354 "file %s: line %d: should not be reached", \
00355 __FILE__, \
00356 __LINE__); \
00357 return (val); }G_STMT_END
00358
00359 #endif
00360
00361 #endif
00362
00363 G_END_DECLS
00364
00365 #endif
00366