[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 01/18] scripts/qapi-types.py: Add dummy member to emp
From: |
Peter Maydell |
Subject: |
[Qemu-devel] [PULL 01/18] scripts/qapi-types.py: Add dummy member to empty structs |
Date: |
Tue, 20 Jan 2015 15:45:30 +0000 |
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>
Reviewed-by: Eric Blake <address@hidden>
Message-id: address@hidden
---
scripts/qapi-types.py | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index d2f815b..1eb272d 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -99,6 +99,14 @@ struct %(name)s
ret += generate_struct_fields(members)
+ # Make sure that all structs have at least one field; this avoids
+ # potential issues with attempting to malloc space for zero-length structs
+ # in C, and also incompatibility with C++ (where an empty struct is size
1).
+ if not base and not members:
+ ret += mcgen('''
+ char qapi_dummy_field_for_empty_struct;
+''')
+
if len(fieldname):
fieldname = " " + fieldname
ret += mcgen('''
--
1.9.1
- [Qemu-devel] [PULL 00/18] misc cross-tree patches queue, Peter Maydell, 2015/01/20
- [Qemu-devel] [PULL 01/18] scripts/qapi-types.py: Add dummy member to empty structs,
Peter Maydell <=
- [Qemu-devel] [PULL 18/18] cpu_ldst.h: Don't define helpers if MMU_MODE*_SUFFIX not defined, Peter Maydell, 2015/01/20
- [Qemu-devel] [PULL 16/18] cpu_ldst_template.h: Drop unused cpu_ldfq/stfq/ldfl/stfl accessors, Peter Maydell, 2015/01/20
- [Qemu-devel] [PULL 15/18] cpu_ldst.h: Drop unused _raw macros, saddr() and laddr(), Peter Maydell, 2015/01/20
- [Qemu-devel] [PULL 14/18] cpu_ldst_template.h: Use ld*_p directly rather than via ld*_raw macros, Peter Maydell, 2015/01/20
- [Qemu-devel] [PULL 10/18] target-mips: Don't use _raw load/store accessors, Peter Maydell, 2015/01/20
- [Qemu-devel] [PULL 09/18] linux-user/main.c (m68k): Use get_user_u16 rather than lduw in cpu_loop, Peter Maydell, 2015/01/20
- [Qemu-devel] [PULL 13/18] cpu_ldst.h: Use inline functions for usermode cpu_ld/st accessors, Peter Maydell, 2015/01/20
- [Qemu-devel] [PULL 06/18] linux-user/elfload.c: Don't use _raw accessor functions, Peter Maydell, 2015/01/20
- [Qemu-devel] [PULL 08/18] linux-user/vm86.c: Use cpu_ldl_data &c rather than plain ldl &c, Peter Maydell, 2015/01/20
- [Qemu-devel] [PULL 17/18] cpu_ldst.h, cpu-all.h, bswap.h: Update documentation on ld/st accessors, Peter Maydell, 2015/01/20