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')) From patchwork Mon Feb 26 14:11:04 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: 775867 Delivered-To: patch@linaro.org Received: by 2002:a5d:6103:0:b0:33d:da16:65b6 with SMTP id v3csp348702wrt; Mon, 26 Feb 2024 06:12:36 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVhvK0JvuzaRboXOCeeUfiIhx5IMHQ15rYEF5ov+iRY45e6C4vhqXFNjBLKlgEsC9P7KQxixkzvqoLF1Oj0HNxm X-Google-Smtp-Source: AGHT+IF4kpF2e9kqQJ5lrAU8QZ8A3tsbC75NtMLUS07MaphQbiVGGiXtcseS1joOKQZiEdNII00W X-Received: by 2002:a05:622a:1a86:b0:42d:f362:8c8e with SMTP id s6-20020a05622a1a8600b0042df3628c8emr9343258qtc.23.1708956756732; Mon, 26 Feb 2024 06:12:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708956756; cv=none; d=google.com; s=arc-20160816; b=BPnn7lj+DHd6UWENELf1KjeBnwdET26XBR1+W0hwXO6mpZ/5oAYBZWLXzhKVDmx5gb jUggz3hHzFFNGZsx9ujeyq9LbJWWTwenaIdgzes0dRHBKRNPlmsToirYGtiVZ42cks2k qUp4E/MOpf32WKPv3R/F7OA/k4/NJ7ARQeHI2z49cbqUaS7ZtRM2miZVsVyUY9AXzdmj 3K85uiBBZVp0myWwITaZd1NVbhbBScl9ap+I+w5oFNZELlsl8IwIGG82LZnzWKlqJdAs kKGKRpVwcqaTWPTuyC9jxpRvFdofqOv59Ao3OQZ3Y8U1+mHnKKkm5LhX+qIx3vkuG4rM +DJA== 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=vKjecqdxRCZ5NMK4buR6wBDSR91vGXc+/LHUa2wYvFI=; fh=IQu3r+cHSJqlwj21O6VeVFreqrZ9Z8Fr9GRd1S5VkGc=; b=sgIUrOrWGjvS1gu9zODah1JacnOa2LLAPJfJavb0HEhFrU87f/7ZSoAZFqO1nQJfo3 wUeeKBVAHoH3h1E9mq26QjHXwsfHYxtuVqTwPCQ04YU5tM21dMhdZZtq6os8ZkEt4D4L v+FE9XxZ61bDgYrMtyIA/Agxldg8SOB8VPcQAwuYY2mm90eDXkFtYaAt9yBakZZL6SsU 1pEq2bYSG3VlI+T9o87Eb5eL9RezcacW/6STKZCOQJhaZHjCBnKYHojfgQgEUUTPZFb2 yXPr+Akzv+7Znh/WNsG9+XTszvT7vFuT4ad15PdJLxxXtyu0xhrLTt0+PV0jw3dqw9ba RIuQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XFvPHYIy; 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 y5-20020a05622a004500b0042e8756684fsi1923116qtw.112.2024.02.26.06.12.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Feb 2024 06:12:36 -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=XFvPHYIy; 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 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) 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-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) 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) 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?Ma?= =?utf-8?q?rc-Andr=C3=A9_Lureau?= 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Steve Sistare Signed-off-by: Steve Sistare Reviewed-by: Marc-André 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) = &(*(tail))->next; \ } while (0) +/* + * For any GenericList @list, return its length. + */ +#define QAPI_LIST_LENGTH(list) \ + ({ \ + size_t _len = 0; \ + typeof(list) _tail; \ + for (_tail = list; _tail != NULL; _tail = _tail->next) { \ + _len++; \ + } \ + _len; \ + }) + #endif From patchwork Mon Feb 26 14:11:05 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: 775870 Delivered-To: patch@linaro.org Received: by 2002:a5d:6103:0:b0:33d:da16:65b6 with SMTP id v3csp348969wrt; Mon, 26 Feb 2024 06:13:04 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCX3JqLAnHNiyWb5uQ+hgTyI9trEHMkpzcPVRLUSIydYXtxD0BQBUmX8IslRXXKBXsrG/HYMDlGVtdlo/W9ip9C9 X-Google-Smtp-Source: AGHT+IFTfOPgh3a5dVLLg8qN2SdRLdW17eFW1t419F2LwoSEK6xrNUeUspiooPiWVf6p02CZMkAy X-Received: by 2002:ac8:5f91:0:b0:42e:7ece:8f96 with SMTP id j17-20020ac85f91000000b0042e7ece8f96mr6155504qta.19.1708956784602; Mon, 26 Feb 2024 06:13:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708956784; cv=none; d=google.com; s=arc-20160816; b=oe2CiJyCIdEYQcMXi7i3IKYEIXzVLovzgMG5kW2n+2CyAaOb2rqiMeQ5Yqr/LtEMTp HSVI1X+5IYwccV6OHAEqZEHkLevyJ8Z2MJ/eL8FLma+WiAAkpjy2XBGwcLjQ/T2xFH0i ynA4ho6ffHsy5mWO8iAJkTfQGY46G0io1G/npUoddsNv6T75s6YljYrgYmw2WjXdToP1 RlS4Rl7tGWCnJvHPRXM1m4o+TtZOAmkYSx4fc9RkqWO/dJiLYkNGWawMz2cNkboJtEkm jzpDNoHlVc4ccjznSqnGx9jMfPfMrfEUQzNI22Ek3UipHRiNozm1f8nzoATl8H1dEgH4 nrnA== 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=ECJWBAuFizFY5M+8BFfcvUn+iW291fgpghDCdO55uQY=; fh=ZBsiCBGz5jaXAQ4DyGdtDqpkDJPpebqEUZWnvrNsvRY=; b=eMTiH4FQiM0a10SOL8l/bkE+nlm5uAjegBUyIzK7ef3UdtBZnl3oj5dvorBqI5MuUo kT9tldTDr6xdn9NQuFkkiKUk3lXAEOL1244EjuWKZyjBR5KknFWvlLMWgvA5MSJdQc33 1zunnKL6zIYhEd5y2a88i+Uz9veeCPw4iCDs5iCU7SpDS2z4rY8Kyie+6/dciya+pl7G nMmeNaieARg1u03MoExRTIZ5p9dBOUuUiUqhoQfZwCkDbpi5TGkq+0OIb977ceU8eiCK 96PP42XRBdF1uEXp6xPBt/tDfAW5sLqSdXstaWbUv5qfe6D+kVEC4zA63QLW7Xwr3cJz tIoA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yPR99tnn; 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 g26-20020ac870da000000b0042e80d034desi2780616qtp.66.2024.02.26.06.13.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Feb 2024 06:13:04 -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=yPR99tnn; 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 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) 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-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) 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) 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?Ma?= =?utf-8?q?rc-Andr=C3=A9_Lureau?= 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Steve Sistare Signed-off-by: Steve Sistare Reviewed-by: Marc-André 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); +/* + * 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) return res; } + +char **strv_from_strList(const strList *list) +{ + const strList *tail; + int i = 0; + char **argv = g_new(char *, QAPI_LIST_LENGTH(list) + 1); + + for (tail = list; tail != NULL; tail = tail->next) { + argv[i++] = g_strdup(tail->value); + } + argv[i] = NULL; + + return argv; +} From patchwork Mon Feb 26 14:11:06 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: 775868 Delivered-To: patch@linaro.org Received: by 2002:a5d:6103:0:b0:33d:da16:65b6 with SMTP id v3csp348703wrt; Mon, 26 Feb 2024 06:12:37 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVIvk+Nj7CuVcfDcdixXgaOzYI3FWT/mBg2kNZyJ64dykvPRkUuE1LRbQX3QPdxrOKnn8zQHdg4mtYBhgS8OuQz X-Google-Smtp-Source: AGHT+IGBXurQu40d1XZ7Lvze0bwIv2itCcNHGiSPPvShudk0DSf5rkOwKdC6PKeYuj5nxsu1usCU X-Received: by 2002:ac8:5a41:0:b0:42e:8d1e:1cf6 with SMTP id o1-20020ac85a41000000b0042e8d1e1cf6mr1393722qta.10.1708956756776; Mon, 26 Feb 2024 06:12:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708956756; cv=none; d=google.com; s=arc-20160816; b=WuhWN3c8hVBLfcmZulbDElyy8CeMZk9lnofJvuqOUrsAp5pRbmiRZiJ06DXtvXwHBH 75l0Krj+yRcFPfRet2jbAE0KCAjl8XyllBEHr548JlVQC8JwMn5p2qM09v2HiJXgOc+c SaF9SJkFyni4L2NVaxrYRzEKg1xGnJRhoIBoUlok38+Krgy4zenzbuUYNBOEdSFacqmu KYS6qAmWgfX/KhfOAEdKgm+yTBLozUF+apT2VutJyBAPZ4dHrCrH7LCtPdbW0dXioHss USYF4gFw5talqN3DtbOjrxTkLm3ofJvUcLuaNRKhrSVv3FrM8qcPm+OxIKI5lg2XrZuc IDAg== 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=WqJvgmD2xSxG0JQjLIcAdWT5nW/VU/NqNnXte/SlaSQ=; fh=rrdawBiabB2BvF5LirDty9GjZtgb7ZSnQZHFBgn7Db0=; b=eFqv3Wu2i5hKejqN+XBnmx3GyFOpLNN8DxYx0WPQrV/LkEVwluPLjkxaZ5Nu2Ol6GR Ia/aeqe9vbzO6XptfrZq4wccR/V3BYGNeHIqs6142s2hBgSopG1pnbTCWT5qiDj031BR JpODScRm05kTzbu3rHLQ9HIacWxhZrJVSfE4QdB1m0hOESJYtm+PQqgh7dCmB+LODSv+ uEdb0z7U/ZNwexWrWekT7SncXsIOdSVrxPFyBmFhScDZIivxIObpOgnsH6bGyiafkPRb DHlr9yHIa7sAj2Ec6FtvYWCgkK9RweLpVE3p+C1wPu5AxMNNMx1a4hyyalAyiB5w+YqL T/Iw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fDCz4KaV; 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 wg23-20020a05620a569700b007872024671csi5082611qkn.732.2024.02.26.06.12.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Feb 2024 06:12:36 -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=fDCz4KaV; 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 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) 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-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) 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) 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?Ma?= =?utf-8?q?rc-Andr=C3=A9_Lureau?= 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Steve Sistare Signed-off-by: Steve Sistare Reviewed-by: Marc-André 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 later. + * 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 = 0, *list, **prev = &head; + + while (length--) { + list = *prev = g_new0(strList, 1); + list->value = g_strdup("aaa"); + prev = &list->next; + } + return head; +} + +static void test_length(void) +{ + strList *list; + int i; + + for (i = 0; i < 5; i++) { + list = make_list(i); + g_assert_cmpint(i, ==, QAPI_LIST_LENGTH(list)); + qapi_free_strList(list); + } +} + +struct { + const char *string; + const char *delim; + const char *argv[5]; +} list_data[] = { + { 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 = 0; i < ARRAY_SIZE(list_data); i++) { + expect = list_data[i].argv; + list = str_split(list_data[i].string, list_data[i].delim); + argv = strv_from_strList(list); + qapi_free_strList(list); + for (j = 0; expect[j] && argv[j]; j++) { + g_assert_cmpstr(expect[j], ==, 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 = { 'test-rcu-simpleq': [], 'test-rcu-tailq': [], 'test-rcu-slist': [], + 'test-strList': [], 'test-qdist': [], 'test-qht': [], 'test-qtree': [], From patchwork Mon Feb 26 14:11:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 775871 Delivered-To: patch@linaro.org Received: by 2002:a5d:6103:0:b0:33d:da16:65b6 with SMTP id v3csp349227wrt; Mon, 26 Feb 2024 06:13:30 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCW8TAlhFWuxfkIhBrf2BR8t8UTNiwhHwdzGULiE0agbv+3VCmik9B8znakY7pvoi160qgkUoeIC92v8jbVk6U12 X-Google-Smtp-Source: AGHT+IEESMK6/fzeNIU2cXSM9LrYPXh3g8Bj8MAVEKvWiXugN5PLXv8lmjK+kVsp73xVNGCrWgPe X-Received: by 2002:a05:6358:9148:b0:179:24b4:41fb with SMTP id r8-20020a056358914800b0017924b441fbmr4207484rwr.3.1708956810243; Mon, 26 Feb 2024 06:13:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708956810; cv=none; d=google.com; s=arc-20160816; b=B74zo6kn4aTdjxeFSuppc2xyImugE57gGp5ZkcIWIXPZ8MdTKPnBRU5P1UXKqJLScX pvB9vXGCGC4ZR5VAx4RB3h8z99IT9hUFS0yIKgrvMdmTj2UBP5jMsl+RvujMxItVI3H+ mjhfUkpo14nM9kB//KtK907kouC++/T+bqAg98z/RPevptkIWsdyDI6O2Ojn7Jg5jcGW P4EYcEKDZkLXB/SgX3hI9VYoRFwfetb/y+119YBP8/F0TNVcK2qoJYs1l0jt3RHRkNhf meVrZNEPvCgtNukjHg0xiyGJpT65y72OMY/wZEf84ZuHFQd8wfKJtK9Br3G8KbGOI9v4 wR7Q== 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=eYUzkIrd2Io/eKJ09aaUbtIZJEnxRyBXW0AQqqMbZXw=; fh=k1vPAXquUc2EydDaefzATpGx9DFb05ahSbXBAdTSjso=; b=XGl8Ts0QLAZGOQNafCJ7/GBBDYs/WZYGggq38mI8gJYzutMngOfClDQCmuRmNplMDO LRYyoiPu7Yygz8tGfOQZWfMCM20xCzz5+mEOAfxYxgOGj/TiyqAnZr5CZBGeJGx9lwMr HdKBdYkiJroMdYi307H3a6jgeQcttUM71rUnc6akLSQhgUiDOvyFkDEhlqxaRtZf7wSC kdBiSi1GJdH/g4br+HbRkxGs/SgLizwJpQDV7hrDncD9NuAXQvLxBvey+19mb4E6u3B0 S6tMaIMIhYGc/XmX3GyZxNfcJWQgs/FTYR3sPZWSbx9LQD9aVkp2p67ok/z5TQcSNp74 PRyg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=impZdyAD; 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 z23-20020ae9c117000000b007873bfc2e16si5170853qki.623.2024.02.26.06.13.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Feb 2024 06:13:30 -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=impZdyAD; 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-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) 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-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) 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) 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 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 @@ #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 -/* provides the length of strList */ -static int -str_list_length(strList *list) -{ - int len = 0; - strList *elem; - - for (elem = list; elem != NULL; elem = elem->next) { - len++; - } - - return len; -} - -static void -init_exec_array(strList *command, char **argv, Error **errp) -{ - int i = 0; - strList *lst; - - for (lst = command; lst; lst = lst->next) { - argv[i++] = lst->value; - } - - argv[i] = NULL; - return; -} - void exec_start_outgoing_migration(MigrationState *s, strList *command, Error **errp) { - QIOChannel *ioc; - - int length = str_list_length(command); - g_auto(GStrv) argv = (char **) g_new0(const char *, length + 1); - - init_exec_array(command, argv, errp); + QIOChannel *ioc = NULL; + g_auto(GStrv) argv = strv_from_strList(command); + const char * const *args = (const char * const *) argv; g_autofree char *new_command = g_strjoinv(" ", (char **)argv); trace_migration_exec_outgoing(new_command); - ioc = QIO_CHANNEL( - qio_channel_command_new_spawn( - (const char * const *) g_steal_pointer(&argv), - O_RDWR, - errp)); + ioc = QIO_CHANNEL(qio_channel_command_new_spawn(args, O_RDWR, errp)); if (!ioc) { return; } @@ -105,19 +71,12 @@ static gboolean exec_accept_incoming_migration(QIOChannel *ioc, void exec_start_incoming_migration(strList *command, Error **errp) { QIOChannel *ioc; - - int length = str_list_length(command); - g_auto(GStrv) argv = (char **) g_new0(const char *, length + 1); - - init_exec_array(command, argv, errp); + g_auto(GStrv) argv = strv_from_strList(command); + const char * const *args = (const char * const *) argv; g_autofree char *new_command = g_strjoinv(" ", (char **)argv); trace_migration_exec_incoming(new_command); - ioc = QIO_CHANNEL( - qio_channel_command_new_spawn( - (const char * const *) g_steal_pointer(&argv), - O_RDWR, - errp)); + ioc = QIO_CHANNEL(qio_channel_command_new_spawn(args, O_RDWR, errp)); if (!ioc) { return; }