From patchwork Mon Jan 20 21:02:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 858772 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:cc8:b0:385:e875:8a9e with SMTP id dq8csp2121902wrb; Mon, 20 Jan 2025 13:04:03 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWMCO9NtPQe9Lt7X0ezMYSGRrHymEzZFEZtXIbH1zgQ8BoD1gejBXO+1/OHfrrgXyqP5VLueg==@linaro.org X-Google-Smtp-Source: AGHT+IGEE07m/UEul/i7D/PbtClQMr9AqFq4WdIamYekSCw0mvBIXgFsmiFMqYGjxgnx7PXeZjRw X-Received: by 2002:ac8:5713:0:b0:466:85eb:6118 with SMTP id d75a77b69052e-46e12a637b1mr225700251cf.16.1737407043615; Mon, 20 Jan 2025 13:04:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1737407043; cv=none; d=google.com; s=arc-20240605; b=M4du7OH78RCO2n0MYMq7EvARODGGJO+lazsLZDISrpF4Qb2C3qU9E2SS46pyiJvHCX lHAXChz0DgiJjEAzi1jnk4vmtWMxf+MTsSsEj21YzNLlih/tpMZGHCNS0e4IMBenxyrR ZiFbD08Fj2gMBti7y9gOa7spg/cJZfJo4tuKQwzU14zbcCbn+Gh1w5kC9wGjIT4UaY/C 4+8vv4qFNxCB2AMPjD8UGi/MF3fV5iT1ZwzO+3SOuXEluw2VIB4xFYhv/Cpfle2UuVsM EjEQKLkX/nOP18gT/yJ/gssGXhuO1AvkEUIFVpe1C5REN6sBxRwftMkJuNhkIZsdDzdj 6qEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=ptvjzIuVDQT2UCn5M7MTp4nlZSIRLqW4pGkuqXQqZnQ=; fh=g+DwzFOvFlHHnH1XTIEKlzjmBvVkftQxzS3vh+kbty4=; b=DVCBfMd5THFzt5pggxj8zmolm2MIPpfn7Ts9w97438PoW9EhkDp3mvXaN4I7Obi9WF nVdhw4YR8Tef+SIpdQXfcR7C5qnXKID7AXrtbnLMbiCT7YC3+mi79X3J3LSqeDVyCMPf 7HnmDr8pHpRlEA0DklFW/x4cyW4KzNOaCWxHHR1Q4QevXx1xe/u7XHUeSFa186XHVyvl +dLL8TIZjh7v7xcWiFtL2SMsPU+8qr97Gt5gzF+9iW5jyX+rNJ3II9IlJNe76/oy4jv1 QoYOke+WOF79udHTxMc3EsAXN88/k+LkYuFMmb16GkVzoMZGQttliI9DARUFpynMrGYR z6MA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gWL5oCrM; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-46e1040a8f2si102619601cf.206.2025.01.20.13.04.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 20 Jan 2025 13:04:03 -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=gWL5oCrM; 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; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tZyv0-00029t-GJ; Mon, 20 Jan 2025 16:02:46 -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 1tZyub-0001cU-GA for qemu-devel@nongnu.org; Mon, 20 Jan 2025 16:02:25 -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 1tZyuY-0002x3-Rn for qemu-devel@nongnu.org; Mon, 20 Jan 2025 16:02:21 -0500 Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-5d9837f201aso10886783a12.0 for ; Mon, 20 Jan 2025 13:02:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1737406937; x=1738011737; 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=ptvjzIuVDQT2UCn5M7MTp4nlZSIRLqW4pGkuqXQqZnQ=; b=gWL5oCrMq1p46LoYyWfGNHlihzfQlZ78aMZAxao9Sermz0HFtyJ+uE+lRNYDVy3d7C /UK8T4/yfL+t4LKMDJMf/FfubZ/CZD1dL6tl7eT22f1oFezX3Ki32KKXvXOhntp9LkFI e84qGhgWbPd6cB0/IragWLYrP6uZxZjB8wfiJprnl+Wwo9P9YPDpkMWs8dwQIsO3E9uc 8TbBg/ngylzoAhaolDNC6h8HCdDNP0CzBgQdJL8I+eyaEvWO5JtWFYIE5kiy15Zuujz6 S7Qt57dOJzftAp+cVe2Cz9o1ANBKhHsc65ybWWvbxDfJ5yPjtYT6yqjpkYQFXtn/q5br CD8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737406937; x=1738011737; 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=ptvjzIuVDQT2UCn5M7MTp4nlZSIRLqW4pGkuqXQqZnQ=; b=xCdufuqjsHgHMx9jk3mJbDmPf+tOdh8e1LFj0UyksM5NaJtbUnBKkdFbB7IOr94BSM D6jg/o+freIwO4I2bYuydlq6A7Hhpt8sE4pzJwyFkIKrd38Lb6GNK/527TmTo8+16xLy ignmCW0lu3HuTQlNjaTOLB2zfQQ28XnVHues5x3ICga3fUAXzd8CQ2TnyIKhnEZ+NhKL ilg9vv4yeWaEtk/g9H1isEUsQVDjJv9J2q09dX+e9A6q6GVficYYcYGq5/iQ0Qu7wPEl 5vzGSld1Th/tKpDq/1u2c6Zx39vM0B/JgyR9aF9UePWVBVOE7uiyhhHCUguYQUSfrbJB dkfQ== X-Gm-Message-State: AOJu0Ywrzg6Tw+5BVQbzQXThk37RHBmqLjOlbxVTl9/t9ey8bXUX6hfa DK6LhkObUrpv1P1/xDe6kauC5lhUj7k4i2Mssi9JX8P9tmvO8gWAQCQrk8BS954= X-Gm-Gg: ASbGncv7g/lt2p5ers9ErkXqTQvCx6EZZnYMp/zelAFdNvVB2YFjF7uKILFLr+V2uzR YxxHYZ/c63CeuIOg4OFCKQ7rwgCndqSkli13pr7UNF73MLInnCloDzIqzbp5yHU3ooKIFul04HG oau5SFDFLFeiPQoxO0wANXB02E2Mmma99ZlfVcu3deq0Tk4OPkAZQeElpNlsmNlnM+ZxPBfs+UB 3lPmKb3FuPC5NV3k6cg9NeZoQUlDQJBucOXT/eLXy25argc3T4oAarxVS3gEXWXyara X-Received: by 2002:a17:906:794d:b0:aae:8687:c41e with SMTP id a640c23a62f3a-ab38cd913ebmr1339787666b.26.1737406936897; Mon, 20 Jan 2025 13:02:16 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab384f223f3sm664050266b.116.2025.01.20.13.02.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jan 2025 13:02:15 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 380E15F9F8; Mon, 20 Jan 2025 21:02:13 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, qemu-arm@nongnu.org, Thomas Huth , Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , Fabiano Rosas , Laurent Vivier , Paolo Bonzini Subject: [PATCH 4/7] tests/qtest: simplify qtest_process_inbuf Date: Mon, 20 Jan 2025 21:02:09 +0000 Message-Id: <20250120210212.3890255-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250120210212.3890255-1-alex.bennee@linaro.org> References: <20250120210212.3890255-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::529; envelope-from=alex.bennee@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 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Don't both creating a GString to temporarily hold our qtest command. Instead do a simpler g_strndup and use autofree to clean up afterwards. Signed-off-by: Alex Bennée --- system/qtest.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/system/qtest.c b/system/qtest.c index e68ed0f2a8..bb1efba9fd 100644 --- a/system/qtest.c +++ b/system/qtest.c @@ -763,25 +763,21 @@ static void qtest_process_command(CharBackend *chr, gchar **words) } } +/* + * Process as much of @inbuf as we can in newline terminated chunks. + * Remove the processed commands from @inbuf as we go. + */ static void qtest_process_inbuf(CharBackend *chr, GString *inbuf) { char *end; while ((end = strchr(inbuf->str, '\n')) != NULL) { - size_t offset; - GString *cmd; - gchar **words; - - offset = end - inbuf->str; + size_t len = end - inbuf->str; + g_autofree char *cmd = g_strndup(inbuf->str, len); + g_auto(GStrv) words = g_strsplit(cmd, " ", 0); - cmd = g_string_new_len(inbuf->str, offset); - g_string_erase(inbuf, 0, offset + 1); - - words = g_strsplit(cmd->str, " ", 0); + g_string_erase(inbuf, 0, len + 1); qtest_process_command(chr, words); - g_strfreev(words); - - g_string_free(cmd, TRUE); } }