[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v9 12/37] qapi: Don't cast Enum* to int*
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH v9 12/37] qapi: Don't cast Enum* to int* |
Date: |
Wed, 20 Jan 2016 12:58:59 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 |
On 01/20/2016 11:08 AM, Markus Armbruster wrote:
> Eric Blake <address@hidden> 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.
>> 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.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
- Re: [Qemu-devel] [PATCH v9 01/37] qobject: Document more shortcomings in our number handling, (continued)
[Qemu-devel] [PATCH v9 13/37] qom: Use typedef for Visitor, Eric Blake, 2016/01/19
[Qemu-devel] [PATCH v9 02/37] qapi: Avoid use of misnamed DO_UPCAST(), Eric Blake, 2016/01/19
[Qemu-devel] [PATCH v9 12/37] qapi: Don't cast Enum* to int*, Eric Blake, 2016/01/19
[Qemu-devel] [PATCH v9 10/37] qapi: Make all visitors supply uint64 callbacks, Eric Blake, 2016/01/19
[Qemu-devel] [PATCH v9 11/37] qapi: Consolidate visitor small integer callbacks, Eric Blake, 2016/01/19