From patchwork Tue Mar 11 13:41:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 329107 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 9BAA12C00A1 for ; Wed, 12 Mar 2014 00:44:11 +1100 (EST) Received: from localhost ([::1]:55044 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNMyX-0003gq-Gw for incoming@patchwork.ozlabs.org; Tue, 11 Mar 2014 09:44:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41834) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNMw8-0000A4-VO for qemu-devel@nongnu.org; Tue, 11 Mar 2014 09:41:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WNMvy-00067H-TS for qemu-devel@nongnu.org; Tue, 11 Mar 2014 09:41:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33552) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNMvy-000676-K3 for qemu-devel@nongnu.org; Tue, 11 Mar 2014 09:41:30 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s2BDfOaQ028974 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 11 Mar 2014 09:41:25 -0400 Received: from localhost (ovpn-113-134.phx2.redhat.com [10.3.113.134]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s2BDfNNW016527; Tue, 11 Mar 2014 09:41:23 -0400 From: Luiz Capitulino To: peter.maydell@linaro.org Date: Tue, 11 Mar 2014 09:41:02 -0400 Message-Id: <1394545271-27573-3-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1394545271-27573-1-git-send-email-lcapitulino@redhat.com> References: <1394545271-27573-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: qemu-devel@nongnu.org, anthony@codemonkey.ws Subject: [Qemu-devel] [PULL 02/11] qapi script: add check for duplicated key 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: Wenchao Xia It is bad that same key was specified twice, especially when a union has two branches with same condition. This patch can prevent it. Signed-off-by: Wenchao Xia Reviewed-by: Eric Blake Reviewed-by: Markus Armbruster Signed-off-by: Luiz Capitulino --- scripts/qapi.py | 2 ++ tests/Makefile | 3 ++- tests/qapi-schema/duplicate-key.err | 1 + tests/qapi-schema/duplicate-key.exit | 1 + tests/qapi-schema/duplicate-key.json | 2 ++ tests/qapi-schema/duplicate-key.out | 0 6 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 tests/qapi-schema/duplicate-key.err create mode 100644 tests/qapi-schema/duplicate-key.exit create mode 100644 tests/qapi-schema/duplicate-key.json create mode 100644 tests/qapi-schema/duplicate-key.out diff --git a/tests/qapi-schema/duplicate-key.out b/tests/qapi-schema/duplicate-key.out new file mode 100644 index 0000000..e69de29 diff --git a/scripts/qapi.py b/scripts/qapi.py index 023930e..d0e7934 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -116,6 +116,8 @@ class QAPISchema: if self.tok != ':': raise QAPISchemaError(self, 'Expected ":"') self.accept() + if key in expr: + raise QAPISchemaError(self, 'Duplicate key "%s"' % key) expr[key] = self.get_expr(True) if self.tok == '}': self.accept() diff --git a/tests/Makefile b/tests/Makefile index b17d41e..dfe06eb 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -142,7 +142,8 @@ check-qapi-schema-y := $(addprefix tests/qapi-schema/, \ missing-comma-object.json non-objects.json \ qapi-schema-test.json quoted-structural-chars.json \ trailing-comma-list.json trailing-comma-object.json \ - unclosed-list.json unclosed-object.json unclosed-string.json) + unclosed-list.json unclosed-object.json unclosed-string.json \ + duplicate-key.json) GENERATED_HEADERS += tests/test-qapi-types.h tests/test-qapi-visit.h tests/test-qmp-commands.h diff --git a/tests/qapi-schema/duplicate-key.err b/tests/qapi-schema/duplicate-key.err new file mode 100644 index 0000000..0801c6a --- /dev/null +++ b/tests/qapi-schema/duplicate-key.err @@ -0,0 +1 @@ +:2:10: Duplicate key "key" diff --git a/tests/qapi-schema/duplicate-key.exit b/tests/qapi-schema/duplicate-key.exit new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/tests/qapi-schema/duplicate-key.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/duplicate-key.json b/tests/qapi-schema/duplicate-key.json new file mode 100644 index 0000000..1b55d88 --- /dev/null +++ b/tests/qapi-schema/duplicate-key.json @@ -0,0 +1,2 @@ +{ 'key': 'value', + 'key': 'value' }