qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Cc: Markus Armbruster <armbru@redhat.com>,
	Luiz Capitulino <lcapitulino@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] scripts/qapi-types.py: Add dummy member to empty structs
Date: Tue, 23 Dec 2014 13:04:10 -0700	[thread overview]
Message-ID: <5499CABA.5080008@redhat.com> (raw)
In-Reply-To: <1419359069-16611-1-git-send-email-peter.maydell@linaro.org>

[-- Attachment #1: Type: text/plain, Size: 1223 bytes --]

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 <peter.maydell@linaro.org>
> ---
>  scripts/qapi-types.py | 8 ++++++++
>  1 file changed, 8 insertions(+)

Reviewed-by: Eric Blake <eblake@redhat.com>

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


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

      reply	other threads:[~2014-12-23 20:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-23 18:24 [Qemu-devel] [PATCH] scripts/qapi-types.py: Add dummy member to empty structs Peter Maydell
2014-12-23 20:04 ` Eric Blake [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5499CABA.5080008@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).