mirror of
https://github.com/yuzu-mirror/unicorn.git
synced 2026-01-03 23:30:36 +01:00
scripts/qapi-types.py: Add dummy member to empty structs
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
^
Backports commit 83ecb22ba2c91a4674ae109595a8ed1da8de4d7a from qemu
This commit is contained in:
parent
5efb546d6f
commit
9a3972b6b2
|
|
@ -90,6 +90,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('''
|
||||
|
|
|
|||
Loading…
Reference in a new issue