Received: from eggs.gnu.org ([2001:4830:134:3::10]:47659) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMBEO-00059j-RN for qemu-devel@nongnu.org; Thu, 21 Jan 2016 04:08:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aMBEK-0004kd-Nj for qemu-devel@nongnu.org; Thu, 21 Jan 2016 04:08:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38369) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMBEK-0004kT-I7 for qemu-devel@nongnu.org; Thu, 21 Jan 2016 04:08:36 -0500 From: Markus Armbruster 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> <569FE703.10704@redhat.com> Date: Thu, 21 Jan 2016 10:08:33 +0100 In-Reply-To: <569FE703.10704@redhat.com> (Eric Blake's message of "Wed, 20 Jan 2016 12:58:59 -0700") Message-ID: <871t9bnvu6.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain 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: Eric Blake Cc: marcandre.lureau@redhat.com, qemu-devel@nongnu.org, Michael Roth Eric Blake writes: > On 01/20/2016 11:08 AM, Markus Armbruster wrote: >> Eric Blake writes: >> >>> 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. >> >> Suggest "although using them". >> > > 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, "GuestDiskBusType", name, errp); >>> |+ int tmp = *obj; >>> |+ visit_type_enum(v, &tmp, GuestDiskBusType_lookup, "GuestDiskBusType", name, errp); >>> |+ *obj = tmp; >>> | } >> >> Long lines. Do we have an example with a shorter enum name handy? > > Shortest is QType; runner-ups RxState and TpmType. QType comes out okay: | void visit_type_QType(Visitor *v, QType *obj, const char *name, Error **errp) | { |- visit_type_enum(v, (int *)obj, QType_lookup, "QType", name, errp); |+ int tmp = *obj; |+ visit_type_enum(v, &tmp, QType_lookup, "QType", name, errp); |+ *obj = tmp; | } Let's use it. >>> void visit_type_%(c_name)s(Visitor *v, %(c_name)s *obj, const char *name, Error **errp) >>> { >>> - visit_type_enum(v, (int *)obj, %(c_name)s_lookup, "%(name)s", name, errp); >>> + int tmp = *obj; >>> + visit_type_enum(v, &tmp, %(c_name)s_lookup, "%(name)s", name, errp); >>> + *obj = tmp; >>> } >>> ''', >>> c_name=c_name(name), name=name) >> >> 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. Okay.