[glib] Use G_STMT_START/END in gtestutils
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Use G_STMT_START/END in gtestutils
- Date: Wed, 14 Jan 2015 15:24:26 +0000 (UTC)
commit be0c9e507a59aec5655a1c109adb3b0a588e2502
Author: Paolo Borelli <pborelli gnome org>
Date: Tue Jan 13 13:19:58 2015 +0100
Use G_STMT_START/END in gtestutils
glib/gtestutils.h | 72 +++++++++++++++++++++++++++++++++--------------------
1 files changed, 45 insertions(+), 27 deletions(-)
---
diff --git a/glib/gtestutils.h b/glib/gtestutils.h
index 95e6de1..6e1d786 100644
--- a/glib/gtestutils.h
+++ b/glib/gtestutils.h
@@ -38,57 +38,75 @@ typedef void (*GTestFixtureFunc) (gpointer fixture,
gconstpointer user_data);
/* assertion API */
-#define g_assert_cmpstr(s1, cmp, s2) do { const char *__s1 = (s1), *__s2 = (s2); \
+#define g_assert_cmpstr(s1, cmp, s2) G_STMT_START { \
+ const char *__s1 = (s1), *__s2 = (s2); \
if (g_strcmp0 (__s1, __s2) cmp 0) ; else \
g_assertion_message_cmpstr (G_LOG_DOMAIN, __FILE__, __LINE__,
G_STRFUNC, \
- #s1 " " #cmp " " #s2, __s1, #cmp, __s2); } while (0)
-#define g_assert_cmpint(n1, cmp, n2) do { gint64 __n1 = (n1), __n2 = (n2); \
+ #s1 " " #cmp " " #s2, __s1, #cmp, __s2); \
+ } G_STMT_END
+#define g_assert_cmpint(n1, cmp, n2) G_STMT_START { \
+ gint64 __n1 = (n1), __n2 = (n2); \
if (__n1 cmp __n2) ; else \
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__,
G_STRFUNC, \
- #n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'i'); } while (0)
-#define g_assert_cmpuint(n1, cmp, n2) do { guint64 __n1 = (n1), __n2 = (n2); \
+ #n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'i'); \
+ } G_STMT_END
+#define g_assert_cmpuint(n1, cmp, n2) G_STMT_START { \
+ guint64 __n1 = (n1), __n2 = (n2); \
if (__n1 cmp __n2) ; else \
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__,
G_STRFUNC, \
- #n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'i'); } while (0)
-#define g_assert_cmphex(n1, cmp, n2) do { guint64 __n1 = (n1), __n2 = (n2); \
+ #n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'i'); \
+ } G_STMT_END
+#define g_assert_cmphex(n1, cmp, n2) G_STMT_START {\
+ guint64 __n1 = (n1), __n2 = (n2); \
if (__n1 cmp __n2) ; else \
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__,
G_STRFUNC, \
- #n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'x'); } while (0)
-#define g_assert_cmpfloat(n1,cmp,n2) do { long double __n1 = (n1), __n2 = (n2); \
+ #n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'x'); \
+ } G_STMT_END
+#define g_assert_cmpfloat(n1,cmp,n2) G_STMT_START { \
+ long double __n1 = (n1), __n2 = (n2); \
if (__n1 cmp __n2) ; else \
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__,
G_STRFUNC, \
- #n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'f'); } while (0)
-#define g_assert_no_error(err) do { if (err) \
+ #n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'f'); \
+ } G_STMT_END
+#define g_assert_no_error(err) G_STMT_START { \
+ if (err) \
g_assertion_message_error (G_LOG_DOMAIN, __FILE__, __LINE__,
G_STRFUNC, \
- #err, err, 0, 0); } while (0)
-#define g_assert_error(err, dom, c) do { if (!err || (err)->domain != dom || (err)->code != c) \
+ #err, err, 0, 0); \
+ } G_STMT_END
+#define g_assert_error(err, dom, c) G_STMT_START { \
+ if (!err || (err)->domain != dom || (err)->code != c) \
g_assertion_message_error (G_LOG_DOMAIN, __FILE__, __LINE__,
G_STRFUNC, \
- #err, err, dom, c); } while (0)
-#define g_assert_true(expr) do { if G_LIKELY (expr) ; else \
+ #err, err, dom, c); \
+ } G_STMT_END
+#define g_assert_true(expr) G_STMT_START { \
+ if G_LIKELY (expr) ; else \
g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__,
G_STRFUNC, \
"'" #expr "' should be TRUE"); \
- } while (0)
-#define g_assert_false(expr) do { if G_LIKELY (!(expr)) ; else \
+ } G_STMT_END
+#define g_assert_false(expr) G_STMT_START { \
+ if G_LIKELY (!(expr)) ; else \
g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__,
G_STRFUNC, \
"'" #expr "' should be FALSE"); \
- } while (0)
-#define g_assert_null(expr) do { if G_LIKELY ((expr) == NULL) ; else \
+ } G_STMT_END
+#define g_assert_null(expr) G_STMT_START { if G_LIKELY ((expr) == NULL) ; else \
g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__,
G_STRFUNC, \
"'" #expr "' should be NULL"); \
- } while (0)
-#define g_assert_nonnull(expr) do { if G_LIKELY ((expr) != NULL) ; else \
+ } G_STMT_END
+#define g_assert_nonnull(expr) G_STMT_START { \
+ if G_LIKELY ((expr) != NULL) ; else \
g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__,
G_STRFUNC, \
"'" #expr "' should not be NULL"); \
- } while (0)
+ } G_STMT_END
#ifdef G_DISABLE_ASSERT
-#define g_assert_not_reached() do { (void) 0; } while (0)
-#define g_assert(expr) do { (void) 0; } while (0)
+#define g_assert_not_reached() G_STMT_START { (void) 0; } G_STMT_END
+#define g_assert(expr) G_STMT_START { (void) 0; } G_STMT_END
#else /* !G_DISABLE_ASSERT */
-#define g_assert_not_reached() do { g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__,
G_STRFUNC, NULL); } while (0)
-#define g_assert(expr) do { if G_LIKELY (expr) ; else \
+#define g_assert_not_reached() G_STMT_START { g_assertion_message_expr (G_LOG_DOMAIN, __FILE__,
__LINE__, G_STRFUNC, NULL); } G_STMT_END
+#define g_assert(expr) G_STMT_START { \
+ if G_LIKELY (expr) ; else \
g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__,
G_STRFUNC, \
#expr); \
- } while (0)
+ } G_STMT_END
#endif /* !G_DISABLE_ASSERT */
GLIB_AVAILABLE_IN_ALL
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]