diff options
| author | Peter Maydell <peter.maydell@linaro.org> | 2021-01-28 22:43:18 +0000 |
|---|---|---|
| committer | Peter Maydell <peter.maydell@linaro.org> | 2021-01-28 22:43:18 +0000 |
| commit | 7e7eb9f852a46b51a71ae9d82590b2e4d28827ee (patch) | |
| tree | d63017ecda357d29659abe087aa6a09d808b06b5 /monitor | |
| parent | 0bcd12fb1513bad44f05f2d3a8eef2a99b3077b6 (diff) | |
| parent | 95b3a8c8a82a34ca874ac0d4a9bbbdb38034acf3 (diff) | |
| download | focaccia-qemu-7e7eb9f852a46b51a71ae9d82590b2e4d28827ee.tar.gz focaccia-qemu-7e7eb9f852a46b51a71ae9d82590b2e4d28827ee.zip | |
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2021-01-28' into staging
QAPI patches patches for 2021-01-28 # gpg: Signature made Thu 28 Jan 2021 07:10:21 GMT # gpg: using RSA key 354BC8B3D7EB2A6B68674E5F3870B400EB918653 # gpg: issuer "armbru@redhat.com" # gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" [full] # gpg: aka "Markus Armbruster <armbru@pond.sub.org>" [full] # Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867 4E5F 3870 B400 EB91 8653 * remotes/armbru/tags/pull-qapi-2021-01-28: qapi: More complex uses of QAPI_LIST_APPEND qapi: Use QAPI_LIST_APPEND in trivial cases qapi: Introduce QAPI_LIST_APPEND qapi: A couple more QAPI_LIST_PREPEND() stragglers net: Clarify early exit condition Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'monitor')
| -rw-r--r-- | monitor/hmp-cmds.c | 35 | ||||
| -rw-r--r-- | monitor/qmp-cmds-control.c | 9 |
2 files changed, 19 insertions, 25 deletions
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 499647a578..a48bc1e904 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -76,20 +76,20 @@ void hmp_handle_error(Monitor *mon, Error *err) static strList *strList_from_comma_list(const char *in) { strList *res = NULL; - strList **hook = &res; + strList **tail = &res; while (in && in[0]) { char *comma = strchr(in, ','); - *hook = g_new0(strList, 1); + char *value; if (comma) { - (*hook)->value = g_strndup(in, comma - in); + value = g_strndup(in, comma - in); in = comma + 1; /* skip the , */ } else { - (*hook)->value = g_strdup(in); + value = g_strdup(in); in = NULL; } - hook = &(*hook)->next; + QAPI_LIST_APPEND(tail, value); } return res; @@ -1706,7 +1706,8 @@ void hmp_closefd(Monitor *mon, const QDict *qdict) void hmp_sendkey(Monitor *mon, const QDict *qdict) { const char *keys = qdict_get_str(qdict, "keys"); - KeyValueList *keylist, *head = NULL, *tmp = NULL; + KeyValue *v = NULL; + KeyValueList *head = NULL, **tail = &head; int has_hold_time = qdict_haskey(qdict, "hold-time"); int hold_time = qdict_get_try_int(qdict, "hold-time", -1); Error *err = NULL; @@ -1723,16 +1724,7 @@ void hmp_sendkey(Monitor *mon, const QDict *qdict) keyname_len = 4; } - keylist = g_malloc0(sizeof(*keylist)); - keylist->value = g_malloc0(sizeof(*keylist->value)); - - if (!head) { - head = keylist; - } - if (tmp) { - tmp->next = keylist; - } - tmp = keylist; + v = g_malloc0(sizeof(*v)); if (strstart(keys, "0x", NULL)) { char *endp; @@ -1741,16 +1733,18 @@ void hmp_sendkey(Monitor *mon, const QDict *qdict) if (endp != keys + keyname_len) { goto err_out; } - keylist->value->type = KEY_VALUE_KIND_NUMBER; - keylist->value->u.number.data = value; + v->type = KEY_VALUE_KIND_NUMBER; + v->u.number.data = value; } else { int idx = index_from_key(keys, keyname_len); if (idx == Q_KEY_CODE__MAX) { goto err_out; } - keylist->value->type = KEY_VALUE_KIND_QCODE; - keylist->value->u.qcode.data = idx; + v->type = KEY_VALUE_KIND_QCODE; + v->u.qcode.data = idx; } + QAPI_LIST_APPEND(tail, v); + v = NULL; if (!*separator) { break; @@ -1762,6 +1756,7 @@ void hmp_sendkey(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, err); out: + qapi_free_KeyValue(v); qapi_free_KeyValueList(head); return; diff --git a/monitor/qmp-cmds-control.c b/monitor/qmp-cmds-control.c index 17514f4959..509ae870bd 100644 --- a/monitor/qmp-cmds-control.c +++ b/monitor/qmp-cmds-control.c @@ -104,17 +104,16 @@ VersionInfo *qmp_query_version(Error **errp) static void query_commands_cb(const QmpCommand *cmd, void *opaque) { - CommandInfoList *info, **list = opaque; + CommandInfo *info; + CommandInfoList **list = opaque; if (!cmd->enabled) { return; } info = g_malloc0(sizeof(*info)); - info->value = g_malloc0(sizeof(*info->value)); - info->value->name = g_strdup(cmd->name); - info->next = *list; - *list = info; + info->name = g_strdup(cmd->name); + QAPI_LIST_PREPEND(*list, info); } CommandInfoList *qmp_query_commands(Error **errp) |