From patchwork Tue Feb 16 17:35:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 583582 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 57E5514017E for ; Wed, 17 Feb 2016 04:36:14 +1100 (AEDT) Received: from localhost ([::1]:48736 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVjXo-0008Hc-Fr for incoming@patchwork.ozlabs.org; Tue, 16 Feb 2016 12:36:12 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35632) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVjXS-0007w0-4x for qemu-devel@nongnu.org; Tue, 16 Feb 2016 12:35:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aVjXO-0006Gy-Pd for qemu-devel@nongnu.org; Tue, 16 Feb 2016 12:35:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33157) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVjXO-0006Gs-E5 for qemu-devel@nongnu.org; Tue, 16 Feb 2016 12:35:46 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 0771729AE5 for ; Tue, 16 Feb 2016 17:35:46 +0000 (UTC) Received: from redhat.com (vpn1-4-188.ams2.redhat.com [10.36.4.188]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1GHZeSE007566 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 16 Feb 2016 12:35:44 -0500 Date: Tue, 16 Feb 2016 17:35:40 +0000 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Message-ID: <20160216173540.GG11370@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: armbru@redhat.com Subject: [Qemu-devel] Problem with discriminated unions with enum prefixes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: "Daniel P. Berrange" 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 In my LUKS encryption series, I have a discriminated union for storing options for different encryption formats. See qapi/crypto.json in this file: https://lists.gnu.org/archive/html/qemu-devel/2016-02/msg03187.html You'll notice I have the 'prefix' line for the enum commented out. When I uncomment this, I discovered that the discriminated union visitor does not deal with prefixes. To save having to wade through that big series, here is a quick reproducer Apply that and then try to build and it'll fail with: qapi-visit.c: In function ‘visit_type_QDemo’: qapi-visit.c:7596:10: error: ‘Q_DEMO_TYPE_FOO’ undeclared (first use in this function) case Q_DEMO_TYPE_FOO: ^ qapi-visit.c:7596:10: note: each undeclared identifier is reported only once for each function it appears in qapi-visit.c:7599:10: error: ‘Q_DEMO_TYPE_BAR’ undeclared (first use in this function) case Q_DEMO_TYPE_BAR: ^ The issue is that we used the 'QDEMO_TYPE' custom prefix for generating the enum, but we didn't use the prefix in the union visitor. I know we had had previous discussions with Markus strongly wanting to kill off the support for enum prefixes. So before I waste time trying to fix this union visitor code to handle prefixes, I figure we should decide if we actually want to fix it, or go with Markus' plan to kill custom prefixes on enums. Per previous discussions, I think the ability to have custom prefixes is quite desirable, to get more natural enum constant names. At the end of the day though, the default enum naming is far from the worst bit of QEMU, so I'm not ultimately too bothered either way. We either make custom enum prefixes work everything they need to, or remove them. Regards, Daniel diff --git a/qapi-schema.json b/qapi-schema.json index 8d04897..a58648d 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4083,3 +4083,22 @@ ## { 'enum': 'ReplayMode', 'data': [ 'none', 'record', 'play' ] } + + +{ 'enum': 'QDemoType', + 'prefix': 'QDEMO_TYPE', + 'data': ['foo', 'bar' ] } + +{ 'struct': 'QDemoBase', + 'data': { 'type': 'QDemoType' } } + +{ 'struct': 'QDemoFoo', + 'data': { 'eek': 'int' } } + +{ 'struct': 'QDemoBar', + 'data': { 'wizz': 'str' } } + +{ 'union': 'QDemo', + 'base': 'QDemoBase', + 'discriminator': 'type', + 'data': { 'foo': 'QDemoFoo', 'bar': 'QDemoBar' } }