{"id":808728,"url":"http://patchwork.ozlabs.org/api/patches/808728/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20170901153758.8628-2-armbru@redhat.com/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170901153758.8628-2-armbru@redhat.com>","list_archive_url":null,"date":"2017-09-01T15:37:12","name":"[PULL,v2,01/47] qapi: Fix error handling code on alternate conflict","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"46bfa2d0e6271be7097b72feaa14ad94ab91c1a9","submitter":{"id":2645,"url":"http://patchwork.ozlabs.org/api/people/2645/?format=json","name":"Markus Armbruster","email":"armbru@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20170901153758.8628-2-armbru@redhat.com/mbox/","series":[{"id":1049,"url":"http://patchwork.ozlabs.org/api/series/1049/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=1049","date":"2017-09-01T15:37:14","name":"[PULL,v2,01/47] qapi: Fix error handling code on alternate conflict","version":2,"mbox":"http://patchwork.ozlabs.org/series/1049/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/808728/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/808728/checks/","tags":{},"related":[],"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ext-mx06.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx06.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=armbru@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xkNlY5Fscz9t2x\n\tfor <incoming@patchwork.ozlabs.org>;\n\tSat,  2 Sep 2017 01:42:01 +1000 (AEST)","from localhost ([::1]:46393 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dno51-0000wG-QZ\n\tfor incoming@patchwork.ozlabs.org; Fri, 01 Sep 2017 11:41:59 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:51351)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <armbru@redhat.com>) id 1dno1E-0006Vg-8t\n\tfor qemu-devel@nongnu.org; Fri, 01 Sep 2017 11:38:05 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <armbru@redhat.com>) id 1dno1D-0001br-1P\n\tfor qemu-devel@nongnu.org; Fri, 01 Sep 2017 11:38:04 -0400","from mx1.redhat.com ([209.132.183.28]:55824)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <armbru@redhat.com>) id 1dno1C-0001bT-Oh\n\tfor qemu-devel@nongnu.org; Fri, 01 Sep 2017 11:38:02 -0400","from smtp.corp.redhat.com\n\t(int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id C4B8F20B0C\n\tfor <qemu-devel@nongnu.org>; Fri,  1 Sep 2017 15:38:01 +0000 (UTC)","from blackfin.pond.sub.org (ovpn-116-75.ams2.redhat.com\n\t[10.36.116.75])\n\tby smtp.corp.redhat.com (Postfix) with ESMTPS id C014481F9E;\n\tFri,  1 Sep 2017 15:37:59 +0000 (UTC)","by blackfin.pond.sub.org (Postfix, from userid 1000)\n\tid 455EF1138663; Fri,  1 Sep 2017 17:37:58 +0200 (CEST)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com C4B8F20B0C","From":"Markus Armbruster <armbru@redhat.com>","To":"qemu-devel@nongnu.org","Date":"Fri,  1 Sep 2017 17:37:12 +0200","Message-Id":"<20170901153758.8628-2-armbru@redhat.com>","In-Reply-To":"<20170901153758.8628-1-armbru@redhat.com>","References":"<20170901153758.8628-1-armbru@redhat.com>","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.12","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.30]);\n\tFri, 01 Sep 2017 15:38:01 +0000 (UTC)","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","Subject":"[Qemu-devel] [PULL v2 01/47] qapi: Fix error handling code on\n\talternate conflict","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Eduardo Habkost <ehabkost@redhat.com>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"},"content":"From: Eduardo Habkost <ehabkost@redhat.com>\n\nThe conflict check added by commit c0644771 (\"qapi: Reject\nalternates that can't work with keyval_parse()\") doesn't work\nwith the following declaration:\n\n  { 'alternate': 'Alt',\n    'data': { 'one': 'bool',\n              'two': 'str' } }\n\nIt crashes with:\n\n  Traceback (most recent call last):\n    File \"./scripts/qapi-types.py\", line 295, in <module>\n      schema = QAPISchema(input_file)\n    File \"/home/ehabkost/rh/proj/virt/qemu/scripts/qapi.py\", line 1468, in __init__\n      self.exprs = check_exprs(parser.exprs)\n    File \"/home/ehabkost/rh/proj/virt/qemu/scripts/qapi.py\", line 958, in check_exprs\n      check_alternate(expr, info)\n    File \"/home/ehabkost/rh/proj/virt/qemu/scripts/qapi.py\", line 830, in check_alternate\n      % (name, key, types_seen[qtype]))\n  KeyError: 'QTYPE_QSTRING'\n\nThis happens because the previously-seen conflicting member\n('one') can't be found at types_seen[qtype], but at\ntypes_seen['QTYPE_BOOL'].\n\nFix the bug by moving the error check to the same loop that adds\nnew items to types_seen, raising an exception if types_seen[qt]\nis already set.\n\nAdd two additional test cases that can detect the bug.\n\nSigned-off-by: Eduardo Habkost <ehabkost@redhat.com>\nMessage-Id: <20170717180926.14924-1-ehabkost@redhat.com>\nSigned-off-by: Markus Armbruster <armbru@redhat.com>\n---\n scripts/qapi.py                                       | 8 ++++----\n tests/Makefile.include                                | 2 ++\n tests/qapi-schema/alternate-conflict-bool-string.err  | 1 +\n tests/qapi-schema/alternate-conflict-bool-string.exit | 1 +\n tests/qapi-schema/alternate-conflict-bool-string.json | 4 ++++\n tests/qapi-schema/alternate-conflict-bool-string.out  | 0\n tests/qapi-schema/alternate-conflict-num-string.err   | 1 +\n tests/qapi-schema/alternate-conflict-num-string.exit  | 1 +\n tests/qapi-schema/alternate-conflict-num-string.json  | 4 ++++\n tests/qapi-schema/alternate-conflict-num-string.out   | 0\n 10 files changed, 18 insertions(+), 4 deletions(-)\n create mode 100644 tests/qapi-schema/alternate-conflict-bool-string.err\n create mode 100644 tests/qapi-schema/alternate-conflict-bool-string.exit\n create mode 100644 tests/qapi-schema/alternate-conflict-bool-string.json\n create mode 100644 tests/qapi-schema/alternate-conflict-bool-string.out\n create mode 100644 tests/qapi-schema/alternate-conflict-num-string.err\n create mode 100644 tests/qapi-schema/alternate-conflict-num-string.exit\n create mode 100644 tests/qapi-schema/alternate-conflict-num-string.json\n create mode 100644 tests/qapi-schema/alternate-conflict-num-string.out\n\ndiff --git a/tests/qapi-schema/alternate-conflict-num-string.out b/tests/qapi-schema/alternate-conflict-num-string.out\nnew file mode 100644\nindex 0000000000..e69de29bb2","diff":"diff --git a/scripts/qapi.py b/scripts/qapi.py\nindex 8aa2775f12..3693b520da 100644\n--- a/scripts/qapi.py\n+++ b/scripts/qapi.py\n@@ -825,11 +825,11 @@ def check_alternate(expr, info):\n             else:\n                 conflicting.add('QTYPE_QNUM')\n                 conflicting.add('QTYPE_QBOOL')\n-        if conflicting & set(types_seen):\n-            raise QAPISemError(info, \"Alternate '%s' member '%s' can't \"\n-                               \"be distinguished from member '%s'\"\n-                               % (name, key, types_seen[qtype]))\n         for qt in conflicting:\n+            if qt in types_seen:\n+                raise QAPISemError(info, \"Alternate '%s' member '%s' can't \"\n+                                   \"be distinguished from member '%s'\"\n+                                   % (name, key, types_seen[qt]))\n             types_seen[qt] = key\n \n \ndiff --git a/tests/Makefile.include b/tests/Makefile.include\nindex f08b7418f0..00af45ca85 100644\n--- a/tests/Makefile.include\n+++ b/tests/Makefile.include\n@@ -376,6 +376,8 @@ qapi-schema += alternate-conflict-dict.json\n qapi-schema += alternate-conflict-enum-bool.json\n qapi-schema += alternate-conflict-enum-int.json\n qapi-schema += alternate-conflict-string.json\n+qapi-schema += alternate-conflict-bool-string.json\n+qapi-schema += alternate-conflict-num-string.json\n qapi-schema += alternate-empty.json\n qapi-schema += alternate-nested.json\n qapi-schema += alternate-unknown.json\ndiff --git a/tests/qapi-schema/alternate-conflict-bool-string.err b/tests/qapi-schema/alternate-conflict-bool-string.err\nnew file mode 100644\nindex 0000000000..e52fee7620\n--- /dev/null\n+++ b/tests/qapi-schema/alternate-conflict-bool-string.err\n@@ -0,0 +1 @@\n+tests/qapi-schema/alternate-conflict-bool-string.json:2: Alternate 'Alt' member 'two' can't be distinguished from member 'one'\ndiff --git a/tests/qapi-schema/alternate-conflict-bool-string.exit b/tests/qapi-schema/alternate-conflict-bool-string.exit\nnew file mode 100644\nindex 0000000000..d00491fd7e\n--- /dev/null\n+++ b/tests/qapi-schema/alternate-conflict-bool-string.exit\n@@ -0,0 +1 @@\n+1\ndiff --git a/tests/qapi-schema/alternate-conflict-bool-string.json b/tests/qapi-schema/alternate-conflict-bool-string.json\nnew file mode 100644\nindex 0000000000..0544de10f3\n--- /dev/null\n+++ b/tests/qapi-schema/alternate-conflict-bool-string.json\n@@ -0,0 +1,4 @@\n+# alternate branches of 'str' type conflict with all scalar types\n+{ 'alternate': 'Alt',\n+  'data': { 'one': 'bool',\n+            'two': 'str' } }\ndiff --git a/tests/qapi-schema/alternate-conflict-bool-string.out b/tests/qapi-schema/alternate-conflict-bool-string.out\nnew file mode 100644\nindex 0000000000..e69de29bb2\ndiff --git a/tests/qapi-schema/alternate-conflict-num-string.err b/tests/qapi-schema/alternate-conflict-num-string.err\nnew file mode 100644\nindex 0000000000..5ba3827dd1\n--- /dev/null\n+++ b/tests/qapi-schema/alternate-conflict-num-string.err\n@@ -0,0 +1 @@\n+tests/qapi-schema/alternate-conflict-num-string.json:2: Alternate 'Alt' member 'two' can't be distinguished from member 'one'\ndiff --git a/tests/qapi-schema/alternate-conflict-num-string.exit b/tests/qapi-schema/alternate-conflict-num-string.exit\nnew file mode 100644\nindex 0000000000..d00491fd7e\n--- /dev/null\n+++ b/tests/qapi-schema/alternate-conflict-num-string.exit\n@@ -0,0 +1 @@\n+1\ndiff --git a/tests/qapi-schema/alternate-conflict-num-string.json b/tests/qapi-schema/alternate-conflict-num-string.json\nnew file mode 100644\nindex 0000000000..ae901449af\n--- /dev/null\n+++ b/tests/qapi-schema/alternate-conflict-num-string.json\n@@ -0,0 +1,4 @@\n+# alternate branches of 'str' type conflict with all scalar types\n+{ 'alternate': 'Alt',\n+  'data': { 'one': 'number',\n+            'two': 'str' } }\n","prefixes":["PULL","v2","01/47"]}