From nobody Tue Nov 26 09:00:21 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 From nobody Tue Nov 26 09:00:21 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=1708956757; cv=none; d=zohomail.com; s=zohoarc; b=BjF92dswx7ZJsWLSHE0IfiZGqzYxlavY7+YOpYIYIGZR6kpGVzpMpZYF8QaHIGcNPI5QDs91y3jRi9QqC1rjLTwCXgF7MstLXfX+zceWs2U3BfQvewDS8r8+UK/64ic5tDwtuPGzIk3q+vzbeJsE/0/XcIi05fdSH08uP/9Q1pQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708956757; 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=vKjecqdxRCZ5NMK4buR6wBDSR91vGXc+/LHUa2wYvFI=; b=NcA3yeucwm6tgC7J/x2o61zZAnGMKDFbgB+7zZm4aqLF5gpnSWTVQRZKZbMLQVPaxZq28u/1wm53vyN8kVYLAtrSTBiEo4BfljGujE06HtnUA37RF3obQvvcYu1p2iVXpXlC2TtcO+6HIpveRxI9HblKoIJ3ObGPQj+XgTuqcf4= 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 1708956757026462.2671930643445; Mon, 26 Feb 2024 06:12:37 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rebhb-00039f-05; Mon, 26 Feb 2024 09:11:31 -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 1rebhX-000396-5e for qemu-devel@nongnu.org; Mon, 26 Feb 2024 09:11:27 -0500 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rebhV-00024A-H5 for qemu-devel@nongnu.org; Mon, 26 Feb 2024 09:11:26 -0500 Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-565ef8af2f5so1276032a12.3 for ; Mon, 26 Feb 2024 06:11:24 -0800 (PST) Received: from m1x-phil.lan ([176.187.223.153]) by smtp.gmail.com with ESMTPSA id eo8-20020a056402530800b00565001948dfsm2374623edb.44.2024.02.26.06.11.22 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 26 Feb 2024 06:11:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708956684; x=1709561484; 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=vKjecqdxRCZ5NMK4buR6wBDSR91vGXc+/LHUa2wYvFI=; b=XFvPHYIy8rbpshtkBkvNl9VXn6hnwQj3Y2qWZRXvSHnjxIiz+O1XAzqMY+0DSBY3eP oQuNfHC7sSWPd9fVF3444nVIzz/tDEvdAIEMf6EPqhGiDZTfMBCbnponDGySsFL+t9Js 3IjLUeSjPWfLefyvKhmN9JJ78AaNb4WHPY6wrvJ2DQuRieEqG32ABAXEf8U6LwcDIskX DgF7JVK4IhqVqW89nozt3g08o2WxKcBudaD9xEycPy6pAdr7a/JafGW4gAxH/HNwJypr lZw0+K+SYlx1F+yqQjXSb+JsdDGmOhmvuOELo18IsVrPFB52ixPE5BBekMp8UDM2G63/ /mwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708956684; x=1709561484; 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=vKjecqdxRCZ5NMK4buR6wBDSR91vGXc+/LHUa2wYvFI=; b=fArWBlVnVSim7/SjU+aqeghIqJbE2ONc62R5JrjwCebjZ8gTOkrWroawCovJiLC3kP J752vwgA7Wyc4nLiKNapIoaSAhI0WQbjxuPDYWukOb1sawQ0+OW3zNYLvC4mw0W8RZX2 u0P9ACfKudDoiSDV0oHbOUJoKBLNhA+LtrotAR+gjRIwh5cXTGI1vglKnn7wSDG+x6nA ntnIcZLhw0m51ZANHAqgnCEFJgZZlGjnsxL3UHaazk/UDkliMsZhj9gp2tEEjUr6MGUJ wt1NUxtw9FBEEt7L5YJf1i3lXYcrSq4ro6RuEtcbN2ZBAsxIOQOGBnO3n1sCONDLON8Y nofw== X-Forwarded-Encrypted: i=1; AJvYcCXE0ndVnzVJeXyq/zgTQMQ13TTy7O8Zm2zia4VMHLZmBk7rekm0hxCB4o0ET0cyUlP3CuswbM6VkvPVibj9S9v7dACOs2A= X-Gm-Message-State: AOJu0YwdvmNx9LY9iY+AtP07ZmiB6Bb7lAoVYLI3eaZ+A6WxtolGVOks JxzlGCTJ0Yp7EsYVwXRHm9/Qm8FvFskaLi2BOabUo1CiwzQe4sdAmIuFFOc2/gg= X-Google-Smtp-Source: AGHT+IFxGhT9FNZWJ+dorAita6X6FN6sgnQt3C3KAKJ8Rhq0QI8Hp9eZimdEcW0d36MaOC2hI/54RA== X-Received: by 2002:aa7:d48f:0:b0:565:9f59:b3bf with SMTP id b15-20020aa7d48f000000b005659f59b3bfmr4383451edr.6.1708956683815; Mon, 26 Feb 2024 06:11:23 -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?Marc-Andr=C3=A9=20Lureau?= Subject: [PATCH v6 2/5] qapi: QAPI_LIST_LENGTH Date: Mon, 26 Feb 2024 15:11:04 +0100 Message-ID: <20240226141108.73664-3-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::530; envelope-from=philmd@linaro.org; helo=mail-ed1-x530.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: 1708956758460100001 From: Steve Sistare Signed-off-by: Steve Sistare Reviewed-by: Marc-Andr=C3=A9 Lureau Message-ID: <1708638470-114846-3-git-send-email-steven.sistare@oracle.com> --- include/qapi/util.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/qapi/util.h b/include/qapi/util.h index 81a2b13a33..20dfea8a54 100644 --- a/include/qapi/util.h +++ b/include/qapi/util.h @@ -56,4 +56,17 @@ int parse_qapi_name(const char *name, bool complete); (tail) =3D &(*(tail))->next; \ } while (0) =20 +/* + * For any GenericList @list, return its length. + */ +#define QAPI_LIST_LENGTH(list) \ + ({ \ + size_t _len =3D 0; \ + typeof(list) _tail; \ + for (_tail =3D list; _tail !=3D NULL; _tail =3D _tail->next) { \ + _len++; \ + } \ + _len; \ + }) + #endif --=20 2.41.0 From nobody Tue Nov 26 09:00:21 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=1708956784; cv=none; d=zohomail.com; s=zohoarc; b=HEZ4+1rcx0lkF5CAhdj/bA5uVWO8IN83Mv4+cJJKtmgNyQwJ+zVZ1epur8+z/WYuM6GGjGc82bHnDFhWAizT9cEKRLS2ZVU71ilrgnxbjv8tmgGVxV875P4MpftnYXi4fo8YokqQnjHJDOe6L4t6dT+tP2/DX0l2qBrA/AmZvUo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708956784; 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=ECJWBAuFizFY5M+8BFfcvUn+iW291fgpghDCdO55uQY=; b=hcJvix6vCJ8c3w3EsUn1h9pBTaldsjRMUeECimC1ioBLRrgRAwp/fAdPIL1ezkDvOkQ14G9hbLXLU4U7+xxdj0h5dCW19/iseYfE03l0UU/Y+LkZjJNLh5zY0ovOYquWCvoIG6MVEnfuQIdEd3rVN+AMu68/hcoRhIHBa8YeGHk= 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 1708956784869619.4202122223285; Mon, 26 Feb 2024 06:13:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rebhh-0003Bz-6F; Mon, 26 Feb 2024 09:11:37 -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 1rebhd-0003BR-Ev for qemu-devel@nongnu.org; Mon, 26 Feb 2024 09:11:33 -0500 Received: from mail-lj1-x22e.google.com ([2a00:1450:4864:20::22e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rebhb-00024l-Pt for qemu-devel@nongnu.org; Mon, 26 Feb 2024 09:11:33 -0500 Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2d204e102a9so36270061fa.0 for ; Mon, 26 Feb 2024 06:11:31 -0800 (PST) Received: from m1x-phil.lan ([176.187.223.153]) by smtp.gmail.com with ESMTPSA id gq9-20020a170906e24900b00a3fa275de38sm2438554ejb.162.2024.02.26.06.11.28 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 26 Feb 2024 06:11:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708956690; x=1709561490; 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=ECJWBAuFizFY5M+8BFfcvUn+iW291fgpghDCdO55uQY=; b=yPR99tnn/j98GrzA5rhv2EpShQjrtUSgsqSBFpdxnFXCHdC+WMPfwDyUGvv8WZuWlk tANTbiqOLqgtsVt1/btZpmsrmWscyrPZrH0dQe90JArkLaQZTO9wyZE1utETGXCGcOMb z0DUEme3tGQ3V8NhSuaf8EHHR7gchRex4pB5/nRtJ2xqtStSPEDDcraV3MuYPqpZrdz0 a8lkmZMFXqJSHB28yhjjQm9ZK7pbZUAr3SYziv2tQXZhRmiIDQnjhA+9NSq3g/yzLf/P 9/Y7STi0mlzh7FBx3pu5rvea+NGXJadVp/0PDkPf54x8vVCt2tewG745ehBJqWs9M7wW tFHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708956690; x=1709561490; 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=ECJWBAuFizFY5M+8BFfcvUn+iW291fgpghDCdO55uQY=; b=m/Ex5bk+BrnGf35MFj2uYsXolod4LTGXLCQxDctneuKAGG4hglojQabBqhq6Gqsg80 a56t2kVTM4sJhcHsWI3cRZ9juDmSl133iYuyF2I7QkIwimFKxqvWWmsXJ9408xfN+PwD nPHmdCht71Z6OZDa9WCL0Ne8ECXGdt/r6vuMLQrds4/ekbYBtiDECkXm//8tzVUOOO3t xUk/T76QkNokctTzESQrY6qy7Hf4keRcxUfd+nrw//wSQgUfqexLjcbIQCt2QTL6mH/j oXMmasjm+xRqGsNkxlnTczOGLErveMpZrZKrAdwZ5VqQKyDEIIyv8Ma4IwPfBsjD4cJj xGow== X-Forwarded-Encrypted: i=1; AJvYcCWXlMDIjoblbZn1iOE/MvSGG92DPRGrytep2tIRy31QyMebEqfaZ0B+AogujSEN+es+hyvV0LwcgLZgjS45wp5/LksMRK0= X-Gm-Message-State: AOJu0YyAe+O3XSk9aNtw4X6FsNuic8RxiMZJc4weNKk0buEcNtt0e+5a SnRyeM3YNyISK8V3oNqiYklAewhhhUcel1ylzTAOORXb3Aijgpj5bL7DcKFkXDA= X-Google-Smtp-Source: AGHT+IEPkgQkCpspdhaP96yTf1JqLnTZw0O7hCCeEzaCub6DsRYfYXaUBI+4AeKoCQT1NglpriGtZg== X-Received: by 2002:a05:6512:3b2c:b0:512:f719:aec5 with SMTP id f44-20020a0565123b2c00b00512f719aec5mr4068070lfv.9.1708956689785; Mon, 26 Feb 2024 06:11:29 -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?Marc-Andr=C3=A9=20Lureau?= Subject: [PATCH v6 3/5] util: strv_from_strList Date: Mon, 26 Feb 2024 15:11:05 +0100 Message-ID: <20240226141108.73664-4-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::22e; envelope-from=philmd@linaro.org; helo=mail-lj1-x22e.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: 1708956786477100003 From: Steve Sistare Signed-off-by: Steve Sistare Reviewed-by: Marc-Andr=C3=A9 Lureau Message-ID: <1708638470-114846-4-git-send-email-steven.sistare@oracle.com> Message-ID: --- include/qemu/strList.h | 8 ++++++++ util/strList.c | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/qemu/strList.h b/include/qemu/strList.h index 4e2e78624e..b13bd539c3 100644 --- a/include/qemu/strList.h +++ b/include/qemu/strList.h @@ -22,4 +22,12 @@ */ strList *str_split(const char *str, const char *delim); =20 +/* + * Produce and return a NULL-terminated array of strings from @list. + * The result is g_malloc'd and all strings are g_strdup'd. The result + * can be freed using g_strfreev, or by declaring a local variable with + * g_auto(GStrv). + */ +char **strv_from_strList(const strList *list); + #endif diff --git a/util/strList.c b/util/strList.c index 7588c7c797..6da6762c08 100644 --- a/util/strList.c +++ b/util/strList.c @@ -22,3 +22,17 @@ strList *str_split(const char *str, const char *delim) =20 return res; } + +char **strv_from_strList(const strList *list) +{ + const strList *tail; + int i =3D 0; + char **argv =3D g_new(char *, QAPI_LIST_LENGTH(list) + 1); + + for (tail =3D list; tail !=3D NULL; tail =3D tail->next) { + argv[i++] =3D g_strdup(tail->value); + } + argv[i] =3D NULL; + + return argv; +} --=20 2.41.0 From nobody Tue Nov 26 09:00:21 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=1708956757; cv=none; d=zohomail.com; s=zohoarc; b=V0yemWY42lcdb+BetuvTZaKQve/jtfBViiPVYRbuN6YSNrackCrYmYyXLsvOGmrtq/Cdwp62tFt4QyK5eo8x8lhHFUAH9qEg4bj5uoKJ7cbfhSWMjbSONKuvPi/eL0ijig8D8g72D8Kx+/3a/R5qAsjvxTq8SJp14eMh1V3MZuM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708956757; 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=WqJvgmD2xSxG0JQjLIcAdWT5nW/VU/NqNnXte/SlaSQ=; b=WHBgd7/mfchWFq9YKnH8im7t97h3P1AEmR3M9B4YKxz/LuBFRIAnLNxVX+1COliiY2lQNxIKqp0MJ9vjHxCB2d949Hd5Xb3B9b7TCegfdbyvRvUjzt7DGsqF6Y7tltFpHMH+vlJwl6lfDif3y1yLv0gdcFkuAEO+KFjKOpDyR6w= 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 1708956757010839.847545030308; Mon, 26 Feb 2024 06:12:37 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rebhk-0003Cu-Ha; Mon, 26 Feb 2024 09:11:40 -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 1rebhj-0003Ca-9V for qemu-devel@nongnu.org; Mon, 26 Feb 2024 09:11:39 -0500 Received: from mail-lf1-x12f.google.com ([2a00:1450:4864:20::12f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rebhh-00026Z-IO for qemu-devel@nongnu.org; Mon, 26 Feb 2024 09:11:39 -0500 Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-51197ca63f5so4704273e87.1 for ; Mon, 26 Feb 2024 06:11:37 -0800 (PST) Received: from m1x-phil.lan ([176.187.223.153]) by smtp.gmail.com with ESMTPSA id vo9-20020a170907a80900b00a4136d18988sm2452797ejc.36.2024.02.26.06.11.34 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 26 Feb 2024 06:11:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708956696; x=1709561496; 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=WqJvgmD2xSxG0JQjLIcAdWT5nW/VU/NqNnXte/SlaSQ=; b=fDCz4KaVpB+M2bdcQdv/WbPRVXaODcE/twaxehBDIPvMpuobHDplE7ofy9iwdwQb4g 2Jere7GIvGEtBH+JZas/e1G8U6reHsQY8V48QTm6zOpHmONj1AqtllxL/WixjMQo0D7H UY98DUE/hFxN2x6bMqTH/y32p9m7LFHOvBrr6vQ/lmkof4ndRPEkrFyyxc7pwVKQHAB+ fgisbkZ/lIRJI1XAvYhJnFB6eEAVEiZgszvsZ81p3F6QxEPGU0/Of1wMZPeyGBR4oh7O WhXha1CVHPuVYnimM4olkmRdP0fXn2fCWHNzw5YDZrZc2BC0sFwNcvesJq/GQBNqatXX DOMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708956696; x=1709561496; 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=WqJvgmD2xSxG0JQjLIcAdWT5nW/VU/NqNnXte/SlaSQ=; b=NCVT9q+2/plKAkG8LEnyULGMkNcqFHXrseumUwspyi3xy9Gdrch17rjieT7Cl9hH/r obt0JxZpcV+KXafW7EkX/a36JHLvKXATe8WQODbOWEcT5tmvKObJ+OUFEZ4EH8mQ7LZY fsJMmjiU0tgoX0aKBrzLq5lWcyyjcMW5xaurP9zMwc+vVyxUDv0dbya+NYcbbiFTsbFi iKyLH/iaxuKvokX/pe1SJcLZpRf6hoKB3F77u+C0Qzu/NI2lsQJosZ7C0WUjR88t+XaD 5P7QIkeRFQ3FAnCGlxN0/JbvmwNrPtxECXTUf0reiJqnET/VkrM1ZaDJgOeh+nCoRzCM Qr8A== X-Forwarded-Encrypted: i=1; AJvYcCUxVX0BJQ+9GMYYIF0yDT8b50n96uy3YPQOe8DaVOZqLWqI0PFF5rHsx8Cn+Imkai/J1lfphla2Kivx/BGo/CfhoTtW5kU= X-Gm-Message-State: AOJu0YyG/A3ZZF4xvrAq35QifDjfIhHTnNbaGF4OPRnALfWgaX+DYWe0 NuYU8WU8/MH1uuGrlWXjQiNwYufs4cVbiwV6SAybuY+tGO+2IhQzEPht0tTE1yg= X-Google-Smtp-Source: AGHT+IFy7Kz8UxGVoTYHzdHFYMQ5Kogk9oFyxnqGzEnLlbDRElYDdUN1yJ05h9Ebt3hS6L+tibMPRw== X-Received: by 2002:ac2:4344:0:b0:512:bebf:1a with SMTP id o4-20020ac24344000000b00512bebf001amr4798235lfl.57.1708956695939; Mon, 26 Feb 2024 06:11:35 -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?Marc-Andr=C3=A9=20Lureau?= Subject: [PATCH v6 4/5] util: strList unit tests Date: Mon, 26 Feb 2024 15:11:06 +0100 Message-ID: <20240226141108.73664-5-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::12f; envelope-from=philmd@linaro.org; helo=mail-lf1-x12f.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: 1708956758479100003 From: Steve Sistare Signed-off-by: Steve Sistare Reviewed-by: Marc-Andr=C3=A9 Lureau Message-ID: <1708638470-114846-5-git-send-email-steven.sistare@oracle.com> --- tests/unit/test-strList.c | 80 +++++++++++++++++++++++++++++++++++++++ tests/unit/meson.build | 1 + 2 files changed, 81 insertions(+) create mode 100644 tests/unit/test-strList.c diff --git a/tests/unit/test-strList.c b/tests/unit/test-strList.c new file mode 100644 index 0000000000..40af6b2ad1 --- /dev/null +++ b/tests/unit/test-strList.c @@ -0,0 +1,80 @@ +/* + * 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" + +static strList *make_list(int length) +{ + strList *head =3D 0, *list, **prev =3D &head; + + while (length--) { + list =3D *prev =3D g_new0(strList, 1); + list->value =3D g_strdup("aaa"); + prev =3D &list->next; + } + return head; +} + +static void test_length(void) +{ + strList *list; + int i; + + for (i =3D 0; i < 5; i++) { + list =3D make_list(i); + g_assert_cmpint(i, =3D=3D, QAPI_LIST_LENGTH(list)); + qapi_free_strList(list); + } +} + +struct { + const char *string; + const char *delim; + const char *argv[5]; +} list_data[] =3D { + { NULL, ",", { NULL } }, + { "", ",", { NULL } }, + { "a", ",", { "a", NULL } }, + { "a,b", ",", { "a", "b", NULL } }, + { "a,b,c", ",", { "a", "b", "c", NULL } }, + { "first last", " ", { "first", "last", NULL } }, + { "a:", ":", { "a", "", NULL } }, + { "a::b", ":", { "a", "", "b", NULL } }, + { ":", ":", { "", "", NULL } }, + { ":a", ":", { "", "a", NULL } }, + { "::a", ":", { "", "", "a", NULL } }, +}; + +static void test_strv(void) +{ + int i, j; + const char **expect; + strList *list; + char **argv; + + for (i =3D 0; i < ARRAY_SIZE(list_data); i++) { + expect =3D list_data[i].argv; + list =3D str_split(list_data[i].string, list_data[i].delim); + argv =3D strv_from_strList(list); + qapi_free_strList(list); + for (j =3D 0; expect[j] && argv[j]; j++) { + g_assert_cmpstr(expect[j], =3D=3D, argv[j]); + } + g_assert_null(expect[j]); + g_assert_null(argv[j]); + g_strfreev(argv); + } +} + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + g_test_add_func("/test-string/length", test_length); + g_test_add_func("/test-string/strv", test_strv); + return g_test_run(); +} diff --git a/tests/unit/meson.build b/tests/unit/meson.build index cae925c132..9984860f0f 100644 --- a/tests/unit/meson.build +++ b/tests/unit/meson.build @@ -35,6 +35,7 @@ tests =3D { 'test-rcu-simpleq': [], 'test-rcu-tailq': [], 'test-rcu-slist': [], + 'test-strList': [], 'test-qdist': [], 'test-qht': [], 'test-qtree': [], --=20 2.41.0 From nobody Tue Nov 26 09:00:21 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=1708956810; cv=none; d=zohomail.com; s=zohoarc; b=FYUddv1HKksUthK6sKuSFZXGbR1IAu7O4/EVRQOzkZcExKDMB+Z+ey0U99HgApr7sjqtOTOd0PDsRKa8CJlcOHtoYj6x4GCUVsMkXF2h7oUae2BO2pcjO1CaS4oqaSzlKBI+h46rtM4+TFdY3XvezwoHilv87yZeozRTMGWYlR0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708956810; h=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=eYUzkIrd2Io/eKJ09aaUbtIZJEnxRyBXW0AQqqMbZXw=; b=FycPI0yFA4y83glSInKneMSYsmq0v0XePnExUtjv/GsOytxDCXvq2RymaAXWJb7NZYhpr79lqhHqwOXYSHOz2ou5x8tLhNts3AAvlUvZb0TU2kcq6qwMj38OuWknjXSIBgpweIzUQW5u49xyWYYbrhNiyUzlcnADFu9O1dQzk6Q= 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 1708956810683304.06164746927664; Mon, 26 Feb 2024 06:13:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rebht-0003FU-Dt; Mon, 26 Feb 2024 09:11:49 -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 1rebho-0003ER-VT for qemu-devel@nongnu.org; Mon, 26 Feb 2024 09:11:47 -0500 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rebhn-00026p-CP for qemu-devel@nongnu.org; Mon, 26 Feb 2024 09:11:44 -0500 Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-a437a2a46b1so67995766b.2 for ; Mon, 26 Feb 2024 06:11:42 -0800 (PST) Received: from m1x-phil.lan ([176.187.223.153]) by smtp.gmail.com with ESMTPSA id ty6-20020a170907c70600b00a4354b9893csm892192ejc.74.2024.02.26.06.11.40 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 26 Feb 2024 06:11:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708956702; x=1709561502; 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=eYUzkIrd2Io/eKJ09aaUbtIZJEnxRyBXW0AQqqMbZXw=; b=impZdyADCj9awrzTG6hDalX5GtWW6MJK/zbfMfW+hovc44OrHI+SnydVQT6bY59fZL CUwqtaHlv1Bj2NutnuJEtFaxarEelh9FLSjCDWPN/Mk6RChWtpHJjeI+VQPqVltB69UI vqUs9NtnxxpvLHZPooeLL4UQEcy3yqi6swYfoSa05Fy2/xWiFyYbEFANLYHg/ryz91Vj AfVUS9NfKNP475sDXmKVvN++nSTKAifLqlMSqOHkJ0xaPQabyCv59nvqbULfXpjWWPBR OQs7NAIEGk5PxELcqnvc/gUUg4H4qxh+C9Lt83spOpKMBrQ7b+ErOBY3QwHtWncp+rWn JiUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708956702; x=1709561502; 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=eYUzkIrd2Io/eKJ09aaUbtIZJEnxRyBXW0AQqqMbZXw=; b=QGfKY4PvJGVL6txsxZqDoLfjk5aEJFLKjHWh9w1ktMpMXN49DueQN06I6mbslSpWMV jfVxh1tyOhxASN/aGsjvDLU220MDt2d9KFKZ8P6UX4xuVyYWM3hYRtGbKlnLlXS9/gLw RHQUy28kyvFRWYUrcEL806rzcpUk5jUAmCANfIFdwv1PtBSMAu0UjvdZJt5sVTHlTcUF eZHpGMotDVV2vkEBfPa6cTXIqkYa4B3dOJzJ969XoqzJuf4lOH5L9OwVk/8jxTifANBw K9TbtwHaIeGUXj7h+an6T9VDUTemiPfK1qFSo7sUVkHjX4WxcNlMFNxSrALz3+MljKVw N5/g== X-Forwarded-Encrypted: i=1; AJvYcCU8qekCCej40zS1RdTQENIFyTwpK2T4iWW/KrEMKj5UCXpGk+x6ZHZd93sv1HA7RGyjOHvaXcxVIxpuoXJAB13WDDSKqeE= X-Gm-Message-State: AOJu0Yx6yAd3X7oGN0Vse0irluXQdmND7bJV+oVmI0bJRCV85fNfSMsl X8uYycCCmiKgRZHuKS0nM563S/sxXly2sRjlzZUkjys+4E4sh4owaaHU7xjxnmY= X-Google-Smtp-Source: AGHT+IHYfK9hmkc4J6P7Fo51Pp0AOm8ul8y2aewVLJkMTrG1ankM5rND0PGiQl1aPxOqSROblQHjGw== X-Received: by 2002:a17:906:c30f:b0:a43:8f7e:4249 with SMTP id s15-20020a170906c30f00b00a438f7e4249mr201861ejz.72.1708956701849; Mon, 26 Feb 2024 06:11:41 -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 Subject: [PATCH v6 5/5] migration: simplify exec migration functions Date: Mon, 26 Feb 2024 15:11:07 +0100 Message-ID: <20240226141108.73664-6-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-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::62d; envelope-from=philmd@linaro.org; helo=mail-ej1-x62d.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: 1708956812557100005 Content-Type: text/plain; charset="utf-8" From: Steve Sistare Simplify the exec migration code by using list utility functions. As a side effect, this also fixes a minor memory leak. On function return, "g_auto(GStrv) argv" frees argv and each element, which is wrong, because the function does not own the individual elements. To compensate, the code uses g_steal_pointer which NULLs argv and prevents the destructor from running, but argv is leaked. Fixes: cbab4face57b ("migration: convert exec backend ...") Signed-off-by: Steve Sistare Reviewed-by: Fabiano Rosas Message-ID: <1708638470-114846-6-git-send-email-steven.sistare@oracle.com> --- migration/exec.c | 57 +++++++----------------------------------------- 1 file changed, 8 insertions(+), 49 deletions(-) diff --git a/migration/exec.c b/migration/exec.c index 47d2f3b8fb..15184096ac 100644 --- a/migration/exec.c +++ b/migration/exec.c @@ -19,6 +19,7 @@ =20 #include "qemu/osdep.h" #include "qemu/error-report.h" +#include "qemu/strList.h" #include "channel.h" #include "exec.h" #include "migration.h" @@ -39,51 +40,16 @@ const char *exec_get_cmd_path(void) } #endif =20 -/* provides the length of strList */ -static int -str_list_length(strList *list) -{ - int len =3D 0; - strList *elem; - - for (elem =3D list; elem !=3D NULL; elem =3D elem->next) { - len++; - } - - return len; -} - -static void -init_exec_array(strList *command, char **argv, Error **errp) -{ - int i =3D 0; - strList *lst; - - for (lst =3D command; lst; lst =3D lst->next) { - argv[i++] =3D lst->value; - } - - argv[i] =3D NULL; - return; -} - void exec_start_outgoing_migration(MigrationState *s, strList *command, Error **errp) { - QIOChannel *ioc; - - int length =3D str_list_length(command); - g_auto(GStrv) argv =3D (char **) g_new0(const char *, length + 1); - - init_exec_array(command, argv, errp); + QIOChannel *ioc =3D NULL; + g_auto(GStrv) argv =3D strv_from_strList(command); + const char * const *args =3D (const char * const *) argv; g_autofree char *new_command =3D g_strjoinv(" ", (char **)argv); =20 trace_migration_exec_outgoing(new_command); - ioc =3D QIO_CHANNEL( - qio_channel_command_new_spawn( - (const char * const *) g_steal_pointer(&argv), - O_RDWR, - errp)); + ioc =3D QIO_CHANNEL(qio_channel_command_new_spawn(args, O_RDWR, errp)); if (!ioc) { return; } @@ -105,19 +71,12 @@ static gboolean exec_accept_incoming_migration(QIOChan= nel *ioc, void exec_start_incoming_migration(strList *command, Error **errp) { QIOChannel *ioc; - - int length =3D str_list_length(command); - g_auto(GStrv) argv =3D (char **) g_new0(const char *, length + 1); - - init_exec_array(command, argv, errp); + g_auto(GStrv) argv =3D strv_from_strList(command); + const char * const *args =3D (const char * const *) argv; g_autofree char *new_command =3D g_strjoinv(" ", (char **)argv); =20 trace_migration_exec_incoming(new_command); - ioc =3D QIO_CHANNEL( - qio_channel_command_new_spawn( - (const char * const *) g_steal_pointer(&argv), - O_RDWR, - errp)); + ioc =3D QIO_CHANNEL(qio_channel_command_new_spawn(args, O_RDWR, errp)); if (!ioc) { return; } --=20 2.41.0