summaryrefslogtreecommitdiff
path: root/json-glib/json-debug.h
blob: 20f22c66e840f743519e77a6f13833477f1c07c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef __JSON_DEBUG_H__
#define __JSON_DEBUG_H__

#include <glib.h>

G_BEGIN_DECLS

typedef enum {
  JSON_DEBUG_PARSER  = 1 << 0,
  JSON_DEBUG_GOBJECT = 1 << 1
} 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__ */