qemu-patch-raspberry4/util
Eric Blake 3b098d5697 qapi: Add new visit_complete() function
Making each output visitor provide its own output collection
function was the only remaining reason for exposing visitor
sub-types to the rest of the code base.  Add a polymorphic
visit_complete() function which is a no-op for input visitors,
and which populates an opaque pointer for output visitors.  For
maximum type-safety, also add a parameter to the output visitor
constructors with a type-correct version of the output pointer,
and assert that the two uses match.

This approach was considered superior to either passing the
output parameter only during construction (action at a distance
during visit_free() feels awkward) or only during visit_complete()
(defeating type safety makes it easier to use incorrectly).

Most callers were function-local, and therefore a mechanical
conversion; the testsuite was a bit trickier, but the previous
cleanup patch minimized the churn here.

The visit_complete() function may be called at most once; doing
so lets us use transfer semantics rather than duplication or
ref-count semantics to get the just-built output back to the
caller, even though it means our behavior is not idempotent.

Generated code is simplified as follows for events:

|@@ -26,7 +26,7 @@ void qapi_event_send_acpi_device_ost(ACP
|     QDict *qmp;
|     Error *err = NULL;
|     QMPEventFuncEmit emit;
|-    QmpOutputVisitor *qov;
|+    QObject *obj;
|     Visitor *v;
|     q_obj_ACPI_DEVICE_OST_arg param = {
|         info
|@@ -39,8 +39,7 @@ void qapi_event_send_acpi_device_ost(ACP
|
|     qmp = qmp_event_build_dict("ACPI_DEVICE_OST");
|
|-    qov = qmp_output_visitor_new();
|-    v = qmp_output_get_visitor(qov);
|+    v = qmp_output_visitor_new(&obj);
|
|     visit_start_struct(v, "ACPI_DEVICE_OST", NULL, 0, &err);
|     if (err) {
|@@ -55,7 +54,8 @@ void qapi_event_send_acpi_device_ost(ACP
|         goto out;
|     }
|
|-    qdict_put_obj(qmp, "data", qmp_output_get_qobject(qov));
|+    visit_complete(v, &obj);
|+    qdict_put_obj(qmp, "data", obj);
|     emit(QAPI_EVENT_ACPI_DEVICE_OST, qmp, &err);

and for commands:

| {
|     Error *err = NULL;
|-    QmpOutputVisitor *qov = qmp_output_visitor_new();
|     Visitor *v;
|
|-    v = qmp_output_get_visitor(qov);
|+    v = qmp_output_visitor_new(ret_out);
|     visit_type_AddfdInfo(v, "unused", &ret_in, &err);
|-    if (err) {
|-        goto out;
|+    if (!err) {
|+        visit_complete(v, ret_out);
|     }
|-    *ret_out = qmp_output_get_qobject(qov);
|-
|-out:
|     error_propagate(errp, err);

Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1465490926-28625-13-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-07-06 10:52:04 +02:00
..
acl.c util: Clean up includes 2016-02-04 17:01:04 +00:00
base64.c include/qemu/osdep.h: Don't include qapi/error.h 2016-03-22 22:20:15 +01:00
bitmap.c util: Clean up includes 2016-02-04 17:01:04 +00:00
bitops.c util: Clean up includes 2016-02-04 17:01:04 +00:00
buffer.c qemu-common: stop including qemu/host-utils.h from qemu-common.h 2016-05-19 16:42:28 +02:00
compatfd.c util: Clean up includes 2016-02-04 17:01:04 +00:00
coroutine-gthread.c all: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
coroutine-sigaltstack.c Remove unneeded include statements for setjmp.h 2016-03-22 19:11:15 +01:00
coroutine-ucontext.c Remove unneeded include statements for setjmp.h 2016-03-22 19:11:15 +01:00
coroutine-win32.c util: Clean up includes 2016-02-04 17:01:04 +00:00
crc32c.c util: Clean up includes 2016-02-04 17:01:04 +00:00
cutils.c avx2 configure: Use primitives in test 2016-06-16 18:39:04 +02:00
envlist.c util: Clean up includes 2016-02-04 17:01:04 +00:00
error.c migration: add reporting of errors for outgoing migration 2016-05-26 11:31:30 +05:30
event_notifier-posix.c event-notifier: Add "is_external" parameter 2016-04-22 16:43:56 +02:00
event_notifier-win32.c event-notifier: Add "is_external" parameter 2016-04-22 16:43:56 +02:00
fifo8.c util: Clean up includes 2016-02-04 17:01:04 +00:00
getauxval.c util: Clean up includes 2016-02-04 17:01:04 +00:00
hbitmap.c hbitmap: add 'pos < size' asserts 2016-06-16 15:20:37 +02:00
hexdump.c util: Improved qemu_hexmap() to include an ascii dump of the buffer 2016-04-06 09:52:07 +08:00
host-utils.c util: Clean up includes 2016-02-04 17:01:04 +00:00
id.c util: move declarations out of qemu-common.h 2016-03-22 22:20:17 +01:00
iov.c util: move declarations out of qemu-common.h 2016-03-22 22:20:17 +01:00
log.c log: Permit -dfilter 0..0xffffffffffffffff 2016-07-04 16:49:33 +03:00
Makefile.objs range: Create range.c for code that should not be inline 2016-06-30 15:28:40 +02:00
memfd.c os-posix: include sys/mman.h 2016-06-16 18:39:03 +02:00
mmap-alloc.c os-posix: include sys/mman.h 2016-06-16 18:39:03 +02:00
module.c coccinelle: Remove unnecessary variables for function return value 2016-06-20 16:38:13 +02:00
notify.c util: Clean up includes 2016-02-04 17:01:04 +00:00
osdep.c os-posix: include sys/mman.h 2016-06-16 18:39:03 +02:00
oslib-posix.c os-posix: include sys/mman.h 2016-06-16 18:39:03 +02:00
oslib-win32.c all: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00
path.c util: move declarations out of qemu-common.h 2016-03-22 22:20:17 +01:00
qdist.c clean-includes: run it once more 2016-06-16 18:39:03 +02:00
qemu-config.c util: Clean up includes 2016-02-04 17:01:04 +00:00
qemu-coroutine-io.c osdep: remove use of socket_error() from all code 2016-03-10 17:19:34 +00:00
qemu-coroutine-lock.c util: Clean up includes 2016-02-04 17:01:04 +00:00
qemu-coroutine-sleep.c util: Clean up includes 2016-02-04 17:01:04 +00:00
qemu-coroutine.c util: Clean up includes 2016-02-04 17:01:04 +00:00
qemu-error.c util: Clean up includes 2016-02-04 17:01:04 +00:00
qemu-openpty.c util: Clean up includes 2016-02-04 17:01:04 +00:00
qemu-option.c QemuOpts: Fix qemu_opts_foreach() dangling location regression 2016-04-28 08:18:56 +02:00
qemu-progress.c util: Clean up includes 2016-02-04 17:01:04 +00:00
qemu-sockets.c qapi: Add new visit_complete() function 2016-07-06 10:52:04 +02:00
qemu-thread-posix.c util: Clean up includes 2016-02-04 17:01:04 +00:00
qemu-thread-win32.c util: Clean up includes 2016-02-04 17:01:04 +00:00
qemu-timer-common.c util: Clean up includes 2016-02-04 17:01:04 +00:00
qht.c clean-includes: run it once more 2016-06-16 18:39:03 +02:00
range.c range: Replace internal representation of Range 2016-07-04 16:49:33 +03:00
rcu.c util: Clean up includes 2016-02-04 17:01:04 +00:00
readline.c util: move declarations out of qemu-common.h 2016-03-22 22:20:17 +01:00
rfifolock.c rfifolock: no need to get thread identifier when nesting 2016-05-16 15:29:44 -07:00
throttle.c throttle: refuse iops-size without iops-total/read/write 2016-06-07 14:40:51 +01:00
timed-average.c Fix some typos found by codespell 2016-05-18 15:04:27 +03:00
trace-events trace: split out trace events for util/ directory 2016-06-20 17:22:14 +01:00
unicode.c util: move declarations out of qemu-common.h 2016-03-22 22:20:17 +01:00
uri.c all: Remove unnecessary glib.h includes 2016-06-07 18:19:24 +03:00