From nobody Wed Nov 19 00:12:04 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613068917; cv=none; d=zohomail.com; s=zohoarc; b=UM+NSEIKJ3RinI30io2veCnrm3eb62NVzXIAX6yt5axmZCQf6OBqtXloLoPH19hF74dUFBDaLp0lj2F3lIkAEPKrAI7TPNIxt3/d7G0SnL9O1R16V2DdjlO17SY1ZRggFFEm5sBK4STJJsMKUu8YWL/JvCN1uxIyofP8tCL1Q5Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613068917; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YtWnpxgSynxYNfkEmIFF9qrS7ajvKamh+DoUKn1xrko=; b=HIBR4KJ9znT2TZr/eBcJiVNvj09C39STvZYpIjfhGaqoaJfA2/Pca0IHEq8MXhDVZuVEQnyYVgtJgIlhSh/EQB78GHCvh3/cW4Wr8XWeQc3MmfJmKJQImotbWz+3Mm7RkeYLLDV/Vb2xMZIcOs5YFpLHpTNWIlwZ+SbVy5zrO7k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1613068917542883.609025332866; Thu, 11 Feb 2021 10:41:57 -0800 (PST) Received: from localhost ([::1]:60710 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lAGuZ-0002WW-CI for importer@patchew.org; Thu, 11 Feb 2021 13:41:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41580) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lAGlV-0003uB-NS for qemu-devel@nongnu.org; Thu, 11 Feb 2021 13:32:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:27458) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lAGlM-0002aK-7m for qemu-devel@nongnu.org; Thu, 11 Feb 2021 13:32:33 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-316-4EkLj1axPumMRC3tV1yYrA-1; Thu, 11 Feb 2021 13:32:20 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A1D5C1851B14 for ; Thu, 11 Feb 2021 18:31:34 +0000 (UTC) Received: from merkur.fritz.box (ovpn-113-82.ams2.redhat.com [10.36.113.82]) by smtp.corp.redhat.com (Postfix) with ESMTP id AB04C5C260; Thu, 11 Feb 2021 18:31:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613068341; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YtWnpxgSynxYNfkEmIFF9qrS7ajvKamh+DoUKn1xrko=; b=Wp6qffEQB+MGShBy5D7f+4THF8mmOF7pg5F/fBGNI5ZOYgt+dG3ctZo4Fe291/24yjx9dO KSruS0PvxSdiO92SsTjNFNO/ARxfBH94yxXjjLA5oSfmvyhPgIYfJVIKf+adf+72KC2WlG GWal7IgMFGFoOaJ2xfHlNdgUIZq/8XU= X-MC-Unique: 4EkLj1axPumMRC3tV1yYrA-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [PATCH v2 3/6] qapi: Simplify full_name_nth() in qobject-input-visitor Date: Thu, 11 Feb 2021 19:31:15 +0100 Message-Id: <20210211183118.422036-4-kwolf@redhat.com> In-Reply-To: <20210211183118.422036-1-kwolf@redhat.com> References: <20210211183118.422036-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=63.128.21.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.569, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, jsnow@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Instead of counting how many elements from the top of the stack we need to ignore until we find the thing we're interested in, we can just directly pass the StackObject pointer because all callers already know it. We only need a different way now to tell if we want to know the name of something contained in the given StackObject or of the StackObject itself. Passing name =3D NULL is the obvious way to request the latter. This simplifies the interface and makes it easier to use in cases where we have the StackObject, but don't know how many steps down the stack it is. Signed-off-by: Kevin Wolf --- qapi/qobject-input-visitor.c | 43 ++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c index aa95cd49bd..dd04ef0027 100644 --- a/qapi/qobject-input-visitor.c +++ b/qapi/qobject-input-visitor.c @@ -108,20 +108,20 @@ static QObjectInputVisitor *to_qiv(Visitor *v) } =20 /* - * Find the full name of something @qiv is currently visiting. - * @qiv is visiting something named @name in the stack of containers - * @qiv->stack. - * If @n is zero, return its full name. - * If @n is positive, return the full name of the @n-th container - * counting from the top. The stack of containers must have at least - * @n elements. - * The returned string is valid until the next full_name_nth(@v) or - * destruction of @v. + * Find the full name of a member in @so which @qiv is currently + * visiting. If the currently visited thing is an object, @name is + * the (local) name of the member to describe. If it is a list, @name + * is ignored and the current index (so->index) is included. + * + * If @skip_member is true, find the full name of @so itself instead. + * @name must be NULL then. + * + * The returned string is valid until the next full_name_so(@qiv) or + * destruction of @qiv. */ -static const char *full_name_nth(QObjectInputVisitor *qiv, const char *nam= e, - int n) +static const char *full_name_so(QObjectInputVisitor *qiv, const char *name, + bool skip_member, StackObject *so) { - StackObject *so; char buf[32]; =20 if (qiv->errname) { @@ -130,10 +130,14 @@ static const char *full_name_nth(QObjectInputVisitor = *qiv, const char *name, qiv->errname =3D g_string_new(""); } =20 - QSLIST_FOREACH(so , &qiv->stack, node) { - if (n) { - n--; - } else if (qobject_type(so->obj) =3D=3D QTYPE_QDICT) { + if (skip_member && so) { + assert(name =3D=3D NULL); + name =3D so->name; + so =3D QSLIST_NEXT(so, node); + } + + for (; so; so =3D QSLIST_NEXT(so, node)) { + if (qobject_type(so->obj) =3D=3D QTYPE_QDICT) { g_string_prepend(qiv->errname, name ?: ""); g_string_prepend_c(qiv->errname, '.'); } else { @@ -144,7 +148,6 @@ static const char *full_name_nth(QObjectInputVisitor *q= iv, const char *name, } name =3D so->name; } - assert(!n); =20 if (name) { g_string_prepend(qiv->errname, name); @@ -159,7 +162,9 @@ static const char *full_name_nth(QObjectInputVisitor *q= iv, const char *name, =20 static const char *full_name(QObjectInputVisitor *qiv, const char *name) { - return full_name_nth(qiv, name, 0); + StackObject *tos =3D QSLIST_FIRST(&qiv->stack); + + return full_name_so(qiv, name, false, tos); } =20 static QObject *qobject_input_try_get_object(QObjectInputVisitor *qiv, @@ -503,7 +508,7 @@ static bool qobject_input_check_list(Visitor *v, Error = **errp) =20 if (tos->entry) { error_setg(errp, "Only %u list elements expected in %s", - tos->index + 1, full_name_nth(qiv, NULL, 1)); + tos->index + 1, full_name_so(qiv, NULL, true, tos)); return false; } return true; --=20 2.29.2