From patchwork Mon Feb 23 16:55:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 442615 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 EA09614017C for ; Tue, 24 Feb 2015 03:56:29 +1100 (AEDT) Received: from localhost ([::1]:44435 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YPwJ2-0006Fj-4f for incoming@patchwork.ozlabs.org; Mon, 23 Feb 2015 11:56:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57313) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YPwIH-0004oN-P6 for qemu-devel@nongnu.org; Mon, 23 Feb 2015 11:55:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YPwIB-0000sf-6W for qemu-devel@nongnu.org; Mon, 23 Feb 2015 11:55:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59166) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YPwIA-0000sY-Pq for qemu-devel@nongnu.org; Mon, 23 Feb 2015 11:55:35 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t1NGtWuT030743 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 23 Feb 2015 11:55:32 -0500 Received: from localhost (ovpn-113-64.phx2.redhat.com [10.3.113.64]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t1NGtWVW020527; Mon, 23 Feb 2015 11:55:32 -0500 From: Luiz Capitulino To: peter.maydell@linaro.org Date: Mon, 23 Feb 2015 11:55:26 -0500 Message-Id: <1424710526-21474-5-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1424710526-21474-1-git-send-email-lcapitulino@redhat.com> References: <1424710526-21474-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: qemu-devel@nongnu.org Subject: [Qemu-devel] [PULL 4/4] qapi-types: add C99 index names to arrays 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: "Michael S. Tsirkin" It's not easy to figure out how monitor translates strings: most QEMU code deals with translated indexes, these are translated using _lookup arrays, so you need to find the array name, and find the appropriate offset. This patch adds C99 indexes to lookup arrays, which makes it possible to find the correct key using simple grep, and see that the matching is correct at a glance. Example: Before: const char *MigrationCapability_lookup[] = { "xbzrle", "rdma-pin-all", "auto-converge", "zero-blocks", NULL, }; After: const char *MigrationCapability_lookup[] = { [MIGRATION_CAPABILITY_XBZRLE] = "xbzrle", [MIGRATION_CAPABILITY_RDMA_PIN_ALL] = "rdma-pin-all", [MIGRATION_CAPABILITY_AUTO_CONVERGE] = "auto-converge", [MIGRATION_CAPABILITY_ZERO_BLOCKS] = "zero-blocks", [MIGRATION_CAPABILITY_MAX] = NULL, }; Signed-off-by: Michael S. Tsirkin Reviewed-by: Eric Blake Signed-off-by: Luiz Capitulino --- scripts/qapi-types.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index 1eb272d..db87218 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -123,16 +123,19 @@ const char *%(name)s_lookup[] = { name=name) i = 0 for value in values: + index = generate_enum_full_value(name, value) ret += mcgen(''' - "%(value)s", + [%(index)s] = "%(value)s", ''', - value=value) + index = index, value = value) + max_index = generate_enum_full_value(name, 'MAX') ret += mcgen(''' - NULL, + [%(max_index)s] = NULL, }; -''') +''', + max_index=max_index) return ret def generate_enum(name, values):