When dealing with simple qapi unions, the code was generating a discriminator field of 'kind' even though the discriminator is sent as 'type' over QMP. Renaming things to match gets us one step closer to reusing common generator code for both simple and flat unions, without having to special case the naming choice for simple unions. It also gets rid of some TODO markers in using the raw QAPISchemaObjectTypeVariants.tag_name field, although we can't yet convert that field to private until later fixes to alternate types also quit using it.
However, this patch does not rename the generated enum, which is still 'unionnameKind'; if we wanted, a further patch could generate implicit enums as 'unionnameType', with even more churn to C code to react, and probably update the qapi generator to reserve the 'fooType' namespace instead of 'fooKind', or better yet ensure that generated names do not conflict with user names. But that is a lot harder, as we already have existing qapi usage of types that end in 'Type'. Signed-off-by: Eric Blake <ebl...@redhat.com> --- block/qcow2.c | 2 +- block/vmdk.c | 2 +- blockdev.c | 16 ++++++++-------- hmp.c | 12 ++++++------ hw/input/hid.c | 2 +- hw/input/ps2.c | 2 +- hw/input/virtio-input-hid.c | 2 +- hw/mem/pc-dimm.c | 2 +- net/dump.c | 2 +- net/hub.c | 2 +- net/l2tpv3.c | 2 +- net/net.c | 20 ++++++++++---------- net/slirp.c | 2 +- net/socket.c | 2 +- net/tap.c | 4 ++-- net/vhost-user.c | 2 +- numa.c | 4 ++-- qemu-char.c | 24 ++++++++++++------------ scripts/qapi-types.py | 7 ++----- scripts/qapi-visit.py | 13 +++---------- tests/test-qmp-commands.c | 2 +- tests/test-qmp-input-visitor.c | 10 +++++----- tests/test-qmp-output-visitor.c | 8 ++++---- tpm.c | 2 +- ui/input-keymap.c | 10 +++++----- ui/input-legacy.c | 2 +- ui/input.c | 22 +++++++++++----------- util/qemu-sockets.c | 12 ++++++------ 28 files changed, 91 insertions(+), 101 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index ea34ae2..dc3a73f 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2596,7 +2596,7 @@ static ImageInfoSpecific *qcow2_get_specific_info(BlockDriverState *bs) ImageInfoSpecific *spec_info = g_new(ImageInfoSpecific, 1); *spec_info = (ImageInfoSpecific){ - .kind = IMAGE_INFO_SPECIFIC_KIND_QCOW2, + .type = IMAGE_INFO_SPECIFIC_KIND_QCOW2, { .qcow2 = g_new(ImageInfoSpecificQCow2, 1), }, diff --git a/block/vmdk.c b/block/vmdk.c index fbaab67..180f416 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -2153,7 +2153,7 @@ static ImageInfoSpecific *vmdk_get_specific_info(BlockDriverState *bs) ImageInfoList **next; *spec_info = (ImageInfoSpecific){ - .kind = IMAGE_INFO_SPECIFIC_KIND_VMDK, + .type = IMAGE_INFO_SPECIFIC_KIND_VMDK, { .vmdk = g_new0(ImageInfoSpecificVmdk, 1), }, diff --git a/blockdev.c b/blockdev.c index 6b48be6..e4cec0e 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1052,12 +1052,12 @@ void hmp_commit(Monitor *mon, const QDict *qdict) } } -static void blockdev_do_action(int kind, void *data, Error **errp) +static void blockdev_do_action(int type, void *data, Error **errp) { TransactionAction action; TransactionActionList list; - action.kind = kind; + action.type = type; action.data = data; list.value = &action; list.next = NULL; @@ -1297,7 +1297,7 @@ static void internal_snapshot_prepare(BlkTransactionState *common, InternalSnapshotState *state; int ret1; - g_assert(common->action->kind == + g_assert(common->action->type == TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_INTERNAL_SYNC); internal = common->action->blockdev_snapshot_internal_sync; state = DO_UPCAST(InternalSnapshotState, common, common); @@ -1440,7 +1440,7 @@ static void external_snapshot_prepare(BlkTransactionState *common, TransactionAction *action = common->action; /* get parameters */ - g_assert(action->kind == TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC); + g_assert(action->type == TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC); has_device = action->blockdev_snapshot_sync->has_device; device = action->blockdev_snapshot_sync->device; @@ -1585,7 +1585,7 @@ static void drive_backup_prepare(BlkTransactionState *common, Error **errp) DriveBackup *backup; Error *local_err = NULL; - assert(common->action->kind == TRANSACTION_ACTION_KIND_DRIVE_BACKUP); + assert(common->action->type == TRANSACTION_ACTION_KIND_DRIVE_BACKUP); backup = common->action->drive_backup; blk = blk_by_name(backup->device); @@ -1653,7 +1653,7 @@ static void blockdev_backup_prepare(BlkTransactionState *common, Error **errp) BlockBackend *blk; Error *local_err = NULL; - assert(common->action->kind == TRANSACTION_ACTION_KIND_BLOCKDEV_BACKUP); + assert(common->action->type == TRANSACTION_ACTION_KIND_BLOCKDEV_BACKUP); backup = common->action->blockdev_backup; blk = blk_by_name(backup->device); @@ -1780,9 +1780,9 @@ void qmp_transaction(TransactionActionList *dev_list, Error **errp) dev_info = dev_entry->value; dev_entry = dev_entry->next; - assert(dev_info->kind < ARRAY_SIZE(actions)); + assert(dev_info->type < ARRAY_SIZE(actions)); - ops = &actions[dev_info->kind]; + ops = &actions[dev_info->type]; assert(ops->instance_size > 0); state = g_malloc0(ops->instance_size); diff --git a/hmp.c b/hmp.c index 3f807b7..849b292 100644 --- a/hmp.c +++ b/hmp.c @@ -830,9 +830,9 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict) c, TpmModel_lookup[ti->model]); monitor_printf(mon, " \\ %s: type=%s", - ti->id, TpmTypeOptionsKind_lookup[ti->options->kind]); + ti->id, TpmTypeOptionsKind_lookup[ti->options->type]); - switch (ti->options->kind) { + switch (ti->options->type) { case TPM_TYPE_OPTIONS_KIND_PASSTHROUGH: tpo = ti->options->passthrough; monitor_printf(mon, "%s%s%s%s", @@ -1714,14 +1714,14 @@ void hmp_sendkey(Monitor *mon, const QDict *qdict) if (*endp != '\0') { goto err_out; } - keylist->value->kind = KEY_VALUE_KIND_NUMBER; + keylist->value->type = KEY_VALUE_KIND_NUMBER; keylist->value->number = value; } else { int idx = index_from_key(keyname_buf); if (idx == Q_KEY_CODE_MAX) { goto err_out; } - keylist->value->kind = KEY_VALUE_KIND_QCODE; + keylist->value->type = KEY_VALUE_KIND_QCODE; keylist->value->qcode = idx; } @@ -1937,12 +1937,12 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict) value = info->value; if (value) { - switch (value->kind) { + switch (value->type) { case MEMORY_DEVICE_INFO_KIND_DIMM: di = value->dimm; monitor_printf(mon, "Memory device [%s]: \"%s\"\n", - MemoryDeviceInfoKind_lookup[value->kind], + MemoryDeviceInfoKind_lookup[value->type], di->id ? di->id : ""); monitor_printf(mon, " addr: 0x%" PRIx64 "\n", di->addr); monitor_printf(mon, " slot: %" PRId64 "\n", di->slot); diff --git a/hw/input/hid.c b/hw/input/hid.c index 21ebd9e..ac02f88 100644 --- a/hw/input/hid.c +++ b/hw/input/hid.c @@ -119,7 +119,7 @@ static void hid_pointer_event(DeviceState *dev, QemuConsole *src, assert(hs->n < QUEUE_LENGTH); e = &hs->ptr.queue[(hs->head + hs->n) & QUEUE_MASK]; - switch (evt->kind) { + switch (evt->type) { case INPUT_EVENT_KIND_REL: if (evt->rel->axis == INPUT_AXIS_X) { e->xdx += evt->rel->value; diff --git a/hw/input/ps2.c b/hw/input/ps2.c index fdbe565..58decf2 100644 --- a/hw/input/ps2.c +++ b/hw/input/ps2.c @@ -393,7 +393,7 @@ static void ps2_mouse_event(DeviceState *dev, QemuConsole *src, if (!(s->mouse_status & MOUSE_STATUS_ENABLED)) return; - switch (evt->kind) { + switch (evt->type) { case INPUT_EVENT_KIND_REL: if (evt->rel->axis == INPUT_AXIS_X) { s->mouse_dx += evt->rel->value; diff --git a/hw/input/virtio-input-hid.c b/hw/input/virtio-input-hid.c index 4d85dad..362dad3 100644 --- a/hw/input/virtio-input-hid.c +++ b/hw/input/virtio-input-hid.c @@ -191,7 +191,7 @@ static void virtio_input_handle_event(DeviceState *dev, QemuConsole *src, virtio_input_event event; int qcode; - switch (evt->kind) { + switch (evt->type) { case INPUT_EVENT_KIND_KEY: qcode = qemu_input_key_value_to_qcode(evt->key->key); if (qcode && keymap_qcode[qcode]) { diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index bb04862..a444195 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -196,7 +196,7 @@ ram_addr_t get_current_ram_size(void) MemoryDeviceInfo *value = info->value; if (value) { - switch (value->kind) { + switch (value->type) { case MEMORY_DEVICE_INFO_KIND_DIMM: size += value->dimm->size; break; diff --git a/net/dump.c b/net/dump.c index d80fa94..a1f99c3 100644 --- a/net/dump.c +++ b/net/dump.c @@ -154,7 +154,7 @@ int net_init_dump(const Netdev *netdev, const char *name, char def_file[128]; const NetdevDumpOptions *dump; - assert(netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_DUMP); + assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_DUMP); dump = netdev->opts->dump; assert(peer); diff --git a/net/hub.c b/net/hub.c index 29f65b2..047d861 100644 --- a/net/hub.c +++ b/net/hub.c @@ -285,7 +285,7 @@ int net_init_hubport(const Netdev *netdev, const char *name, { const NetdevHubPortOptions *hubport; - assert(netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_HUBPORT); + assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_HUBPORT); assert(!peer); hubport = netdev->opts->hubport; diff --git a/net/l2tpv3.c b/net/l2tpv3.c index d2f8431..bdb13fa 100644 --- a/net/l2tpv3.c +++ b/net/l2tpv3.c @@ -545,7 +545,7 @@ int net_init_l2tpv3(const Netdev *netdev, s->queue_tail = 0; s->header_mismatch = false; - assert(netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_L2TPV3); + assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_L2TPV3); l2tpv3 = netdev->opts->l2tpv3; if (l2tpv3->has_ipv6 && l2tpv3->ipv6) { diff --git a/net/net.c b/net/net.c index 4d99b48..94a3d18 100644 --- a/net/net.c +++ b/net/net.c @@ -820,7 +820,7 @@ static int net_init_nic(const Netdev *netdev, const char *name, NICInfo *nd; const NetLegacyNicOptions *nic; - assert(netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_NIC); + assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_NIC); nic = netdev->opts->nic; idx = nic_get_free_idx(); @@ -924,9 +924,9 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp) opts = netdev->opts; name = netdev->id; - if (opts->kind == NET_CLIENT_OPTIONS_KIND_DUMP || - opts->kind == NET_CLIENT_OPTIONS_KIND_NIC || - !net_client_init_fun[opts->kind]) { + if (opts->type == NET_CLIENT_OPTIONS_KIND_DUMP || + opts->type == NET_CLIENT_OPTIONS_KIND_NIC || + !net_client_init_fun[opts->type]) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type", "a netdev backend type"); return -1; @@ -939,16 +939,16 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp) /* missing optional values have been initialized to "all bits zero" */ name = net->has_id ? net->id : net->name; - if (opts->kind == NET_CLIENT_OPTIONS_KIND_NONE) { + if (opts->type == NET_CLIENT_OPTIONS_KIND_NONE) { return 0; /* nothing to do */ } - if (opts->kind == NET_CLIENT_OPTIONS_KIND_HUBPORT) { + if (opts->type == NET_CLIENT_OPTIONS_KIND_HUBPORT) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type", "a net type"); return -1; } - if (!net_client_init_fun[opts->kind]) { + if (!net_client_init_fun[opts->type]) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type", "a net backend type (maybe it is not compiled " "into this binary)"); @@ -956,17 +956,17 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp) } /* Do not add to a vlan if it's a nic with a netdev= parameter. */ - if (opts->kind != NET_CLIENT_OPTIONS_KIND_NIC || + if (opts->type != NET_CLIENT_OPTIONS_KIND_NIC || !opts->nic->has_netdev) { peer = net_hub_add_port(net->has_vlan ? net->vlan : 0, NULL); } } - if (net_client_init_fun[opts->kind](netdev, name, peer, errp) < 0) { + if (net_client_init_fun[opts->type](netdev, name, peer, errp) < 0) { /* FIXME drop when all init functions store an Error */ if (errp && !*errp) { error_setg(errp, QERR_DEVICE_INIT_FAILED, - NetClientOptionsKind_lookup[opts->kind]); + NetClientOptionsKind_lookup[opts->type]); } return -1; } diff --git a/net/slirp.c b/net/slirp.c index 0fc2c52..e160b9c 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -746,7 +746,7 @@ int net_init_slirp(const Netdev *netdev, const char *name, const NetdevUserOptions *user; const char **dnssearch; - assert(netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_USER); + assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_USER); user = netdev->opts->user; vnet = user->has_net ? g_strdup(user->net) : diff --git a/net/socket.c b/net/socket.c index 75f693c..7f949e2 100644 --- a/net/socket.c +++ b/net/socket.c @@ -706,7 +706,7 @@ int net_init_socket(const Netdev *netdev, const char *name, Error *err = NULL; const NetdevSocketOptions *sock; - assert(netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_SOCKET); + assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_SOCKET); sock = netdev->opts->socket; if (sock->has_fd + sock->has_listen + sock->has_connect + sock->has_mcast + diff --git a/net/tap.c b/net/tap.c index 263f807..aecc759 100644 --- a/net/tap.c +++ b/net/tap.c @@ -565,7 +565,7 @@ int net_init_bridge(const Netdev *netdev, const char *name, TAPState *s; int fd, vnet_hdr; - assert(netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_BRIDGE); + assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_BRIDGE); bridge = netdev->opts->bridge; helper = bridge->has_helper ? bridge->helper : DEFAULT_BRIDGE_HELPER; @@ -728,7 +728,7 @@ int net_init_tap(const Netdev *netdev, const char *name, const char *vhostfdname; char ifname[128]; - assert(netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_TAP); + assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_TAP); tap = netdev->opts->tap; queues = tap->has_queues ? tap->queues : 1; vhostfdname = tap->has_vhostfd ? tap->vhostfd : NULL; diff --git a/net/vhost-user.c b/net/vhost-user.c index 20981a9..8597ec4 100644 --- a/net/vhost-user.c +++ b/net/vhost-user.c @@ -229,7 +229,7 @@ int net_init_vhost_user(const Netdev *netdev, const char *name, const NetdevVhostUserOptions *vhost_user_opts; CharDriverState *chr; - assert(netdev->opts->kind == NET_CLIENT_OPTIONS_KIND_VHOST_USER); + assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER); vhost_user_opts = netdev->opts->vhost_user; chr = net_vhost_parse_chardev(vhost_user_opts, errp); diff --git a/numa.c b/numa.c index 402804b..aa9e0f7 100644 --- a/numa.c +++ b/numa.c @@ -226,7 +226,7 @@ static int parse_numa(void *opaque, QemuOpts *opts, Error **errp) goto error; } - switch (object->kind) { + switch (object->type) { case NUMA_OPTIONS_KIND_NODE: numa_node_parse(object->node, opts, &err); if (err) { @@ -487,7 +487,7 @@ static void numa_stat_memory_devices(uint64_t node_mem[]) MemoryDeviceInfo *value = info->value; if (value) { - switch (value->kind) { + switch (value->type) { case MEMORY_DEVICE_INFO_KIND_DIMM: node_mem[value->dimm->node] += value->dimm->size; break; diff --git a/qemu-char.c b/qemu-char.c index d956f8d..20fc51f 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -123,7 +123,7 @@ static int SocketAddress_to_str(char *dest, int max_len, const char *prefix, SocketAddress *addr, bool is_listen, bool is_telnet) { - switch (addr->kind) { + switch (addr->type) { case SOCKET_ADDRESS_KIND_INET: return snprintf(dest, max_len, "%s%s:%s:%s%s", prefix, is_telnet ? "telnet" : "tcp", addr->inet->host, @@ -3570,11 +3570,11 @@ static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend, addr = g_new0(SocketAddress, 1); if (path) { - addr->kind = SOCKET_ADDRESS_KIND_UNIX; + addr->type = SOCKET_ADDRESS_KIND_UNIX; addr->q_unix = g_new0(UnixSocketAddress, 1); addr->q_unix->path = g_strdup(path); } else { - addr->kind = SOCKET_ADDRESS_KIND_INET; + addr->type = SOCKET_ADDRESS_KIND_INET; addr->inet = g_new0(InetSocketAddress, 1); addr->inet->host = g_strdup(host); addr->inet->port = g_strdup(port); @@ -3619,7 +3619,7 @@ static void qemu_chr_parse_udp(QemuOpts *opts, ChardevBackend *backend, backend->udp = g_new0(ChardevUdp, 1); addr = g_new0(SocketAddress, 1); - addr->kind = SOCKET_ADDRESS_KIND_INET; + addr->type = SOCKET_ADDRESS_KIND_INET; addr->inet = g_new0(InetSocketAddress, 1); addr->inet->host = g_strdup(host); addr->inet->port = g_strdup(port); @@ -3632,7 +3632,7 @@ static void qemu_chr_parse_udp(QemuOpts *opts, ChardevBackend *backend, if (has_local) { backend->udp->has_local = true; addr = g_new0(SocketAddress, 1); - addr->kind = SOCKET_ADDRESS_KIND_INET; + addr->type = SOCKET_ADDRESS_KIND_INET; addr->inet = g_new0(InetSocketAddress, 1); addr->inet->host = g_strdup(localaddr); addr->inet->port = g_strdup(localport); @@ -3704,7 +3704,7 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, } chr = NULL; - backend->kind = cd->kind; + backend->type = cd->kind; if (cd->parse) { cd->parse(opts, backend, &local_err); if (local_err) { @@ -3722,7 +3722,7 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, qapi_free_ChardevReturn(ret); backend = g_new0(ChardevBackend, 1); backend->mux = g_new0(ChardevMux, 1); - backend->kind = CHARDEV_BACKEND_KIND_MUX; + backend->type = CHARDEV_BACKEND_KIND_MUX; backend->mux->chardev = g_strdup(bid); ret = qmp_chardev_add(id, backend, errp); if (!ret) { @@ -4151,7 +4151,7 @@ static CharDriverState *qmp_chardev_open_socket(ChardevSocket *sock, s->fd = -1; s->listen_fd = -1; - s->is_unix = addr->kind == SOCKET_ADDRESS_KIND_UNIX; + s->is_unix = addr->type == SOCKET_ADDRESS_KIND_UNIX; s->is_listen = is_listen; s->is_telnet = is_telnet; s->do_nodelay = do_nodelay; @@ -4225,7 +4225,7 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend, return NULL; } - switch (backend->kind) { + switch (backend->type) { case CHARDEV_BACKEND_KIND_FILE: chr = qmp_chardev_open_file(backend->file, errp); break; @@ -4296,7 +4296,7 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend, chr = qemu_chr_open_ringbuf(backend->ringbuf, errp); break; default: - error_setg(errp, "unknown chardev backend (%d)", backend->kind); + error_setg(errp, "unknown chardev backend (%d)", backend->type); break; } @@ -4312,9 +4312,9 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend, if (chr) { chr->label = g_strdup(id); chr->avail_connections = - (backend->kind == CHARDEV_BACKEND_KIND_MUX) ? MAX_MUX : 1; + (backend->type == CHARDEV_BACKEND_KIND_MUX) ? MAX_MUX : 1; if (!chr->filename) { - chr->filename = g_strdup(ChardevBackendKind_lookup[backend->kind]); + chr->filename = g_strdup(ChardevBackendKind_lookup[backend->type]); } if (!chr->explicit_be_open) { qemu_chr_be_event(chr, CHR_EVENT_OPENED); diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index 6c9fecd..99bf00a 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -136,7 +136,7 @@ struct %(c_name)s { ''') else: ret += mcgen(''' - %(c_type)s kind; + %(c_type)s type; ''', c_type=c_name(variants.tag_member.type.name)) @@ -152,10 +152,7 @@ struct %(c_name)s { union { /* union tag is @%(c_name)s */ void *data; ''', - # TODO ugly special case for simple union - # Use same tag name in C as on the wire to get rid of - # it, then: c_name=c_name(variants.tag_member.name) - c_name=c_name(variants.tag_name or 'kind')) + c_name=c_name(variants.tag_member.name)) for var in variants.variants: # Ugly special case for simple union TODO get rid of it diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index d776948..59b46e9 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -207,11 +207,11 @@ void visit_type_%(c_name)s(Visitor *m, %(c_name)s **obj, const char *name, Error if (err) { goto out; } - visit_get_next_type(m, (int*) &(*obj)->kind, %(c_name)s_qtypes, name, &err); + visit_get_next_type(m, (int*) &(*obj)->type, %(c_name)s_qtypes, name, &err); if (err) { goto out_end; } - switch ((*obj)->kind) { + switch ((*obj)->type) { ''', c_name=c_name(name)) @@ -278,9 +278,6 @@ void visit_type_%(c_name)s(Visitor *m, %(c_name)s **obj, const char *name, Error c_name=c_name(name)) tag_key = variants.tag_member.name - if not variants.tag_name: - # we pointlessly use a different key for simple unions - tag_key = 'type' ret += mcgen(''' visit_type_%(c_type)s(m, &(*obj)->%(c_name)s, "%(name)s", &err); if (err) { @@ -292,11 +289,7 @@ void visit_type_%(c_name)s(Visitor *m, %(c_name)s **obj, const char *name, Error switch ((*obj)->%(c_name)s) { ''', c_type=variants.tag_member.type.c_name(), - # TODO ugly special case for simple union - # Use same tag name in C as on the wire to get rid of - # it, then: c_name=c_name(variants.tag_member.name) - c_name=c_name(variants.tag_name or 'kind'), - name=tag_key) + c_name=c_name(tag_key), name=tag_key) for var in variants.variants: # TODO ugly special case for simple union diff --git a/tests/test-qmp-commands.c b/tests/test-qmp-commands.c index 8d5249e..6a67e73 100644 --- a/tests/test-qmp-commands.c +++ b/tests/test-qmp-commands.c @@ -64,7 +64,7 @@ __org_qemu_x_Union1 *qmp___org_qemu_x_command(__org_qemu_x_EnumList *a, { __org_qemu_x_Union1 *ret = g_new0(__org_qemu_x_Union1, 1); - ret->kind = ORG_QEMU_X_UNION1_KIND___ORG_QEMU_X_BRANCH; + ret->type = ORG_QEMU_X_UNION1_KIND___ORG_QEMU_X_BRANCH; ret->__org_qemu_x_branch = strdup("blah1"); return ret; diff --git a/tests/test-qmp-input-visitor.c b/tests/test-qmp-input-visitor.c index 61715b3..da84993 100644 --- a/tests/test-qmp-input-visitor.c +++ b/tests/test-qmp-input-visitor.c @@ -374,7 +374,7 @@ static void test_visitor_in_alternate(TestInputVisitorData *data, visit_type_UserDefAlternate(v, &tmp, NULL, &err); g_assert(err == NULL); - g_assert_cmpint(tmp->kind, ==, USER_DEF_ALTERNATE_KIND_I); + g_assert_cmpint(tmp->type, ==, USER_DEF_ALTERNATE_KIND_I); g_assert_cmpint(tmp->i, ==, 42); qapi_free_UserDefAlternate(tmp); } @@ -404,7 +404,7 @@ static void test_native_list_integer_helper(TestInputVisitorData *data, visit_type_UserDefNativeListUnion(v, &cvalue, NULL, &err); g_assert(err == NULL); g_assert(cvalue != NULL); - g_assert_cmpint(cvalue->kind, ==, kind); + g_assert_cmpint(cvalue->type, ==, kind); switch (kind) { case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER: { @@ -567,7 +567,7 @@ static void test_visitor_in_native_list_bool(TestInputVisitorData *data, visit_type_UserDefNativeListUnion(v, &cvalue, NULL, &err); g_assert(err == NULL); g_assert(cvalue != NULL); - g_assert_cmpint(cvalue->kind, ==, USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN); + g_assert_cmpint(cvalue->type, ==, USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN); for (i = 0, elem = cvalue->boolean; elem; elem = elem->next, i++) { g_assert_cmpint(elem->value, ==, (i % 3 == 0) ? 1 : 0); @@ -602,7 +602,7 @@ static void test_visitor_in_native_list_string(TestInputVisitorData *data, visit_type_UserDefNativeListUnion(v, &cvalue, NULL, &err); g_assert(err == NULL); g_assert(cvalue != NULL); - g_assert_cmpint(cvalue->kind, ==, USER_DEF_NATIVE_LIST_UNION_KIND_STRING); + g_assert_cmpint(cvalue->type, ==, USER_DEF_NATIVE_LIST_UNION_KIND_STRING); for (i = 0, elem = cvalue->string; elem; elem = elem->next, i++) { gchar str[8]; @@ -641,7 +641,7 @@ static void test_visitor_in_native_list_number(TestInputVisitorData *data, visit_type_UserDefNativeListUnion(v, &cvalue, NULL, &err); g_assert(err == NULL); g_assert(cvalue != NULL); - g_assert_cmpint(cvalue->kind, ==, USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER); + g_assert_cmpint(cvalue->type, ==, USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER); for (i = 0, elem = cvalue->number; elem; elem = elem->next, i++) { GString *double_expected = g_string_new(""); diff --git a/tests/test-qmp-output-visitor.c b/tests/test-qmp-output-visitor.c index 1a28dc2..2162a4a 100644 --- a/tests/test-qmp-output-visitor.c +++ b/tests/test-qmp-output-visitor.c @@ -517,7 +517,7 @@ static void test_visitor_out_alternate(TestOutputVisitorData *data, Error *err = NULL; UserDefAlternate *tmp = g_malloc0(sizeof(UserDefAlternate)); - tmp->kind = USER_DEF_ALTERNATE_KIND_I; + tmp->type = USER_DEF_ALTERNATE_KIND_I; tmp->i = 42; visit_type_UserDefAlternate(data->ov, &tmp, NULL, &err); @@ -542,7 +542,7 @@ static void test_visitor_out_empty(TestOutputVisitorData *data, static void init_native_list(UserDefNativeListUnion *cvalue) { int i; - switch (cvalue->kind) { + switch (cvalue->type) { case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER: { intList **list = &cvalue->integer; for (i = 0; i < 32; i++) { @@ -763,14 +763,14 @@ static void test_native_list(TestOutputVisitorData *data, Error *err = NULL; QObject *obj; - cvalue->kind = kind; + cvalue->type = kind; init_native_list(cvalue); visit_type_UserDefNativeListUnion(data->ov, &cvalue, NULL, &err); g_assert(err == NULL); obj = qmp_output_get_qobject(data->qov); - check_native_list(obj, cvalue->kind); + check_native_list(obj, cvalue->type); qapi_free_UserDefNativeListUnion(cvalue); qobject_decref(obj); } diff --git a/tpm.c b/tpm.c index 4e9b109..fcab81c 100644 --- a/tpm.c +++ b/tpm.c @@ -260,7 +260,7 @@ static TPMInfo *qmp_query_tpm_inst(TPMBackend *drv) switch (drv->ops->type) { case TPM_TYPE_PASSTHROUGH: - res->options->kind = TPM_TYPE_OPTIONS_KIND_PASSTHROUGH; + res->options->type = TPM_TYPE_OPTIONS_KIND_PASSTHROUGH; tpo = g_new0(TPMPassthroughOptions, 1); res->options->passthrough = tpo; if (drv->path) { diff --git a/ui/input-keymap.c b/ui/input-keymap.c index 7635cb0..088523d 100644 --- a/ui/input-keymap.c +++ b/ui/input-keymap.c @@ -139,10 +139,10 @@ static int number_to_qcode[0x100]; int qemu_input_key_value_to_number(const KeyValue *value) { - if (value->kind == KEY_VALUE_KIND_QCODE) { + if (value->type == KEY_VALUE_KIND_QCODE) { return qcode_to_number[value->qcode]; } else { - assert(value->kind == KEY_VALUE_KIND_NUMBER); + assert(value->type == KEY_VALUE_KIND_NUMBER); return value->number; } } @@ -166,10 +166,10 @@ int qemu_input_key_number_to_qcode(uint8_t nr) int qemu_input_key_value_to_qcode(const KeyValue *value) { - if (value->kind == KEY_VALUE_KIND_QCODE) { + if (value->type == KEY_VALUE_KIND_QCODE) { return value->qcode; } else { - assert(value->kind == KEY_VALUE_KIND_NUMBER); + assert(value->type == KEY_VALUE_KIND_NUMBER); return qemu_input_key_number_to_qcode(value->number); } } @@ -180,7 +180,7 @@ int qemu_input_key_value_to_scancode(const KeyValue *value, bool down, int keycode = qemu_input_key_value_to_number(value); int count = 0; - if (value->kind == KEY_VALUE_KIND_QCODE && + if (value->type == KEY_VALUE_KIND_QCODE && value->qcode == Q_KEY_CODE_PAUSE) { /* specific case */ int v = down ? 0 : 0x80; diff --git a/ui/input-legacy.c b/ui/input-legacy.c index e50f296..6149648 100644 --- a/ui/input-legacy.c +++ b/ui/input-legacy.c @@ -150,7 +150,7 @@ static void legacy_mouse_event(DeviceState *dev, QemuConsole *src, }; QEMUPutMouseEntry *s = (QEMUPutMouseEntry *)dev; - switch (evt->kind) { + switch (evt->type) { case INPUT_EVENT_KIND_BTN: if (evt->btn->down) { s->buttons |= bmap[evt->btn->button]; diff --git a/ui/input.c b/ui/input.c index 1a552d1..fd86571 100644 --- a/ui/input.c +++ b/ui/input.c @@ -147,10 +147,10 @@ void qmp_x_input_send_event(bool has_console, int64_t console, for (e = events; e != NULL; e = e->next) { InputEvent *event = e->value; - if (!qemu_input_find_handler(1 << event->kind, con)) { + if (!qemu_input_find_handler(1 << event->type, con)) { error_setg(errp, "Input handler not found for " "event type %s", - InputEventKind_lookup[event->kind]); + InputEventKind_lookup[event->type]); return; } } @@ -197,9 +197,9 @@ static void qemu_input_event_trace(QemuConsole *src, InputEvent *evt) if (src) { idx = qemu_console_get_index(src); } - switch (evt->kind) { + switch (evt->type) { case INPUT_EVENT_KIND_KEY: - switch (evt->key->key->kind) { + switch (evt->key->key->type) { case KEY_VALUE_KIND_NUMBER: qcode = qemu_input_key_number_to_qcode(evt->key->key->number); name = QKeyCode_lookup[qcode]; @@ -311,12 +311,12 @@ void qemu_input_event_send(QemuConsole *src, InputEvent *evt) qemu_input_event_trace(src, evt); /* pre processing */ - if (graphic_rotate && (evt->kind == INPUT_EVENT_KIND_ABS)) { + if (graphic_rotate && (evt->type == INPUT_EVENT_KIND_ABS)) { qemu_input_transform_abs_rotate(evt); } /* send event */ - s = qemu_input_find_handler(1 << evt->kind, src); + s = qemu_input_find_handler(1 << evt->type, src); if (!s) { return; } @@ -349,7 +349,7 @@ InputEvent *qemu_input_event_new_key(KeyValue *key, bool down) { InputEvent *evt = g_new0(InputEvent, 1); evt->key = g_new0(InputKeyEvent, 1); - evt->kind = INPUT_EVENT_KIND_KEY; + evt->type = INPUT_EVENT_KIND_KEY; evt->key->key = key; evt->key->down = down; return evt; @@ -372,7 +372,7 @@ void qemu_input_event_send_key(QemuConsole *src, KeyValue *key, bool down) void qemu_input_event_send_key_number(QemuConsole *src, int num, bool down) { KeyValue *key = g_new0(KeyValue, 1); - key->kind = KEY_VALUE_KIND_NUMBER; + key->type = KEY_VALUE_KIND_NUMBER; key->number = num; qemu_input_event_send_key(src, key, down); } @@ -380,7 +380,7 @@ void qemu_input_event_send_key_number(QemuConsole *src, int num, bool down) void qemu_input_event_send_key_qcode(QemuConsole *src, QKeyCode q, bool down) { KeyValue *key = g_new0(KeyValue, 1); - key->kind = KEY_VALUE_KIND_QCODE; + key->type = KEY_VALUE_KIND_QCODE; key->qcode = q; qemu_input_event_send_key(src, key, down); } @@ -399,7 +399,7 @@ InputEvent *qemu_input_event_new_btn(InputButton btn, bool down) { InputEvent *evt = g_new0(InputEvent, 1); evt->btn = g_new0(InputBtnEvent, 1); - evt->kind = INPUT_EVENT_KIND_BTN; + evt->type = INPUT_EVENT_KIND_BTN; evt->btn->button = btn; evt->btn->down = down; return evt; @@ -451,7 +451,7 @@ InputEvent *qemu_input_event_new_move(InputEventKind kind, InputEvent *evt = g_new0(InputEvent, 1); InputMoveEvent *move = g_new0(InputMoveEvent, 1); - evt->kind = kind; + evt->type = kind; evt->data = move; move->axis = axis; move->value = value; diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 2add83a..277b139 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -904,7 +904,7 @@ SocketAddress *socket_parse(const char *str, Error **errp) error_setg(errp, "invalid Unix socket address"); goto fail; } else { - addr->kind = SOCKET_ADDRESS_KIND_UNIX; + addr->type = SOCKET_ADDRESS_KIND_UNIX; addr->q_unix = g_new(UnixSocketAddress, 1); addr->q_unix->path = g_strdup(str + 5); } @@ -913,12 +913,12 @@ SocketAddress *socket_parse(const char *str, Error **errp) error_setg(errp, "invalid file descriptor address"); goto fail; } else { - addr->kind = SOCKET_ADDRESS_KIND_FD; + addr->type = SOCKET_ADDRESS_KIND_FD; addr->fd = g_new(String, 1); addr->fd->str = g_strdup(str + 3); } } else { - addr->kind = SOCKET_ADDRESS_KIND_INET; + addr->type = SOCKET_ADDRESS_KIND_INET; addr->inet = inet_parse(str, errp); if (addr->inet == NULL) { goto fail; @@ -938,7 +938,7 @@ int socket_connect(SocketAddress *addr, Error **errp, int fd; opts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort); - switch (addr->kind) { + switch (addr->type) { case SOCKET_ADDRESS_KIND_INET: inet_addr_to_opts(opts, addr->inet); fd = inet_connect_opts(opts, errp, callback, opaque); @@ -970,7 +970,7 @@ int socket_listen(SocketAddress *addr, Error **errp) int fd; opts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort); - switch (addr->kind) { + switch (addr->type) { case SOCKET_ADDRESS_KIND_INET: inet_addr_to_opts(opts, addr->inet); fd = inet_listen_opts(opts, 0, errp); @@ -998,7 +998,7 @@ int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp) int fd; opts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort); - switch (remote->kind) { + switch (remote->type) { case SOCKET_ADDRESS_KIND_INET: inet_addr_to_opts(opts, remote->inet); if (local) { -- 2.4.3