[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] scripts/qapi-types.py: Add dummy member to empt
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH] scripts/qapi-types.py: Add dummy member to empty structs |
Date: |
Tue, 23 Dec 2014 13:04:10 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 |
On 12/23/2014 11:24 AM, Peter Maydell wrote:
> Make sure that all generated C structs have at least one field; this
> avoids potential issues with attempting to malloc space for
> zero-length structs in C (g_malloc(sizeof struct) would return NULL).
> It also avoids an incompatibility with C++ (where an empty struct is
> size 1); that isn't important to us now but might be in future.
>
> Generated empty structures look like this:
> struct Abort
> {
> char qapi_dummy_field_for_empty_struct;
> };
>
> This silences clang warnings like:
> ./qapi-types.h:3752:1: warning: empty struct has size 0 in C, size 1 in C++
> [-Wextern-c-compat]
> struct Abort
> ^
>
> Signed-off-by: Peter Maydell <address@hidden>
> ---
> scripts/qapi-types.py | 8 ++++++++
> 1 file changed, 8 insertions(+)
Reviewed-by: Eric Blake <address@hidden>
However, I'm a bit surprised that there is no testsuite coverage for
this; it would be nice if we had at least one test that used an empty
struct to prove that we continue to generate them and their visitors
correctly.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature