From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51629) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLyuG-0005DW-JI for qemu-devel@nongnu.org; Wed, 20 Jan 2016 14:59:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aLyuD-0006Gf-Cq for qemu-devel@nongnu.org; Wed, 20 Jan 2016 14:59:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41159) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLyuD-0006Gb-7u for qemu-devel@nongnu.org; Wed, 20 Jan 2016 14:59:01 -0500 References: <1453219845-30939-1-git-send-email-eblake@redhat.com> <1453219845-30939-13-git-send-email-eblake@redhat.com> <87lh7km8de.fsf@blackfin.pond.sub.org> From: Eric Blake Message-ID: <569FE703.10704@redhat.com> Date: Wed, 20 Jan 2016 12:58:59 -0700 MIME-Version: 1.0 In-Reply-To: <87lh7km8de.fsf@blackfin.pond.sub.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="UjD3Vwh6HCCpiKR6PpFAWhlqwOV8qeGdQ" Subject: Re: [Qemu-devel] [PATCH v9 12/37] qapi: Don't cast Enum* to int* List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: marcandre.lureau@redhat.com, qemu-devel@nongnu.org, Michael Roth This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --UjD3Vwh6HCCpiKR6PpFAWhlqwOV8qeGdQ Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 01/20/2016 11:08 AM, Markus Armbruster wrote: > Eric Blake writes: >=20 >> C compilers are allowed to represent enums as a smaller type >> than int, if all enum values fit in the smaller type. There >> are even compiler flags that force the use of this smaller >> representation, and using them changes the ABI of a binary. >=20 > Suggest "although using them". >=20 Okay. >> with generated code changing as: >> >> | void visit_type_GuestDiskBusType(Visitor *v, GuestDiskBusType *obj, = const char *name, Error **errp) >> | { >> |- visit_type_enum(v, (int *)obj, GuestDiskBusType_lookup, "GuestDi= skBusType", name, errp); >> |+ int tmp =3D *obj; >> |+ visit_type_enum(v, &tmp, GuestDiskBusType_lookup, "GuestDiskBusT= ype", name, errp); >> |+ *obj =3D tmp; >> | } >=20 > Long lines. Do we have an example with a shorter enum name handy? Shortest is QType; runner-ups RxState and TpmType. >> void visit_type_%(c_name)s(Visitor *v, %(c_name)s *obj, const char *n= ame, Error **errp) >> { >> - visit_type_enum(v, (int *)obj, %(c_name)s_lookup, "%(name)s", nam= e, errp); >> + int tmp =3D *obj; >> + visit_type_enum(v, &tmp, %(c_name)s_lookup, "%(name)s", name, err= p); >> + *obj =3D tmp; >> } >> ''', >> c_name=3Dc_name(name), name=3Dname) >=20 > Same pattern in qapi-visit-core.c, except we name the variable @value > there. Your choice. 'value' sounds consistent. An easy swap on a respin. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --UjD3Vwh6HCCpiKR6PpFAWhlqwOV8qeGdQ 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/ iQEcBAEBCAAGBQJWn+cDAAoJEKeha0olJ0NqaOgH/isg0x9Z84rflfE2OWIhJUa0 NalHV5hl8spnOqqdYMkMpoRVXZqC6kQ+c2P3P7A36ZiJW77QqeH++/TGAqXsbPMQ u0hXWFYuV7C+Rkd2D5mHvmkKl8bcEooz7aPG4z9qNrc8ztAT5ZTCwGWxFQ2f5G79 RMwF6+ISmwrTR5XEhETNlCDvHVq2yae/2h+EfjNi4Hrz6hVc2+3MKUB6u7SsUG/r Wly7uzO5wYtMTc01HqnnHOcYD34mOsZYjnI8RQn3EFcxtY1233AkgIk9O3RpnJ6p G96KpfrnNQE2dS0EU95SQgTUxaBKSHjyoGn0RRbvMVkL8JU0uoW0ska08WgL1RM= =U/rP -----END PGP SIGNATURE----- --UjD3Vwh6HCCpiKR6PpFAWhlqwOV8qeGdQ--