[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH RFC v2 22/47] qapi: QAPISchema code generation h
From: |
Markus Armbruster |
Subject: |
Re: [Qemu-devel] [PATCH RFC v2 22/47] qapi: QAPISchema code generation helper methods |
Date: |
Fri, 31 Jul 2015 16:00:23 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) |
Eric Blake <address@hidden> writes:
> On 07/27/2015 03:54 AM, Markus Armbruster wrote:
>> Eric Blake <address@hidden> writes:
>>
>>> On 07/01/2015 02:22 PM, Markus Armbruster wrote:
>>>> New methods c_name(), c_type(), c_null(), json_type(),
>>>> alternate_qtype().
>>>>
>>>> Signed-off-by: Markus Armbruster <address@hidden>
>>>> ---
>>>> scripts/qapi.py | 72
>>>> +++++++++++++++++++++++++++++++++++++++++++++++++++------
>>>> 1 file changed, 65 insertions(+), 7 deletions(-)
>>>>
>>>
>>> I just noticed:
>>>
>>>> @@ -779,6 +811,12 @@ class QAPISchemaEnumType(QAPISchemaType):
>>>> for v in values:
>>>> assert isinstance(v, str)
>>>> self.values = values
>>>> + def c_type(self, is_param=False):
>>>> + return c_name(self.name)
>>>> + def c_null(self):
>>>> + return c_enum_const(self.name, self.values[0])
>>>
>>> What does this return for an empty enum, as in { 'enum':'Empty',
>>> 'data':[] }?
>>
>> I suspect self.values will be [] then, and self.values[0] will bomb.
>>
>> Possible fixes:
>>
>> * Outlaw empty enums
>>
>> * Add the implicit MAX member to self.values[] (other code may have to
>> skip it)
>>
>> * Catch the special case here, and return the implicit MAX member.
>
> I'm leaning toward the third option here.
Me too now, because it's easy:
return c_enum_const(self.name, (self.values + [ 'MAX' ])[0])
>>> Our testsuite proves we can do that, even if our normal
>>> .json code doesn't use it.
>>
>> tests/qapi-schema/enum-empty.json:{ 'enum': 'MyEnum', 'data': [ ] }
>
> As I've mentioned elsewhere, most of our tests/qapi-schema/*.json merely
> cover whether the parser is okay with the input, while
> tests/qapi-schema/qapi-schema-test.json is the one that also tests that
> the generated C code works; so sounds like that test should be enhanced
> to cover some of these corner cases we have been considering in this
> series (empty enum, command with no arguments and no returns, and so forth).
Yes, that would be nice, but I feel I have to leave it for another day.
- [Qemu-devel] [PATCH RFC v2 23/47] qapi: New QAPISchemaVisitor, (continued)
[Qemu-devel] [PATCH RFC v2 30/47] qapi: De-duplicate enum code generation, Markus Armbruster, 2015/07/01
[Qemu-devel] [PATCH RFC v2 34/47] qapi-visit: Rearrange code a bit, Markus Armbruster, 2015/07/01
[Qemu-devel] [PATCH RFC v2 26/47] qapi-types: Convert to QAPISchemaVisitor, fixing flat unions, Markus Armbruster, 2015/07/01