[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] QAPI and empty structs
From: |
Markus Armbruster |
Subject: |
Re: [Qemu-devel] QAPI and empty structs |
Date: |
Mon, 12 Jan 2015 16:31:28 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
Eric Blake <address@hidden> writes:
> On 12/23/2014 08:50 AM, Peter Maydell wrote:
>> In qapi-schema.json we have a couple of entries that define
>> empty structures, like this:
>>
>> { 'type': 'ChardevDummy', 'data': { } }
>>
>> In the generated qapi-types.h these are turned into empty C structs:
>>
>
>> Although you could argue that we don't care about differences
>> in C and C++ semantics, having a zero-sized struct floating
>> around seems a bit risky to me, since for instance a naive
>> attempt to g_malloc() space for it will return NULL.
>
> Oh, good point.
Less of an issue than with malloc(), because NULL isn't both an error
and a success value.
>> How should we handle these? Should the qapi-types generator
>> stick a dummy field in so they aren't zero sized?
>
> Sounds like the best plan to me.
I wouldn't bother myself, but if somebody posted working patches, I
wouldn't bother objecting to the idea, either.
>> Are they
>> actually an error in the schema? (what's the point of them?)
>
> No, they are valid - it is how you express a union between a branch that
> needs no additional members compared to any other branch.
Yes.
>> Do we claim that actually all our code correctly handles
>> zero sized structs and just suppress the clang warning?
>
> I'd be fine with adding a dummy member.
The clang warning is for code meant to be compiled both as C and as C++,
i.e. it's of no interest to us. Suppressing it sounds fine to me.
- Re: [Qemu-devel] QAPI and empty structs,
Markus Armbruster <=