qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] QAPI and empty structs


From: Eric Blake
Subject: Re: [Qemu-devel] QAPI and empty structs
Date: Tue, 23 Dec 2014 08:54:25 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0

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.

> 
> 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.

> 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.

> 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.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]