From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49322) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZoK0w-00027Z-P8 for qemu-devel@nongnu.org; Mon, 19 Oct 2015 19:38:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZoK0t-00024p-JJ for qemu-devel@nongnu.org; Mon, 19 Oct 2015 19:38:50 -0400 Received: from e39.co.us.ibm.com ([32.97.110.160]:49864) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZoK0p-00024G-E0 for qemu-devel@nongnu.org; Mon, 19 Oct 2015 19:38:47 -0400 Received: from localhost by e39.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 19 Oct 2015 17:38:42 -0600 Received: from b03cxnp07029.gho.boulder.ibm.com (b03cxnp07029.gho.boulder.ibm.com [9.17.130.16]) by d03dlp03.boulder.ibm.com (Postfix) with ESMTP id 07B8019D803F for ; Mon, 19 Oct 2015 17:26:50 -0600 (MDT) Received: from d03av01.boulder.ibm.com (d03av01.boulder.ibm.com [9.17.195.167]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t9JNcd7u11469082 for ; Mon, 19 Oct 2015 16:38:39 -0700 Received: from d03av01.boulder.ibm.com (localhost [127.0.0.1]) by d03av01.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t9JNccAj025220 for ; Mon, 19 Oct 2015 17:38:39 -0600 From: Michael Roth Date: Mon, 19 Oct 2015 18:38:11 -0500 Message-Id: <1445297899-20527-7-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1445297899-20527-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1445297899-20527-1-git-send-email-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PULL v4 06/14] glib-compat: add 2.38/2.40/2.46 asserts List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Michael Roth , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= From: Marc-André Lureau Those are mostly useful for writing tests. Signed-off-by: Marc-André Lureau Reviewed-by: Claudio Fontana Signed-off-by: Michael Roth --- include/glib-compat.h | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/include/glib-compat.h b/include/glib-compat.h index 318e000..fb25f43 100644 --- a/include/glib-compat.h +++ b/include/glib-compat.h @@ -165,4 +165,65 @@ static inline GThread *g_thread_new(const char *name, #define CompatGCond GCond #endif /* glib 2.31 */ +#ifndef g_assert_true +#define g_assert_true(expr) \ + do { \ + if (G_LIKELY(expr)) { \ + } else { \ + g_assertion_message(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ + "'" #expr "' should be TRUE"); \ + } \ + } while (0) +#endif + +#ifndef g_assert_false +#define g_assert_false(expr) \ + do { \ + if (G_LIKELY(!(expr))) { \ + } else { \ + g_assertion_message(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ + "'" #expr "' should be FALSE"); \ + } \ + } while (0) +#endif + +#ifndef g_assert_null +#define g_assert_null(expr) \ + do { \ + if (G_LIKELY((expr) == NULL)) { \ + } else { \ + g_assertion_message(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ + "'" #expr "' should be NULL"); \ + } \ + } while (0) +#endif + +#ifndef g_assert_nonnull +#define g_assert_nonnull(expr) \ + do { \ + if (G_LIKELY((expr) != NULL)) { \ + } else { \ + g_assertion_message(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ + "'" #expr "' should not be NULL"); \ + } \ + } while (0) +#endif + +#ifndef g_assert_cmpmem +#define g_assert_cmpmem(m1, l1, m2, l2) \ + do { \ + gconstpointer __m1 = m1, __m2 = m2; \ + int __l1 = l1, __l2 = l2; \ + if (__l1 != __l2) { \ + g_assertion_message_cmpnum( \ + G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ + #l1 " (len(" #m1 ")) == " #l2 " (len(" #m2 "))", __l1, "==", \ + __l2, 'i'); \ + } else if (memcmp(__m1, __m2, __l1) != 0) { \ + g_assertion_message(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ + "assertion failed (" #m1 " == " #m2 ")"); \ + } \ + } while (0) +#endif + #endif -- 1.9.1