From patchwork Wed Jun 20 05:34:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 931956 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 419YS30XTSz9s7F for ; Wed, 20 Jun 2018 15:34:43 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 419YS25yDwzF0xF for ; Wed, 20 Jun 2018 15:34:42 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 419YRY626tzF0wf for ; Wed, 20 Jun 2018 15:34:17 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 419YRY3V2tz9s4n; Wed, 20 Jun 2018 15:34:17 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=popple.id.au From: Alistair Popple To: pdbg@lists.ozlabs.org Date: Wed, 20 Jun 2018 15:34:03 +1000 Message-Id: <20180620053409.14538-3-alistair@popple.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180620053409.14538-1-alistair@popple.id.au> References: <20180620053409.14538-1-alistair@popple.id.au> Subject: [Pdbg] [PATCH 2/8] ccan/cppmagic: Fix NONEMPTY macro X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" The original implementation of non-empty will fail to compile if passed an argument of the form 'CPPMAGIC_NONEMPTY((...))'. Add a check for parentheses and return true if passed. Signed-off-by: Alistair Popple --- ccan/cppmagic/cppmagic.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ccan/cppmagic/cppmagic.h b/ccan/cppmagic/cppmagic.h index f1f6868..587fe4e 100644 --- a/ccan/cppmagic/cppmagic.h +++ b/ccan/cppmagic/cppmagic.h @@ -68,9 +68,15 @@ * CPPMAGIC_NONEMPTY(@a, ...) * expand to '1' */ -#define _CPPMAGIC_EOA() 0 +#define CHECK_N(x, n, ...) n +#define CHECK(...) CHECK_N(__VA_ARGS__, , ) +#define PROBE(x) x, 1, +#define IS_PAREN(x, ...) CHECK(IS_PAREN_PROBE x) +#define IS_PAREN_PROBE(...) PROBE(~) + +#define _CPPMAGIC_EOA(a_, ...) 0 #define CPPMAGIC_NONEMPTY(...) \ - CPPMAGIC_NONZERO(CPPMAGIC_1ST(_CPPMAGIC_EOA __VA_ARGS__)()) + CPPMAGIC_NONZERO(CPPMAGIC_1ST(_CPPMAGIC_EOA IS_PAREN(__VA_ARGS__) __VA_ARGS__)()) /** * CPPMAGIC_ISEMPTY - does the macro have no arguments?