From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41864) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZKBgy-0001t2-9B for qemu-devel@nongnu.org; Tue, 28 Jul 2015 16:41:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZKBgv-0004XW-Dm for qemu-devel@nongnu.org; Tue, 28 Jul 2015 16:41:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40671) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZKBgv-0004XO-6m for qemu-devel@nongnu.org; Tue, 28 Jul 2015 16:41:37 -0400 References: <1435782155-31412-1-git-send-email-armbru@redhat.com> <1435782155-31412-28-git-send-email-armbru@redhat.com> <55B6A40A.8070400@redhat.com> <874mkopyrj.fsf@blackfin.pond.sub.org> From: Eric Blake Message-ID: <55B7E8F7.6030604@redhat.com> Date: Tue, 28 Jul 2015 14:41:27 -0600 MIME-Version: 1.0 In-Reply-To: <874mkopyrj.fsf@blackfin.pond.sub.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="EwGjCTJNB5jevmnMLd56Kk8COVguVLDMi" Subject: Re: [Qemu-devel] [PATCH RFC v2 27/47] qapi-visit: Convert to QAPISchemaVisitor, fixing bugs List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: kwolf@redhat.com, berto@igalia.com, qemu-devel@nongnu.org, mdroth@linux.vnet.ibm.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --EwGjCTJNB5jevmnMLd56Kk8COVguVLDMi Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 07/28/2015 12:44 AM, Markus Armbruster wrote: >> >>> +def gen_visit_union(name, base, variants): >>> + ret =3D '' >>> =20 >>> if base: >>> - assert discriminator >>> - base_fields =3D find_struct(base)['data'].copy() >>> - del base_fields[discriminator] >>> - ret +=3D generate_visit_struct_fields(name, base_fields) >>> + members =3D [m for m in base.members if m !=3D variants.tag_= member] >>> + ret +=3D generate_visit_struct_fields(name, members) >> >> Ouch. This hurts. If the same class is used as both the base class of= a >> flat union, and the base class of an ordinary struct, then the struct >> tries to visit the base class, but no longer parses the field that the= >> union was using as its discriminator. >> >> We don't have any code that demonstrates this, but probably should. I= >> ran into it while working up my POC of what it would take to unbox >> inherited structs (http://thread.gmane.org/gmane.comp.emulators.qemu/3= 53204) >=20 > Is this broken in master, or do my patches break it? >=20 > Got a reproducer? Turns out I'm mistaken; we got lucky. The call to generate_visit_struct_fields() creates a function for 'name' (aka the union name), and not for 'base' (aka the class name that owns the fields). So even if we have Base as a common struct between Child and Union, the code emitted for Child generates visit_Base_fields(), while the code emitted for Union generates visit_Union_fields(). So there is no reproducer, but _only_ as long as we reject unions as a base class for any other object. And there is redundancy: we could reuse visit_Base_fields() for the sake of the union, then avoid (re-)visiting the discriminator, and we would no longer need to emit visit_Union_fields(). But I can do that as part of the followup cleanups; since I don't see anything broken with your patch, we don't have to worry about it during this series. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --EwGjCTJNB5jevmnMLd56Kk8COVguVLDMi Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJVt+j3AAoJEKeha0olJ0NqoVwH/jAcDu+YWxaxyV8Y/qQ8NHm5 m/dNG5gJyEjqn4QpskFWn9riNnlXfW/p6u1UuDc45n4ZztIT3Bp/J9Nd8L8xhSwv 1iBbGW+ivx0JMq9xNKq1eQAuW5eJerAKD+gYgTHAgunGwK3DtvRZPooe6CYZU5Qo 7T+4GgCY7scRvlP5+Of+Ip2V5DBkid0tG1VN3RMFBy65nvdB5hqtvRubenDj7jfv +zQtx/gh00hRrO+PWoEzT2jB3csZMYSKT7SA6NVsg0+8xphbWoEYpnqxB3/sUB1t TEMMMtSubAoRH6MIJXaMGWXp/1pR1nfFmj4z6Jxl61ZkEefbisc9AWc2nDVq8P4= =7uzZ -----END PGP SIGNATURE----- --EwGjCTJNB5jevmnMLd56Kk8COVguVLDMi--