From nobody Tue May 21 22:07:56 2024 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=1612208400; cv=none; d=zohomail.com; s=zohoarc; b=Z841E73V9dLEaJvPeMs+i7NjbF8Mh2ig+fKOBR3nA997tYaJ2t9LqoEq9Qhv1yLn7QtJfHlTkn7Qc7AL7zruoDoniuGpffrC2BYjf2S4J02/FFQztesmlNtIZxo9YduNs/GnPibCBw3eKB54lOR3VaiL0XSVWu79nnUXlOY6N9Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612208400; 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=89ruhbdp2nuaTclD6+y97IbubISt2Xw9/RkXNOqAxvg=; b=Yt0SILOnr6AQA0NGb7RtQzkqyMGcL/maaLWcrRTfUZ5qt+mb+GxH4t1IzHI41tvhagCsr9w039PDQCP/qIIFfy1sM+w+/8FwbN+ftu3iVwTm7/NHx3CRaR5OneScr2nXXC40SM20Fx46dAghJ95F+cHqY2NoWgIxEJhNpesYFpY= 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 1612208400267517.2467554061251; Mon, 1 Feb 2021 11:40:00 -0800 (PST) Received: from localhost ([::1]:57966 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6f3G-0005BE-IB for importer@patchew.org; Mon, 01 Feb 2021 14:39:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49420) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6f1W-000380-61 for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:10 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:22323) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6f1M-0005Zw-Ln for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:09 -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-502-TWQvpfgDOz2Nd117CGVNZQ-1; Mon, 01 Feb 2021 14:37:55 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 935181005513; Mon, 1 Feb 2021 19:37:53 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1EFF60C05; Mon, 1 Feb 2021 19:37:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612208279; 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=89ruhbdp2nuaTclD6+y97IbubISt2Xw9/RkXNOqAxvg=; b=KcyNo8Z4pRGQmmNbe7DcOhn1lqhdiYGb6IZfy2kYv6dfB6QX4SuhGJX/7P9NHZ5ly8yxGC CfVYy63Nwm3tHgrADT3N7Ksj4FFjPV+81+gavsvBXzNzuZCcU17d5JIgjfJpZDwKsUrD0o vnOFEalSUGnEUuzeHOHqJp+BBPKW1oU= X-MC-Unique: TWQvpfgDOz2Nd117CGVNZQ-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v4 01/16] qapi/commands: assert arg_type is not None Date: Mon, 1 Feb 2021 14:37:32 -0500 Message-Id: <20210201193747.2169670-2-jsnow@redhat.com> In-Reply-To: <20210201193747.2169670-1-jsnow@redhat.com> References: <20210201193747.2169670-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@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=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Eduardo Habkost , Michael Roth , Markus Armbruster , Cleber Rosa , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , John Snow 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" When boxed is True, expr.py asserts that we must have arguments. Ultimately, this should mean that if boxed is True that arg_type should be defined. Mypy cannot infer this, and does not support 'stateful' type inference, e.g.: ``` if x: assert y is not None ... if x: y.etc() ``` does not work, because mypy does not statefully remember the conditional assertion in the second block. Help mypy out by creating a new local that it can track more easily. Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/commands.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index 50978090b44..71744f48a35 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -126,6 +126,9 @@ def gen_marshal(name: str, boxed: bool, ret_type: Optional[QAPISchemaType]) -> str: have_args =3D boxed or (arg_type and not arg_type.is_empty()) + if have_args: + assert arg_type is not None + arg_type_c_name =3D arg_type.c_name() =20 ret =3D mcgen(''' =20 @@ -147,7 +150,7 @@ def gen_marshal(name: str, ret +=3D mcgen(''' %(c_name)s arg =3D {0}; ''', - c_name=3Darg_type.c_name()) + c_name=3Darg_type_c_name) =20 ret +=3D mcgen(''' =20 @@ -163,7 +166,7 @@ def gen_marshal(name: str, ok =3D visit_check_struct(v, errp); } ''', - c_arg_type=3Darg_type.c_name()) + c_arg_type=3Darg_type_c_name) else: ret +=3D mcgen(''' ok =3D visit_check_struct(v, errp); @@ -193,7 +196,7 @@ def gen_marshal(name: str, ret +=3D mcgen(''' visit_type_%(c_arg_type)s_members(v, &arg, NULL); ''', - c_arg_type=3Darg_type.c_name()) + c_arg_type=3Darg_type_c_name) =20 ret +=3D mcgen(''' visit_end_struct(v, NULL); --=20 2.29.2 From nobody Tue May 21 22:07:56 2024 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=1612208591; cv=none; d=zohomail.com; s=zohoarc; b=FMrXeLIy0B9Ncg+04VrDC9NHbPfp14xdUMsrOCLTQkDdP0WQDJF6hD0QZymaMYMq9yCpN6P5VrgNbXZoLbz7EljSL2p3IuFN/tyqXCbPF3lVbD9j4d2A12p5LTSWT9VPjQPhrIOi6+GEH8kk5bVwd6uBTAjyXelrqPdJ1ukH7Bk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612208591; 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=vpdUUQqYcU67G7DPzVF3jWorxgz4UW1DYd4ktGcpFNM=; b=IRy4AxZU3ihiHZtne/u9GcqSxdONkSFZMMqrzc/uHpL4Zf5ImWvombUc4tICc3E2ItmLarJcMfbRhxZvo2WzDi2tWf0fD/bcEx5pJ1StB68aUCV+0CU8QE+YtcGSusGIKEQbhcSTvo8zDghTCm2HfxaJjtio89vAUi4mqJ8TywU= 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 1612208591795164.0512822019922; Mon, 1 Feb 2021 11:43:11 -0800 (PST) Received: from localhost ([::1]:40666 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6f6M-0001Iu-PH for importer@patchew.org; Mon, 01 Feb 2021 14:43:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49404) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6f1V-00037K-Ou for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:09 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:47692) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6f1M-0005ZA-Kr for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:09 -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-28-LjD76NIfM1yeqYkUagh_iA-1; Mon, 01 Feb 2021 14:37:55 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B48CD107ACE3; Mon, 1 Feb 2021 19:37:54 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id C27A160C05; Mon, 1 Feb 2021 19:37:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612208278; 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=vpdUUQqYcU67G7DPzVF3jWorxgz4UW1DYd4ktGcpFNM=; b=LI4pNYlrT5znIz6KZlfyyUplYW5wo8ZRMhUGIPsTHpsKnTeb4XEDQkaX2SXgWP0haD4pJI yp7obNKvQjJwSnt8CxS+klpCa+QHJoLRjYvjIaeZhYwPQlyCG5cjzGq4ozIIsRPmWBZq1N 5KGdF7OTm/4Tnygx0thfhHdsQIUIpMs= X-MC-Unique: LjD76NIfM1yeqYkUagh_iA-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v4 02/16] qapi/events: fix visit_event typing Date: Mon, 1 Feb 2021 14:37:33 -0500 Message-Id: <20210201193747.2169670-3-jsnow@redhat.com> In-Reply-To: <20210201193747.2169670-1-jsnow@redhat.com> References: <20210201193747.2169670-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@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=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Eduardo Habkost , Michael Roth , Markus Armbruster , Cleber Rosa , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , John Snow 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" Actually, the arg_type can indeed be Optional. Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/events.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index 599f3d1f564..9851653b9d1 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -12,7 +12,7 @@ See the COPYING file in the top-level directory. """ =20 -from typing import List +from typing import List, Optional =20 from .common import c_enum_const, c_name, mcgen from .gen import QAPISchemaModularCVisitor, build_params, ifcontext @@ -27,7 +27,7 @@ =20 =20 def build_event_send_proto(name: str, - arg_type: QAPISchemaObjectType, + arg_type: Optional[QAPISchemaObjectType], boxed: bool) -> str: return 'void qapi_event_send_%(c_name)s(%(param)s)' % { 'c_name': c_name(name.lower()), @@ -35,7 +35,7 @@ def build_event_send_proto(name: str, =20 =20 def gen_event_send_decl(name: str, - arg_type: QAPISchemaObjectType, + arg_type: Optional[QAPISchemaObjectType], boxed: bool) -> str: return mcgen(''' =20 @@ -78,7 +78,7 @@ def gen_param_var(typ: QAPISchemaObjectType) -> str: =20 =20 def gen_event_send(name: str, - arg_type: QAPISchemaObjectType, + arg_type: Optional[QAPISchemaObjectType], boxed: bool, event_enum_name: str, event_emit: str) -> str: @@ -99,6 +99,7 @@ def gen_event_send(name: str, proto=3Dbuild_event_send_proto(name, arg_type, boxed)) =20 if have_args: + assert arg_type is not None ret +=3D mcgen(''' QObject *obj; Visitor *v; @@ -114,6 +115,7 @@ def gen_event_send(name: str, name=3Dname) =20 if have_args: + assert arg_type is not None ret +=3D mcgen(''' v =3D qobject_output_visitor_new(&obj); ''') @@ -214,7 +216,7 @@ def visit_event(self, info: QAPISourceInfo, ifcond: List[str], features: List[QAPISchemaFeature], - arg_type: QAPISchemaObjectType, + arg_type: Optional[QAPISchemaObjectType], boxed: bool) -> None: with ifcontext(ifcond, self._genh, self._genc): self._genh.add(gen_event_send_decl(name, arg_type, boxed)) --=20 2.29.2 From nobody Tue May 21 22:07:56 2024 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=1612208495; cv=none; d=zohomail.com; s=zohoarc; b=GjkAb80Op3KHnAij1aHcGRoe073bSjEZ2vs+D79OqsUgoNzsmpIawGnfHb9a8YzFqpb9eFIZjXaBIEAlPlyTXPRd5CwWoKzUjEg5nyzbXXcKv+tteLJho8dEll4YWmis/2Y4phuyCPhkALverkv28puKPbVjTvMo/XedEM2rKjk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612208495; 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=7DenN3noeLnUH/dWExOjt2h30O+qiuhQ342QMX9ClGw=; b=L+idJMj8VIg/RyUJoEHgSyhndc56DtfitQTdev4Qt1bQQxcebkTfYU/gfyJWrx0hQNy3NbaGTF7Rx3C2tYOHEvk9E4BxwEizbItq+1i0NzWIHhdQ09n5I4DfyE2O1X6J10gF2UghiYA9jsTYpBVCdJJJ9j63iFBunyRa0F6X6JQ= 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 161220849542091.80582802473998; Mon, 1 Feb 2021 11:41:35 -0800 (PST) Received: from localhost ([::1]:36228 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6f4o-0007oU-Da for importer@patchew.org; Mon, 01 Feb 2021 14:41:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49382) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6f1U-000359-RA for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:26529) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6f1M-0005ZU-Jr for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:08 -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-233-7zR5r3CGPiGQ8OlZQFYU9w-1; Mon, 01 Feb 2021 14:37:56 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D12DBB8102; Mon, 1 Feb 2021 19:37:55 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id E18D960C05; Mon, 1 Feb 2021 19:37:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612208278; 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=7DenN3noeLnUH/dWExOjt2h30O+qiuhQ342QMX9ClGw=; b=ZTwsdRiA+yGwuDN8uiRiJUdat67e5pXfdNLJWLZE5DakHwvxd5hiHAT7vvb9Zdbw1mYN4c O/uJsixSTAChhQbl+iZpRsvGvp3KlIO96x7CIxx7h5UuNOwUFqi163PqXFARylYFXsU0y7 y8rgBTQ/d9adjeqqNDwWZhAPNjneS24= X-MC-Unique: 7zR5r3CGPiGQ8OlZQFYU9w-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v4 03/16] qapi/main: handle theoretical None-return from re.match() Date: Mon, 1 Feb 2021 14:37:34 -0500 Message-Id: <20210201193747.2169670-4-jsnow@redhat.com> In-Reply-To: <20210201193747.2169670-1-jsnow@redhat.com> References: <20210201193747.2169670-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@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=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Eduardo Habkost , Michael Roth , Markus Armbruster , Cleber Rosa , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , John Snow 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" Mypy cannot understand that this match can never be None, so help it along. Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/qapi/main.py b/scripts/qapi/main.py index 42517210b80..703e7ed1ed5 100644 --- a/scripts/qapi/main.py +++ b/scripts/qapi/main.py @@ -23,6 +23,8 @@ =20 def invalid_prefix_char(prefix: str) -> Optional[str]: match =3D re.match(r'([A-Za-z_.-][A-Za-z0-9_.-]*)?', prefix) + # match cannot be None, but mypy cannot infer that. + assert match is not None if match.end() !=3D len(prefix): return prefix[match.end()] return None --=20 2.29.2 From nobody Tue May 21 22:07:56 2024 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=1612208717; cv=none; d=zohomail.com; s=zohoarc; b=GdcRWLHWyj14qIoXPtsiEDAfU1TNGTTu9wcITLAtR/JtPn6yYy5q8n7Pd9INY3kboL9BdHvWxGaCrlfhS8ORtI1rvPZAM35g+Xco8sgXeweSFuwBB/rRFmj3VUbj/C00bct4XfmugGnptUpBMp+vQNDqlinFD12wBOzBKqUivEA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612208717; 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=6+Vvr8ZNvaZB+B6btD6hQ5WPCE1cJBqkbTYpI07vXpc=; b=Rk4k0/0jRZ1xlvdTfJZ91G/gcld6dtiZdTnmjnuG0T2Af0JHhS4BAFeyHsyukGm/vGSLFdYPLuS1julEBzKBiCLx7SgC1g1zCXqhOD7OB3fvKZwJxrBqdlq1FSu99UE7zV/ap0EFDyWug+NHZ5fMSgdr9IuWCyqvJ67ZXzWJcw0= 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 1612208717058376.0797186346565; Mon, 1 Feb 2021 11:45:17 -0800 (PST) Received: from localhost ([::1]:44828 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6f8G-00032K-5v for importer@patchew.org; Mon, 01 Feb 2021 14:45:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49416) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6f1V-00037e-Va for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:09 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:35438) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6f1Q-0005ai-TK for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:09 -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-395-ywvRlB-pOha3vQuIG3z8OA-1; Mon, 01 Feb 2021 14:37:58 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 14BA51005513; Mon, 1 Feb 2021 19:37:57 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 113AA60C05; Mon, 1 Feb 2021 19:37:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612208281; 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=6+Vvr8ZNvaZB+B6btD6hQ5WPCE1cJBqkbTYpI07vXpc=; b=R9HDkq0kZ13O5y1OlsmsqJOaZRzpySIcgNi+rHWWXSAQUF9vsG8c28NCdgoAiCBRsGPmHz kfnGaeGS6QHWRxHCf7FgIMaI2yh3aIBPajT4u145SNTpdCJZnnGtAHbgEWlNHB9UITCVVn DnclpKVAhbJg7Mu7pJiYNTqfD4PzgWc= X-MC-Unique: ywvRlB-pOha3vQuIG3z8OA-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v4 04/16] qapi/gen: inline _wrap_ifcond into end_if() Date: Mon, 1 Feb 2021 14:37:35 -0500 Message-Id: <20210201193747.2169670-5-jsnow@redhat.com> In-Reply-To: <20210201193747.2169670-1-jsnow@redhat.com> References: <20210201193747.2169670-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@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=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Eduardo Habkost , Michael Roth , Markus Armbruster , Cleber Rosa , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , John Snow 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" We assert _start_if is not None in end_if, but that's opaque to mypy. By inlining _wrap_ifcond, that constraint becomes provable to mypy. Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/gen.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index b40f18eee3c..3d81b90ab71 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -130,15 +130,12 @@ def start_if(self, ifcond: List[str]) -> None: self._start_if =3D (ifcond, self._body, self._preamble) =20 def end_if(self) -> None: - assert self._start_if - self._wrap_ifcond() - self._start_if =3D None - - def _wrap_ifcond(self) -> None: + assert self._start_if is not None self._body =3D _wrap_ifcond(self._start_if[0], self._start_if[1], self._body) self._preamble =3D _wrap_ifcond(self._start_if[0], self._start_if[2], self._preamble) + self._start_if =3D None =20 def get_content(self) -> str: assert self._start_if is None --=20 2.29.2 From nobody Tue May 21 22:07:56 2024 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=1612208604; cv=none; d=zohomail.com; s=zohoarc; b=gZm9jhzERwwz0VV4nHSisfQFa6q+GTXmQdW0V0NmlAHSi1JjpNUPC39SnawMyJg2GKIxhX/iUUZUub+AB7p1e9pmmuFIc4X9P9a1y8R8h2xo578zS5bzq1GsI0uSfxEsUzAyA/qa7wD+GCWNLpe8yib1rv4oadadF4DyUjjR5J8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612208604; 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=aae64tPvuaxqKLnjLqM+1bdqLUUUPIZ0fxZePwQWUSI=; b=SjoJ9hxfKpAo+AAOELgj4kxVCDTER89bcaioBi/QslqWsSrbccJNn9zugAvwj2R9XXizw9bXFQBm2FfbJNEqRoLn07lHWyQFdJr6eLEIXlPsLJOxK4wieeNBOByMAxpDWmF5vWDtkc4i3YdVaMehJyNfUxQh6qAiVRt1hhXkc80= 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 1612208604523652.381831806906; Mon, 1 Feb 2021 11:43:24 -0800 (PST) Received: from localhost ([::1]:40986 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6f6Z-0001Qe-C1 for importer@patchew.org; Mon, 01 Feb 2021 14:43:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49638) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6f1s-0003SG-2e for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:32 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:52221) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6f1p-0005n6-EK for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:31 -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-457-6g-7FWHCMfydbqvCx2E4zg-1; Mon, 01 Feb 2021 14:38:01 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CEC67801817; Mon, 1 Feb 2021 19:38:00 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 45FBE60C05; Mon, 1 Feb 2021 19:37:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612208308; 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=aae64tPvuaxqKLnjLqM+1bdqLUUUPIZ0fxZePwQWUSI=; b=HwcXLOT6PAZ0llsPQt3saKBEmo5j0jI+xO9cp+mWqr9eNrMbg/IfMaQJXbq8YifpK3t2dL d4RXMHD5fDmeV/nPq0u6mJlUCVcIdU7XqF7KHxc+/W0pnJ9eajVr4RD2SMbVNXRSWT8V10 0q+CYjj3MfrBSKpAiW9wKj3zT8iPC38= X-MC-Unique: 6g-7FWHCMfydbqvCx2E4zg-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v4 05/16] qapi: centralize is_[user|system|builtin]_module methods Date: Mon, 1 Feb 2021 14:37:36 -0500 Message-Id: <20210201193747.2169670-6-jsnow@redhat.com> In-Reply-To: <20210201193747.2169670-1-jsnow@redhat.com> References: <20210201193747.2169670-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@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=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Eduardo Habkost , Michael Roth , Markus Armbruster , Cleber Rosa , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , John Snow 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" Define what a module is and define what kind of a module it is once and for all, in one place. Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/gen.py | 25 +++++++++++-------------- scripts/qapi/schema.py | 31 +++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index 3d81b90ab71..2aec6d34365 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -31,7 +31,11 @@ guardstart, mcgen, ) -from .schema import QAPISchemaObjectType, QAPISchemaVisitor +from .schema import ( + QAPISchemaModule, + QAPISchemaObjectType, + QAPISchemaVisitor, +) from .source import QAPISourceInfo =20 =20 @@ -246,21 +250,14 @@ def __init__(self, self._main_module: Optional[str] =3D None =20 @staticmethod - def _is_user_module(name: Optional[str]) -> bool: - return bool(name and not name.startswith('./')) - - @staticmethod - def _is_builtin_module(name: Optional[str]) -> bool: - return not name - - def _module_dirname(self, name: Optional[str]) -> str: - if self._is_user_module(name): + def _module_dirname(name: Optional[str]) -> str: + if QAPISchemaModule.is_user_module(name): return os.path.dirname(name) return '' =20 def _module_basename(self, what: str, name: Optional[str]) -> str: - ret =3D '' if self._is_builtin_module(name) else self._prefix - if self._is_user_module(name): + ret =3D '' if QAPISchemaModule.is_builtin_module(name) else self._= prefix + if QAPISchemaModule.is_user_module(name): basename =3D os.path.basename(name) ret +=3D what if name !=3D self._main_module: @@ -282,7 +279,7 @@ def _add_module(self, name: Optional[str], blurb: str) = -> None: self._genc, self._genh =3D self._module[name] =20 def _add_user_module(self, name: str, blurb: str) -> None: - assert self._is_user_module(name) + assert QAPISchemaModule.is_user_module(name) if self._main_module is None: self._main_module =3D name self._add_module(name, blurb) @@ -292,7 +289,7 @@ def _add_system_module(self, name: Optional[str], blurb= : str) -> None: =20 def write(self, output_dir: str, opt_builtins: bool =3D False) -> None: for name in self._module: - if self._is_builtin_module(name) and not opt_builtins: + if QAPISchemaModule.is_builtin_module(name) and not opt_builti= ns: continue (genc, genh) =3D self._module[name] genc.write(output_dir) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 720449feee4..e80d9320eda 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -141,6 +141,33 @@ def __init__(self, name): self.name =3D name self._entity_list =3D [] =20 + @staticmethod + def is_system_module(name: Optional[str]) -> bool: + """ + System modules are internally defined modules. + + Their names start with the "./" prefix. + """ + return name is None or name.startswith('./') + + @classmethod + def is_user_module(cls, name: Optional[str]) -> bool: + """ + User modules are those defined by the user in qapi JSON files. + + They do not start with the "./" prefix. + """ + return not cls.is_system_module(name) + + @staticmethod + def is_builtin_module(name: Optional[str]) -> bool: + """ + The built-in module is a single System module for the built-in typ= es. + + It is presently always the value 'None'. + """ + return name is None + def add_entity(self, ent): self._entity_list.append(ent) =20 @@ -871,8 +898,8 @@ def resolve_type(self, name, info, what): return typ =20 def _module_name(self, fname): - if fname is None: - return None + if QAPISchemaModule.is_system_module(fname): + return fname return os.path.relpath(fname, self._schema_dir) =20 def _make_module(self, fname): --=20 2.29.2 From nobody Tue May 21 22:07:56 2024 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=1612208536; cv=none; d=zohomail.com; s=zohoarc; b=PE2xCK93r2DOw8Fe6FSfeLweUkMBeKYOIu0QUfZEpdhbYtGm2kcpJ7vVyi1H3eDRqEYWpEHw4V3JWpRUbnu8eY83o5BCcc6RWuVFHesLyq0iNU0O2eCOF59LIkTAIPqOmcMgyi/PuOt2yBdWPTKFyy1JtVhWEzZmW11oYnM9znc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612208536; 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=lb7V/mm7zQa8yrfFR/zgKPDM7V7rJbjKwC0qBdFefDU=; b=D+udhB05QnLQk5D5mN7XYAKyfCNYt+cu6A43XsYaqn5sqsK3vD5gxljS6vOr/UuKlLKh/bbaXpF5G7/yqAzOkcxWZ9nfJp4W+US8yJaGgcrzsUdS5yTQ03/JByw1WJWyAVUs8VNDbhfRQh5OIl1HQ1dKgrB+bF8fT9LMXXZ1Az8= 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 1612208536273906.355446811038; Mon, 1 Feb 2021 11:42:16 -0800 (PST) Received: from localhost ([::1]:38210 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6f5T-0000AK-5o for importer@patchew.org; Mon, 01 Feb 2021 14:42:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49456) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6f1Y-0003Dr-OR for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:12 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:54945) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6f1X-0005fB-2W for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:12 -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-112-Ysr62lDMPV68fdM4dACBjQ-1; Mon, 01 Feb 2021 14:38:08 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 316F01005513; Mon, 1 Feb 2021 19:38:07 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0765360C05; Mon, 1 Feb 2021 19:38:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612208290; 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=lb7V/mm7zQa8yrfFR/zgKPDM7V7rJbjKwC0qBdFefDU=; b=Ix9OggtbyW8NICxcIlg/z5dSHIe22pZy+dTYs4MosWIcmGOcI4+a/bCq47qHdPh5+/7Wlx eprwcbQpNy9Fouq/cf+tGekWXVXCtmtocA6RuB+GDGrkXBU8TktLNeZBxBozyznevlL7YX 08tPToyDugw2KGk+jRykseF+18DZYXc= X-MC-Unique: Ysr62lDMPV68fdM4dACBjQ-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v4 06/16] qapi/gen: Replace ._begin_system_module() Date: Mon, 1 Feb 2021 14:37:37 -0500 Message-Id: <20210201193747.2169670-7-jsnow@redhat.com> In-Reply-To: <20210201193747.2169670-1-jsnow@redhat.com> References: <20210201193747.2169670-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@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=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Eduardo Habkost , Michael Roth , Markus Armbruster , Cleber Rosa , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , John Snow 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" From: Markus Armbruster QAPISchemaModularCVisitor._begin_system_module() is actually just for the builtin module. Rename it to ._begin_builtin_module() and drop its useless @name parameter. Clarify conditionals in visit_module to make this clear. Signed-off-by: Markus Armbruster Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/gen.py | 9 +++++---- scripts/qapi/types.py | 2 +- scripts/qapi/visit.py | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index 2aec6d34365..aaed78eed5e 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -295,23 +295,24 @@ def write(self, output_dir: str, opt_builtins: bool = =3D False) -> None: genc.write(output_dir) genh.write(output_dir) =20 - def _begin_system_module(self, name: None) -> None: + def _begin_builtin_module(self) -> None: pass =20 def _begin_user_module(self, name: str) -> None: pass =20 def visit_module(self, name: Optional[str]) -> None: - if name is None: + if QAPISchemaModule.is_builtin_module(name): if self._builtin_blurb: - self._add_system_module(None, self._builtin_blurb) - self._begin_system_module(name) + self._add_system_module(name, self._builtin_blurb) + self._begin_builtin_module() else: # The built-in module has not been created. No code may # be generated. self._genc =3D None self._genh =3D None else: + assert QAPISchemaModule.is_user_module(name) self._add_user_module(name, self._user_blurb) self._begin_user_module(name) =20 diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index 2b4916cdaa1..dbf58c0b91d 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -271,7 +271,7 @@ def __init__(self, prefix: str): prefix, 'qapi-types', ' * Schema-defined QAPI types', ' * Built-in QAPI types', __doc__) =20 - def _begin_system_module(self, name: None) -> None: + def _begin_builtin_module(self) -> None: self._genc.preamble_add(mcgen(''' #include "qemu/osdep.h" #include "qapi/dealloc-visitor.h" diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 339f1521524..568ba35592c 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -305,7 +305,7 @@ def __init__(self, prefix: str): prefix, 'qapi-visit', ' * Schema-defined QAPI visitors', ' * Built-in QAPI visitors', __doc__) =20 - def _begin_system_module(self, name: None) -> None: + def _begin_builtin_module(self) -> None: self._genc.preamble_add(mcgen(''' #include "qemu/osdep.h" #include "qapi/error.h" --=20 2.29.2 From nobody Tue May 21 22:07:56 2024 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=1612208752; cv=none; d=zohomail.com; s=zohoarc; b=FeVO2VDZOmOSiLblZ7v/gSmfupheWtWf/d7Jzv725LfbjUVN6gKrt+zhWAvpM6kkZoeu9t/MXs382RlHB1AT8IFFDqppJ+42aTQzOJEpKh0wh7oHrai9Fxswb8j0wvPQxv9GXbOMm8K3x++1/ttMcu0as4ri01GptL2lE1lRuu8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612208752; 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=SaCcIhMlHVElTZeN1unpYppAZKErXSyyzn9Tc9BOmis=; b=U84Ctyy0oLUapLyv0aQtfRg7+dNMv2feTKulYnhtAT7LLeR19lNQ5YWUiiGOoXlU/ILVR2z2bczG06LkrE1ZiVsV77JQJWeNpDZ9ZU17HP5MWb4yHi5GdOaM5x0kpAle4LG2W1Av0M9n6QhnPY1S5X9ZzC7I5U4JGgjkJcAVqRU= 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 1612208752471976.5875960848714; Mon, 1 Feb 2021 11:45:52 -0800 (PST) Received: from localhost ([::1]:46754 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6f8x-0003rd-A4 for importer@patchew.org; Mon, 01 Feb 2021 14:45:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49476) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6f1d-0003H7-Py for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:42704) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6f1a-0005iI-V2 for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:17 -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-572-8L9dzP6NMrS412depCcaaQ-1; Mon, 01 Feb 2021 14:38:12 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CA1448015DE; Mon, 1 Feb 2021 19:38:11 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6048F60C05; Mon, 1 Feb 2021 19:38:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612208294; 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=SaCcIhMlHVElTZeN1unpYppAZKErXSyyzn9Tc9BOmis=; b=DZqY8udnvd89kJk1zL1OiQHdUUiyw2rkiHzo4ZQ/Zh097GU9lIQW9TApvUf9Dr3U5nikrZ VzBn8DyJtfKr6IXFQoFeQDkW2VadZyvsAaNzTP5D6Vs+yk9jxn7MD8xjcvPQP1V0He9MUJ Ssowm6JOyXqBbxZG+xMJyF2otXCx6uQ= X-MC-Unique: 8L9dzP6NMrS412depCcaaQ-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v4 07/16] qapi: use explicitly internal module names Date: Mon, 1 Feb 2021 14:37:38 -0500 Message-Id: <20210201193747.2169670-8-jsnow@redhat.com> In-Reply-To: <20210201193747.2169670-1-jsnow@redhat.com> References: <20210201193747.2169670-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@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=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Eduardo Habkost , Michael Roth , Markus Armbruster , Cleber Rosa , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , John Snow 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" Use ./emit and ./init explicitly instead of "emit" and "init" and adding the prefix based on the specific method called, which later allows us to coalesce the two different methods into one. Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/commands.py | 2 +- scripts/qapi/events.py | 2 +- scripts/qapi/gen.py | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index 71744f48a35..fc5fe27c472 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -286,7 +286,7 @@ def _begin_user_module(self, name: str) -> None: types=3Dtypes)) =20 def visit_end(self) -> None: - self._add_system_module('init', ' * QAPI Commands initialization') + self._add_system_module('./init', ' * QAPI Commands initialization= ') self._genh.add(mcgen(''' #include "qapi/qmp/dispatch.h" =20 diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index 9851653b9d1..26faa829898 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -191,7 +191,7 @@ def _begin_user_module(self, name: str) -> None: types=3Dtypes)) =20 def visit_end(self) -> None: - self._add_system_module('emit', ' * QAPI Events emission') + self._add_system_module('./emit', ' * QAPI Events emission') self._genc.preamble_add(mcgen(''' #include "qemu/osdep.h" #include "%(prefix)sqapi-emit-events.h" diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index aaed78eed5e..da9d4d2d373 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -285,7 +285,8 @@ def _add_user_module(self, name: str, blurb: str) -> No= ne: self._add_module(name, blurb) =20 def _add_system_module(self, name: Optional[str], blurb: str) -> None: - self._add_module(name and './' + name, blurb) + assert QAPISchemaModule.is_system_module(name) + self._add_module(name, blurb) =20 def write(self, output_dir: str, opt_builtins: bool =3D False) -> None: for name in self._module: --=20 2.29.2 From nobody Tue May 21 22:07:56 2024 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=1612208926; cv=none; d=zohomail.com; s=zohoarc; b=diNqjEtWe9cUqxb29JwD6aeCTbYrwyJPFkVwrxTBO8v/AaLhsKEGfICTxEt20yrgvaLhuV/dzfgxvG3Li5b2U3OfL4SPCRgnp45H5P5K9VL8pn7h3vvHcSlJFWjJdbW5spwvGOLNdPGj/QOpXRoutDAoh1Pqq18vZ24+p/iQMLs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612208926; 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=LCrL02U/DJmzJgE3X/a0/mQGjW6hsPElWxLhSb2Fkq4=; b=R51bUYd0u1X24btwyg77MxiVtf+OkL3Pn7ZBb6t7hjoM4NRsaKYPTydWqLoNoo6mVO2tAmqbXUAgFDDqJK1qHcNLGpVs8Mmx5xY4SX0CndlIn2PZ04GEhlZMpThbRPa236QrEdHHqJve9Hwo6U52t19CyrjwanqBkZaSNBiuNVA= 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 1612208925993902.1907595721906; Mon, 1 Feb 2021 11:48:45 -0800 (PST) Received: from localhost ([::1]:57048 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6fBk-0008G4-TR for importer@patchew.org; Mon, 01 Feb 2021 14:48:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49708) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6f23-0003n4-L4 for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:24358) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6f21-0005sF-Dq for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:43 -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-153-oqj47l6TMCu9mzHqZtY1YQ-1; Mon, 01 Feb 2021 14:38:14 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CD4971800D41; Mon, 1 Feb 2021 19:38:13 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 139C760C66; Mon, 1 Feb 2021 19:38:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612208318; 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=LCrL02U/DJmzJgE3X/a0/mQGjW6hsPElWxLhSb2Fkq4=; b=eYUAgdnHrdCQnw1jIhTK207x6s7KpCiNrYzNiISxCVSzdx3wYFTtzGnODIS8L5l5q1vlU6 mbEktyoXZJGd4tbqZ7wM4i6Vq6ZCDPYTy6dEymzA8Fy9dOGlep+4ESClJWtG2JachCaaqn rd47n/caizc+CQ/pmEN9vLYeqNwXASU= X-MC-Unique: oqj47l6TMCu9mzHqZtY1YQ-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v4 08/16] qapi: use './builtin' as the built-in module name Date: Mon, 1 Feb 2021 14:37:39 -0500 Message-Id: <20210201193747.2169670-9-jsnow@redhat.com> In-Reply-To: <20210201193747.2169670-1-jsnow@redhat.com> References: <20210201193747.2169670-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@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=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Eduardo Habkost , Michael Roth , Markus Armbruster , Cleber Rosa , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , John Snow 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" Use './builtin' as the built-in module name instead of None. Clarify the typing that this is now always a string. Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/gen.py | 18 +++++++++--------- scripts/qapi/schema.py | 20 ++++++++++---------- tests/qapi-schema/comments.out | 2 +- tests/qapi-schema/doc-good.out | 2 +- tests/qapi-schema/empty.out | 2 +- tests/qapi-schema/event-case.out | 2 +- tests/qapi-schema/include-repetition.out | 2 +- tests/qapi-schema/include-simple.out | 2 +- tests/qapi-schema/indented-expr.out | 2 +- tests/qapi-schema/qapi-schema-test.out | 2 +- 10 files changed, 27 insertions(+), 27 deletions(-) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index da9d4d2d373..9352d79c3a4 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -246,16 +246,16 @@ def __init__(self, self._pydoc =3D pydoc self._genc: Optional[QAPIGenC] =3D None self._genh: Optional[QAPIGenH] =3D None - self._module: Dict[Optional[str], Tuple[QAPIGenC, QAPIGenH]] =3D {} + self._module: Dict[str, Tuple[QAPIGenC, QAPIGenH]] =3D {} self._main_module: Optional[str] =3D None =20 @staticmethod - def _module_dirname(name: Optional[str]) -> str: + def _module_dirname(name: str) -> str: if QAPISchemaModule.is_user_module(name): return os.path.dirname(name) return '' =20 - def _module_basename(self, what: str, name: Optional[str]) -> str: + def _module_basename(self, what: str, name: str) -> str: ret =3D '' if QAPISchemaModule.is_builtin_module(name) else self._= prefix if QAPISchemaModule.is_user_module(name): basename =3D os.path.basename(name) @@ -263,15 +263,15 @@ def _module_basename(self, what: str, name: Optional[= str]) -> str: if name !=3D self._main_module: ret +=3D '-' + os.path.splitext(basename)[0] else: - name =3D name[2:] if name else 'builtin' - ret +=3D re.sub(r'-', '-' + name + '-', what) + assert QAPISchemaModule.is_system_module(name) + ret +=3D re.sub(r'-', '-' + name[2:] + '-', what) return ret =20 - def _module_filename(self, what: str, name: Optional[str]) -> str: + def _module_filename(self, what: str, name: str) -> str: return os.path.join(self._module_dirname(name), self._module_basename(what, name)) =20 - def _add_module(self, name: Optional[str], blurb: str) -> None: + def _add_module(self, name: str, blurb: str) -> None: basename =3D self._module_filename(self._what, name) genc =3D QAPIGenC(basename + '.c', blurb, self._pydoc) genh =3D QAPIGenH(basename + '.h', blurb, self._pydoc) @@ -284,7 +284,7 @@ def _add_user_module(self, name: str, blurb: str) -> No= ne: self._main_module =3D name self._add_module(name, blurb) =20 - def _add_system_module(self, name: Optional[str], blurb: str) -> None: + def _add_system_module(self, name: str, blurb: str) -> None: assert QAPISchemaModule.is_system_module(name) self._add_module(name, blurb) =20 @@ -302,7 +302,7 @@ def _begin_builtin_module(self) -> None: def _begin_user_module(self, name: str) -> None: pass =20 - def visit_module(self, name: Optional[str]) -> None: + def visit_module(self, name: str) -> None: if QAPISchemaModule.is_builtin_module(name): if self._builtin_blurb: self._add_system_module(name, self._builtin_blurb) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index e80d9320eda..14cf9da7842 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -68,7 +68,8 @@ def check_doc(self): =20 def _set_module(self, schema, info): assert self._checked - self._module =3D schema.module_by_fname(info and info.fname) + fname =3D info.fname if info else './builtin' + self._module =3D schema.module_by_fname(fname) self._module.add_entity(self) =20 def set_module(self, schema): @@ -142,16 +143,16 @@ def __init__(self, name): self._entity_list =3D [] =20 @staticmethod - def is_system_module(name: Optional[str]) -> bool: + def is_system_module(name: str) -> bool: """ System modules are internally defined modules. =20 Their names start with the "./" prefix. """ - return name is None or name.startswith('./') + return name.startswith('./') =20 @classmethod - def is_user_module(cls, name: Optional[str]) -> bool: + def is_user_module(cls, name: str) -> bool: """ User modules are those defined by the user in qapi JSON files. =20 @@ -160,13 +161,13 @@ def is_user_module(cls, name: Optional[str]) -> bool: return not cls.is_system_module(name) =20 @staticmethod - def is_builtin_module(name: Optional[str]) -> bool: + def is_builtin_module(name: str) -> bool: """ The built-in module is a single System module for the built-in typ= es. =20 - It is presently always the value 'None'. + It is always "./builtin". """ - return name is None + return name =3D=3D './builtin' =20 def add_entity(self, ent): self._entity_list.append(ent) @@ -852,7 +853,7 @@ def __init__(self, fname): self._entity_dict =3D {} self._module_dict =3D OrderedDict() self._schema_dir =3D os.path.dirname(fname) - self._make_module(None) # built-ins + self._make_module('./builtin') self._make_module(fname) self._predefining =3D True self._def_predefineds() @@ -897,7 +898,7 @@ def resolve_type(self, name, info, what): info, "%s uses unknown type '%s'" % (what, name)) return typ =20 - def _module_name(self, fname): + def _module_name(self, fname: str) -> str: if QAPISchemaModule.is_system_module(fname): return fname return os.path.relpath(fname, self._schema_dir) @@ -910,7 +911,6 @@ def _make_module(self, fname): =20 def module_by_fname(self, fname): name =3D self._module_name(fname) - assert name in self._module_dict return self._module_dict[name] =20 def _def_include(self, expr, info, doc): diff --git a/tests/qapi-schema/comments.out b/tests/qapi-schema/comments.out index 273f0f54e16..ce4f6a4f0f5 100644 --- a/tests/qapi-schema/comments.out +++ b/tests/qapi-schema/comments.out @@ -1,4 +1,4 @@ -module None +module ./builtin object q_empty enum QType prefix QTYPE diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out index 419284dae29..715b0bbc1af 100644 --- a/tests/qapi-schema/doc-good.out +++ b/tests/qapi-schema/doc-good.out @@ -1,4 +1,4 @@ -module None +module ./builtin object q_empty enum QType prefix QTYPE diff --git a/tests/qapi-schema/empty.out b/tests/qapi-schema/empty.out index 69666c39ad2..3feb3f69d3d 100644 --- a/tests/qapi-schema/empty.out +++ b/tests/qapi-schema/empty.out @@ -1,4 +1,4 @@ -module None +module ./builtin object q_empty enum QType prefix QTYPE diff --git a/tests/qapi-schema/event-case.out b/tests/qapi-schema/event-cas= e.out index 42ae519656d..9ae44052ac4 100644 --- a/tests/qapi-schema/event-case.out +++ b/tests/qapi-schema/event-case.out @@ -1,4 +1,4 @@ -module None +module ./builtin object q_empty enum QType prefix QTYPE diff --git a/tests/qapi-schema/include-repetition.out b/tests/qapi-schema/i= nclude-repetition.out index 0b654ddebb6..16dbd9b8194 100644 --- a/tests/qapi-schema/include-repetition.out +++ b/tests/qapi-schema/include-repetition.out @@ -1,4 +1,4 @@ -module None +module ./builtin object q_empty enum QType prefix QTYPE diff --git a/tests/qapi-schema/include-simple.out b/tests/qapi-schema/inclu= de-simple.out index 061f81e5090..48e923bfbc8 100644 --- a/tests/qapi-schema/include-simple.out +++ b/tests/qapi-schema/include-simple.out @@ -1,4 +1,4 @@ -module None +module ./builtin object q_empty enum QType prefix QTYPE diff --git a/tests/qapi-schema/indented-expr.out b/tests/qapi-schema/indent= ed-expr.out index 04356775cd1..6a30ded3fa6 100644 --- a/tests/qapi-schema/indented-expr.out +++ b/tests/qapi-schema/indented-expr.out @@ -1,4 +1,4 @@ -module None +module ./builtin object q_empty enum QType prefix QTYPE diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 8868ca0dca9..3b1387d9f18 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -1,4 +1,4 @@ -module None +module ./builtin object q_empty enum QType prefix QTYPE --=20 2.29.2 From nobody Tue May 21 22:07:56 2024 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=1612209005; cv=none; d=zohomail.com; s=zohoarc; b=Lz7QE1Bkx2iEs80jirDrZHGNEl79wUQRHdKP5Er1uHIoao9MfehyTNqkzj52b/mT0QEgczVv291r/iiRBFYEM7dDsSgcHItSBWV8Y+I3ktEBvMFhvJswyIFAZlVvUvQwSyKwEglxH0YTfygwqRoZMQhsHst2rAHjg0rFNvEaaOk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612209005; 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=a6kRdoDQslGi02rtVP1Hb8EutRkIXNdPPq5ld+jXAiw=; b=EMEi6Bh2sAkRghu3Wd9z4C+mzA1oWHgq0qhI/9HWMhg5ioYnWpYLwhKms5aXOGQ4eAX+zIW++CqJMXI2BdmONMo3YvpPIDymzD0/u2NERZm+ZBUvUQYRVWhBVowZhcDEnIwvV/zb4XHA8c7KVM7AhMAz8fBhGIHfhIG0q+fJgQs= 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 1612209005467762.5868131315091; Mon, 1 Feb 2021 11:50:05 -0800 (PST) Received: from localhost ([::1]:59686 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6fD2-0000yz-9i for importer@patchew.org; Mon, 01 Feb 2021 14:50:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49560) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6f1p-0003LX-7A for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:29 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:32012) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6f1k-0005lY-8a for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:28 -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-477-Tp2Uqzt_N0SWv0jj5hdoxg-1; Mon, 01 Feb 2021 14:38:19 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 696DAB8102; Mon, 1 Feb 2021 19:38:17 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D20260C05; Mon, 1 Feb 2021 19:38:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612208303; 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=a6kRdoDQslGi02rtVP1Hb8EutRkIXNdPPq5ld+jXAiw=; b=hdrFzw/ja8wt//Gldy4/oXHJgX1hgrhylfPsQT0VVUpssrUSGaQUdimXJAQ6uP0CA2IpUw f+Nh/MdWQNQhynVLt9tJ72Bfm5ZdWiEjdkF1xNT/Xou8J93T4OEubQ49qkQobGgIBbWRp2 7C1l1oGGUwUsttRtYnydxg98G2tQOwc= X-MC-Unique: Tp2Uqzt_N0SWv0jj5hdoxg-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v4 09/16] qapi/gen: Combine ._add_[user|system]_module Date: Mon, 1 Feb 2021 14:37:40 -0500 Message-Id: <20210201193747.2169670-10-jsnow@redhat.com> In-Reply-To: <20210201193747.2169670-1-jsnow@redhat.com> References: <20210201193747.2169670-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@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=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Eduardo Habkost , Michael Roth , Markus Armbruster , Cleber Rosa , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , John Snow 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" From: Markus Armbruster With callers to _add_system_module now explicitly using the './' prefix to indicate a system module, there is no longer any reason to have separate interfaces for adding system vs user modules; use a unified interface that differentiates based on the name. Signed-off-by: Markus Armbruster Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/commands.py | 2 +- scripts/qapi/events.py | 2 +- scripts/qapi/gen.py | 17 +++++------------ 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index fc5fe27c472..49111663394 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -286,7 +286,7 @@ def _begin_user_module(self, name: str) -> None: types=3Dtypes)) =20 def visit_end(self) -> None: - self._add_system_module('./init', ' * QAPI Commands initialization= ') + self._add_module('./init', ' * QAPI Commands initialization') self._genh.add(mcgen(''' #include "qapi/qmp/dispatch.h" =20 diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index 26faa829898..079c666ec69 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -191,7 +191,7 @@ def _begin_user_module(self, name: str) -> None: types=3Dtypes)) =20 def visit_end(self) -> None: - self._add_system_module('./emit', ' * QAPI Events emission') + self._add_module('./emit', ' * QAPI Events emission') self._genc.preamble_add(mcgen(''' #include "qemu/osdep.h" #include "%(prefix)sqapi-emit-events.h" diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index 9352d79c3a4..8ded0f7e5ad 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -272,22 +272,15 @@ def _module_filename(self, what: str, name: str) -> s= tr: self._module_basename(what, name)) =20 def _add_module(self, name: str, blurb: str) -> None: + if QAPISchemaModule.is_user_module(name): + if self._main_module is None: + self._main_module =3D name basename =3D self._module_filename(self._what, name) genc =3D QAPIGenC(basename + '.c', blurb, self._pydoc) genh =3D QAPIGenH(basename + '.h', blurb, self._pydoc) self._module[name] =3D (genc, genh) self._genc, self._genh =3D self._module[name] =20 - def _add_user_module(self, name: str, blurb: str) -> None: - assert QAPISchemaModule.is_user_module(name) - if self._main_module is None: - self._main_module =3D name - self._add_module(name, blurb) - - def _add_system_module(self, name: str, blurb: str) -> None: - assert QAPISchemaModule.is_system_module(name) - self._add_module(name, blurb) - def write(self, output_dir: str, opt_builtins: bool =3D False) -> None: for name in self._module: if QAPISchemaModule.is_builtin_module(name) and not opt_builti= ns: @@ -305,7 +298,7 @@ def _begin_user_module(self, name: str) -> None: def visit_module(self, name: str) -> None: if QAPISchemaModule.is_builtin_module(name): if self._builtin_blurb: - self._add_system_module(name, self._builtin_blurb) + self._add_module(name, self._builtin_blurb) self._begin_builtin_module() else: # The built-in module has not been created. No code may @@ -314,7 +307,7 @@ def visit_module(self, name: str) -> None: self._genh =3D None else: assert QAPISchemaModule.is_user_module(name) - self._add_user_module(name, self._user_blurb) + self._add_module(name, self._user_blurb) self._begin_user_module(name) =20 def visit_include(self, name: str, info: QAPISourceInfo) -> None: --=20 2.29.2 From nobody Tue May 21 22:07:56 2024 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=1612208851; cv=none; d=zohomail.com; s=zohoarc; b=R9cH68KgR1xSGiuZB9w0DEP+RF+qxWFAS+f2pNqlX1qTlEvER3NVO2CgGKH/YZAwKce3cAmAljiUIx9uBwEU6EqAXMRbew1rJn68Jga48p5YR5P25LiY7Qu3Hx/DntF4eTP8rRTxsKjGMhrwWWgQqIQmJVAOLC6Ebuh3b66rvL0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612208851; 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=OTJGBfiuOP+Mhp/Tlw9eNzOAMYiV308J4dX0rCdyl7I=; b=Wn79VmrCBlYZQDGK0lRkGRVFYAGJirzeKfk9lweRBxLo7xtI6ddydfcSIRWCh7N8qY3uECTS5ZtIyoZwdaW0/MnR1JNPt6eiva+HzhA6UVVaWuDfW9L6TU8e8GRsMnwGOVZPMXh18vXa2LZoMc/a6bpOPVjWPhffkP6V5zEjT2s= 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 1612208851643441.01366396163337; Mon, 1 Feb 2021 11:47:31 -0800 (PST) Received: from localhost ([::1]:52068 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6fAY-0006A1-Cq for importer@patchew.org; Mon, 01 Feb 2021 14:47:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49518) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6f1k-0003KW-FB for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:24 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:54117) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6f1h-0005kE-On for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:24 -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-211-GG60HUOTP5ud7UnIkt2O3A-1; Mon, 01 Feb 2021 14:38:19 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 766E18145FB; Mon, 1 Feb 2021 19:38:18 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9277160C66; Mon, 1 Feb 2021 19:38:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612208301; 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=OTJGBfiuOP+Mhp/Tlw9eNzOAMYiV308J4dX0rCdyl7I=; b=Zq1MNpTWnQw1yZuzI73qoVTy4wg7ffU08Rux/HW5g/DQsLrOtDgWY6BTjioOYA6u79Mlxs 3w58TlMI3dLbmE5LeIkLaTr8a7NOHKps0MAKEQJ5OGs5V1BQdIzN5p78S0xmopGYd33SCp J3jvCStmpLP8Q68ZD+PS+BGhbqvb6eU= X-MC-Unique: GG60HUOTP5ud7UnIkt2O3A-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v4 10/16] qapi: centralize the built-in module name definition Date: Mon, 1 Feb 2021 14:37:41 -0500 Message-Id: <20210201193747.2169670-11-jsnow@redhat.com> In-Reply-To: <20210201193747.2169670-1-jsnow@redhat.com> References: <20210201193747.2169670-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@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=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Eduardo Habkost , Michael Roth , Markus Armbruster , Cleber Rosa , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , John Snow 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" Use a constant to make it obvious we're referring to a very specific thing. Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/schema.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 14cf9da7842..353e8020a27 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -68,7 +68,7 @@ def check_doc(self): =20 def _set_module(self, schema, info): assert self._checked - fname =3D info.fname if info else './builtin' + fname =3D info.fname if info else QAPISchemaModule.BUILTIN_MODULE_= NAME self._module =3D schema.module_by_fname(fname) self._module.add_entity(self) =20 @@ -138,6 +138,9 @@ def visit_event(self, name, info, ifcond, features, arg= _type, boxed): =20 =20 class QAPISchemaModule: + + BUILTIN_MODULE_NAME =3D './builtin' + def __init__(self, name): self.name =3D name self._entity_list =3D [] @@ -160,14 +163,14 @@ def is_user_module(cls, name: str) -> bool: """ return not cls.is_system_module(name) =20 - @staticmethod - def is_builtin_module(name: str) -> bool: + @classmethod + def is_builtin_module(cls, name: str) -> bool: """ The built-in module is a single System module for the built-in typ= es. =20 It is always "./builtin". """ - return name =3D=3D './builtin' + return name =3D=3D cls.BUILTIN_MODULE_NAME =20 def add_entity(self, ent): self._entity_list.append(ent) @@ -853,7 +856,7 @@ def __init__(self, fname): self._entity_dict =3D {} self._module_dict =3D OrderedDict() self._schema_dir =3D os.path.dirname(fname) - self._make_module('./builtin') + self._make_module(QAPISchemaModule.BUILTIN_MODULE_NAME) self._make_module(fname) self._predefining =3D True self._def_predefineds() --=20 2.29.2 From nobody Tue May 21 22:07:56 2024 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=1612208440; cv=none; d=zohomail.com; s=zohoarc; b=jNuZEkgYHjFm/RA8G++rGCVcKsmm0V2n/wqBWXEEy5JnM6mIlLYSrJ/fnNgoxi7cH8ruKvlu16nTq4kvTEYE7xguVnqrqODk9RK70X1Ex4hOIh20wSa9LTo2JQli3Ow1OkVDc2kRMVHdckUWvweauwnKbv7OtC1kkoaniPCzY0k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612208440; 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=dDhdWAZvkCPb+FQ+r2+OFPVRscU+5EwrFcEaIfY0O2o=; b=Y3Uw5L+4YLx/Rq0BqwVzhBI9lFht3rLtOhb/TACq9RgHq7X7eXgA51c6/g8Aw8vPUNW9KZ4MDIX/fC9GmbHWP5LrOQlpCjfDTx3Gg/I8i3tjE3pwcpO/Zp5NXtYqSadW9B/HpdaBMAm+xdxyPCp+3n2YVoMNbIRNVifxJ4nNMOM= 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 1612208440788918.036971312911; Mon, 1 Feb 2021 11:40:40 -0800 (PST) Received: from localhost ([::1]:60616 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6f3v-0006EP-Pw for importer@patchew.org; Mon, 01 Feb 2021 14:40:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49594) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6f1q-0003NO-Er for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:59862) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6f1i-0005kr-Pu for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:30 -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-496-1QkKdFqFOhOUW6T17FrU2g-1; Mon, 01 Feb 2021 14:38:20 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8B21C107ACE6; Mon, 1 Feb 2021 19:38:19 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id A5DAE60C05; Mon, 1 Feb 2021 19:38:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612208302; 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=dDhdWAZvkCPb+FQ+r2+OFPVRscU+5EwrFcEaIfY0O2o=; b=X9PDgMovro+uTDjPQh9tchxzDSi97jRALu4ty3o2zENGkWqbI7gSYB7Iko6ISz7huRHvVH G+hqEDY/AhkWKVZVLoN1bBnTgHWUrMtPXUUm5xbKDgr8csSSPdfGg+nQCokvlp1V4Mk442 +4W1ZcQ2xgPwoPge3ESLzkM89GeHTYE= X-MC-Unique: 1QkKdFqFOhOUW6T17FrU2g-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v4 11/16] qapi/gen: write _genc/_genh access shims Date: Mon, 1 Feb 2021 14:37:42 -0500 Message-Id: <20210201193747.2169670-12-jsnow@redhat.com> In-Reply-To: <20210201193747.2169670-1-jsnow@redhat.com> References: <20210201193747.2169670-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@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=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Eduardo Habkost , Michael Roth , Markus Armbruster , Cleber Rosa , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , John Snow 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" Many places assume they can access these fields without checking them first to ensure they are defined. Eliminating the _genc and _genh fields and replacing them with functional properties that check for correct state can ease the typing overhead by eliminating the Optional[T] return type. Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/gen.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index 8ded0f7e5ad..b2bb9d12ffc 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -244,11 +244,20 @@ def __init__(self, self._user_blurb =3D user_blurb self._builtin_blurb =3D builtin_blurb self._pydoc =3D pydoc - self._genc: Optional[QAPIGenC] =3D None - self._genh: Optional[QAPIGenH] =3D None + self._current_module: Optional[str] =3D None self._module: Dict[str, Tuple[QAPIGenC, QAPIGenH]] =3D {} self._main_module: Optional[str] =3D None =20 + @property + def _genc(self) -> QAPIGenC: + assert self._current_module is not None + return self._module[self._current_module][0] + + @property + def _genh(self) -> QAPIGenH: + assert self._current_module is not None + return self._module[self._current_module][1] + @staticmethod def _module_dirname(name: str) -> str: if QAPISchemaModule.is_user_module(name): @@ -279,7 +288,7 @@ def _add_module(self, name: str, blurb: str) -> None: genc =3D QAPIGenC(basename + '.c', blurb, self._pydoc) genh =3D QAPIGenH(basename + '.h', blurb, self._pydoc) self._module[name] =3D (genc, genh) - self._genc, self._genh =3D self._module[name] + self._current_module =3D name =20 def write(self, output_dir: str, opt_builtins: bool =3D False) -> None: for name in self._module: @@ -303,8 +312,7 @@ def visit_module(self, name: str) -> None: else: # The built-in module has not been created. No code may # be generated. - self._genc =3D None - self._genh =3D None + self._current_module =3D None else: assert QAPISchemaModule.is_user_module(name) self._add_module(name, self._user_blurb) --=20 2.29.2 From nobody Tue May 21 22:07:56 2024 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=1612208869; cv=none; d=zohomail.com; s=zohoarc; b=W3J3UwyyDM/SRWgiRB1FI8qWr6SUJQpLW1LHafzLODhgdKbWx0tAImtCydatO7io9dS09SADqcxG3KtiY9MfoyZGU+pYtlPOzt0fou+y0k/X3X+UBWcsGqSsw8u3fsEtNprtLIbqR5Iw3eo78ESSjDz7fHFlQk6Y0bhTpBgblgg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612208869; 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=b9qk247eIhc+fKn8oWnKzH/5O8fVRxygCDws3cO6i6U=; b=VDsKacHU99ziS1ibzmiykXZ021FX/H2pInOWLyEFcffcFrXXehbQ4H3xPIB3oz53+mchhh8PpvRK261ZyXgpYakp/v7OpOdTadFJyBNiD0Gmik4yy7Mg9st6dt7+izGob6RhijXNLFwH4r8sHO6KyBYZj+9cetd+TILvmPLUGs8= 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 1612208869816673.8004549382875; Mon, 1 Feb 2021 11:47:49 -0800 (PST) Received: from localhost ([::1]:53612 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6fAq-0006q7-GS for importer@patchew.org; Mon, 01 Feb 2021 14:47:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49572) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6f1p-0003Lf-Mr for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:29 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58235) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6f1k-0005lX-83 for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:29 -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-279-kaDdSzYZNbiIXUruKKoxeQ-1; Mon, 01 Feb 2021 14:38:21 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A2B431842140; Mon, 1 Feb 2021 19:38:20 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id BAC1760C05; Mon, 1 Feb 2021 19:38:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612208303; 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=b9qk247eIhc+fKn8oWnKzH/5O8fVRxygCDws3cO6i6U=; b=DxyhffsEawe8C9t+yF00B/L3Mhsn533vGNQkXvxRVwNm1UJL3Z9nl177jlL2p1gsJbo2FH BKnIsL/Z2FDxz1ZM3rKY4A3kUNXgeQHnOPZqtPvI2M863BVoE5JydhbiOL7k2NBIzpY/Ex wjwQmveezNfBqrUShqwifN6NNRejLl8= X-MC-Unique: kaDdSzYZNbiIXUruKKoxeQ-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v4 12/16] qapi/gen: Support for switching to another module temporarily Date: Mon, 1 Feb 2021 14:37:43 -0500 Message-Id: <20210201193747.2169670-13-jsnow@redhat.com> In-Reply-To: <20210201193747.2169670-1-jsnow@redhat.com> References: <20210201193747.2169670-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@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=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Eduardo Habkost , Michael Roth , Markus Armbruster , Cleber Rosa , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , John Snow 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" From: Markus Armbruster Signed-off-by: Markus Armbruster Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/gen.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index b2bb9d12ffc..a0a5df333e0 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -290,6 +290,13 @@ def _add_module(self, name: str, blurb: str) -> None: self._module[name] =3D (genc, genh) self._current_module =3D name =20 + @contextmanager + def _temp_module(self, name: str) -> Iterator[None]: + old_module =3D self._current_module + self._current_module =3D name + yield + self._current_module =3D old_module + def write(self, output_dir: str, opt_builtins: bool =3D False) -> None: for name in self._module: if QAPISchemaModule.is_builtin_module(name) and not opt_builti= ns: --=20 2.29.2 From nobody Tue May 21 22:07:56 2024 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=1612209167; cv=none; d=zohomail.com; s=zohoarc; b=Vo3Pk7eFunsZ/+53ZTEIw5alFJgTUFbws6R3Xu5t8+xKBgm0mgA8VIYHSRM9p6n1s/XcWAZyRKofeQohmaiBJxs1x4dV0fx7MFQrdHujNDQORJ2Pnyaz5jEbvwnzGky4svvOgDHeF7bDwOvmTHlQt/suMAne8VF0TuK3Km+PYIQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612209167; 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=A3ucbUMdgAdrqp+dRb+adpHdVI5VdG3a8651pbDBHQ0=; b=hum8i573txPUT7YZFJXc2tJ4yk/hrB7lmatXQq+XUHqpficAZHLdaMHvFeJ8SdmHLl67Y1vz+fdoVQdZqCtZjd/UIsJl7rYuQpV6Y4YValSnd1R0QBjSwBAoAoE9NPEbOjizjVed+16R4UWZ8ZNxdqA7GtpxNBhp0MJEWdXDc3Y= 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 1612209167378960.634247910323; Mon, 1 Feb 2021 11:52:47 -0800 (PST) Received: from localhost ([::1]:38522 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6fFe-00048v-B3 for importer@patchew.org; Mon, 01 Feb 2021 14:52:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49602) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6f1q-0003Nw-K5 for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:26070) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6f1o-0005m1-Dp for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:30 -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-14-55R_4kyBNImvPz6vH60dXg-1; Mon, 01 Feb 2021 14:38:22 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C6F5E8145E2; Mon, 1 Feb 2021 19:38:21 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id C964D60C05; Mon, 1 Feb 2021 19:38:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612208305; 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=A3ucbUMdgAdrqp+dRb+adpHdVI5VdG3a8651pbDBHQ0=; b=KjFFN0C9QVVOl7HO6PkpVKEILNX3dqsv6koxwosiqVduOkJWLRqasJ9+pmq4gV9ABPmLUR 0SdeRXNYDgxLNAlNPuchqQLfx/LLXT4BsVPmltncuvWdi0SB0inoXG7mplbs5uriJLNmnQ QNZ2fztlaQ5DLYq8FGWfO5OqEHdDvLE= X-MC-Unique: 55R_4kyBNImvPz6vH60dXg-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v4 13/16] qapi/commands: Simplify command registry generation Date: Mon, 1 Feb 2021 14:37:44 -0500 Message-Id: <20210201193747.2169670-14-jsnow@redhat.com> In-Reply-To: <20210201193747.2169670-1-jsnow@redhat.com> References: <20210201193747.2169670-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@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=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Eduardo Habkost , Michael Roth , Markus Armbruster , Cleber Rosa , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , John Snow 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" From: Markus Armbruster QAPISchemaGenCommandVisitor.visit_command() needs to generate the marshalling function into the current module, and also generate its registration into the ./init system module. The latter is done somewhat awkwardly: .__init__() creates a QAPIGenCCode that will not be written out, each .visit_command() adds its registration to it, and .visit_end() copies its contents into the ./init module it creates. Instead provide the means to temporarily switch to another module. Create the ./init module in .visit_begin(), and generate its initial part. Add registrations to it in .visit_command(). Finish it in .visit_end(). Signed-off-by: Markus Armbruster Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/commands.py | 49 ++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index 49111663394..13a9dcaf894 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -23,7 +23,6 @@ from .common import c_name, mcgen from .gen import ( QAPIGenC, - QAPIGenCCode, QAPISchemaModularCVisitor, build_params, ifcontext, @@ -237,28 +236,11 @@ def gen_register_command(name: str, return ret =20 =20 -def gen_registry(registry: str, prefix: str) -> str: - ret =3D mcgen(''' - -void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds) -{ - QTAILQ_INIT(cmds); - -''', - c_prefix=3Dc_name(prefix, protect=3DFalse)) - ret +=3D registry - ret +=3D mcgen(''' -} -''') - return ret - - class QAPISchemaGenCommandVisitor(QAPISchemaModularCVisitor): def __init__(self, prefix: str): super().__init__( prefix, 'qapi-commands', ' * Schema-defined QAPI/QMP commands', None, __doc__) - self._regy =3D QAPIGenCCode(None) self._visited_ret_types: Dict[QAPIGenC, Set[QAPISchemaType]] =3D {} =20 def _begin_user_module(self, name: str) -> None: @@ -285,7 +267,7 @@ def _begin_user_module(self, name: str) -> None: ''', types=3Dtypes)) =20 - def visit_end(self) -> None: + def visit_begin(self, schema: QAPISchema) -> None: self._add_module('./init', ' * QAPI Commands initialization') self._genh.add(mcgen(''' #include "qapi/qmp/dispatch.h" @@ -293,13 +275,24 @@ def visit_end(self) -> None: void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds); ''', c_prefix=3Dc_name(self._prefix, protect=3DFal= se))) - self._genc.preamble_add(mcgen(''' + self._genc.add(mcgen(''' #include "qemu/osdep.h" #include "%(prefix)sqapi-commands.h" #include "%(prefix)sqapi-init-commands.h" + +void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds) +{ + QTAILQ_INIT(cmds); + ''', - prefix=3Dself._prefix)) - self._genc.add(gen_registry(self._regy.get_content(), self._prefix= )) + prefix=3Dself._prefix, + c_prefix=3Dc_name(self._prefix, protect=3DFal= se))) + + def visit_end(self) -> None: + with self._temp_module('./init'): + self._genc.add(mcgen(''' +} +''')) =20 def visit_command(self, name: str, @@ -324,15 +317,17 @@ def visit_command(self, if ret_type and ret_type not in self._visited_ret_types[self._genc= ]: self._visited_ret_types[self._genc].add(ret_type) with ifcontext(ret_type.ifcond, - self._genh, self._genc, self._regy): + self._genh, self._genc): self._genc.add(gen_marshal_output(ret_type)) - with ifcontext(ifcond, self._genh, self._genc, self._regy): + with ifcontext(ifcond, self._genh, self._genc): self._genh.add(gen_command_decl(name, arg_type, boxed, ret_typ= e)) self._genh.add(gen_marshal_decl(name)) self._genc.add(gen_marshal(name, arg_type, boxed, ret_type)) - self._regy.add(gen_register_command(name, success_response, - allow_oob, allow_preconfig, - coroutine)) + with self._temp_module('./init'): + with ifcontext(ifcond, self._genh, self._genc): + self._genc.add(gen_register_command(name, success_response, + allow_oob, allow_preco= nfig, + coroutine)) =20 =20 def gen_commands(schema: QAPISchema, --=20 2.29.2 From nobody Tue May 21 22:07:56 2024 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=1612208791; cv=none; d=zohomail.com; s=zohoarc; b=CBAnzwPmLSunFiJWazKxJ/KUE5Uhq9vOik0wCHaoQWaJsnpKDc7TsR+KCZVbQmUHNqKOPXNfqQ611ZZ2pO3j6tLLnjOBWAFyk7eSAs9NVvfqtDMKQweHqxRUrz/t77NesrxKXFDkDlhi+eD5UoeRv0prdTQfr5MRdy8UqmNaPTU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612208791; 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=BHJZfsV/8GG56zBvmF7zq1Jb9P2mj0Au0hrFf+Gliis=; b=Op2zMT9IoN9dT3/wuN4wq2iHtjli+xiso6vgpF3z/KT52j7Lx0pSfFokisv6g8tRD1IL38sj3+LhHuLS/esobC8i3PMdEQEv70YuzKElb/nHIFtzHZT2HKmq53rUho4M3dgN1bFYrigXIB9vqLdmZ9Smi8iC3OvOuMWxTVpRT9c= 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 1612208791335751.7082863148527; Mon, 1 Feb 2021 11:46:31 -0800 (PST) Received: from localhost ([::1]:50052 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6f9a-0005K6-7W for importer@patchew.org; Mon, 01 Feb 2021 14:46:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49614) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6f1r-0003Oz-4d for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:20161) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6f1o-0005mx-Pz for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:30 -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-348-Dtm2ugZkPPSU_75MWsduaQ-1; Mon, 01 Feb 2021 14:38:23 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E7D00800D55; Mon, 1 Feb 2021 19:38:22 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 054C760C05; Mon, 1 Feb 2021 19:38:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612208307; 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=BHJZfsV/8GG56zBvmF7zq1Jb9P2mj0Au0hrFf+Gliis=; b=i8xI5V1vUsU3oEfTJ0EOnzyoxSGWOQgTDgAzJlMQ1awtWn0u3aQRox3cgGBf3Av9Yd9MjA SCVK0LWc1Zm+wiAsRhru+RZdIehDoIusHedblqQ1cAx9OFP2Oq2cJmIj3l/KpYXaTCzoV5 q5z0n/F7fsuqgW4lVI4BDDiYrEyx9ic= X-MC-Unique: Dtm2ugZkPPSU_75MWsduaQ-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v4 14/16] qapi/gen: Drop support for QAPIGen without a file name Date: Mon, 1 Feb 2021 14:37:45 -0500 Message-Id: <20210201193747.2169670-15-jsnow@redhat.com> In-Reply-To: <20210201193747.2169670-1-jsnow@redhat.com> References: <20210201193747.2169670-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@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=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Eduardo Habkost , Michael Roth , Markus Armbruster , Cleber Rosa , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , John Snow 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" From: Markus Armbruster The previous commit removed the only user of QAPIGen(None). Tighten the type hint. Signed-off-by: Markus Armbruster Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/gen.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index a0a5df333e0..ac3d3e687ef 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -40,7 +40,7 @@ =20 =20 class QAPIGen: - def __init__(self, fname: Optional[str]): + def __init__(self, fname: str): self.fname =3D fname self._preamble =3D '' self._body =3D '' @@ -125,7 +125,7 @@ def build_params(arg_type: Optional[QAPISchemaObjectTyp= e], =20 =20 class QAPIGenCCode(QAPIGen): - def __init__(self, fname: Optional[str]): + def __init__(self, fname: str): super().__init__(fname) self._start_if: Optional[Tuple[List[str], str, str]] =3D None =20 --=20 2.29.2 From nobody Tue May 21 22:07:56 2024 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=1612209077; cv=none; d=zohomail.com; s=zohoarc; b=fbtLvsXn92q+zSseogzCmfYFuLWZbdZ8Fmx1qsXpmPkTKtcq2N5ALlTqvBEK3Dey0U2o1mZa16X/QAMRjj9x+CIlAteCNk2OmMNPyR9ZU/EC0uto4avR7trwxR1heunoNH2Xp/kt8sJC2siH8GTNqKMFaUoOvD8mP9mU6Ngs23M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612209077; 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=c3+ryZNwoGVvGYw7CoQhMgPDqLmYLIIR3HRlFNFcfdc=; b=BQ2UiLVgcCCBPFlhRyMgc+YB3RgXKGx2XmCZB52UgoyfPUMAidaSKdoUgnFmGUkcX/QL1/9m3ysTvo2wUlPYcZ3gT0M4OvSKLEJpAijlLXj6RsJEUQE74Whorf44mOVJVuZybWFFVfsKWQjHmPsi8eP9yHtIQFxXluv9tJad2tk= 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 1612209077107755.0561063640079; Mon, 1 Feb 2021 11:51:17 -0800 (PST) Received: from localhost ([::1]:33408 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6fE8-0001ma-VU for importer@patchew.org; Mon, 01 Feb 2021 14:51:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49632) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6f1r-0003R5-KC for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:40661) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6f1p-0005mq-1H for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:31 -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-596-gW2VWeIrOqK-rw7efwsxVw-1; Mon, 01 Feb 2021 14:38:25 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 408BA1005D4C; Mon, 1 Feb 2021 19:38:24 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 20DA760C05; Mon, 1 Feb 2021 19:38:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612208307; 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=c3+ryZNwoGVvGYw7CoQhMgPDqLmYLIIR3HRlFNFcfdc=; b=HJzvfVO/DkIF2IaRZSLFIPfndQpJ6HsJrnmLLOB3HlUXnfVochncY5wc/IGVqZyGiyispG Ab0sgjKKncRV92zsjLl7zNzxbrQsXR9QbuwpvzG40oveduYLbav5CBvPXxBKCcae2cjOft nMxR8LxU75z2lLq3ZvrrpyKdV3gSQb8= X-MC-Unique: gW2VWeIrOqK-rw7efwsxVw-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v4 15/16] qapi: type 'info' as Optional[QAPISourceInfo] Date: Mon, 1 Feb 2021 14:37:46 -0500 Message-Id: <20210201193747.2169670-16-jsnow@redhat.com> In-Reply-To: <20210201193747.2169670-1-jsnow@redhat.com> References: <20210201193747.2169670-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@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=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Eduardo Habkost , Michael Roth , Markus Armbruster , Cleber Rosa , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , John Snow 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" For everything typed so far, type this parameter as Optional[QAPISourceInfo]. In the most generic case, QAPISchemaEntity's info field may be None to represent types that come from built-in definitions. Although some Entity types may not currently have any built-in definitions, it is not easily possible to constrain the type except on an ad-hoc basis using assertions. It's easier and simpler, then, to just say it's always an Optional type. Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/commands.py | 2 +- scripts/qapi/events.py | 2 +- scripts/qapi/gen.py | 2 +- scripts/qapi/types.py | 2 +- scripts/qapi/visit.py | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index 13a9dcaf894..54af519f44d 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -296,7 +296,7 @@ def visit_end(self) -> None: =20 def visit_command(self, name: str, - info: QAPISourceInfo, + info: Optional[QAPISourceInfo], ifcond: List[str], features: List[QAPISchemaFeature], arg_type: Optional[QAPISchemaObjectType], diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index 079c666ec69..8c57deb2b89 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -213,7 +213,7 @@ def visit_end(self) -> None: =20 def visit_event(self, name: str, - info: QAPISourceInfo, + info: Optional[QAPISourceInfo], ifcond: List[str], features: List[QAPISchemaFeature], arg_type: Optional[QAPISchemaObjectType], diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index ac3d3e687ef..63549cc8d47 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -325,7 +325,7 @@ def visit_module(self, name: str) -> None: self._add_module(name, self._user_blurb) self._begin_user_module(name) =20 - def visit_include(self, name: str, info: QAPISourceInfo) -> None: + def visit_include(self, name: str, info: Optional[QAPISourceInfo]) -> = None: relname =3D os.path.relpath(self._module_filename(self._what, name= ), os.path.dirname(self._genh.fname)) self._genh.preamble_add(mcgen(''' diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index dbf58c0b91d..2bdd6268476 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -350,7 +350,7 @@ def visit_object_type(self, =20 def visit_alternate_type(self, name: str, - info: QAPISourceInfo, + info: Optional[QAPISourceInfo], ifcond: List[str], features: List[QAPISchemaFeature], variants: QAPISchemaVariants) -> None: diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 568ba35592c..22e62df9017 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -336,7 +336,7 @@ def _begin_user_module(self, name: str) -> None: =20 def visit_enum_type(self, name: str, - info: QAPISourceInfo, + info: Optional[QAPISourceInfo], ifcond: List[str], features: List[QAPISchemaFeature], members: List[QAPISchemaEnumMember], @@ -378,7 +378,7 @@ def visit_object_type(self, =20 def visit_alternate_type(self, name: str, - info: QAPISourceInfo, + info: Optional[QAPISourceInfo], ifcond: List[str], features: List[QAPISchemaFeature], variants: QAPISchemaVariants) -> None: --=20 2.29.2 From nobody Tue May 21 22:07:56 2024 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=1612209270; cv=none; d=zohomail.com; s=zohoarc; b=CCTLYahvZCRuXxHWndYg+Ya4q/p+h5MwwXStENfw9m2aRAPvyBcxhwmpN5pxskTvaiNW5aBlcYY8XpPexkBHmj3UNGTpzB5Uog01lA7KW57AJ/Gylz2Fp/iLyxVc2wb69GxAHuai611SHG1ySmQd8d82OZ3eXX/GQgptp2MUpA4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612209270; 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=/UrbnJIoTY6N/WoRvNd17puFvkWDf9JkExS4pcXAahw=; b=VouHSOhlKdg/hLudwHn4MpFjrj5TJmF0vO50Ws+g1sp864bJ8mw/mzBTMsKwkm2ubDj1Wh+HTWiO1/ZuLQKM+mZPttVtLVg18ZysMNYe/wtOv+zrha2Knf7nXHlz/QCLxA4vavpgpK0TtZvUEnOCr0J4cTQZEQebe84QwzOdru0= 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 1612209270466761.710112875942; Mon, 1 Feb 2021 11:54:30 -0800 (PST) Received: from localhost ([::1]:42810 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6fHJ-0005xn-78 for importer@patchew.org; Mon, 01 Feb 2021 14:54:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49622) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6f1r-0003Pu-8p for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:22343) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6f1p-0005n1-1P for qemu-devel@nongnu.org; Mon, 01 Feb 2021 14:38:31 -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-90-TCEcUh1xMoipKFOSVspMYw-1; Mon, 01 Feb 2021 14:38:26 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 992AD1800D41; Mon, 1 Feb 2021 19:38:25 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6888E60C05; Mon, 1 Feb 2021 19:38:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612208308; 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=/UrbnJIoTY6N/WoRvNd17puFvkWDf9JkExS4pcXAahw=; b=OHAxJjJt3NCsMQYGLJN5pRG2eJyLp3BShcm7PR34MhfKqeSH5R1QXYBchlojUf+fpLZKuk Z/e9QOUD+o9Lzt8NElIuJ+dLrVVeEuyojmsNCGPr79i1vwAmGrY3UVjTy93pW6dUUjrNgH aXYTROOzOsSrQJNuvxYBUkjcpgLj7ic= X-MC-Unique: TCEcUh1xMoipKFOSVspMYw-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v4 16/16] qapi: enable strict-optional checks Date: Mon, 1 Feb 2021 14:37:47 -0500 Message-Id: <20210201193747.2169670-17-jsnow@redhat.com> In-Reply-To: <20210201193747.2169670-1-jsnow@redhat.com> References: <20210201193747.2169670-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@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=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.351, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Eduardo Habkost , Michael Roth , Markus Armbruster , Cleber Rosa , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , John Snow 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" In the modules that we are checking so far, we can be stricter about the difference between Optional[T] and T types. Enable that check. Enabling it now will assist review on further typing and cleanup work. Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/mypy.ini | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/qapi/mypy.ini b/scripts/qapi/mypy.ini index 74fc6c82153..04bd5db5278 100644 --- a/scripts/qapi/mypy.ini +++ b/scripts/qapi/mypy.ini @@ -1,6 +1,5 @@ [mypy] strict =3D True -strict_optional =3D False disallow_untyped_calls =3D False python_version =3D 3.6 =20 --=20 2.29.2