From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C817ACA5FA1 for ; Mon, 28 Sep 2026 22:39:40 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBJzZ-0008UR-EX; Mon, 28 Sep 2026 18:38:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBJzX-0008QV-Vz for qemu-devel@nongnu.org; Mon, 28 Sep 2026 18:38:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBJzW-0006Jh-Cg for qemu-devel@nongnu.org; Mon, 28 Sep 2026 18:38:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1790635113; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HqujMG7L1zB279NV937q9CGI6HmnX68fxAdMTaokF+0=; b=ZQBmd8QHHKy71x03gmxMoayxLwAQqfxdLRzLLQBkm92GZG5aVWM7r1MfwzNjwSt9lyXzGJ KbB5g2am8y2mLNEeSgdRYRZNm+Qf0QlYVZ24oAjDeFkKfX02tQtkRNQhD/yEE4P7+a9447 YSpyUkkwG+8ONDhtD8TxakAl8EJvC6s= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-684-AyfzX5b-Nx6TsakKxYQCNw-1; Mon, 28 Sep 2026 18:38:30 -0400 X-MC-Unique: AyfzX5b-Nx6TsakKxYQCNw-1 X-Mimecast-MFC-AGG-ID: AyfzX5b-Nx6TsakKxYQCNw_1790635108 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F079C1956052; Mon, 28 Sep 2026 22:38:27 +0000 (UTC) Received: from jsnow-thinkpadp16vgen1.westford.csb (unknown [10.22.64.217]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C0E9019560AB; Mon, 28 Sep 2026 22:38:22 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Cc: Peter Xu , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefan Berger , Fabiano Rosas , Hanna Reitz , Paolo Bonzini , Zhao Liu , Kevin Wolf , Ani Sinha , Pierrick Bouvier , Jiri Pirko , Alex Williamson , Markus Armbruster , Kashyap Chamarthy , Peter Maydell , Kostiantyn Kostiuk , Stefan Hajnoczi , John Snow , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Michael Roth , Mauro Carvalho Chehab , Vladimir Sementsov-Ogievskiy , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , qemu-block@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Stefano Garzarella , Richard Henderson , "Michael S. Tsirkin" , Igor Mammedov , Jason Wang , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Eric Blake Subject: [PATCH 12/14] qapi/parser: add _active_section private member Date: Mon, 28 Sep 2026 18:36:55 -0400 Message-ID: <20260928223657.2303684-13-jsnow@redhat.com> In-Reply-To: <20260928223657.2303684-1-jsnow@redhat.com> References: <20260928223657.2303684-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 10 X-Spam_score: 1.0 X-Spam_bar: + X-Spam_report: (1.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.238, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Instead of peeking inside the section list and always pulling the -1th item, keep track specifically of the last added section. This is because as we allow generated documentation to be inserted into arbitrary positions, the last item in the list will not always actually be the active section under consideration. (Also, the simple list representation is going away, and accessing the -1th item won't actually work anymore.) Signed-off-by: John Snow --- scripts/qapi/parser.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index bdd0f1ec3ff..894b8979b9e 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -760,6 +760,10 @@ def __init__(self, info: QAPISourceInfo, symbol: Optional[str] = None): self.symbol: Optional[str] = symbol # the sections in textual order self._sections: List[QAPIDoc.Section] = [] + + # The most recently appended section, on which append_line operates + self._active_section: Optional[QAPIDoc.Section] = None + # dicts mapping parameter/feature names to their description self._args: Dict[str, QAPIDoc.ArgSection] = {} self._features: Dict[str, QAPIDoc.ArgSection] = {} @@ -799,6 +803,7 @@ def _append(self, section: 'QAPIDoc.Section') -> None: section.info, "duplicated '%s' section" % section.kind) self.since = section self._sections.append(section) + self._active_section = section def __iter__(self) -> Iterator['QAPIDoc.Section']: return iter(self._sections) @@ -820,13 +825,12 @@ def end(self) -> None: def ensure_untagged_section(self, info: QAPISourceInfo) -> None: kind = QAPIDoc.Kind.DETAILS - if self._sections and self._sections[-1].kind == kind: + if self._active_section and self._active_section.kind == kind: # extend current section - section = self._sections[-1] - if not section.text: + if not self._active_section.text: # Section is empty so far; update info to start *here*. - section.info = info - section.text += '\n' + self._active_section.info = info + self._active_section.text += '\n' return # start new section @@ -863,7 +867,8 @@ def new_feature(self, info: QAPISourceInfo, name: str) -> None: self._new_description(info, name, QAPIDoc.Kind.FEATURE, self._features) def append_line(self, line: str) -> None: - self._sections[-1].append_line(line) + assert self._active_section is not None + self._active_section.append_line(line) def _insert_near_kind( self, -- 2.55.0