From patchwork Fri Oct 2 19:09:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 525775 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 02DF9140D80 for ; Sat, 3 Oct 2015 05:47:40 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=en+HK0hV; dkim-atps=neutral Received: from localhost ([::1]:34841 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi6Ir-0005xl-W0 for incoming@patchwork.ozlabs.org; Fri, 02 Oct 2015 15:47:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34442) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi5jX-0007jB-4p for qemu-devel@nongnu.org; Fri, 02 Oct 2015 15:11:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zi5jW-00083a-4B for qemu-devel@nongnu.org; Fri, 02 Oct 2015 15:11:07 -0400 Received: from mail-wi0-x22b.google.com ([2a00:1450:400c:c05::22b]:33199) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi5jV-000835-Q5 for qemu-devel@nongnu.org; Fri, 02 Oct 2015 15:11:05 -0400 Received: by wiclk2 with SMTP id lk2so46731325wic.0 for ; Fri, 02 Oct 2015 12:11:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=LoB2vB/Ghvhc4pdBx9hG9Pm0KPdxmH1ZsanXphnWYoY=; b=en+HK0hVlKpM9xHbNoSuMpJekcHzd0Fd6Fb3sI125fKJCe+tEJ7J2LHZGSQvNLjfDn uBdjYVKzCTepU/7Lle4dKwyoLvPme2R3YFitSwDTQk/KVp8e7fchRWZ+x2bc68FySYBI FUyx4PjKqL+m3L4p9s/ymb3AtmUxtP2zRsc7HnCyNeUAAPPRUsAAjjw39bBSAMZwHctg JR4cL36cItRrcUIZ6q5orCAjMZTvCzb4jz/7WZHdJ8LXV0xWAIX7yLaPd2r6XA6/j/9a icg1bxVNvqbaWyxltxoX5cej9xMlHf8FnOKzzRNaUpDP08SaydHIsRDzRPu6TqEgM7sa mJnA== X-Received: by 10.180.103.167 with SMTP id fx7mr397949wib.89.1443813065267; Fri, 02 Oct 2015 12:11:05 -0700 (PDT) Received: from localhost (bne75-h02-31-39-163-232.dsl.sta.abo.bbox.fr. [31.39.163.232]) by smtp.gmail.com with ESMTPSA id x7sm432858wia.5.2015.10.02.12.11.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Oct 2015 12:11:04 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Fri, 2 Oct 2015 21:09:43 +0200 Message-Id: <1443812991-17356-41-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1443812991-17356-1-git-send-email-marcandre.lureau@redhat.com> References: <1443812991-17356-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::22b Cc: drjones@redhat.com, claudio.fontana@huawei.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, cam@cs.ualberta.ca Subject: [Qemu-devel] [PATCH v5 40/48] glib-compat: add 2.38/2.40/2.46 asserts X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Marc-André Lureau Those are mostly useful for writing tests. Signed-off-by: Marc-André Lureau Reviewed-by: Claudio Fontana --- 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