From nobody Fri May 17 11:05:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612817109; cv=none; d=zohomail.com; s=zohoarc; b=gLiq7yTaPsNOKyC5zk9UzGVOvZNvNmSqK7L2cWnDYgtjAhVwHeDqDl2LaJJwVMwxtubVX0qU5E6imr6T7bOU9I5W6VegOqEanuPrFu5iSZA8rXZsmPE++n0WSLH7/kzG1eOP7MW+D6y7FXDzKxZOKizN1C2LUr+RQoduBNW1HoM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612817109; 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=QWrusQf7vms/Kn07LD+g6+lC5FHvfnFhI3dW9a1AHS4=; b=HLR394i12JHo3zC4v+lIMsrdupUhdo0Tzhc/7aHNGqgEqzMlHN5Wk0jua0X8yyP988ZXoupfxxvMlgIvdFOeyM/0ewwqw61+vYWbVaYwx3wsTAtPg8RHDPi8FfUNzd9tZq05y1+0Wp7kUJdntlPxYprDZaQBCpVxOn1l5jnPyh4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1612817109433239.44648497876653; Mon, 8 Feb 2021 12:45:09 -0800 (PST) Received: from localhost ([::1]:51466 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9DPA-0002F4-8F for importer@patchew.org; Mon, 08 Feb 2021 15:45:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51812) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l974P-0005aW-IX for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:59:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:46648) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9742-0001b0-V3 for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:59:16 -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-423-UwF47ELhOgWkBtOEoNSJxQ-1; Mon, 08 Feb 2021 08:58:49 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1357685B665; Mon, 8 Feb 2021 13:58:48 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-51.ams2.redhat.com [10.36.115.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C1A061007612; Mon, 8 Feb 2021 13:58:47 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 4D5CA113861E; Mon, 8 Feb 2021 14:58:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612792732; 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=QWrusQf7vms/Kn07LD+g6+lC5FHvfnFhI3dW9a1AHS4=; b=dpiEt2QPKJuWUHfqec4uo13CEOt3rx7oCv6vytXauS/IsTF3MDbe1UY2W/a75wpEGfkVlq LPltfXUzupTDiKUeHbWX97MqgATDfHnhvPkkmklfL5X54Bn6mfD884NO5I6vzHX9D53uVH hOUxv3Acg42YJCSH2mzIHjVeYzBxZ8Y= X-MC-Unique: UwF47ELhOgWkBtOEoNSJxQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 01/16] qapi/commands: assert arg_type is not None Date: Mon, 8 Feb 2021 14:58:31 +0100 Message-Id: <20210208135846.3707170-2-armbru@redhat.com> In-Reply-To: <20210208135846.3707170-1-armbru@redhat.com> References: <20210208135846.3707170-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, 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=unavailable 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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow 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 Message-Id: <20210201193747.2169670-2-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-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 50978090b4..71744f48a3 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 @@ out: 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.26.2 From nobody Fri May 17 11:05:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612815181; cv=none; d=zohomail.com; s=zohoarc; b=LM6IAhMvku2KxeRwx8kIUzVf2ZTQpL07eIZYw7rpG/UN8CVUge8tBAE5Hh1Os+rWbXrAAZpeT7Qh9vft46ZYVHPfDFySjUhf7i2DbxZLZ63c177RsjjlJ2tkNPZsiDRRHE709rT3JgOrG1x1FOPLXzw0ZWuhHuvOUkMWWYgJq7I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612815181; 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=tOZwGY7D9KaRHRkLU+yS6h+Rp6VjdAHAxeL0lnmC3I0=; b=baEwaNagf7erlorVqMKBbT5dvzv+WMINvKJUb3doFgLWK6MreEVpZIhPPq/GXGJCUg10mgdvb371EKj5BhraRHCkvGPVZFaufj+KaPFR2F+NIsydllGHB+pET1QIZZe23ajwnNeA/lLT+eVaxn7gwuFJ89ovIluceYUNWEv5ZVU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1612815181944386.5030414222765; Mon, 8 Feb 2021 12:13:01 -0800 (PST) Received: from localhost ([::1]:47418 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9Cu4-00005Z-1U for importer@patchew.org; Mon, 08 Feb 2021 15:13:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51692) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9743-0005WZ-RB for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:58:55 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:50129) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9740-0001aj-9L for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:58:55 -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-520-mJGfihlsOCO2zYXdL95ofg-1; Mon, 08 Feb 2021 08:58:49 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0D0BA1005501; Mon, 8 Feb 2021 13:58:48 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-51.ams2.redhat.com [10.36.115.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BE68F5D9DC; Mon, 8 Feb 2021 13:58:47 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5099C1138461; Mon, 8 Feb 2021 14:58:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612792731; 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=tOZwGY7D9KaRHRkLU+yS6h+Rp6VjdAHAxeL0lnmC3I0=; b=NTFMuW3Fl/6v+SWCCV3jJHMDnDx6PDygauU+EViyXDo4NQVlD6OT3qwVRYbCKlbt/PqybL pC/RTxIaAcikrs7/Df3rRZfJWmxG4InA6RNlvUUBg/MoAE0Qx8SG9pp4fDNRIvnekO/fE2 +owF3Wb0JXB9MNSJb0spkF08O5N6Xns= X-MC-Unique: mJGfihlsOCO2zYXdL95ofg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 02/16] qapi/events: fix visit_event typing Date: Mon, 8 Feb 2021 14:58:32 +0100 Message-Id: <20210208135846.3707170-3-armbru@redhat.com> In-Reply-To: <20210208135846.3707170-1-armbru@redhat.com> References: <20210208135846.3707170-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, 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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow Actually, the arg_type can indeed be Optional. Signed-off-by: John Snow Message-Id: <20210201193747.2169670-3-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-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 599f3d1f56..9851653b9d 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -12,7 +12,7 @@ This work is licensed under the terms of the GNU GPL, ver= sion 2. 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 @@ from .types import gen_enum, gen_enum_lookup =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 @@ void %(event_emit)s(%(event_enum)s event, QDict *qdict); 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.26.2 From nobody Fri May 17 11:05:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612816715; cv=none; d=zohomail.com; s=zohoarc; b=cw0CXAIa0GvWj6RMvwhLRHCVVhtlF8i6SpFs1nYZO9p0ggfQ4m6I/wNUyqP562Ou89tsLDCpwmBhWx8FThKAZwMdyDYDAWvQ+30tCs7vrHFdS6SHTljppFdYYA4QrfsTLAPC3j1CJ1x11KPhxNd8H4YtzudlIGv2X+XzQ3xI5kI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612816715; 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=K+zZxFJBxSuX2L1RklS9OZOEZLEKu47kVzsHNkiWi1A=; b=kXTEmgUX6v0KBOoUm/ml78h3yTf7biJKzb74MB48hGqDOE4fJlR0epNlRxQB8JOixCL0OXhXdsAxtmOohHtLNvxO4g0qJW2pdOoHSk9S3T+IZLPCJ/xy0ByY43sRHxYEmZS5QHjiayJgASNygBarSIbWe0SvxEN8QqLAJEmXoh0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1612816715155915.0603416477454; Mon, 8 Feb 2021 12:38:35 -0800 (PST) Received: from localhost ([::1]:34752 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9DIn-00037S-TN for importer@patchew.org; Mon, 08 Feb 2021 15:38:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51764) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l974K-0005Yo-8l for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:59:12 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:32180) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9741-0001ay-TP for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:59:06 -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-372-Vtzb6BXuMJWTy1goZdToZw-1; Mon, 08 Feb 2021 08:58:49 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 123C979EC1; Mon, 8 Feb 2021 13:58:48 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-51.ams2.redhat.com [10.36.115.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C2B5060C5B; Mon, 8 Feb 2021 13:58:47 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 53CBF1138468; Mon, 8 Feb 2021 14:58:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612792731; 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=K+zZxFJBxSuX2L1RklS9OZOEZLEKu47kVzsHNkiWi1A=; b=BJK0onBBS2zx+D3PFWKgH3ZDX6LcnZWJLDui5kmkfWOEMOJMuLpu2oa76hF9EFs/vbNzL4 vRDB9zstfdL+XplUpNH8ERqf3SxtFqdgh/OXLM6NeNyRL0kAnbcoUWRYMPy87ZkFefD9b9 Z+uGFB+lKX8u25vfgiAEVTmSBtbyqdM= X-MC-Unique: Vtzb6BXuMJWTy1goZdToZw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 03/16] qapi/main: handle theoretical None-return from re.match() Date: Mon, 8 Feb 2021 14:58:33 +0100 Message-Id: <20210208135846.3707170-4-armbru@redhat.com> In-Reply-To: <20210208135846.3707170-1-armbru@redhat.com> References: <20210208135846.3707170-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, 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=unavailable 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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow Mypy cannot understand that this match can never be None, so help it along. Signed-off-by: John Snow Message-Id: <20210201193747.2169670-4-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-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 42517210b8..703e7ed1ed 100644 --- a/scripts/qapi/main.py +++ b/scripts/qapi/main.py @@ -23,6 +23,8 @@ from .visit import gen_visit =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.26.2 From nobody Fri May 17 11:05:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612815338; cv=none; d=zohomail.com; s=zohoarc; b=dKPUtkn3UQwlpkVr9lAd2oyB2k5CBHj51Nq4fIGqZ0aPYmd9IW1fAYw731aObA9vHLAsGSlq1TAJpsBSCYGnC9oNfDcnMkCz99Js8xh530KLkwUscA04uANwka85Z44FHh7gkaVYlfWTO5yeuexOjxmdLmL9+Uh0SjLznuVEpu8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612815338; 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=JWB0JzXdObsP5q1eKtjSjijyVmEU6f0/Z3ra3E4sdFs=; b=eBqcyLtrzonHwQRY3rR2ay0Hyg3xczrfyYoW/VW2PQ2SmiqOlBEYSzaqvMs4nlhbuy4EBdxdd/RSDCb6mByFMCzul2aIooNVpHuo2lyWDGjfaUPnQUDJ9dH1ZbOnxShC9p5RP8+3Wr9jk2duCO0piEgH0MDDtgmbnS+ZleD3TGI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1612815338652706.5817755707196; Mon, 8 Feb 2021 12:15:38 -0800 (PST) Received: from localhost ([::1]:54462 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9Cwb-0003Mb-5S for importer@patchew.org; Mon, 08 Feb 2021 15:15:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51662) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9743-0005WS-PO for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:58:55 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:35293) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9740-0001ak-6r for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:58:54 -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-126-_v4VrjR1Ntq4lRyZ3zHM3A-1; Mon, 08 Feb 2021 08:58:49 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0FA0C1020C23; Mon, 8 Feb 2021 13:58:48 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-51.ams2.redhat.com [10.36.115.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C32CA62A1B; Mon, 8 Feb 2021 13:58:47 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 571041132FD3; Mon, 8 Feb 2021 14:58:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612792731; 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=JWB0JzXdObsP5q1eKtjSjijyVmEU6f0/Z3ra3E4sdFs=; b=Q5jvxbkDVQkWJK7G/OEbBUMJ+dr7AmeUFFPfWvlbkw9ltoyVr9X3HaDZNHnB3JVkgicycz ohGoXZ+JOfA20b2zr2d4h+6KW6OffiO414uo1hl4QiYQgzUDkFtRqhleh5GGP8UyVqPSoq pjAzFpbQF0tMQVaSyVj9Uspif3tIq6U= X-MC-Unique: _v4VrjR1Ntq4lRyZ3zHM3A-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 04/16] qapi/gen: inline _wrap_ifcond into end_if() Date: Mon, 8 Feb 2021 14:58:34 +0100 Message-Id: <20210208135846.3707170-5-armbru@redhat.com> In-Reply-To: <20210208135846.3707170-1-armbru@redhat.com> References: <20210208135846.3707170-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, 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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow 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 Message-Id: <20210201193747.2169670-5-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-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 b40f18eee3..3d81b90ab7 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -130,15 +130,12 @@ class QAPIGenCCode(QAPIGen): 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.26.2 From nobody Fri May 17 11:05:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612809344; cv=none; d=zohomail.com; s=zohoarc; b=BlyQuJrb/Qd9fCvHzi1tR5qqylwILmIpgn/v7zMOR1eIulwbNVB8ByU44ZepbmAEeSY+0j5NdIww7zkIzayhOrI+2EMJzUTjVsRTGUjY8pTNCsf4hzIyO2dSMqlSEJmhnUslTyoZsH8Oij4JhUK3B9Jlf909vyUBwZPn0F/PVPQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612809344; 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=csUV8I8SWb0ruDZPQgjB6Ey2CibyQJ2OLFYrR8KhqbA=; b=nBpiInTfqEyjVifr8RI8HI2h+LSO5mxdHtgiRhwcT7r9Hevz67HzA+8Fx5YZBNfuf+GP5JQbs0Wq2FkN9aTZGo//csTgZYP6d3zMCtty4dIgh0WcyMUPYAQdll++vb8mGFuWwCYJYxdsSrLwakYt4F0fiKsveVdeO327Dvd4AEg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1612809344683353.37286324434456; Mon, 8 Feb 2021 10:35:44 -0800 (PST) Received: from localhost ([::1]:45468 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9BNv-0007D4-KW for importer@patchew.org; Mon, 08 Feb 2021 13:35:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51818) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l974P-0005ag-LB for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:59:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:26254) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9742-0001cw-OI for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:59: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-570-V9NRWYelPl2bVWROKQCeOg-1; Mon, 08 Feb 2021 08:58:50 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E0179107ACC7; Mon, 8 Feb 2021 13:58:49 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-51.ams2.redhat.com [10.36.115.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8840C10016F0; Mon, 8 Feb 2021 13:58:49 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5A57F1132E9A; Mon, 8 Feb 2021 14:58:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612792734; 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=csUV8I8SWb0ruDZPQgjB6Ey2CibyQJ2OLFYrR8KhqbA=; b=HGW1QDvW4wAfV1pmCFcBHffsmuQ5xWh50yFl7x4eIZaWR+Kr26+s46TlmQaECX71GJqY31 qSG23oxHLjBG967+Qeqa1eq8BUjpgglAwHYmqv+U3HNIo19TzNm7KKN62NMZchtaPv+rBv EeQYonDnBtESzv7sLlAgbLuOIylSlYI= X-MC-Unique: V9NRWYelPl2bVWROKQCeOg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 05/16] qapi: centralize is_[user|system|builtin]_module methods Date: Mon, 8 Feb 2021 14:58:35 +0100 Message-Id: <20210208135846.3707170-6-armbru@redhat.com> In-Reply-To: <20210208135846.3707170-1-armbru@redhat.com> References: <20210208135846.3707170-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, 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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow 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 Message-Id: <20210201193747.2169670-6-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-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 3d81b90ab7..2aec6d3436 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -31,7 +31,11 @@ from .common import ( guardstart, mcgen, ) -from .schema import QAPISchemaObjectType, QAPISchemaVisitor +from .schema import ( + QAPISchemaModule, + QAPISchemaObjectType, + QAPISchemaVisitor, +) from .source import QAPISourceInfo =20 =20 @@ -246,21 +250,14 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): 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 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): 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 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): =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 720449feee..e80d9320ed 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -141,6 +141,33 @@ class QAPISchemaModule: 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 @@ class QAPISchema: 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.26.2 From nobody Fri May 17 11:05:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612816907; cv=none; d=zohomail.com; s=zohoarc; b=RU64b97vHdrMWehKLJdh5bt0qTtxoSB++vcq7wjiuSMGKAIlHozTk6xefpYLQ2toXYfhU+0VnibOlEHqvRHYuxEPYS9r52KX3w/Z2De/D1W5usEAEkK3CUhIMzzScqk1R4H/0/TzwSh3r9dQaQjpD442vsC5c55t6vj1DigBOZ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612816907; 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=ELyR8k+nisfGJRLnb7LDOZoFT8MT+r9AQuV5mx2Pn4w=; b=kmBbfqhlaj4nU1bdmFFZxeu6+PVQZplYW7YSmTkvKs+o3QCrWrJYQ4x84jLC3Qv3DU7sIFtpBddAN+w0nvRTu/NKJ015IpGEP7aPLQVypZdj4hZ87Sub7iP/nBrxwkEBOK0AiHr+8pwrnB8/t69GzdNy48b/5eo8RAUoWPbJI4I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 161281690789993.32744523752638; Mon, 8 Feb 2021 12:41:47 -0800 (PST) Received: from localhost ([::1]:43110 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9DLu-0006sT-Oq for importer@patchew.org; Mon, 08 Feb 2021 15:41:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51804) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l974P-0005aC-C9 for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:59:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:37510) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9742-0001cr-Od for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:59:14 -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-503-3GoPkhA6Oo21o6AxPMAIsQ-1; Mon, 08 Feb 2021 08:58:51 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BA91C85B660; Mon, 8 Feb 2021 13:58:49 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-51.ams2.redhat.com [10.36.115.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 88BCE1007612; Mon, 8 Feb 2021 13:58:49 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5DA241132EA4; Mon, 8 Feb 2021 14:58:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612792733; 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=ELyR8k+nisfGJRLnb7LDOZoFT8MT+r9AQuV5mx2Pn4w=; b=gXWYZYPMDWFlK/no6M7ns+nqe/TQCjV0gjSx6jTMQM7VqpOm7oCPT2MTOuuVM34JvdadCW mLdbG5HMVd9wn3ujkMz3RTszWke2jf3mbWRkhOHHj/sP7zogdDfW0BxRLVlCgraEXhQXee G3x5/Nj1HP+LLfvgTpFKpV2URmbPhRk= X-MC-Unique: 3GoPkhA6Oo21o6AxPMAIsQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 06/16] qapi/gen: Replace ._begin_system_module() Date: Mon, 8 Feb 2021 14:58:36 +0100 Message-Id: <20210208135846.3707170-7-armbru@redhat.com> In-Reply-To: <20210208135846.3707170-1-armbru@redhat.com> References: <20210208135846.3707170-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, 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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" 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 Message-Id: <20210201193747.2169670-7-jsnow@redhat.com> --- 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 2aec6d3436..aaed78eed5 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -295,23 +295,24 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): 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 2b4916cdaa..dbf58c0b91 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -271,7 +271,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisito= r): 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 339f152152..568ba35592 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -305,7 +305,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisit= or): 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.26.2 From nobody Fri May 17 11:05:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612815843; cv=none; d=zohomail.com; s=zohoarc; b=Fzoj1ujVYDgn1fjwYMFb7Ht7RX1lZaGlmRavGU4kFxGYOh4cuJIqwEagR2ijJL9gpbGvRWOMLG7qmFRlg3KZSMyngl8gcOmXU5vbofYTyaNLTxPiRujuYewXLo4rGpdELaqulybwYYi+iYRHDpUGQza2ot3j9glWT1rCyqFc/ms= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612815843; 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=VC+Huus2RfkS4dN3aMo8Q6uX73uf8rUlZd963vplIQQ=; b=MpldxYxo0lr8xSb94u7IEftPSillZrRhoAjgL7iI7uK4qEalIGADngnFudylav2AQNe1MbsFb5l1jk/SH3/smPx04oybp86IZ+kWsHoiG3AiGEfpniANJ8x6ARdkXzWQWLu7PfWYn9/aV2UBqmxCoJDrpdnexwvfDkTs8eBopbk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1612815843992256.2119394596914; Mon, 8 Feb 2021 12:24:03 -0800 (PST) Received: from localhost ([::1]:40894 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9D4k-0001eq-W4 for importer@patchew.org; Mon, 08 Feb 2021 15:24:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51760) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l974K-0005Ym-8E for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:59:12 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:44844) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9742-0001by-FG for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:59:03 -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-568-Is7J-CrkPpSEVH-eaTw7gw-1; Mon, 08 Feb 2021 08:58:50 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B56D0180E470; Mon, 8 Feb 2021 13:58:49 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-51.ams2.redhat.com [10.36.115.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 881C95D9DC; Mon, 8 Feb 2021 13:58:49 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 60EF51132D67; Mon, 8 Feb 2021 14:58:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612792732; 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=VC+Huus2RfkS4dN3aMo8Q6uX73uf8rUlZd963vplIQQ=; b=b3NaHeUBa0gVmFG5Rz+j1i0DQ0FjnwphVygUY7ouqRdQynhx2hQL2qOfkBByTSk5Kpiewb QezM9KBB9xSnaU8BSlcHrpm8JVfwcS/UuhPR27B+DYZKLGfd0To7E+cnaDQiKvjBJTPoLc JBkAaJ/XCE5M0OByresVGahsTpZEtgQ= X-MC-Unique: Is7J-CrkPpSEVH-eaTw7gw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 07/16] qapi: use explicitly internal module names Date: Mon, 8 Feb 2021 14:58:37 +0100 Message-Id: <20210208135846.3707170-8-armbru@redhat.com> In-Reply-To: <20210208135846.3707170-1-armbru@redhat.com> References: <20210208135846.3707170-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, 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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow QAPISchemaModularCVisitor._add_system_module() prefixes './' to its name argument to make it a module name. Pass the module name instead. This will allow us to coalesce the methods to add modules later on. Signed-off-by: John Snow Message-Id: <20210201193747.2169670-8-jsnow@redhat.com> Reviewed-by: Markus Armbruster [Commit message reworded] Signed-off-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 71744f48a3..fc5fe27c47 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -286,7 +286,7 @@ class QAPISchemaGenCommandVisitor(QAPISchemaModularCVis= itor): 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 9851653b9d..26faa82989 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -191,7 +191,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaModularCVisit= or): 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 aaed78eed5..da9d4d2d37 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -285,7 +285,8 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): 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.26.2 From nobody Fri May 17 11:05:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612815659; cv=none; d=zohomail.com; s=zohoarc; b=SvqmkOj3E809k6BK2xcrySlbjOP3E/Yj9xXAE+6GbD5sLsS5Wv3t2iVdSTu9G5TH4FLp8fYI5NNLc8tpy/URr6+WAnjqUNnXCFtKTP65Q6GxZx77LqzXRDN7ukgvbNVJK/I/ckPCdwc6a0OXevHzJ9YkRffRGLXnGRU/U6vvw08= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612815659; 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=h2lG645VUDvw4MeZiKdOV5d8kEiTYqWGbD4d/AaUV/Y=; b=Y6sDfRqSvZ32v59a98Ie2NnSnO554M9XAE+VHhJYgzY2vjt8XAMP6+ybjzDw5Vj5YC+REzcaihaEasfZ+xSaE7S53eOKYxE0RQfJLfG9ugjKJKjYsKtTqkpoTkdMKnk/CxZ4yrQCynLhECNhfPJX15EGEj+SiowuxJYIGGp8VeY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 16128156594535.79547320682093; Mon, 8 Feb 2021 12:20:59 -0800 (PST) Received: from localhost ([::1]:36068 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9D1m-0007nt-7o for importer@patchew.org; Mon, 08 Feb 2021 15:20:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51844) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l974Q-0005cU-Nl for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:59:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:44429) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9743-0001dJ-P4 for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:59:18 -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-531-w5nQwg0XN2OssL2q-3wt0w-1; Mon, 08 Feb 2021 08:58:51 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E1AED107ACE3; Mon, 8 Feb 2021 13:58:49 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-51.ams2.redhat.com [10.36.115.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8D62E101E243; Mon, 8 Feb 2021 13:58:49 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 646A41132CB1; Mon, 8 Feb 2021 14:58:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612792735; 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=h2lG645VUDvw4MeZiKdOV5d8kEiTYqWGbD4d/AaUV/Y=; b=IeupjSoitiBbBP/mXEzT5ferEHMW/JYGeyQt7phaGTqrA1D13ulf+qzLoU1ibTDCyAdv7q fvJMu+lOQLnFNECS9/KpW9w+tN96eAdvq+VNNlUeT/4aXg6fyzwa4Tg8QYO9OUTdFadwGA PoR0nWXv6xr6FOgfQAckGlnN8BwMKcw= X-MC-Unique: w5nQwg0XN2OssL2q-3wt0w-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 08/16] qapi: use './builtin' as the built-in module name Date: Mon, 8 Feb 2021 14:58:38 +0100 Message-Id: <20210208135846.3707170-9-armbru@redhat.com> In-Reply-To: <20210208135846.3707170-1-armbru@redhat.com> References: <20210208135846.3707170-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, 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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow 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 Message-Id: <20210201193747.2169670-9-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-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 da9d4d2d37..9352d79c3a 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -246,16 +246,16 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): 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 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): 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 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): 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 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): 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 e80d9320ed..14cf9da784 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -68,7 +68,8 @@ class QAPISchemaEntity: =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 @@ class QAPISchemaModule: 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 @@ class QAPISchemaModule: 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 @@ class QAPISchema: 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 @@ class QAPISchema: 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 @@ class QAPISchema: =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 273f0f54e1..ce4f6a4f0f 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 419284dae2..715b0bbc1a 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 69666c39ad..3feb3f69d3 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 42ae519656..9ae44052ac 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 0b654ddebb..16dbd9b819 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 061f81e509..48e923bfbc 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 04356775cd..6a30ded3fa 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 8868ca0dca..3b1387d9f1 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.26.2 From nobody Fri May 17 11:05:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612815396; cv=none; d=zohomail.com; s=zohoarc; b=m9s/pjWloDqyayQhoZx7EFQMIyqKd4P2zXqV27yV7zn3GlANajfTKiP34v3HWEpoCdagJu6J16MW6HURJxhhe5XsfAiP3bv/J4ExIGOYNru1W0ODHhfYsIl/SWIKxJOL1vw18KUa/R+P05Ygp72kx1DGNre+c+4KMFo/ExEAaD0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612815396; 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=0lFsuvdTBY0RlUXyPOYGW+C+avllTSV6d2/cvT7x8e0=; b=L98CJPnJMVwPlIv+52r2Jp6jiDQfDMZqFRJFhLPUrJQKq/c+GN01WyvPXI7MgJsjqwfv7QpxmVxEELYQY+TJjUW74D86BchZDBpxYURac+nxiFBHaW1H7O9AXM451bVi7gPAYqt2yVjhY1KdKA5qKqiHCF5IdregKn9WKascGGo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 161281539653245.631607813515984; Mon, 8 Feb 2021 12:16:36 -0800 (PST) Received: from localhost ([::1]:57098 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9CxX-0004aa-2s for importer@patchew.org; Mon, 08 Feb 2021 15:16:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51836) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l974Q-0005bt-7F for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:59:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:21187) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9743-0001ct-4F for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:59: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-568-BrUa0MTRNg2cSQ2spmsNXw-1; Mon, 08 Feb 2021 08:58:51 -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 B81E5180E471; Mon, 8 Feb 2021 13:58:49 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-51.ams2.redhat.com [10.36.115.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8884A60C64; Mon, 8 Feb 2021 13:58:49 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 67F3C11329AC; Mon, 8 Feb 2021 14:58:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612792733; 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=0lFsuvdTBY0RlUXyPOYGW+C+avllTSV6d2/cvT7x8e0=; b=MSJlh5u4R+9d6fOlAkIyLV+HISj3Y7tqVgnheaKelpQj5wZL3TYJ4sNHFKvfU3JRe4LIy9 nECVT/WpCKysVC6T1MXGiZ7ZVPsH5PlGuWN7d38jHwyLwjOFDs12B/tYQyEcOMu/Scu8ci QYNJqT9BcqkpdHvVQwji9rNhQky54L0= X-MC-Unique: BrUa0MTRNg2cSQ2spmsNXw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 09/16] qapi/gen: Combine ._add_[user|system]_module Date: Mon, 8 Feb 2021 14:58:39 +0100 Message-Id: <20210208135846.3707170-10-armbru@redhat.com> In-Reply-To: <20210208135846.3707170-1-armbru@redhat.com> References: <20210208135846.3707170-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, 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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" 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 Message-Id: <20210201193747.2169670-10-jsnow@redhat.com> --- 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 fc5fe27c47..4911166339 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -286,7 +286,7 @@ class QAPISchemaGenCommandVisitor(QAPISchemaModularCVis= itor): 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 26faa82989..079c666ec6 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -191,7 +191,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaModularCVisit= or): 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 9352d79c3a..8ded0f7e5a 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -272,22 +272,15 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): 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 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): 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 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): 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.26.2 From nobody Fri May 17 11:05:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612815907; cv=none; d=zohomail.com; s=zohoarc; b=lOtNxmbyQwkpMSGB2lGqRkrjgDCMUqtyhdYX0bnRc4YoxkydP+395hiXwhs0s3XYBE3NcJ0C2EjruqJhU7lpP2mEjN86c2JRSabI2GCsGf+d28i5iGTNZgqLlswy3qEfk/vO8OMnd/m4Yi2f5g8qr3zyXEAfShIZlVe4mDHFqHQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612815907; 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=yx2KdFKFJXy+auIFa0SIFenoTRP01v3Xdi8GhMvXbvM=; b=XoCRi4mN+ulfUzAS1N+ncK4P5aiDZAYNzygXhRMdP+TAvgtfAozY7VoEkqqbmnsVK5FwyapHeEJCvlLb9g25+Im5WgCLS6PliyU4/j8iNAJlr/PVGdk3/X3L/ko38etjhgILngkB9yEfzBAcfXmrHeAtYa4v3kK8k3KwxM/KupI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1612815907148432.26264141056606; Mon, 8 Feb 2021 12:25:07 -0800 (PST) Received: from localhost ([::1]:44236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9D5l-00034u-Tw for importer@patchew.org; Mon, 08 Feb 2021 15:25:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51904) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l974i-0005gW-JY for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:59:37 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:24119) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9745-0001dW-D8 for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:59: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-216-xM6A2wDiM56brOMxV6gJAQ-1; Mon, 08 Feb 2021 08:58:51 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BC58E79EC0; Mon, 8 Feb 2021 13:58:49 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-51.ams2.redhat.com [10.36.115.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8C1C4189A5; Mon, 8 Feb 2021 13:58:49 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 70F8211329B3; Mon, 8 Feb 2021 14:58:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612792736; 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=yx2KdFKFJXy+auIFa0SIFenoTRP01v3Xdi8GhMvXbvM=; b=gwMRwnKAn1RmtJd0EZwdgAg/nHY6BrpTAhBpx3NSR6NSdG9ZxXLlhBb2R1rvfi6IzqW8Ho CIySvRnpOsWX6BId6dI/PI3X23UciJhz3BTkiELixC477sKVurTUCfiYkn7wi3VUncOOfb svqjhS3SYIaIYd7MEbbjv2eqX0sUzQk= X-MC-Unique: xM6A2wDiM56brOMxV6gJAQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 10/16] qapi: centralize the built-in module name definition Date: Mon, 8 Feb 2021 14:58:40 +0100 Message-Id: <20210208135846.3707170-11-armbru@redhat.com> In-Reply-To: <20210208135846.3707170-1-armbru@redhat.com> References: <20210208135846.3707170-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, 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=unavailable 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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow Use a constant to make it obvious we're referring to a very specific thing. Signed-off-by: John Snow Message-Id: <20210201193747.2169670-11-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-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 14cf9da784..353e8020a2 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -68,7 +68,7 @@ class QAPISchemaEntity: =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 @@ class QAPISchemaVisitor: =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 @@ class QAPISchemaModule: """ 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 @@ class QAPISchema: 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.26.2 From nobody Fri May 17 11:05:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612816199; cv=none; d=zohomail.com; s=zohoarc; b=Y/QKhP2ckXZsRrIqCHk0t08gyBTdch8/+qg8hqo1pPVN6hExK+ctyoIsVADyC0/pVx0++P8NvgsCBq6lLpo33PcbjoBEAMpgwZMkp6fsQ1FNjnhv5D2+UoDan2zg3L9UbIzpxT7F+swdfK0GWoYaF3+oaiOzUnQnxmuHJcKlDJk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612816199; 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=e6dBzBkoypOKW9Nm86k/EMhK8mNDqx0KdnrSSJQsJws=; b=GXIyxzT9U7EW7g76AmZFxyOCfbeOixme9VJYO8exh0fz/BKaVtmTq28mhZDTWfQZeAltw2BugNeuiGycBkDCwDzXPHMVPMPdmL4TwONzOauX++UYUSSIeQbAmbGT6REx2kbLhCGfIKbNOntjYeJ3R5dTQDhVZ9lk6ZP1C70EESQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1612816199489662.0359288144437; Mon, 8 Feb 2021 12:29:59 -0800 (PST) Received: from localhost ([::1]:49518 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9DAO-0005Es-5p for importer@patchew.org; Mon, 08 Feb 2021 15:29:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51754) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l974K-0005Yi-8f for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:59:12 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:41278) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9742-0001bz-BW for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:59:05 -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-503-iCRas8R5MeGoV-cqRmMlRg-1; Mon, 08 Feb 2021 08:58:50 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C0C0B79EC2; Mon, 8 Feb 2021 13:58:49 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-51.ams2.redhat.com [10.36.115.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8DFB519C95; Mon, 8 Feb 2021 13:58:49 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 77B5811329BE; Mon, 8 Feb 2021 14:58:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612792732; 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=e6dBzBkoypOKW9Nm86k/EMhK8mNDqx0KdnrSSJQsJws=; b=iQwQYPA/SllNsQvdoBKunJSb1s/NeK6BV27v5T+HOMc5uRi959qidoEtNsRlrzjDseqNlL 0NIu2lwgVq6y6f1eiS7RgGkcZhwamNMZDM2g1ao7UgGaXvTyYHNK35NiwjshvCGiAEQyvT aOnYsba2J/wM2s2BVB/TsQLKUTGGYGg= X-MC-Unique: iCRas8R5MeGoV-cqRmMlRg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 11/16] qapi/gen: write _genc/_genh access shims Date: Mon, 8 Feb 2021 14:58:41 +0100 Message-Id: <20210208135846.3707170-12-armbru@redhat.com> In-Reply-To: <20210208135846.3707170-1-armbru@redhat.com> References: <20210208135846.3707170-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, 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=unavailable 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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow 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 Message-Id: <20210201193747.2169670-12-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-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 8ded0f7e5a..b2bb9d12ff 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -244,11 +244,20 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): 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 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): 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 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): 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.26.2 From nobody Fri May 17 11:05:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612815495; cv=none; d=zohomail.com; s=zohoarc; b=l2rygKFozL8DHfXhHnXPknoW2DYu5bLsw6Y9BdKjpMhPI1OlIeE5kqTicjw4GtypYF/9w9xPFX/6urMU9/9QHA7VXl7xz5xroyEYgS2V8HiQZ2C2sax0MJOYN6D4LQetw+YUmiZLc4xGnMcfP9T3uih3GJXyjVOED8iojAjBQKI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612815495; 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=cKxhboqo+JBnPy5oOLXcx7d3/EZRWUQPg1AlFPmx5yY=; b=DB3ujRKySre+Y3vxjfBx26bspPOATI+JvyxCzBBvQ4pHFJjSiLFfuA0dWl7EZn2wboRW2z1XRX67oDWasdAWpFl2409suy4XQBI4YC1iSSIQB+yl9vDq4hhZlYSORA9PQlS1D3J7uTifYzKYDyKuRjfxd6mG6dd+bqEFnA57LMQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 161281549576960.89602682106374; Mon, 8 Feb 2021 12:18:15 -0800 (PST) Received: from localhost ([::1]:33418 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9Cz6-0006YQ-S3 for importer@patchew.org; Mon, 08 Feb 2021 15:18:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51762) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l974K-0005Yn-8s for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:59:13 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58970) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9742-0001c2-NF for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:59: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-313-pW-HoDyxO5OiAPVzfHsqZA-1; Mon, 08 Feb 2021 08:58:50 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CB0FA85B663; Mon, 8 Feb 2021 13:58:49 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-51.ams2.redhat.com [10.36.115.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9CDDE5D9DE; Mon, 8 Feb 2021 13:58:49 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 7D28B1132922; Mon, 8 Feb 2021 14:58:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612792732; 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=cKxhboqo+JBnPy5oOLXcx7d3/EZRWUQPg1AlFPmx5yY=; b=UG0vTS2iDMtX0fbvKt9PDXK5omPnZUxFaEdV+g65YIIryDgzXmJf0I61CU+1W6Psph8Az+ Y+Brh7cf1puiGriHVZvG4Vp8sAhBniig5e29AfQ7nwYm6gD3fdRwn1iJsZDoXlqXLC9Cjq 5Y643qKXVBEiD6T4ZWA0hh2IUG4mws8= X-MC-Unique: pW-HoDyxO5OiAPVzfHsqZA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 12/16] qapi/gen: Support switching to another module temporarily Date: Mon, 8 Feb 2021 14:58:42 +0100 Message-Id: <20210208135846.3707170-13-armbru@redhat.com> In-Reply-To: <20210208135846.3707170-1-armbru@redhat.com> References: <20210208135846.3707170-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, 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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Signed-off-by: John Snow Message-Id: <20210201193747.2169670-13-jsnow@redhat.com> [Commit message tweaked] --- scripts/qapi/gen.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index b2bb9d12ff..a0a5df333e 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -290,6 +290,13 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): 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.26.2 From nobody Fri May 17 11:05:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612816419; cv=none; d=zohomail.com; s=zohoarc; b=IH7OPU3woKiupBE1jSTVgEiAEmWDcvd80GP4AKMp0hETJGSM76AO7uZFvgmwt03ElEIT+KdGOMsvU7uVkIFArQzoDrbh2V3W6uByP+NK5HvXEhI+UMvEm5/UosMcxApGHWTHw0thsyHI+XonNCDRnYJanZGmQAfn7SwR+u9Vo6s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612816419; 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=1i+h7+iueBrI5W5I2eFfcNNG5niua3bgXx6OuZp6Y/0=; b=Ym61pCHFN39KXImSjOBxJvnLDQBk6Zm7kVArQb9tHzPHgHscyKeT+yR8myKgAl/FwTywevyWRO1SgLavV9GjYF7MCXckVjMGvR6oi5YWIs/d5mGa4WjHgyGUODEvgIjJPTCMyOe7sCdDIpJS8FniHMb/mcJqy0FlSEyKpcWFHnw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1612816419655460.3051694022555; Mon, 8 Feb 2021 12:33:39 -0800 (PST) Received: from localhost ([::1]:52742 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9DE1-00071T-PV for importer@patchew.org; Mon, 08 Feb 2021 15:33:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51758) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l974K-0005Yl-8w for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:59:13 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:42452) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9742-0001cl-HM for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:59:05 -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-253-Gf-R4oXPMH-bN52P6OViNA-1; Mon, 08 Feb 2021 08:58:51 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 02EA9180A09B; Mon, 8 Feb 2021 13:58:50 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-51.ams2.redhat.com [10.36.115.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A294860938; Mon, 8 Feb 2021 13:58:49 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 8202D113275D; Mon, 8 Feb 2021 14:58:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612792733; 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=1i+h7+iueBrI5W5I2eFfcNNG5niua3bgXx6OuZp6Y/0=; b=HkSwQM3aH6Hu3swbiDJuMf4NuQQg8Y2KJf9+16SF+qceKeaJ0Y4djmimmHoJz1lDRufyw6 qgCpLCW8ZxGUxQMLu2KopVWfFXsoXEFcaZEKIg80djWgjf7m8pP5A2OxX9dUeHdJX8OUXx +viVOXymLPKVmoSJpHGuikLjCjT1+KM= X-MC-Unique: Gf-R4oXPMH-bN52P6OViNA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 13/16] qapi/commands: Simplify command registry generation Date: Mon, 8 Feb 2021 14:58:43 +0100 Message-Id: <20210208135846.3707170-14-armbru@redhat.com> In-Reply-To: <20210208135846.3707170-1-armbru@redhat.com> References: <20210208135846.3707170-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, 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=unavailable 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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" 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 Message-Id: <20210201193747.2169670-14-jsnow@redhat.com> --- 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 4911166339..13a9dcaf89 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -23,7 +23,6 @@ from typing import ( 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 @@ class QAPISchemaGenCommandVisitor(QAPISchemaModularCVis= itor): ''', 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 @@ class QAPISchemaGenCommandVisitor(QAPISchemaModularCV= isitor): 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 @@ void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmd= s); 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.26.2 From nobody Fri May 17 11:05:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612816569; cv=none; d=zohomail.com; s=zohoarc; b=TTpx8GzpJowKTw35iE+jw0j2yKKf9zwUlNcoEL8PhddH2HMFIUdN/RM+sgKyv7kgGRNkHqcD0DNIsba9rSAC10cIpBfSI8YVgxt8hzhyRh03utzAozc3aym9T0D2R0GqnzrOkTgtnxZt8PhH1v1BC7Z6W9oxZ88RqlB4jMeWn1w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612816569; 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=khCllIMP/ACv1T2pzzgNjXzZkeedFtC3A0NdwPR9SaU=; b=kBYnaMQpHauAf4Xh2uKg7jmX1RnfDj2WpvBYUgQpXVI5DEneJ3xN7TabmIXBcUT74dr9MDl/itJVD1RSPUyIbCZMwdM59TnorVwoeEK2TN5xK3K036V4C0DvfxFMbaH/3puNG9q8z22gvgl8rcN+AUGo1B4IYFONFy3b8OGk2WA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 16128165696091011.0327238692744; Mon, 8 Feb 2021 12:36:09 -0800 (PST) Received: from localhost ([::1]:58066 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9DGS-0000rR-B4 for importer@patchew.org; Mon, 08 Feb 2021 15:36:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51808) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l974P-0005aL-GG for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:59:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:43922) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9742-0001bg-O2 for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:59:15 -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-315-6ehSXJclO5C8WiiO50swbQ-1; Mon, 08 Feb 2021 08:58:50 -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 B74C8801965; Mon, 8 Feb 2021 13:58:49 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-51.ams2.redhat.com [10.36.115.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 87F6660C05; Mon, 8 Feb 2021 13:58:49 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 86A5C11326AE; Mon, 8 Feb 2021 14:58:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612792732; 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=khCllIMP/ACv1T2pzzgNjXzZkeedFtC3A0NdwPR9SaU=; b=cDvigjDXCROgJ6w1neL6pXrk3tMMsRvbW674vFHMt9mp5uvyCKaQzABPCX0mjThf9bp9gE PHicEdZiuYoOG1eSGVank3GdrPH5CwfZQQVw6WE+Z5KD9w1thfnUzN2F2XDmMvXSuE+Z3y ijgTrwkLZdTt9GNKQuYYYoV5W2OX4Us= X-MC-Unique: 6ehSXJclO5C8WiiO50swbQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 14/16] qapi/gen: Drop support for QAPIGen without a file name Date: Mon, 8 Feb 2021 14:58:44 +0100 Message-Id: <20210208135846.3707170-15-armbru@redhat.com> In-Reply-To: <20210208135846.3707170-1-armbru@redhat.com> References: <20210208135846.3707170-1-armbru@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=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, 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=unavailable 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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The previous commit removed the only user of QAPIGen(None). Tighten the type hint. Signed-off-by: Markus Armbruster Signed-off-by: John Snow Message-Id: <20210201193747.2169670-15-jsnow@redhat.com> --- 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 a0a5df333e..ac3d3e687e 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -40,7 +40,7 @@ from .source import QAPISourceInfo =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.26.2 From nobody Fri May 17 11:05:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612809576; cv=none; d=zohomail.com; s=zohoarc; b=TvhUKxljP16ZInA0bzhMVfi1k3Uf9qg+0IwwmxA0sjVTAzWohGKMPcWLdZeIBlcuHnVNjJCemTWRi1XZX/eVbE/ZINhghBqp/+5w9+GW4LYoPAQWA7oN6A9dbHnah9BxhbiO85keoym+8Tv3OjldloXdUnpb5JhougwmwN1wYXc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612809576; 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=oy8o2Yg213v5wQfG4LS4hCBKJj0a2TMGUUY09jDMGCA=; b=JP/qSe6fXxUnr9ELh+YsVWSdZ6QfoL6d+29qLfKJLIW3Ci+0oiJe4i2qmHVdIZUQebc3yLftPCm5tHxV2mDN3qcwI85N1hUNLk3WacQ8wJ/4rRCrlKDvJ+26mW2NQd4SfeLkXCvManjMc7obuY16w6ve5VEOEAO2E/EFa8/rLxM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1612809576426496.21345464987496; Mon, 8 Feb 2021 10:39:36 -0800 (PST) Received: from localhost ([::1]:54082 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9BRd-0002yA-OQ for importer@patchew.org; Mon, 08 Feb 2021 13:39:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51838) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l974Q-0005c2-BK for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:59:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:49714) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9743-0001d3-7c for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:59: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-571-fUthpsTeOEqBkhwJUXGWUw-1; Mon, 08 Feb 2021 08:58:52 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 868C985B66D; Mon, 8 Feb 2021 13:58:51 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-51.ams2.redhat.com [10.36.115.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 32FD65D9DC; Mon, 8 Feb 2021 13:58:51 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 8B5881141D22; Mon, 8 Feb 2021 14:58:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612792734; 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=oy8o2Yg213v5wQfG4LS4hCBKJj0a2TMGUUY09jDMGCA=; b=AAo2owxR6Tal0g9FY8eixTKuE+Pvj8oV8CjS6ht1avwB0gJytXUOYDKtL+vnmr2rFVb0QW Ki9aNBv/hpCU7j5iLEH++OGiNoL9L6xgQ/v7G26lTEvTm3N3haI0z7G4WfQURKtlUGlkUt s47kCnf2psfHNPVkJ2ZUZYe8BN+xB3Y= X-MC-Unique: fUthpsTeOEqBkhwJUXGWUw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 15/16] qapi: type 'info' as Optional[QAPISourceInfo] Date: Mon, 8 Feb 2021 14:58:45 +0100 Message-Id: <20210208135846.3707170-16-armbru@redhat.com> In-Reply-To: <20210208135846.3707170-1-armbru@redhat.com> References: <20210208135846.3707170-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, 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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow 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 Message-Id: <20210201193747.2169670-16-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-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 13a9dcaf89..54af519f44 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -296,7 +296,7 @@ void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds) =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 079c666ec6..8c57deb2b8 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -213,7 +213,7 @@ void %(event_emit)s(%(event_enum)s event, QDict *qdict); =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 ac3d3e687e..63549cc8d4 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -325,7 +325,7 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): 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 dbf58c0b91..2bdd626847 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -350,7 +350,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisito= r): =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 568ba35592..22e62df901 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -336,7 +336,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisit= or): =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 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisit= or): =20 def visit_alternate_type(self, name: str, - info: QAPISourceInfo, + info: Optional[QAPISourceInfo], ifcond: List[str], features: List[QAPISchemaFeature], variants: QAPISchemaVariants) -> None: --=20 2.26.2 From nobody Fri May 17 11:05:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612816786; cv=none; d=zohomail.com; s=zohoarc; b=KDKooTITVkpQhOM94Q/ajn0hYwWugSHYGcje0njyZoieeLTNs5H+E6MqWwFRTFKkKaH/Q1o4QBXS6VKcNKNMfXXSHZwSLPJAZ7mp+tGPOb918IAGCSqeaIruhOa5zWGrMqJToX2gk8njZ5Yu6YjiyoGtovmt+fmLJUBjj612+WU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612816786; 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=ufN2FRR7kRW0coIywr3JebCvspZoddE0za12ELhFiNY=; b=SY/P5xkfEX4zBSv/RB05KUdUDcFUXh+HV4lUdYMgW3wAt0YlMKNlmAiVnMEyWbHwAZV1UXvPO9MaPzUWsqOACZdcuMjJXzpGIRCi7bIOlwmJlm+AzHnipbMgZdU9bkIO4YgKbDHhuP6NRxGseun+GuY7+57cjTbRdC9rtyaHI40= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1612816786238575.8340285069837; Mon, 8 Feb 2021 12:39:46 -0800 (PST) Received: from localhost ([::1]:38384 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9DJx-0004mN-41 for importer@patchew.org; Mon, 08 Feb 2021 15:39:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51900) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l974Y-0005fP-9g for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:59:27 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:49586) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l9743-0001d8-Ca for qemu-devel@nongnu.org; Mon, 08 Feb 2021 08:59:22 -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-550-mRrApd3gMr6KeeXiefc_pQ-1; Mon, 08 Feb 2021 08:58:52 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 670A985B66C; Mon, 8 Feb 2021 13:58:51 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-51.ams2.redhat.com [10.36.115.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 354F910016F0; Mon, 8 Feb 2021 13:58:51 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 902051141D66; Mon, 8 Feb 2021 14:58:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612792734; 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=ufN2FRR7kRW0coIywr3JebCvspZoddE0za12ELhFiNY=; b=fQ2rTT7QM8Md+QA2rg2R6+Cn0Sc98D30cl9/UAoxJ18ZvmW43kEKotztHyMv/9TLtYpmBP DrfyooxsqAu3TG3dM5V76ItWaQ2V22Eb8TPD0Y9lLOEQHmFvPPNT7akEQUg+paU5AVswH2 BnGtUeICM2O8EHvjgJKKaPs15xh4LWE= X-MC-Unique: mRrApd3gMr6KeeXiefc_pQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 16/16] qapi: enable strict-optional checks Date: Mon, 8 Feb 2021 14:58:46 +0100 Message-Id: <20210208135846.3707170-17-armbru@redhat.com> In-Reply-To: <20210208135846.3707170-1-armbru@redhat.com> References: <20210208135846.3707170-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.57, 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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow 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 Message-Id: <20210201193747.2169670-17-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-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 74fc6c8215..04bd5db527 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.26.2