From patchwork Mon Feb 10 21:48:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 319125 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 659DF2C0097 for ; Tue, 11 Feb 2014 16:52:21 +1100 (EST) Received: from localhost ([::1]:59590 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WD6GY-0007Wu-RZ for incoming@patchwork.ozlabs.org; Tue, 11 Feb 2014 00:52:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41094) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WD6Dl-0003Bj-Hj for qemu-devel@nongnu.org; Tue, 11 Feb 2014 00:49:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WD6Dc-0003rf-LJ for qemu-devel@nongnu.org; Tue, 11 Feb 2014 00:49:25 -0500 Received: from e28smtp09.in.ibm.com ([122.248.162.9]:34064) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WD6Dc-0003r5-0z for qemu-devel@nongnu.org; Tue, 11 Feb 2014 00:49:16 -0500 Received: from /spool/local by e28smtp09.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 11 Feb 2014 11:19:13 +0530 Received: from d28dlp03.in.ibm.com (9.184.220.128) by e28smtp09.in.ibm.com (192.168.1.139) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 11 Feb 2014 11:19:11 +0530 Received: from d28relay04.in.ibm.com (d28relay04.in.ibm.com [9.184.220.61]) by d28dlp03.in.ibm.com (Postfix) with ESMTP id 709391258056 for ; Tue, 11 Feb 2014 11:21:04 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay04.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s1B5nBwQ24707284 for ; Tue, 11 Feb 2014 11:19:11 +0530 Received: from d28av02.in.ibm.com (localhost [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s1B5nABs030917 for ; Tue, 11 Feb 2014 11:19:10 +0530 Received: from RH64wenchao ([9.181.129.59]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id s1B5mvVt030084; Tue, 11 Feb 2014 11:19:09 +0530 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Tue, 11 Feb 2014 05:48:39 +0800 Message-Id: <1392068921-3327-9-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1392068921-3327-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1392068921-3327-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14021105-2674-0000-0000-00000CA81397 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.9 Cc: kwolf@redhat.com, mdroth@linux.vnet.ibm.com, armbru@redhat.com, lcapitulino@redhat.com, Wenchao Xia Subject: [Qemu-devel] [PATCH V6 08/10] qapi script: do not allow string discriminator 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 Signed-off-by: Wenchao Xia --- docs/qapi-code-gen.txt | 8 +++----- scripts/qapi-visit.py | 6 ++++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/qapi-code-gen.txt b/docs/qapi-code-gen.txt index a2e7921..c92add9 100644 --- a/docs/qapi-code-gen.txt +++ b/docs/qapi-code-gen.txt @@ -123,11 +123,9 @@ And it looks like this on the wire: Flat union types avoid the nesting on the wire. They are used whenever a specific field of the base type is declared as the discriminator ('type' is -then no longer generated). The discriminator can be a string field or a -predefined enum field. If it is a string field, a hidden enum type will be -generated as "[UNION_NAME]Kind". If it is an enum field, a compile time check -will be done to verify the correctness. It is recommended to use an enum field. -The above example can then be modified as follows: +then no longer generated). The discriminator should be a predefined enum field, +and a compile time check will be done to verify the correctness. The above +example can then be modified as follows: { 'enum': 'BlockdevDriver', 'data': [ 'raw', 'qcow2' ] } { 'type': 'BlockdevCommonOptions', diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index 3240921..efa7ec3 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -280,6 +280,12 @@ def generate_visit_union(expr): # Use the predefined enum type as discriminator ret = "" discriminator_type_name = enum_define['enum_name'] + elif discriminator: + # Do not allow string discriminator + sys.stderr.write("Discriminator '%s' is not a pre-defined enum " + "type\n" % + discriminator) + sys.exit(1) else: # There will always be a discriminator in the C switch code, by default it # is an enum type generated silently as "'%sKind' % (name)"