From nobody Tue Nov 26 11:43:20 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1708956776; cv=none; d=zohomail.com; s=zohoarc; b=P96scE25GWL7u9F3FRWwlmZI1yERvXVlq8AIkolkUOKFzasko9oyxxw4rdKZGkwAAVc7YIOP1WPI2Nxib0KTK9tVYNx1wrk7FzAVH3+KT8YbxOVJGYRaLT+Ytl8kB0DPEaKvkmTEd5luvg24eSmOtBqYnWQnKTKrhDiA9m4eZLo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708956776; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=wvzvKLs6IMYvaFbkImFBMdxhcoPyLIxhzY1NCn0H/34=; b=Z5PXDTtig7RER3QcBIg/CEhb03pkqYE0RGwtrPdlSy6ymx0qPKQkBImLkttX7FD2M7RbVhGwcUYTwORr/kOLvQ6Kavee8UT26usucWf6akxtMB0fE9WDcELsQyC7Ftx733PTpTltleS2YyyyyxqOOi86/TgBtVq/JUF/OTU3eCE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708956776592181.65931762692423; Mon, 26 Feb 2024 06:12:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rebhT-00038a-CA; Mon, 26 Feb 2024 09:11:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rebhS-00038Q-AO for qemu-devel@nongnu.org; Mon, 26 Feb 2024 09:11:22 -0500 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rebhQ-00023t-0c for qemu-devel@nongnu.org; Mon, 26 Feb 2024 09:11:21 -0500 Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-5645960cd56so3517893a12.1 for ; Mon, 26 Feb 2024 06:11:19 -0800 (PST) Received: from m1x-phil.lan ([176.187.223.153]) by smtp.gmail.com with ESMTPSA id ld17-20020a170906f95100b00a3cf9b832eesm2453393ejb.40.2024.02.26.06.11.16 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 26 Feb 2024 06:11:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708956677; x=1709561477; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wvzvKLs6IMYvaFbkImFBMdxhcoPyLIxhzY1NCn0H/34=; b=F3bu97khhaWE+UYP8MWAylO0sHz7WE6mIgWLTREP4QnLSFFTiA1wpi003QRmA7qw2s EzkK79zEYHXUmxjrbssvfKW44a9qv4q8xLJLj8BN9RDW2vKhHAu1oEjopPmOdBgqatfm ghn5hpsclAJtCKcJYkEZShFzJ67ta2NwKcccJ8mE8S4uu6jr8tXd11x4UXOQGzxuuwty N2+Z57zB79wUoefgQyD93qFkmrnsvSpeN16Wdv9wOAsqKcdzIGNyOTGmLVy6xV5dthe+ LBmDA4sh1Vh30yJGSTKDEvfHD0Fm0d7tUXZtYblwjzaDFTdLE0Vmn99a+8dt1fK3uIh+ 8QnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708956677; x=1709561477; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wvzvKLs6IMYvaFbkImFBMdxhcoPyLIxhzY1NCn0H/34=; b=PKacu8xwUZQdlJqfaMiGaveHvTGGgvViOfg7Zd26C3vRfVgNPhNQDUsO8+m1FpNiwM uQn3Pr/8a+jLmszYE7DAM40ex32tlr0kWG3dByMBFJmwU+o9dCKblJlkoRNXZPdtcVq5 J2fnlmMZkLThOrYl3ZY7OyWxJFBC6rPEsYz6XAVwpIl+8wi8Swt6DZ24xCF2B53XoRtl PqI4zYrMS/1CxbXPoOR4eu9ljYNGNYNRLGtgJ47zs8M/tTVWkHVEO9ktdLnk84tdGTap 8dHDa8C1Xfk/EEsc9r86+ezMJAAI2ma4MEp6Ax1xJ6v5rHQ0/cn7/2D5m1JdeSDSbBJQ 1I0g== X-Forwarded-Encrypted: i=1; AJvYcCUvEfNvycz3OfrR0YjLSXQL7nMdqkhaabAzrZ5Rqtw79j06L+2JYi2+Qm2GCMl0ao8rwv6+fr0m5QzAork3NsQpGFjJ4/M= X-Gm-Message-State: AOJu0YxgLx6O2AoPrG5WFUaFOHSmcHAt+bG7J2Bjg39I0b/v6YPFwPnF OltrUU0YYi0/srX65bCa0whB1f5fMwPl/IME+LjC6qPLKOJLJlVdWesk3id6Kfue1WhNPY7WSUt 5 X-Google-Smtp-Source: AGHT+IEPwhW0JLcf0feBXL+XrTPlbEZf4bQ57sCWSCdV1Ptoo/yyI7iuMwlBW8LYlXRZUQ+l1qrB4A== X-Received: by 2002:a17:906:a298:b0:a3f:29e0:c9b4 with SMTP id i24-20020a170906a29800b00a3f29e0c9b4mr4853501ejz.30.1708956677584; Mon, 26 Feb 2024 06:11:17 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Markus Armbruster , qemu-devel@nongnu.org, Steve Sistare Cc: "Dr. David Alan Gilbert" , Jason Wang , Michael Roth , Peter Xu , Fabiano Rosas , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v6 1/5] util: str_split Date: Mon, 26 Feb 2024 15:11:03 +0100 Message-ID: <20240226141108.73664-2-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240226141108.73664-1-philmd@linaro.org> References: <20240226141108.73664-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::529; envelope-from=philmd@linaro.org; helo=mail-ed1-x529.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1708956778473100001 From: Steve Sistare Generalize hmp_split_at_comma() to take any delimiter string, rename as str_split(), and move it to util/strList.c. No functional change. Signed-off-by: Steve Sistare Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-ID: <1708638470-114846-2-git-send-email-steven.sistare@oracle.com> [PMD: Cover new files in 'QAPI' section in MAINTAINERS] Message-ID: --- MAINTAINERS | 2 ++ include/monitor/hmp.h | 1 - include/qemu/strList.h | 25 +++++++++++++++++++++++++ monitor/hmp-cmds.c | 19 ------------------- net/net-hmp-cmds.c | 3 ++- stats/stats-hmp-cmds.c | 3 ++- util/strList.c | 24 ++++++++++++++++++++++++ util/meson.build | 1 + 8 files changed, 56 insertions(+), 22 deletions(-) create mode 100644 include/qemu/strList.h create mode 100644 util/strList.c diff --git a/MAINTAINERS b/MAINTAINERS index 992799171f..7970d34cdd 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -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 diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index 13f9a2dedb..2df661ee3a 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -19,7 +19,6 @@ =20 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); =20 void hmp_info_name(Monitor *mon, const QDict *qdict); void hmp_info_version(Monitor *mon, const QDict *qdict); diff --git a/include/qemu/strList.h b/include/qemu/strList.h new file mode 100644 index 0000000000..4e2e78624e --- /dev/null +++ b/include/qemu/strList.h @@ -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 late= r. + * 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 diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 871898ac46..66b68a0ad3 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -38,25 +38,6 @@ bool hmp_handle_error(Monitor *mon, Error *err) return false; } =20 -/* - * Split @str at comma. - * A null @str defaults to "". - */ -strList *hmp_split_at_comma(const char *str) -{ - char **split =3D g_strsplit(str ?: "", ",", -1); - strList *res =3D NULL; - strList **tail =3D &res; - int i; - - for (i =3D 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; diff --git a/net/net-hmp-cmds.c b/net/net-hmp-cmds.c index 41d326bf5f..969cdd1e4d 100644 --- a/net/net-hmp-cmds.c +++ b/net/net-hmp-cmds.c @@ -26,6 +26,7 @@ #include "qemu/config-file.h" #include "qemu/help_option.h" #include "qemu/option.h" +#include "qemu/strList.h" =20 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()); =20 qapi_free_strList(params->interfaces); - params->interfaces =3D hmp_split_at_comma(interfaces_str); + params->interfaces =3D str_split(interfaces_str, ","); params->has_interfaces =3D params->interfaces !=3D NULL; params->id =3D g_strdup(id); qmp_announce_self(params, NULL); diff --git a/stats/stats-hmp-cmds.c b/stats/stats-hmp-cmds.c index 1f91bf8bd5..62db8c613c 100644 --- a/stats/stats-hmp-cmds.c +++ b/stats/stats-hmp-cmds.c @@ -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, co= nst char *names, request->provider =3D provider_idx; if (names && !g_str_equal(names, "*")) { request->has_names =3D true; - request->names =3D hmp_split_at_comma(names); + request->names =3D str_split(names, ","); } QAPI_LIST_PREPEND(request_list, request); } diff --git a/util/strList.c b/util/strList.c new file mode 100644 index 0000000000..7588c7c797 --- /dev/null +++ b/util/strList.c @@ -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 late= r. + * 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 =3D g_strsplit(str ?: "", delim, -1); + strList *res =3D NULL; + strList **tail =3D &res; + int i; + + for (i =3D 0; split[i]; i++) { + QAPI_LIST_APPEND(tail, split[i]); + } + + return res; +} diff --git a/util/meson.build b/util/meson.build index 0ef9886be0..bd125a4094 100644 --- a/util/meson.build +++ b/util/meson.build @@ -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')) --=20 2.41.0