[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: |
Markus Armbruster |
Subject: |
Re: [Qemu-devel] [PATCH v9 12/37] qapi: Don't cast Enum* to int* |
Date: |
Thu, 21 Jan 2016 10:08:33 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) |
Eric Blake <address@hidden> writes:
> 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.
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.
[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
[Qemu-devel] [PATCH v9 08/37] qapi: Track all failures between visit_start/stop, Eric Blake, 2016/01/19