From nobody Thu Jul 17 13:37:48 2025 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1674563069; cv=none; d=zohomail.com; s=zohoarc; b=RCC12DInaUMx4SFgijZm1AsSgMam8LngoXuJYIL7vVZyADc4/GY6JzlNphSBV3tjVX/Hhc7Pi6laRgd+UW0rDQM5dPVJwyk+f129RxgZCt5GcVrkzbSorG3VPxJYX9TOeq/x3qoQArLqJYvVNnM/bwST6LHdSHQ2Nk22T/0Y9JY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674563069; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5YwC4VtXdejT4xi8AfvsT3t0+khiUy2LLRnM+K7/1EU=; b=oDiJ2nX9gJIg8Hk1MTfXBsoN/O+y47Caaz1d/WYtlwvECqDmQqt0tEjuEn9i5KdM+PtF0FO/5pRr/fkmXGVKEM3DGeZC2rQQWIsk9QwHzDfG2DjF05ixgYgBwDkdlVauODHxgtLZ5dN6KdGzStThCWbuV0oJM5GPdR26EethsE4= 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+importer2=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 1674563069550577.9423439078806; Tue, 24 Jan 2023 04:24:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pKIIO-0002WD-Rr; Tue, 24 Jan 2023 07:21:03 -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 1pKIHT-0001yB-Nb for qemu-devel@nongnu.org; Tue, 24 Jan 2023 07:20:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pKIHL-0006Qw-4k for qemu-devel@nongnu.org; Tue, 24 Jan 2023 07:20:03 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-332-CtHZSdq6Oz2C2FXPERqlhQ-1; Tue, 24 Jan 2023 07:19:50 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AC6EB29DD990; Tue, 24 Jan 2023 12:19:49 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.70]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 57E8653A0; Tue, 24 Jan 2023 12:19:49 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id AB97521E6915; Tue, 24 Jan 2023 13:19:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674562794; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5YwC4VtXdejT4xi8AfvsT3t0+khiUy2LLRnM+K7/1EU=; b=LQ02aoOqEs22PyVLgfszeXfjsrUK4PHxTBrbi1iFpWylXy3i4EwksI8A+bx3su7wvc36UP Kgn9NBGpoCS5KPZmbbJVRZ7HNsVszUq8fdNLhIOnAbP+l1Q8RhDoCbqxlZWD+C9Z1T4cDZ CL5zrc+xSuv76mOAU1GHlSj6wQh9Jto= X-MC-Unique: CtHZSdq6Oz2C2FXPERqlhQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, kraxel@redhat.com, kwolf@redhat.com, hreitz@redhat.com, marcandre.lureau@redhat.com, dgilbert@redhat.com, mst@redhat.com, imammedo@redhat.com, ani@anisinha.ca, eduardo@habkost.net, marcel.apfelbaum@gmail.com, philmd@linaro.org, wangyanan55@huawei.com, jasowang@redhat.com, jiri@resnulli.us, berrange@redhat.com, thuth@redhat.com, quintela@redhat.com, stefanb@linux.vnet.ibm.com, stefanha@redhat.com, kvm@vger.kernel.org, qemu-block@nongnu.org Subject: [PATCH 14/32] hmp: Rewrite strlist_from_comma_list() as hmp_split_at_comma() Date: Tue, 24 Jan 2023 13:19:28 +0100 Message-Id: <20230124121946.1139465-15-armbru@redhat.com> In-Reply-To: <20230124121946.1139465-1-armbru@redhat.com> References: <20230124121946.1139465-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1674563071278100015 Content-Type: text/plain; charset="utf-8" Use g_strsplit() for the actual splitting. Give external linkage, so the next commit can move one of its users to another source file. Signed-off-by: Markus Armbruster --- include/monitor/hmp.h | 1 + monitor/hmp-cmds.c | 27 ++++++++++----------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index 6fafa7ffb4..d60d1305b8 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -19,6 +19,7 @@ =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/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index edb50da1ff..2ca869c2ee 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -54,28 +54,21 @@ bool hmp_handle_error(Monitor *mon, Error *err) } =20 /* - * Produce a strList from a comma separated list. - * A NULL or empty input string return NULL. + * Split @str at comma. + * A null @str defaults to "". */ -static strList *strList_from_comma_list(const char *in) +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; =20 - while (in && in[0]) { - char *comma =3D strchr(in, ','); - char *value; - - if (comma) { - value =3D g_strndup(in, comma - in); - in =3D comma + 1; /* skip the , */ - } else { - value =3D g_strdup(in); - in =3D NULL; - } - QAPI_LIST_APPEND(tail, value); + for (i =3D 0; split[i]; i++) { + QAPI_LIST_APPEND(tail, split[i]); } =20 + g_free(split); return res; } =20 @@ -632,7 +625,7 @@ void hmp_announce_self(Monitor *mon, const QDict *qdict) migrate_announce_params()); =20 qapi_free_strList(params->interfaces); - params->interfaces =3D strList_from_comma_list(interfaces_str); + params->interfaces =3D hmp_split_at_comma(interfaces_str); params->has_interfaces =3D params->interfaces !=3D NULL; params->id =3D g_strdup(id); qmp_announce_self(params, NULL); @@ -1234,7 +1227,7 @@ static StatsFilter *stats_filter(StatsTarget target, = const char *names, request->provider =3D provider_idx; if (names && !g_str_equal(names, "*")) { request->has_names =3D true; - request->names =3D strList_from_comma_list(names); + request->names =3D hmp_split_at_comma(names); } QAPI_LIST_PREPEND(request_list, request); } --=20 2.39.0