@@ -3196,6 +3196,8 @@ X: qapi/*.json
F: include/qapi/
X: include/qapi/qmp/
F: include/qapi/qmp/dispatch.h
+F: include/qemu/strList.h
+F: util/strList.c
F: tests/qapi-schema/
F: tests/unit/test-*-visitor.c
F: tests/unit/test-qapi-*.c
@@ -19,7 +19,6 @@
bool hmp_handle_error(Monitor *mon, Error *err);
void hmp_help_cmd(Monitor *mon, const char *name);
-strList *hmp_split_at_comma(const char *str);
void hmp_info_name(Monitor *mon, const QDict *qdict);
void hmp_info_version(Monitor *mon, const QDict *qdict);
new file mode 100644
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2022 - 2024 Oracle and/or its affiliates.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef QEMU_STR_LIST_H
+#define QEMU_STR_LIST_H
+
+#include "qapi/qapi-builtin-types.h"
+
+/*
+ * Split @str into a strList using the delimiter string @delim.
+ * The delimiter is not included in the result.
+ * Return NULL if @str is NULL or an empty string.
+ * A leading, trailing, or consecutive delimiter produces an
+ * empty string at that position in the output.
+ * All strings are g_strdup'd, and the result can be freed
+ * using qapi_free_strList, or by declaring a local variable
+ * with g_autoptr(strList).
+ */
+strList *str_split(const char *str, const char *delim);
+
+#endif
@@ -38,25 +38,6 @@ bool hmp_handle_error(Monitor *mon, Error *err)
return false;
}
-/*
- * Split @str at comma.
- * A null @str defaults to "".
- */
-strList *hmp_split_at_comma(const char *str)
-{
- char **split = g_strsplit(str ?: "", ",", -1);
- strList *res = NULL;
- strList **tail = &res;
- int i;
-
- for (i = 0; split[i]; i++) {
- QAPI_LIST_APPEND(tail, split[i]);
- }
-
- g_free(split);
- return res;
-}
-
void hmp_info_name(Monitor *mon, const QDict *qdict)
{
NameInfo *info;
@@ -26,6 +26,7 @@
#include "qemu/config-file.h"
#include "qemu/help_option.h"
#include "qemu/option.h"
+#include "qemu/strList.h"
void hmp_info_network(Monitor *mon, const QDict *qdict)
{
@@ -72,7 +73,7 @@ void hmp_announce_self(Monitor *mon, const QDict *qdict)
migrate_announce_params());
qapi_free_strList(params->interfaces);
- params->interfaces = hmp_split_at_comma(interfaces_str);
+ params->interfaces = str_split(interfaces_str, ",");
params->has_interfaces = params->interfaces != NULL;
params->id = g_strdup(id);
qmp_announce_self(params, NULL);
@@ -10,6 +10,7 @@
#include "monitor/hmp.h"
#include "monitor/monitor.h"
#include "qemu/cutils.h"
+#include "qemu/strList.h"
#include "hw/core/cpu.h"
#include "qapi/qmp/qdict.h"
#include "qapi/error.h"
@@ -176,7 +177,7 @@ static StatsFilter *stats_filter(StatsTarget target, const char *names,
request->provider = provider_idx;
if (names && !g_str_equal(names, "*")) {
request->has_names = true;
- request->names = hmp_split_at_comma(names);
+ request->names = str_split(names, ",");
}
QAPI_LIST_PREPEND(request_list, request);
}
new file mode 100644
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2023 Red Hat, Inc.
+ * Copyright (c) 2022 - 2024 Oracle and/or its affiliates.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/strList.h"
+
+strList *str_split(const char *str, const char *delim)
+{
+ g_autofree char **split = g_strsplit(str ?: "", delim, -1);
+ strList *res = NULL;
+ strList **tail = &res;
+ int i;
+
+ for (i = 0; split[i]; i++) {
+ QAPI_LIST_APPEND(tail, split[i]);
+ }
+
+ return res;
+}
@@ -1,4 +1,5 @@
util_ss.add(files('osdep.c', 'cutils.c', 'unicode.c', 'qemu-timer-common.c'))
+util_ss.add(files('strList.c'))
util_ss.add(files('thread-context.c'), numa)
if not config_host_data.get('CONFIG_ATOMIC64')
util_ss.add(files('atomic64.c'))