From patchwork Wed Feb 28 08:00:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Pettit X-Patchwork-Id: 878983 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ovn.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zrp396rwNz9ryL for ; Wed, 28 Feb 2018 19:03:17 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 259FFE28; Wed, 28 Feb 2018 08:01:58 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id ECBCE9CD for ; Wed, 28 Feb 2018 08:01:53 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 8CF762F0 for ; Wed, 28 Feb 2018 08:01:53 +0000 (UTC) X-Originating-IP: 98.234.50.139 Received: from localhost.localdomain (unknown [98.234.50.139]) (Authenticated sender: jpettit@ovn.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id DCF4341C088 for ; Wed, 28 Feb 2018 09:01:51 +0100 (CET) From: Justin Pettit To: dev@openvswitch.org Date: Wed, 28 Feb 2018 00:00:57 -0800 Message-Id: <1519804863-73126-3-git-send-email-jpettit@ovn.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519804863-73126-1-git-send-email-jpettit@ovn.org> References: <1519804863-73126-1-git-send-email-jpettit@ovn.org> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [shadow 2/8] cmap: Allow CMAP_FOR_EACH to be nested without shadowing variables. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Signed-off-by: Justin Pettit Acked-by: Ben Pfaff --- lib/cmap.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/cmap.h b/lib/cmap.h index 5a72b65bec5e..2427a6293b64 100644 --- a/lib/cmap.h +++ b/lib/cmap.h @@ -233,11 +233,20 @@ struct cmap_cursor { struct cmap_cursor cmap_cursor_start(const struct cmap *); void cmap_cursor_advance(struct cmap_cursor *); -#define CMAP_FOR_EACH(NODE, MEMBER, CMAP) \ - for (struct cmap_cursor cursor__ = cmap_cursor_start(CMAP); \ - CMAP_CURSOR_FOR_EACH__(NODE, &cursor__, MEMBER); \ +/* Generate a unique name for the cursor with the __COUNTER__ macro to + * allow nesting of CMAP_FOR_EACH loops. */ +#define CURSOR_JOIN2(x,y) x##y +#define CURSOR_JOIN(x, y) CURSOR_JOIN2(x,y) +#define CURSOR_NAME CURSOR_JOIN(cursor_, __COUNTER__) + +#define CMAP_FOR_EACH__(NODE, MEMBER, CMAP, CURSOR_NAME) \ + for (struct cmap_cursor CURSOR_NAME = cmap_cursor_start(CMAP); \ + CMAP_CURSOR_FOR_EACH__(NODE, &CURSOR_NAME, MEMBER); \ ) +#define CMAP_FOR_EACH(NODE, MEMBER, CMAP) \ + CMAP_FOR_EACH__(NODE, MEMBER, CMAP, CURSOR_NAME) + static inline struct cmap_node *cmap_first(const struct cmap *); /* Another, less preferred, form of iteration, for use in situations where it