qemu/scripts
Eric Blake becceedc4d qapi: Don't box struct branch of alternate
There's no reason to do two malloc's for an alternate type visiting
a QAPI struct; let's just inline the struct directly as the C union
branch of the struct.

Surprisingly, no clients were actually using the struct member prior
to this patch outside of the testsuite; an earlier patch in the series
added some testsuite coverage to make the effect of this patch more
obvious.

In qapi.py, c_type() gains a new is_unboxed flag to control when we
are emitting a C struct unboxed within the context of an outer
struct (different from our other two modes of usage with no flags
for normal local variable declarations, and with is_param for adding
'const' in a parameter list).  I don't know if there is any more
pythonic way of collapsing the two flags into a single parameter,
as we never have a caller setting both flags at once.

Ultimately, we want to also unbox branches for QAPI unions, but as
that touches a lot more client code, it is better as separate
patches.  But since unions and alternates share gen_variants(), I
had to hack in a way to test if we are visiting an alternate type
for setting the is_unboxed flag: look for a non-object branch.
This works because alternates have at least two branches, with at
most one object branch, while unions have only object branches.
The hack will go away in a later patch.

The generated code difference to qapi-types.h is relatively small:

| struct BlockdevRef {
|     QType type;
|     union { /* union tag is @type */
|         void *data;
|-        BlockdevOptions *definition;
|+        BlockdevOptions definition;
|         char *reference;
|     } u;
| };

The corresponding spot in qapi-visit.c calls visit_type_FOO(), which
first calls visit_start_struct() to allocate or deallocate the member
and handle a layer of {} from the JSON stream, then visits the
members.  To peel off the indirection and the memory management that
comes with it, we inline this call, then suppress allocation /
deallocation by passing NULL to visit_start_struct(), and adjust the
member visit:

|     switch ((*obj)->type) {
|     case QTYPE_QDICT:
|-        visit_type_BlockdevOptions(v, name, &(*obj)->u.definition, &err);
|+        visit_start_struct(v, name, NULL, 0, &err);
|+        if (err) {
|+            break;
|+        }
|+        visit_type_BlockdevOptions_fields(v, &(*obj)->u.definition, &err);
|+        error_propagate(errp, err);
|+        err = NULL;
|+        visit_end_struct(v, &err);
|         break;
|     case QTYPE_QSTRING:
|         visit_type_str(v, name, &(*obj)->u.reference, &err);

The visit of non-object fields is unchanged.

Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1455778109-6278-13-git-send-email-eblake@redhat.com>
[Commit message tweaked]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-02-19 11:08:57 +01:00
..
kvm scripts/kvm/kvm_stat: Fix tracefs access checking 2016-02-09 15:45:26 +01:00
qemu-guest-agent
qemugdb scripts/gdb: Fix a python exception in mtree.py 2015-12-22 16:01:08 +08:00
qmp scripts/qmp: Use Python 2.6 "except E as ..." syntax 2016-02-08 17:29:54 +01:00
tracetool scripts/tracetool: Include qemu/osdep.h in generated .c files 2016-02-16 14:29:27 +00:00
analyse-9p-simpletrace.py
analyze-migration.py migration: fix analyze-migration.py script 2015-11-04 13:40:13 +01:00
check-qerror.sh
checkpatch.pl checkpatch: Eliminate false positive in case of space before square bracket in a definition 2016-02-15 20:02:09 +01:00
clean-includes scripts: Add new clean-includes script to fix C include directives 2016-01-18 16:33:32 +00:00
cleanup-trace-events.pl
cocci-macro-file.h
coverity-model.c coverity: Model g_memdup() 2015-12-17 17:33:49 +01:00
create_config io: add QIOChannelSocket class 2015-12-18 12:18:31 +00:00
disas-objdump.pl
dump-guest-memory.py scripts/dump-guest-memory.py: Fix module docstring 2016-01-26 15:58:14 +01:00
extract-vsssdk-headers
feature_to_c.sh scripts/feature_to_c.sh: Include qemu/osdep.h rather than config.h 2016-02-16 14:29:27 +00:00
get_maintainer.pl get_maintainer.pl: fall back to git if only lists are found 2016-02-09 17:07:55 +01:00
gtester-cat
hxtool
make-release
make_device_config.sh
ordereddict.py
qapi-commands.py qapi: Clean up includes in generated files 2016-02-16 14:29:27 +00:00
qapi-event.py qapi: Clean up includes in generated files 2016-02-16 14:29:27 +00:00
qapi-introspect.py qapi: Clean up includes in generated files 2016-02-16 14:29:27 +00:00
qapi-types.py qapi: Don't box struct branch of alternate 2016-02-19 11:08:57 +01:00
qapi-visit.py qapi: Don't box struct branch of alternate 2016-02-19 11:08:57 +01:00
qapi.py qapi: Don't box struct branch of alternate 2016-02-19 11:08:57 +01:00
qemu-binfmt-conf.sh
qemu-gdb.py gdb command: qemu handlers 2015-10-29 17:59:27 +00:00
qtest.py
refresh-pxe-roms.sh
shaderinclude.pl
signrom.py
simpletrace.py
switch-timer-api
texi2pod.pl scripts/text2pod.pl: Escape left brace 2015-11-02 14:50:27 +01:00
tracetool.py Revert "tracetool: use Python 2.4-compatible exception handling syntax" 2016-02-08 17:29:54 +01:00
update-linux-headers.sh linux-headers: update from kvm/next 2015-12-17 15:24:34 +01:00
vmstate-static-checker.py static checker: e1000-82540em got aliased to e1000 2016-02-05 19:09:50 +05:30