Skip to content

Commit

Permalink
qapi: Swap visit_* arguments for consistent 'name' placement
Browse files Browse the repository at this point in the history
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp).  This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order.  It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.

Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.

Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.

Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
 $ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings').  The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.

    // Part 1: Swap declaration order
    @@
    type TV, TErr, TObj, T1, T2;
    identifier OBJ, ARG1, ARG2;
    @@
     void visit_start_struct
    -(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
    +(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
     { ... }

    @@
    type bool, TV, T1;
    identifier ARG1;
    @@
     bool visit_optional
    -(TV v, T1 ARG1, const char *name)
    +(TV v, const char *name, T1 ARG1)
     { ... }

    @@
    type TV, TErr, TObj, T1;
    identifier OBJ, ARG1;
    @@
     void visit_get_next_type
    -(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
    +(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
     { ... }

    @@
    type TV, TErr, TObj, T1, T2;
    identifier OBJ, ARG1, ARG2;
    @@
     void visit_type_enum
    -(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
    +(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
     { ... }

    @@
    type TV, TErr, TObj;
    identifier OBJ;
    identifier VISIT_TYPE =~ "^visit_type_";
    @@
     void VISIT_TYPE
    -(TV v, TObj OBJ, const char *name, TErr errp)
    +(TV v, const char *name, TObj OBJ, TErr errp)
     { ... }

    // Part 2: swap caller order
    @@
    expression V, NAME, OBJ, ARG1, ARG2, ERR;
    identifier VISIT_TYPE =~ "^visit_type_";
    @@
    (
    -visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
    +visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
    |
    -visit_optional(V, ARG1, NAME)
    +visit_optional(V, NAME, ARG1)
    |
    -visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
    +visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
    |
    -visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
    +visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
    |
    -VISIT_TYPE(V, OBJ, NAME, ERR)
    +VISIT_TYPE(V, NAME, OBJ, ERR)
    )

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
  • Loading branch information
ebblake authored and Markus Armbruster committed Feb 8, 2016
1 parent 4fa4549 commit 51e72bc
Show file tree
Hide file tree
Showing 52 changed files with 385 additions and 371 deletions.
8 changes: 4 additions & 4 deletions backends/hostmem.c
Expand Up @@ -33,7 +33,7 @@ host_memory_backend_get_size(Object *obj, Visitor *v, void *opaque,
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
uint64_t value = backend->size;

visit_type_size(v, &value, name, errp);
visit_type_size(v, name, &value, errp);
}

static void
Expand All @@ -49,7 +49,7 @@ host_memory_backend_set_size(Object *obj, Visitor *v, void *opaque,
goto out;
}

visit_type_size(v, &value, name, &local_err);
visit_type_size(v, name, &value, &local_err);
if (local_err) {
goto out;
}
Expand Down Expand Up @@ -92,7 +92,7 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor *v, void *opaque,
node = &(*node)->next;
} while (true);

visit_type_uint16List(v, &host_nodes, name, errp);
visit_type_uint16List(v, name, &host_nodes, errp);
}

static void
Expand All @@ -103,7 +103,7 @@ host_memory_backend_set_host_nodes(Object *obj, Visitor *v, void *opaque,
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
uint16List *l = NULL;

visit_type_uint16List(v, &l, name, errp);
visit_type_uint16List(v, name, &l, errp);

while (l) {
bitmap_set(backend->host_nodes, l->value, 1);
Expand Down
2 changes: 1 addition & 1 deletion block/qapi.c
Expand Up @@ -641,7 +641,7 @@ void bdrv_image_info_specific_dump(fprintf_function func_fprintf, void *f,
QmpOutputVisitor *ov = qmp_output_visitor_new();
QObject *obj, *data;

visit_type_ImageInfoSpecific(qmp_output_get_visitor(ov), &info_spec, NULL,
visit_type_ImageInfoSpecific(qmp_output_get_visitor(ov), NULL, &info_spec,
&error_abort);
obj = qmp_output_get_qobject(ov);
assert(qobject_type(obj) == QTYPE_QDICT);
Expand Down
4 changes: 2 additions & 2 deletions blockdev.c
Expand Up @@ -3860,8 +3860,8 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)
}
}

visit_type_BlockdevOptions(qmp_output_get_visitor(ov),
&options, NULL, &local_err);
visit_type_BlockdevOptions(qmp_output_get_visitor(ov), NULL, &options,
&local_err);
if (local_err) {
error_propagate(errp, local_err);
goto fail;
Expand Down
4 changes: 2 additions & 2 deletions bootdevice.c
Expand Up @@ -275,7 +275,7 @@ static void device_get_bootindex(Object *obj, Visitor *v, void *opaque,
const char *name, Error **errp)
{
BootIndexProperty *prop = opaque;
visit_type_int32(v, prop->bootindex, name, errp);
visit_type_int32(v, name, prop->bootindex, errp);
}

static void device_set_bootindex(Object *obj, Visitor *v, void *opaque,
Expand All @@ -285,7 +285,7 @@ static void device_set_bootindex(Object *obj, Visitor *v, void *opaque,
int32_t boot_index;
Error *local_err = NULL;

visit_type_int32(v, &boot_index, name, &local_err);
visit_type_int32(v, name, &boot_index, &local_err);
if (local_err) {
goto out;
}
Expand Down
8 changes: 4 additions & 4 deletions hmp.c
Expand Up @@ -1676,13 +1676,13 @@ void hmp_object_add(Monitor *mon, const QDict *qdict)
}

qdict_del(pdict, "qom-type");
visit_type_str(v, &type, "qom-type", &err);
visit_type_str(v, "qom-type", &type, &err);
if (err) {
goto out_end;
}

qdict_del(pdict, "id");
visit_type_str(v, &id, "id", &err);
visit_type_str(v, "id", &id, &err);
if (err) {
goto out_end;
}
Expand Down Expand Up @@ -1948,8 +1948,8 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict)

while (m) {
ov = string_output_visitor_new(false);
visit_type_uint16List(string_output_get_visitor(ov),
&m->value->host_nodes, NULL, NULL);
visit_type_uint16List(string_output_get_visitor(ov), NULL,
&m->value->host_nodes, NULL);
monitor_printf(mon, "memory backend: %d\n", i);
monitor_printf(mon, " size: %" PRId64 "\n", m->value->size);
monitor_printf(mon, " merge: %s\n",
Expand Down
4 changes: 2 additions & 2 deletions hw/acpi/core.c
Expand Up @@ -243,7 +243,7 @@ void acpi_table_add(const QemuOpts *opts, Error **errp)
OptsVisitor *ov;

ov = opts_visitor_new(opts);
visit_type_AcpiTableOptions(opts_get_visitor(ov), &hdrs, NULL, &err);
visit_type_AcpiTableOptions(opts_get_visitor(ov), NULL, &hdrs, &err);
opts_visitor_cleanup(ov);
}

Expand Down Expand Up @@ -302,7 +302,7 @@ void acpi_table_add(const QemuOpts *opts, Error **errp)
QapiDeallocVisitor *dv;

dv = qapi_dealloc_visitor_new();
visit_type_AcpiTableOptions(qapi_dealloc_get_visitor(dv), &hdrs, NULL,
visit_type_AcpiTableOptions(qapi_dealloc_get_visitor(dv), NULL, &hdrs,
NULL);
qapi_dealloc_visitor_cleanup(dv);
}
Expand Down
14 changes: 7 additions & 7 deletions hw/acpi/ich9.c
Expand Up @@ -290,7 +290,7 @@ static void ich9_pm_get_gpe0_blk(Object *obj, Visitor *v,
ICH9LPCPMRegs *pm = opaque;
uint32_t value = pm->pm_io_base + ICH9_PMIO_GPE0_STS;

visit_type_uint32(v, &value, name, errp);
visit_type_uint32(v, name, &value, errp);
}

static bool ich9_pm_get_memory_hotplug_support(Object *obj, Error **errp)
Expand All @@ -315,7 +315,7 @@ static void ich9_pm_get_disable_s3(Object *obj, Visitor *v,
ICH9LPCPMRegs *pm = opaque;
uint8_t value = pm->disable_s3;

visit_type_uint8(v, &value, name, errp);
visit_type_uint8(v, name, &value, errp);
}

static void ich9_pm_set_disable_s3(Object *obj, Visitor *v,
Expand All @@ -326,7 +326,7 @@ static void ich9_pm_set_disable_s3(Object *obj, Visitor *v,
Error *local_err = NULL;
uint8_t value;

visit_type_uint8(v, &value, name, &local_err);
visit_type_uint8(v, name, &value, &local_err);
if (local_err) {
goto out;
}
Expand All @@ -342,7 +342,7 @@ static void ich9_pm_get_disable_s4(Object *obj, Visitor *v,
ICH9LPCPMRegs *pm = opaque;
uint8_t value = pm->disable_s4;

visit_type_uint8(v, &value, name, errp);
visit_type_uint8(v, name, &value, errp);
}

static void ich9_pm_set_disable_s4(Object *obj, Visitor *v,
Expand All @@ -353,7 +353,7 @@ static void ich9_pm_set_disable_s4(Object *obj, Visitor *v,
Error *local_err = NULL;
uint8_t value;

visit_type_uint8(v, &value, name, &local_err);
visit_type_uint8(v, name, &value, &local_err);
if (local_err) {
goto out;
}
Expand All @@ -369,7 +369,7 @@ static void ich9_pm_get_s4_val(Object *obj, Visitor *v,
ICH9LPCPMRegs *pm = opaque;
uint8_t value = pm->s4_val;

visit_type_uint8(v, &value, name, errp);
visit_type_uint8(v, name, &value, errp);
}

static void ich9_pm_set_s4_val(Object *obj, Visitor *v,
Expand All @@ -380,7 +380,7 @@ static void ich9_pm_set_s4_val(Object *obj, Visitor *v,
Error *local_err = NULL;
uint8_t value;

visit_type_uint8(v, &value, name, &local_err);
visit_type_uint8(v, name, &value, &local_err);
if (local_err) {
goto out;
}
Expand Down
10 changes: 5 additions & 5 deletions hw/core/machine.c
Expand Up @@ -41,7 +41,7 @@ static void machine_set_kernel_irqchip(Object *obj, Visitor *v,
MachineState *ms = MACHINE(obj);
OnOffSplit mode;

visit_type_OnOffSplit(v, &mode, name, &err);
visit_type_OnOffSplit(v, name, &mode, &err);
if (err) {
error_propagate(errp, err);
return;
Expand Down Expand Up @@ -75,7 +75,7 @@ static void machine_get_kvm_shadow_mem(Object *obj, Visitor *v,
MachineState *ms = MACHINE(obj);
int64_t value = ms->kvm_shadow_mem;

visit_type_int(v, &value, name, errp);
visit_type_int(v, name, &value, errp);
}

static void machine_set_kvm_shadow_mem(Object *obj, Visitor *v,
Expand All @@ -86,7 +86,7 @@ static void machine_set_kvm_shadow_mem(Object *obj, Visitor *v,
Error *error = NULL;
int64_t value;

visit_type_int(v, &value, name, &error);
visit_type_int(v, name, &value, &error);
if (error) {
error_propagate(errp, error);
return;
Expand Down Expand Up @@ -177,7 +177,7 @@ static void machine_get_phandle_start(Object *obj, Visitor *v,
MachineState *ms = MACHINE(obj);
int64_t value = ms->phandle_start;

visit_type_int(v, &value, name, errp);
visit_type_int(v, name, &value, errp);
}

static void machine_set_phandle_start(Object *obj, Visitor *v,
Expand All @@ -188,7 +188,7 @@ static void machine_set_phandle_start(Object *obj, Visitor *v,
Error *error = NULL;
int64_t value;

visit_type_int(v, &value, name, &error);
visit_type_int(v, name, &value, &error);
if (error) {
error_propagate(errp, error);
return;
Expand Down
12 changes: 6 additions & 6 deletions hw/core/qdev-properties-system.c
Expand Up @@ -31,7 +31,7 @@ static void get_pointer(Object *obj, Visitor *v, Property *prop,
char *p;

p = *ptr ? print(*ptr) : g_strdup("");
visit_type_str(v, &p, name, errp);
visit_type_str(v, name, &p, errp);
g_free(p);
}

Expand All @@ -51,7 +51,7 @@ static void set_pointer(Object *obj, Visitor *v, Property *prop,
return;
}

visit_type_str(v, &str, name, &local_err);
visit_type_str(v, name, &str, &local_err);
if (local_err) {
error_propagate(errp, local_err);
return;
Expand Down Expand Up @@ -202,7 +202,7 @@ static void get_netdev(Object *obj, Visitor *v, void *opaque,
NICPeers *peers_ptr = qdev_get_prop_ptr(dev, prop);
char *p = g_strdup(peers_ptr->ncs[0] ? peers_ptr->ncs[0]->name : "");

visit_type_str(v, &p, name, errp);
visit_type_str(v, name, &p, errp);
g_free(p);
}

Expand All @@ -223,7 +223,7 @@ static void set_netdev(Object *obj, Visitor *v, void *opaque,
return;
}

visit_type_str(v, &str, name, &local_err);
visit_type_str(v, name, &str, &local_err);
if (local_err) {
error_propagate(errp, local_err);
return;
Expand Down Expand Up @@ -308,7 +308,7 @@ static void get_vlan(Object *obj, Visitor *v, void *opaque,
}
}

visit_type_int32(v, &id, name, errp);
visit_type_int32(v, name, &id, errp);
}

static void set_vlan(Object *obj, Visitor *v, void *opaque,
Expand All @@ -327,7 +327,7 @@ static void set_vlan(Object *obj, Visitor *v, void *opaque,
return;
}

visit_type_int32(v, &id, name, &local_err);
visit_type_int32(v, name, &id, &local_err);
if (local_err) {
error_propagate(errp, local_err);
return;
Expand Down

0 comments on commit 51e72bc

Please sign in to comment.