From patchwork Tue Feb 16 23:39:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 8333151 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9904BC02AA for ; Tue, 16 Feb 2016 23:39:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D2987202F0 for ; Tue, 16 Feb 2016 23:39:47 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id ECF82202AE for ; Tue, 16 Feb 2016 23:39:46 +0000 (UTC) Received: from localhost ([::1]:51816 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVpDe-0007K4-4N for patchwork-qemu-devel@patchwork.kernel.org; Tue, 16 Feb 2016 18:39:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43133) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVpDX-0007JI-5v for qemu-devel@nongnu.org; Tue, 16 Feb 2016 18:39:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aVpDT-00009U-W2 for qemu-devel@nongnu.org; Tue, 16 Feb 2016 18:39:39 -0500 Received: from resqmta-po-11v.sys.comcast.net ([2001:558:fe16:19:96:114:154:170]:49991) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVpDT-00009Q-Oi for qemu-devel@nongnu.org; Tue, 16 Feb 2016 18:39:35 -0500 Received: from resomta-po-17v.sys.comcast.net ([96.114.154.241]) by resqmta-po-11v.sys.comcast.net with comcast id KBfJ1s0055Clt1L01BfZDf; Tue, 16 Feb 2016 23:39:33 +0000 Received: from red.redhat.com ([24.10.254.122]) by resomta-po-17v.sys.comcast.net with comcast id KBfV1s00D2fD5rL01BfZgd; Tue, 16 Feb 2016 23:39:33 +0000 From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 16 Feb 2016 16:39:25 -0700 Message-Id: <1455665965-27638-1-git-send-email-eblake@redhat.com> X-Mailer: git-send-email 2.5.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1455665973; bh=avAHS4F1yvkLKSCo+6qALXstDg3DlNcqzoL3oSDlDec=; h=Received:Received:From:To:Subject:Date:Message-Id; b=g/6BpiGwD4a1BlgvAza9ocsTjezGxCnV29tHCzSD8L7lAVl1TZ8SC7I2j2FN+h+F1 eFAr3zUS5lBoSO8A/bFoqE+hzP5fcZzmH4pDGlZDqp3Okir4AmLzqXzg6Kgcoj92pV Pob7nT25Ylla4EUrPru8qlYzABYHWpgXkM5TQM4vRIQEMZvoQb74Xo/5soFJPgPErb 7a8aupqTTBLFw/T1siE94PecjbTvyY6pa+0779/yiGMrC6DVU48E7Sfm4QCZTUxJr3 WOC1DFUB/fuju8p6RNE8iximVNmNptUTOPPlIeX3eVJUWq1902seP7415l8EUBmLxS cxRQLFZxjZOIg== X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:558:fe16:19:96:114:154:170 Cc: armbru@redhat.com, Michael Roth Subject: [Qemu-devel] [PATCH] qapi-visit: Honor prefix of discriminator enum 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When we added support for a user-specified prefix for an enum type (commit 351d36e), we forgot to teach the qapi-visit code to honor that prefix in the case of using a prefixed enum as the discriminator for a flat union. While there is still some on-list debate on whether we want to keep prefixes, we should at least make it work as long as it is still part of the code base. Reported-by: Daniel P. Berrange Signed-off-by: Eric Blake --- scripts/qapi-visit.py | 3 ++- tests/qapi-schema/qapi-schema-test.json | 9 ++++++--- tests/qapi-schema/qapi-schema-test.out | 7 +++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index 0cc9b08..2bdb5a1 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -293,7 +293,8 @@ void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj, Error case %(case)s: ''', case=c_enum_const(variants.tag_member.type.name, - var.name)) + var.name, + variants.tag_member.type.prefix)) if simple_union_type: ret += mcgen(''' visit_type_%(c_type)s(v, "data", &(*obj)->u.%(c_name)s, &err); diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qapi-schema-test.json index 4b89527..353a34e 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -73,14 +73,17 @@ 'base': 'UserDefZero', 'data': { 'string': 'str', 'enum1': 'EnumOne' } } +{ 'struct': 'UserDefUnionBase2', + 'base': 'UserDefZero', + 'data': { 'string': 'str', 'enum1': 'QEnumTwo' } } + # this variant of UserDefFlatUnion defaults to a union that uses fields with # allocated types to test corner cases in the cleanup/dealloc visitor { 'union': 'UserDefFlatUnion2', - 'base': 'UserDefUnionBase', + 'base': 'UserDefUnionBase2', 'discriminator': 'enum1', 'data': { 'value1' : 'UserDefC', # intentional forward reference - 'value2' : 'UserDefB', - 'value3' : 'UserDefA' } } + 'value2' : 'UserDefB' } } { 'alternate': 'UserDefAlternate', 'data': { 'uda': 'UserDefA', 's': 'str', 'i': 'int' } } diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qapi-schema-test.out index 2c546b7..241aadb 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -121,11 +121,10 @@ object UserDefFlatUnion case value2: UserDefB case value3: UserDefB object UserDefFlatUnion2 - base UserDefUnionBase + base UserDefUnionBase2 tag enum1 case value1: UserDefC case value2: UserDefB - case value3: UserDefA object UserDefNativeListUnion member type: UserDefNativeListUnionKind optional=False case integer: :obj-intList-wrapper @@ -167,6 +166,10 @@ object UserDefUnionBase base UserDefZero member string: str optional=False member enum1: EnumOne optional=False +object UserDefUnionBase2 + base UserDefZero + member string: str optional=False + member enum1: QEnumTwo optional=False object UserDefZero member integer: int optional=False event __ORG.QEMU_X-EVENT __org.qemu_x-Struct