2313
|
1 #ifndef DEBUG_H
|
|
2 #define DEBUG_H
|
|
3
|
|
4 #include <glib.h>
|
|
5
|
|
6 #ifdef NDEBUG
|
|
7
|
|
8 /* void REQUIRE_LOCK(GMutex *m); */
|
|
9 # define REQUIRE_LOCK(m)
|
|
10
|
|
11 /* void REQUIRE_STR_UTF8(const gchar *str); */
|
|
12 # define REQUIRE_STR_UTF8(str)
|
|
13
|
|
14 /* void REQUIRE_STATIC_LOCK(GStaticMutex *m); */
|
|
15 # define REQUIRE_STATIC_LOCK(m)
|
|
16
|
|
17 #else /* !NDEBUG */
|
|
18
|
|
19 /* void REQUIRE_LOCK(GMutex *m); */
|
|
20 # define REQUIRE_LOCK(m) G_STMT_START { \
|
|
21 if (g_mutex_trylock(m)) { \
|
|
22 g_critical(G_STRLOC ": Mutex not locked!"); \
|
|
23 g_mutex_unlock(m); \
|
|
24 } \
|
|
25 } G_STMT_END
|
|
26
|
|
27 /* void REQUIRE_STATIC_LOCK(GStaticMutex *m); */
|
|
28 # define REQUIRE_STATIC_LOCK(m) G_STMT_START { \
|
|
29 if (G_TRYLOCK(m)) { \
|
|
30 g_critical(G_STRLOC ": Mutex not locked!"); \
|
|
31 G_UNLOCK(m); \
|
|
32 } \
|
|
33 } G_STMT_END
|
|
34
|
|
35 /* void REQUIRE_STR_UTF8(const gchar *str); */
|
|
36 # define REQUIRE_STR_UTF8(str) G_STMT_START { \
|
|
37 if (!g_utf_validate(str, -1, NULL)) \
|
|
38 g_warning(G_STRLOC ": String is not UTF-8!"); \
|
|
39 } G_STMT_END
|
|
40
|
|
41 #endif /* NDEBUG */
|
|
42
|
|
43
|
|
44 #endif
|