]> git.proxmox.com Git - mirror_qemu.git/commit
qapi: Share gen_visit_fields()
authorEric Blake <eblake@redhat.com>
Tue, 29 Sep 2015 22:21:14 +0000 (16:21 -0600)
committerMarkus Armbruster <armbru@redhat.com>
Mon, 12 Oct 2015 16:46:50 +0000 (18:46 +0200)
commit82ca8e469666b169ccf818a0e36136aee97d7db0
tree9ad70840241a6e70afb3a2b0784ce546b810ba59
parent1f35334489a43800df4d20cd91362a87cee39a29
qapi: Share gen_visit_fields()

Consolidate the code between visit, command marshalling, and
event generation that iterates over the members of a struct.
It reduces code duplication in the generator, so that a future
patch can reduce the size of generated code while touching only
one instead of three locations.

There are no changes to the generated marshal code.

The visitor code becomes slightly more verbose, but remains
semantically equivalent, and is actually easier to read as
it follows a more common idiom:

|     visit_optional(v, &(*obj)->has_device, "device", &err);
|-    if (!err && (*obj)->has_device) {
|-        visit_type_str(v, &(*obj)->device, "device", &err);
|-    }
|     if (err) {
|         goto out;
|     }
|+    if ((*obj)->has_device) {
|+        visit_type_str(v, &(*obj)->device, "device", &err);
|+        if (err) {
|+            goto out;
|+        }
|+    }

The event code becomes slightly more verbose, but this is
arguably a bug fix: although the visitors are not well
documented, use of an optional member should not be attempted
unless guarded by a prior call to visit_optional().  Works only
because the output qmp visitor has a no-op visit_optional():

|+    visit_optional(v, &has_offset, "offset", &err);
|+    if (err) {
|+        goto out;
|+    }
|     if (has_offset) {
|         visit_type_int(v, &offset, "offset", &err);

Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1443565276-4535-17-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
scripts/qapi-commands.py
scripts/qapi-event.py
scripts/qapi-visit.py
scripts/qapi.py