From patchwork Mon Feb 26 14:11:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 775869 Delivered-To: patch@linaro.org Received: by 2002:a5d:6103:0:b0:33d:da16:65b6 with SMTP id v3csp348876wrt; Mon, 26 Feb 2024 06:12:56 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWhzf+WClr8qZ7b5OMTk+9lPUOc0HF6gSaZiSY4qGcqugvx0/ig4jJEiLmvZY+ZUwylOYx1ghPUXaS3RV+7ojQu X-Google-Smtp-Source: AGHT+IHi1Qx2KmF0WaLeoh71MuNqC/ZNZBCEPL+hsbglpysfZhfTCtNdxgzDxXZAK4tTqd2vttMh X-Received: by 2002:a05:622a:174f:b0:42e:9146:77b2 with SMTP id l15-20020a05622a174f00b0042e914677b2mr720181qtk.61.1708956776277; Mon, 26 Feb 2024 06:12:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708956776; cv=none; d=google.com; s=arc-20160816; b=oitpS1P4gp3Y+f4BikF4Uk1H4GXG0hanErEbcFME2bV9ZgHX9G+IjO1RMU1KcjtdjM 8Qs3Z/K2k+kV+/oUi4limScx11HHozWhlk5P0EztPDkedCfQTlBgJPrGwH3DgmrOhrwM NHAsMy7IW6NU2svt2TWM2kp6/AfO/xz4aQKJ8U1AVvR/T83NS1ACLe249Hgl7Ihjf+Nk tXG/6MGsuDSnNhtPa9sBQML6nNJFUFFhoa09uo2R00PVJ9yAyjwtdrsJNVl2XN0msr+0 lsZGMXbLiTudFfZMW8okqO5cw4H9/gj8Nkh39k44ip73VH4my8psb1NCoX74MT2i8IFE 41og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wvzvKLs6IMYvaFbkImFBMdxhcoPyLIxhzY1NCn0H/34=; fh=W0w3ISjFshYRp2kq1ORIl8wbwqdc6FkjxEDEN0ZZYB8=; b=Mjql8PfwMKo6abWXVgPxm9f8KB6nL5GCR4fKvgN+CwSNXVNX4wB0GQhwt4F+dIHisn oxSHl/HSdioPfQTz9dq1v0XY6UYn1Ec+T496ypCY00qmdIMPlx5/ZP+JO6KLr9ncjxtq ieXvBwHtvY0zAID5zUXXJGuib7UpnAhd7is5yOEgXylxhAVbDELQyQ6StT3MOv0plfCm o8qWSMFk7S6Gk1kGtDBs9XvZtF9uDzBBfV0WH3B7uJfP9mqSGqEbGmKq5Pgh+liqDIZ7 O6X2N35pM7lnvOjDkcsVPtuSZwAg5+eDM9bMEd0MSbju/j7cieCU7T4tGsqCE8P/vCg2 54jA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=F3bu97kh; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id f28-20020a05620a12fc00b00787caf3c9adsi3768773qkl.176.2024.02.26.06.12.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Feb 2024 06:12:56 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=F3bu97kh; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) 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-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) 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) From: =?utf-8?q?Philippe_Mathieu-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?Ph?= =?utf-8?q?ilippe_Mathieu-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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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é 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 @@ 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); 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 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 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; } -/* - * 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; 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" 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); 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, 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); } 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 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; +} 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'))