diff options
Diffstat (limited to 'json-glib')
-rw-r--r-- | json-glib/json-debug.c | 8 | ||||
-rw-r--r-- | json-glib/json-debug.h | 9 | ||||
-rw-r--r-- | json-glib/json-path.c | 7 |
3 files changed, 16 insertions, 8 deletions
diff --git a/json-glib/json-debug.c b/json-glib/json-debug.c index c0dc2e9..2838542 100644 --- a/json-glib/json-debug.c +++ b/json-glib/json-debug.c @@ -4,8 +4,7 @@ #include "json-debug.h" -static unsigned int json_debug_flags = 0; -static gboolean json_debug_flags_set = FALSE; +static unsigned int json_debug_flags = 0; #ifdef JSON_ENABLE_DEBUG static const GDebugKey json_debug_keys[] = { @@ -16,12 +15,13 @@ static const GDebugKey json_debug_keys[] = { #endif /* JSON_ENABLE_DEBUG */ JsonDebugFlags -_json_get_debug_flags (void) +json_get_debug_flags (void) { #ifdef JSON_ENABLE_DEBUG + static gboolean json_debug_flags_set; const gchar *env_str; - if (json_debug_flags_set) + if (G_LIKELY (json_debug_flags_set)) return json_debug_flags; env_str = g_getenv ("JSON_DEBUG"); diff --git a/json-glib/json-debug.h b/json-glib/json-debug.h index 695917f..03ea96b 100644 --- a/json-glib/json-debug.h +++ b/json-glib/json-debug.h @@ -11,12 +11,14 @@ typedef enum { JSON_DEBUG_PATH = 1 << 2 } JsonDebugFlags; +#define JSON_HAS_DEBUG(flag) (json_get_debug_flags () & JSON_DEBUG_##flag) + #ifdef JSON_ENABLE_DEBUG # ifdef __GNUC__ # define JSON_NOTE(type,x,a...) G_STMT_START { \ - if (_json_get_debug_flags () & JSON_DEBUG_##type) { \ + if (JSON_HAS_DEBUG (type)) { \ g_message ("[" #type "] " G_STRLOC ": " x, ##a); \ } } G_STMT_END @@ -26,7 +28,7 @@ typedef enum { * do an intemediate printf. */ # define JSON_NOTE(type,...) G_STMT_START { \ - if (_json_get_debug_flags () & JSON_DEBUG_##type) { \ + if (JSON_HAS_DEBUG (type)) { \ gchar * _fmt = g_strdup_printf (__VA_ARGS__); \ g_message ("[" #type "] " G_STRLOC ": %s",_fmt); \ g_free (_fmt); \ @@ -40,7 +42,8 @@ typedef enum { #endif /* JSON_ENABLE_DEBUG */ -JsonDebugFlags _json_get_debug_flags (void); +G_GNUC_INTERNAL +JsonDebugFlags json_get_debug_flags (void); G_END_DECLS diff --git a/json-glib/json-path.c b/json-glib/json-path.c index f0f9fc5..6f83c90 100644 --- a/json-glib/json-path.c +++ b/json-glib/json-path.c @@ -329,6 +329,10 @@ json_path_new (void) return g_object_new (JSON_TYPE_PATH, NULL); } +#ifdef JSON_ENABLE_DEBUG +/* used as the function for a g_list_foreach() on a list of PathNode; needs + * a GString as the payload to build the output string + */ static void json_path_foreach_print (gpointer data, gpointer user_data) @@ -388,6 +392,7 @@ json_path_foreach_print (gpointer data, g_string_append (buf, ">"); } +#endif /* JSON_ENABLE_DEBUG */ /** * json_path_compile: @@ -692,7 +697,7 @@ json_path_compile (JsonPath *path, nodes = g_list_reverse (nodes); #ifdef JSON_ENABLE_DEBUG - if (_json_get_debug_flags () & JSON_DEBUG_PATH) + if (JSON_HAS_DEBUG (PATH)) { GString *buf = g_string_new (NULL); |