Eric Blake <[email protected]> writes:
> 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 generated marshal code.
>
> The visitor code is slightly more verbose, but semantically
Suggest "becomes slightly more verbose".
> equivalent, and 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 is slightly more verbose, but 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()) - we were lucky that the output
> qmp visitor has a no-op visit_optional():
Suggest "becomes slightly more verbose, but this is arguably a bug fix:
although [...] prior call to visit_optional(). Works only because the
output qmp visitor [...]".
>
> |+ 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 <[email protected]>
>
> ---
> v6: retitle 10/46, split gen_err_check() to its own patch,
> improve commit message, use named parameters in gen_visit_fields()
> to minimize effort of callers
Interdiff to v5 looks sane.