From b3435c6a05ecee58c64dce669ce7e44f829afc98 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Thu, 18 Mar 2010 15:21:29 +0000 Subject: Add debugging macros Similarly to what GTK+ and Clutter do, we can use macros that evaluate to nothing if JSON_ENABLE_DEBUG is disabled; they evaluate to messages when the JSON_DEBUG environment variable is set to a debug domain. --- json-glib/json-debug.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 json-glib/json-debug.h (limited to 'json-glib/json-debug.h') diff --git a/json-glib/json-debug.h b/json-glib/json-debug.h new file mode 100644 index 0000000..dc0d861 --- /dev/null +++ b/json-glib/json-debug.h @@ -0,0 +1,45 @@ +#ifndef __JSON_DEBUG_H__ +#define __JSON_DEBUG_H__ + +#include + +G_BEGIN_DECLS + +typedef enum { + JSON_DEBUG_PARSER = 1 << 0 +} JsonDebugFlags; + +#ifdef JSON_ENABLE_DEBUG + +# ifdef __GNUC__ + +# define JSON_NOTE(type,x,a...) G_STMT_START { \ + if (_json_get_debug_flags () & JSON_DEBUG_##type) { \ + g_message ("[" #type "] " G_STRLOC ": " x, ##a); \ + } } G_STMT_END + +# else +/* Try the C99 version; unfortunately, this does not allow us to pass + * empty arguments to the macro, which means we have to + * do an intemediate printf. + */ +# define JSON_NOTE(type,...) G_STMT_START { \ + if (_json_get_debug_flags () & JSON_DEBUG_##type) { \ + gchar * _fmt = g_strdup_printf (__VA_ARGS__); \ + g_message ("[" #type "] " G_STRLOC ": %s",_fmt); \ + g_free (_fmt); \ + } } G_STMT_END + +# endif /* __GNUC__ */ + +#else + +#define JSON_NOTE(type,...) G_STMT_START { } G_STMT_END + +#endif /* JSON_ENABLE_DEBUG */ + +JsonDebugFlags _json_get_debug_flags (void); + +G_END_DECLS + +#endif /* __JSON_DEBUG_H__ */ -- cgit v1.2.1