From nobody Tue Nov 18 07:46:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608324969; cv=none; d=zohomail.com; s=zohoarc; b=MOkGGDH2IzASd4JsSkBthh0lhwor8rLiMcwEtIf9gnqopJrLEFGRlz2BjgTWXE36Tzin9i2bhclhBS3IRsIoB5uvqH7kL/ISKDt2xarlLSvvfSbOKWQzwtXQZ0RqFW4nWoRDqQ6dKrVe1sYO7NMIz16Kl+YEolVqrFfUQk0sfLg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608324969; 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=iIR5H5b0Fg9hutkcW1H6MLLjU07mQdtHF1VXKSAe6dE=; b=kW3QbVyPTHk2YL5SNPot4Sq8+RkkdzGEQrWuAeonKy6X4ddW6Z0atTqtZH7geMnRfcfDvh0jnVbHTFgZvhMC2aGpD49SpNV6blMBnEJHroKD4gGT8RicfDgcDudveib1c0FfhP4+9BpaUHyJnGaA5xmIkFm51wxOJB3L6ZGEazw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 160832496931394.1964481548207; Fri, 18 Dec 2020 12:56:09 -0800 (PST) Received: from localhost ([::1]:56422 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqMnH-00039q-RL for importer@patchew.org; Fri, 18 Dec 2020 15:56:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55574) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqMlX-0000zW-Hs for qemu-devel@nongnu.org; Fri, 18 Dec 2020 15:54:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:31819) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqMlV-0002uP-2a for qemu-devel@nongnu.org; Fri, 18 Dec 2020 15:54:19 -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-48-g-yBAbAfOViG5myz2VS1sA-1; Fri, 18 Dec 2020 15:54:14 -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 370FF107ACE3 for ; Fri, 18 Dec 2020 20:54:13 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8C8475D9E4; Fri, 18 Dec 2020 20:54:09 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id CDFC31141D30; Fri, 18 Dec 2020 21:54:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608324856; 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=iIR5H5b0Fg9hutkcW1H6MLLjU07mQdtHF1VXKSAe6dE=; b=XkAunY+yh75E+Ql6ZQgF0nsgpAysCSmntBvvG7yB4NeYJmfFAEEiy3Ph87SafsiNRxKeB0 bWpDakk7RR0kMUGMjdh4XJUSO3RCfcxcok+SHAIuPDslztlNopdDwxnK8Dt1xh0otEeOhe bmj2JTNQw9/B1WBI3n0JIeX/S4vi7Mg= X-MC-Unique: g-yBAbAfOViG5myz2VS1sA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH 01/11] qapi/commands: assert arg_type is not None Date: Fri, 18 Dec 2020 21:53:57 +0100 Message-Id: <20201218205407.1326907-2-armbru@redhat.com> In-Reply-To: <20201218205407.1326907-1-armbru@redhat.com> References: <20201218205407.1326907-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_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: marcandre.lureau@redhat.com, jsnow@redhat.com, ehabkost@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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: <20201217015927.197287-2-jsnow@redhat.com> --- 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 Tue Nov 18 07:46:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608325394; cv=none; d=zohomail.com; s=zohoarc; b=L2ABGx5Dtwlxogjfw6BCmOCgRpABxJ3gEPu4opzUTqdUzO/doB/mIXQeqZkS70sjU++PYM+e7l3Z4J3MWOwl1owbH9L2crdSw6tCDDYSnkp0Ac/b/pYOAEyn7cVdrqQxWE3OZIXCvXhcZU7QQLdWITXZAEIrKw7oP0oC4cIC2S4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608325394; 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=MBBddjzuB3KUrXqz2iYd9pAZwPYo6wxpVxICzKsyO2c=; b=FRJ9NKvEaDNaHKZiPcneu5fN3DM3fVbD4XEV6biDjo+TZMLTK/kbXUWRDiUH0NlgDE09Ha6sbHc9VvnpNdRnj5mjEvJYkxRccuTquFYee+QvFNnV6d058XqlFBXQyd11DOfoXqYCMJjkZSybRDClm+gRisv9ana35aiyVDtaPfE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1608325394195487.39593007404267; Fri, 18 Dec 2020 13:03:14 -0800 (PST) Received: from localhost ([::1]:49936 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqMu9-0004FV-60 for importer@patchew.org; Fri, 18 Dec 2020 16:03:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55652) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqMld-00015F-VV for qemu-devel@nongnu.org; Fri, 18 Dec 2020 15:54:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:48432) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqMlU-0002tU-E9 for qemu-devel@nongnu.org; Fri, 18 Dec 2020 15:54:25 -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-172-JLgZfDJhPQiC1rxGpAR9dQ-1; Fri, 18 Dec 2020 15:54:13 -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 D2C0C800D62 for ; Fri, 18 Dec 2020 20:54:12 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 80BF15D769; Fri, 18 Dec 2020 20:54:09 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id D1373114200A; Fri, 18 Dec 2020 21:54:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608324855; 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=MBBddjzuB3KUrXqz2iYd9pAZwPYo6wxpVxICzKsyO2c=; b=OLZr0JSYl61lQKAh4hTBtCB18eCra9kNOPmnAF2crffjTF7xuPL9wdUPQR8d9dHB+PEZ4c yOAIUg3H2LVvw7x8xxbTzHb6ETqyXCziMJ9kQKMqZCNz+Ja4RI65rfMlXCnkv+Ra1P7OC2 wtyFQt74HZcg3WaDFrMF28OvXZ1y7Zk= X-MC-Unique: JLgZfDJhPQiC1rxGpAR9dQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH 02/11] qapi/events: fix visit_event typing Date: Fri, 18 Dec 2020 21:53:58 +0100 Message-Id: <20201218205407.1326907-3-armbru@redhat.com> In-Reply-To: <20201218205407.1326907-1-armbru@redhat.com> References: <20201218205407.1326907-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=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: marcandre.lureau@redhat.com, jsnow@redhat.com, ehabkost@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: John Snow Actually, the arg_type can indeed be Optional. Signed-off-by: John Snow Message-Id: <20201217015927.197287-3-jsnow@redhat.com> --- 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 Tue Nov 18 07:46:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608325111; cv=none; d=zohomail.com; s=zohoarc; b=kPZ/2eVzBj0nW/52JJ+BKl5iEBDPUm+sly+HB96qwY1OSfu/T6C//UBmI8Q6S8nj7K7pYfuhFnvqLBaWK3H02HRWGteGx5b2421G+uIxbI1Ws7iXK+anUipD5RR22uQNXhWuAw3TXu7MkNBacec5DwwhgF5XAlCsJ7OtttDrZPA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608325111; 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=76QBaBaYS27/bxb6F/DaBJM4qQmodtz9/KwoLqBFgPI=; b=NYZtck5YvJqb5heevvnZVvLB1qk6s9wN982YBM08xbaqI8PdOSF4bvUTM0Jxmd4ed7z3Ma+HCHm+iqqtBq7GDd3lFgTmPi59OvZEW0QbmQrjhJLlp8WrZKCol0o0yPD5IEyoatcuNHNOpiEpB96OH27Gut48SW5s4LxhIeIWgYQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1608325111829730.4334918607758; Fri, 18 Dec 2020 12:58:31 -0800 (PST) Received: from localhost ([::1]:35852 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqMpa-0006Od-HO for importer@patchew.org; Fri, 18 Dec 2020 15:58:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55578) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqMlX-0000zk-N5 for qemu-devel@nongnu.org; Fri, 18 Dec 2020 15:54:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:41586) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqMlU-0002ta-Fn for qemu-devel@nongnu.org; Fri, 18 Dec 2020 15:54:19 -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-184-e41qu8LENp-eWQJJLQlGvA-1; Fri, 18 Dec 2020 15:54:14 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3BB68192AB71 for ; Fri, 18 Dec 2020 20:54:13 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8C8EB60C15; Fri, 18 Dec 2020 20:54:09 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id D4771114200B; Fri, 18 Dec 2020 21:54:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608324855; 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=76QBaBaYS27/bxb6F/DaBJM4qQmodtz9/KwoLqBFgPI=; b=Ct5XMkditVoXr6w2rDfoI3vUHJR1HiavE1ExUCAXbZuZTXL1c/N6FIuiBK14VGINJKBq49 pimb7i49DXQLChVnrrFky28Uj4nzZKwZzPDH3bMKL0w+d5IAY9x4kdVWq1lZkydknkA+27 vPZsWHvi2TnSw/3TYgM+YPEuua6lOcc= X-MC-Unique: e41qu8LENp-eWQJJLQlGvA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH 03/11] qapi/main: handle theoretical None-return from re.match() Date: Fri, 18 Dec 2020 21:53:59 +0100 Message-Id: <20201218205407.1326907-4-armbru@redhat.com> In-Reply-To: <20201218205407.1326907-1-armbru@redhat.com> References: <20201218205407.1326907-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_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: marcandre.lureau@redhat.com, jsnow@redhat.com, ehabkost@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: John Snow Mypy cannot understand that this match can never be None, so help it along. Signed-off-by: John Snow Message-Id: <20201217015927.197287-4-jsnow@redhat.com> --- 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 Tue Nov 18 07:46:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608324949; cv=none; d=zohomail.com; s=zohoarc; b=hye8mdG5uMMCWmX2Sh7RFbJS5behGgoUFUGLZnysxqzdFO9tpBh1QElqaBGIUXPvyfhBW9vGgHCFn3yN0zVbK+LU8K3aZ7vLGMNPf6wh3u6hNgnIHdt9i2X6rifMuWn0GT9IbOcVkSkRTtZagntnYS929bTvOOYuE3ydm25VmAs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608324949; 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=f6a4QGjVjs5SeyjbcDfloJloXKqUKmBW0QyReCwbziA=; b=n0XCeJ8+QITuLg89iwtJua9VkqRo+nIQs0WAHku+EBYju8ivjLmye1YY477G0oY9l2iHgbhWXFekYngT/8Aad43ZknhZwlvzU0ghBZFxf/FrCgJy7xMlspR3sJOy60s7R6iOGV61XAMwyXV6DdyqHCf7PgLFiLLaKNxfLuhNaRg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1608324949790384.1475523656926; Fri, 18 Dec 2020 12:55:49 -0800 (PST) Received: from localhost ([::1]:55506 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqMmy-0002lh-LA for importer@patchew.org; Fri, 18 Dec 2020 15:55:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55572) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqMlX-0000zR-Eh for qemu-devel@nongnu.org; Fri, 18 Dec 2020 15:54:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:50117) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqMlU-0002u7-SU for qemu-devel@nongnu.org; Fri, 18 Dec 2020 15:54:19 -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-490-xz-HFr63Oe2SdcG3mL37Mw-1; Fri, 18 Dec 2020 15:54:14 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 83C5E10054FF for ; Fri, 18 Dec 2020 20:54:13 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8C73E299B4; Fri, 18 Dec 2020 20:54:09 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id D793211275D0; Fri, 18 Dec 2020 21:54:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608324856; 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=f6a4QGjVjs5SeyjbcDfloJloXKqUKmBW0QyReCwbziA=; b=fFP9cbEl4ZLiJzoCzo4SJ9o4lYSaxU/5jH/OILzdkG7jUKLMBZaVkT+EnGNDd2qgyPC3e4 Q7a7gze2gz0arj2VIKDmNfFPH+A+U5h4dz7w+B5C/9T9j7nJX/548QYP7o4UC8hwljQ9XR r3vZp7UoJgyNn2Qxz0pnU8ISi/sfZ/I= X-MC-Unique: xz-HFr63Oe2SdcG3mL37Mw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH 04/11] qapi/gen: assert that _start_if is not None in _wrap_ifcond Date: Fri, 18 Dec 2020 21:54:00 +0100 Message-Id: <20201218205407.1326907-5-armbru@redhat.com> In-Reply-To: <20201218205407.1326907-1-armbru@redhat.com> References: <20201218205407.1326907-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_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: marcandre.lureau@redhat.com, jsnow@redhat.com, ehabkost@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: John Snow We already assert this in end_if, but that's opaque to mypy. Do it in _wrap_ifcond instead. Same effect at runtime, but mypy can now infer the type in _wrap_ifcond's body. Signed-off-by: John Snow Message-Id: <20201217015927.197287-5-jsnow@redhat.com> --- scripts/qapi/gen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index b40f18eee3..a6dc991b1d 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -130,11 +130,11 @@ 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 =20 def _wrap_ifcond(self) -> None: + assert self._start_if self._body =3D _wrap_ifcond(self._start_if[0], self._start_if[1], self._body) self._preamble =3D _wrap_ifcond(self._start_if[0], --=20 2.26.2 From nobody Tue Nov 18 07:46:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608325468; cv=none; d=zohomail.com; s=zohoarc; b=AHjvuBUidHcYMwRA4eOLrHQliI3gZJvQSAD3yDJzKPd5USJBlApKs7ToaxOIbAXSp9eZmMk9vW+pXb91wsnf4NnGqS+aEZR4RNLvytWSbIcXOwuOMF/uTr0DOJNEY9EWItPABpmAffu2tnzEjwc6n9PrUkNewCD98VqrFxwvsOc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608325468; 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=lIeubXd7XckMMO0W7jjTE150rCoRB2QVIXzx8IVvklg=; b=EoUjnMyh465mv+Jgikyt4oP2y4OzA2SoGiHig+XJw85aJbq18QACi5aMkQTG4CHiwnHZgjtfizy+z+ub8fdgtT4gk8vgRdFJU2RgNGCKxBfgflFCeJR5ybOESxA7arS2lC/BiXz/R4n3hSR7SS1zyvpUET9prTs544lfxfuvSBw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1608325468581445.28452283914805; Fri, 18 Dec 2020 13:04:28 -0800 (PST) Received: from localhost ([::1]:53022 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqMvL-0005YM-H0 for importer@patchew.org; Fri, 18 Dec 2020 16:04:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55654) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqMlf-00017R-W4 for qemu-devel@nongnu.org; Fri, 18 Dec 2020 15:54:29 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:56718) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqMlZ-0002wB-Ca for qemu-devel@nongnu.org; Fri, 18 Dec 2020 15:54:27 -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-138-tjDrsMrEP-msCwct5XDsWQ-1; Fri, 18 Dec 2020 15:54:18 -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 9F2F9801817 for ; Fri, 18 Dec 2020 20:54:17 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5D926614FF; Fri, 18 Dec 2020 20:54:14 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id DADBE11275D7; Fri, 18 Dec 2020 21:54:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608324860; 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=lIeubXd7XckMMO0W7jjTE150rCoRB2QVIXzx8IVvklg=; b=T2Tw9L/4/J4jxfn+FhyH2LA4unqdQ2Gi3SIwKnYJytZcZB5iMVnQy3tkdkwYFRfi2PkQqR qfRgI3/cE9EXFLu5igQLVVqQuSJew0KWNPnwySTIrt/F0pvuiZp6lK2JqGHLGHqWYifAbp IpPR++XxgwbzkLksZqH4ltLSvnr47lA= X-MC-Unique: tjDrsMrEP-msCwct5XDsWQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH 05/11] qapi/gen: use './builtin' for the built-in module name Date: Fri, 18 Dec 2020 21:54:01 +0100 Message-Id: <20201218205407.1326907-6-armbru@redhat.com> In-Reply-To: <20201218205407.1326907-1-armbru@redhat.com> References: <20201218205407.1326907-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_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: marcandre.lureau@redhat.com, jsnow@redhat.com, ehabkost@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: John Snow Use this in preference to 'None', which helps remove some edge cases in the typing. Signed-off-by: John Snow Message-Id: <20201217015927.197287-6-jsnow@redhat.com> --- scripts/qapi/gen.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index a6dc991b1d..476d0adac4 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -245,23 +245,23 @@ 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 _is_user_module(name: Optional[str]) -> bool: - return bool(name and not name.startswith('./')) + def _is_user_module(name: str) -> bool: + return not name.startswith('./') =20 @staticmethod - def _is_builtin_module(name: Optional[str]) -> bool: - return not name + def _is_builtin_module(name: str) -> bool: + return name =3D=3D './builtin' =20 - def _module_dirname(self, name: Optional[str]) -> str: + def _module_dirname(self, name: str) -> str: if self._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 self._is_builtin_module(name) else self._prefix if self._is_user_module(name): basename =3D os.path.basename(name) @@ -269,15 +269,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 name.startswith('./') + 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) @@ -290,8 +290,8 @@ 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: - self._add_module(name and './' + name, blurb) + def _add_system_module(self, name: str, blurb: str) -> None: + self._add_module('./' + name, blurb) =20 def write(self, output_dir: str, opt_builtins: bool =3D False) -> None: for name in self._module: @@ -310,7 +310,7 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): def visit_module(self, name: Optional[str]) -> None: if name is None: if self._builtin_blurb: - self._add_system_module(None, self._builtin_blurb) + self._add_system_module('builtin', self._builtin_blurb) self._begin_system_module(name) else: # The built-in module has not been created. No code may --=20 2.26.2 From nobody Tue Nov 18 07:46:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608325098; cv=none; d=zohomail.com; s=zohoarc; b=lltfeUlklhJDjpYzCnzDT5ADW+i41x4/Iho8RoZnSF4R9hNydTbucT/4qNRF2jwwZU5tQGqS2ODHgEVzAQwbIfn7+KWGredOO+ubYRI9uFSsa6rzBeQBd7jxjvURMKWpCvK9BcdzJXmWWHK1wXaFeLkZsClg5uKJXj6OwGTjwVQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608325098; 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=sYazpc3XYxcQWKauYYN3lkLQYH+gsX+5rD5UqYJiuQc=; b=Fa67WVRZIdJLWzk/LNjOV6LdH3TEaZ1dqLbgsq/IbiQkeLi5ncvr8b3bdM2ohsuMhmYu2g9p/rF6dr2QrVvmp8Nu88r1DEn8qcBSrggxaqmk8NtDf5UVtna+hZ2lkh3Gtckdgwh+kWJLrxmkoEcf1lhY3G7Ha+/tIb9k+fdyK6k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1608325098592133.1364519883415; Fri, 18 Dec 2020 12:58:18 -0800 (PST) Received: from localhost ([::1]:34690 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqMpM-0005tb-Q5 for importer@patchew.org; Fri, 18 Dec 2020 15:58:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55604) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqMlY-00010q-Nt for qemu-devel@nongnu.org; Fri, 18 Dec 2020 15:54:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40689) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqMlW-0002ud-Cu for qemu-devel@nongnu.org; Fri, 18 Dec 2020 15:54:20 -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-445-8jQoGhR1Poyd2bcT73M40w-1; Fri, 18 Dec 2020 15:54:15 -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 D7CE9800D62 for ; Fri, 18 Dec 2020 20:54:14 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A41AD10013C0; Fri, 18 Dec 2020 20:54:14 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id DE2C811275DA; Fri, 18 Dec 2020 21:54:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608324857; 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=sYazpc3XYxcQWKauYYN3lkLQYH+gsX+5rD5UqYJiuQc=; b=ctEQ4D7QImqmDKT8CyUfOyiAAL3jPQpOybOxXHVwnunkDrZTDsyBHyohdNNrutdp33Wfgj oR+U+xGfnoCxckjrlA+xlWoE585ONkuY2fY9ZJ1G8zzeCNXdntGx1NFn1F3MQsS7X9vZCv F37jMl/f1IjU41PWXQ5v5pVx1rQwr/k= X-MC-Unique: 8jQoGhR1Poyd2bcT73M40w-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH 06/11] qapi/gen: write _genc/_genh access shims Date: Fri, 18 Dec 2020 21:54:02 +0100 Message-Id: <20201218205407.1326907-7-armbru@redhat.com> In-Reply-To: <20201218205407.1326907-1-armbru@redhat.com> References: <20201218205407.1326907-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: marcandre.lureau@redhat.com, jsnow@redhat.com, ehabkost@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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: <20201217015927.197287-9-jsnow@redhat.com> --- 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 476d0adac4..12ea98fb61 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -243,11 +243,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 _is_user_module(name: str) -> bool: return not name.startswith('./') @@ -282,7 +291,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 _add_user_module(self, name: str, blurb: str) -> None: assert self._is_user_module(name) @@ -315,8 +324,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: self._add_user_module(name, self._user_blurb) self._begin_user_module(name) --=20 2.26.2 From nobody Tue Nov 18 07:46:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608325282; cv=none; d=zohomail.com; s=zohoarc; b=iyBuMELeFoWgpLoUQADGh4r7s8vlWLM1n00WDOrlbPSK13xD0KXDqbffjWHxmzdYBDo0C0mKIYtK34recO2MalKIvIiUnUSOj3LFSEPBE8lq+zyFzdeuFcrEYqNK0da8H0RQyyOFtGJ444JZ1tgFLrlE7RJUbfUsZtkDRoKB0FA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608325282; 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=eZIU116KGIzE6OS3ze4xrO/bxNifGBXEoDCMorHNbsg=; b=ORqQ7O8VNnNED+f63EuT0PFhg2fOC05hDPkqHkc4JxxKKe6cxl6qCxqLkkb1WqWmVl3FpyLLOlHzJlFWrHld9eksOkhccbu8DCpNTQVfWCLjvmjqzEKappvJ9l5gRyEfpP3EZ0x408IMwnOQ3kjiWZ68dw/N26b6ed0QpSIkuho= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1608325282190354.70788760647133; Fri, 18 Dec 2020 13:01:22 -0800 (PST) Received: from localhost ([::1]:42816 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqMsJ-0000tR-3f for importer@patchew.org; Fri, 18 Dec 2020 16:01:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55610) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqMlY-000113-V6 for qemu-devel@nongnu.org; Fri, 18 Dec 2020 15:54:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:20410) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqMlW-0002ug-FY for qemu-devel@nongnu.org; Fri, 18 Dec 2020 15:54:20 -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-495-R9EeA7IJO0ywrzJydbcyAw-1; Fri, 18 Dec 2020 15:54:15 -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 D8B24107ACF7 for ; Fri, 18 Dec 2020 20:54:14 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A98235D9D7; Fri, 18 Dec 2020 20:54:14 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id E16DF11275DE; Fri, 18 Dec 2020 21:54:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608324857; 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=eZIU116KGIzE6OS3ze4xrO/bxNifGBXEoDCMorHNbsg=; b=VTEYE9DtXqtTkwvDJlVu59mi5r+kuGB3neNQ2bq7nfuFoE+7Yym9TaxEpngzS3D7tLKZln ha0EjyY/0GA8uzI007wpva5aWI3vsAIQ4WW7xVNWCKXSGh5FSgKrt3SXxMMEL+GxohU4az ezx4rd1HmcajxQajjDxvzN/XW7wxJ7o= X-MC-Unique: R9EeA7IJO0ywrzJydbcyAw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH 07/11] qapi/gen: Replace ._begin_system_module() Date: Fri, 18 Dec 2020 21:54:03 +0100 Message-Id: <20201218205407.1326907-8-armbru@redhat.com> In-Reply-To: <20201218205407.1326907-1-armbru@redhat.com> References: <20201218205407.1326907-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: marcandre.lureau@redhat.com, jsnow@redhat.com, ehabkost@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" QAPISchemaModularCVisitor._begin_system_module() is actually just for the builtin module. Rename it to ._begin_builtin_module() and drop its useless @name parameter. Signed-off-by: Markus Armbruster --- scripts/qapi/gen.py | 4 ++-- scripts/qapi/types.py | 2 +- scripts/qapi/visit.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index 12ea98fb61..67635b6a26 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -310,7 +310,7 @@ 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: @@ -320,7 +320,7 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): if name is None: if self._builtin_blurb: self._add_system_module('builtin', self._builtin_blurb) - self._begin_system_module(name) + self._begin_builtin_module() else: # The built-in module has not been created. No code may # be generated. 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 Tue Nov 18 07:46:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608324998; cv=none; d=zohomail.com; s=zohoarc; b=J4CBgvI22K2Y8tkJKijV1U1lZPHah3X4A+uF1GE9Li/6IpIMC5y8N+5/sju5n0q/3weuuFvv1E5XHWHQqNOkiIkUWC88BUaYU3l2fGy9v6fFx/EByC9p6QDC/abu1RADoclyVIb6qHvXG6NAAQd42CUpn/joBPNpyzd5+gz2hxQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608324998; 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=zfjjjpZnwU913JbXpk4wFG9lzOoHwzDy+tJejANj9Xw=; b=j3QCrnQhGP+qp8O/TpuhZuAmRuwSn9zGveFajS/2hcGnh7RWC+aKD32fxRHVnxV569EO8SsRTghsllXefk4IB5Y9ADKfb07l5efi2Pa2Nv40bLqK59fdRRBHSI6uZEJB6AhNUM+s1VAccLeWeUOyIgkBUevkswYtAbrRJTP+clI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 160832499845518.322305382096147; Fri, 18 Dec 2020 12:56:38 -0800 (PST) Received: from localhost ([::1]:58474 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqMnl-00040q-DT for importer@patchew.org; Fri, 18 Dec 2020 15:56:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55622) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqMlZ-00011Y-BV for qemu-devel@nongnu.org; Fri, 18 Dec 2020 15:54:21 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:59396) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqMlW-0002uk-Jx for qemu-devel@nongnu.org; Fri, 18 Dec 2020 15:54:21 -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-436-7-h_OSoENvubthqUmdNqkQ-1; Fri, 18 Dec 2020 15:54:16 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 47182801817 for ; Fri, 18 Dec 2020 20:54:15 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 11139299A7; Fri, 18 Dec 2020 20:54:14 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id E4A9311275E4; Fri, 18 Dec 2020 21:54:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608324857; 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=zfjjjpZnwU913JbXpk4wFG9lzOoHwzDy+tJejANj9Xw=; b=cFM+jP3HmgRXTvvgMxfIxwEEuH6hklWmApr+Z2q902ts7aJf1DmBK1bnZQapD4kc/Ix/UG /Xg2LuwW/YD5a9DBV0Ys8yps6Bnsq8Vz+R4AmyP4GUNGt2WkJav4liIlpZmavSBJxuW/OZ MJkAEWu5IOcW9iCijvjsXhqhQ/VcU18= X-MC-Unique: 7-h_OSoENvubthqUmdNqkQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH 08/11] qapi/gen: Expose a single module name space Date: Fri, 18 Dec 2020 21:54:04 +0100 Message-Id: <20201218205407.1326907-9-armbru@redhat.com> In-Reply-To: <20201218205407.1326907-1-armbru@redhat.com> References: <20201218205407.1326907-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_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: marcandre.lureau@redhat.com, jsnow@redhat.com, ehabkost@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" QAPISchemaModularCVisitor attempts to encapsulate the way it splits the module name space between user modules (name can't start with './') and system modules (name is None or starts with './') by providing separate ._add_user_module() and ._add_system_module(), where the latter prepends './' to names other than None. Not worthwhile. Dumb down to a single ._add_module(), and have the callers take care of giving system modules names starting with './'. Signed-off-by: Markus Armbruster --- scripts/qapi/commands.py | 2 +- scripts/qapi/events.py | 2 +- scripts/qapi/gen.py | 16 +++++----------- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index 71744f48a3..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 9851653b9d..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 67635b6a26..d9f8bac9aa 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -287,21 +287,15 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): self._module_basename(what, name)) =20 def _add_module(self, name: str, blurb: str) -> None: + if self._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._current_module =3D name =20 - def _add_user_module(self, name: str, blurb: str) -> None: - assert self._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: - self._add_module('./' + name, blurb) - 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: @@ -319,14 +313,14 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): def visit_module(self, name: Optional[str]) -> None: if name is None: if self._builtin_blurb: - self._add_system_module('builtin', self._builtin_blurb) + self._add_module('./builtin', self._builtin_blurb) self._begin_builtin_module() else: # The built-in module has not been created. No code may # be generated. self._current_module =3D None else: - 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 Tue Nov 18 07:46:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608324951; cv=none; d=zohomail.com; s=zohoarc; b=aJ2j9wusVXFeCrKy+DCcby4+Xr2t7U7XvDMqJftpZvbMGfH06dZ0zMLbD5OTpk2as10kh6V0a/hcWWlx3WG717cM1rCx2kZq15TvpTYwYzpOk9JenPTT8h/wqlZgbifGHoXrKq4UVK17/CQfbTewBwsMnwOkrYDeMc00j/1jVG8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608324951; 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=kiu34yZPMbDq9A//PdWwlmecaLa8JCyoCuAnIWCd9jQ=; b=cnXTFIPmtvRTojRWznaVGlFGpKDxFxd3hiR+c2eCPfDiljJWeLe28DewdO7qjRHunE9Kt5azwa1NyXMDV77f4jJDzpLWN0Fg1E9nCoQisj+94S4ig4rtNEFSulGhGhK2Ln05dGRpSQlpwZ3bTUDuuqDHDtm0113Nmjx7QfdGh6o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1608324951149597.7823123510614; Fri, 18 Dec 2020 12:55:51 -0800 (PST) Received: from localhost ([::1]:55622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqMn0-0002os-0q for importer@patchew.org; Fri, 18 Dec 2020 15:55:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55648) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqMlb-000141-Gd for qemu-devel@nongnu.org; Fri, 18 Dec 2020 15:54:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:26690) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqMlZ-0002wE-Fr for qemu-devel@nongnu.org; Fri, 18 Dec 2020 15:54:23 -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-285-VxNn6ZUrMMmX4CmysaYe3A-1; Fri, 18 Dec 2020 15:54:19 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5E7EE10054FF for ; Fri, 18 Dec 2020 20:54:18 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B262D5C233; Fri, 18 Dec 2020 20:54:14 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id E7ECA11275EC; Fri, 18 Dec 2020 21:54:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608324860; 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=kiu34yZPMbDq9A//PdWwlmecaLa8JCyoCuAnIWCd9jQ=; b=BA3uwx5Y5a22cNEJuKT9ZfLcFOL5OH5JFDzTzrTOh0WwQFYxKgORN6N3+HuDoEJQTK9mpn D3O6W4Nc/3WTrTO6B4Acmvm9YutacQtwCKTdYU1kGab1LTs9baZwx7HncQ2+SEt9DCb7Ig ioGxoHD6sxLKatgPtP3bcdWJ/goiprY= X-MC-Unique: VxNn6ZUrMMmX4CmysaYe3A-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH 09/11] qapi/gen: Support for switching to another module temporarily Date: Fri, 18 Dec 2020 21:54:05 +0100 Message-Id: <20201218205407.1326907-10-armbru@redhat.com> In-Reply-To: <20201218205407.1326907-1-armbru@redhat.com> References: <20201218205407.1326907-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: marcandre.lureau@redhat.com, jsnow@redhat.com, ehabkost@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster --- scripts/qapi/gen.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index d9f8bac9aa..cb00229f5d 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -15,6 +15,7 @@ from contextlib import contextmanager import os import re from typing import ( + ContextManager, Dict, Iterator, List, @@ -296,6 +297,13 @@ class QAPISchemaModularCVisitor(QAPISchemaVisitor): self._module[name] =3D (genc, genh) self._current_module =3D name =20 + @contextmanager + def _temp_module(self, name: str) -> ContextManager[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 self._is_builtin_module(name) and not opt_builtins: --=20 2.26.2 From nobody Tue Nov 18 07:46:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608325133; cv=none; d=zohomail.com; s=zohoarc; b=RdEYbRCLRJEZ2aXssBa1JuUJQKnL9aoe4N5Y0UmvKxP5j9ImXr7asw7dhlIE0WKTYd7UJZwU3V3cjFsVLDlg7mteksKkYVWLZ+dU4lexkdzfG0oguNQ3NWBh8UHbMBFg4kaAOWSkZeLIZ3wp55cszPnOJ80wa973T+bYQ/0MU6k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608325133; 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=fNy72KJQm8NtDgfkUBo9YKJjmL7JjBTXL1LMq0uQRv8=; b=Tiu2mwFzjnwWcOIOAH8J/kMgWhL+IifIYCepQtqwGiaQXryAcb/OiIcwQVpNx695lyTan9t7d/rAwa3KoKlemhWAx+STz6M6RtH4R9RRi60Il+/+xoaFXMklZAT3I0YKaeb9jEV8vZPOsWtKADZVECVFcSXVUiDXk6nucXk3s3s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1608325133059844.3017997525974; Fri, 18 Dec 2020 12:58:53 -0800 (PST) Received: from localhost ([::1]:38042 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqMpv-0007IX-Sr for importer@patchew.org; Fri, 18 Dec 2020 15:58:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55732) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqMm7-0001fr-4n for qemu-devel@nongnu.org; Fri, 18 Dec 2020 15:54:55 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:50862) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqMm4-00035X-E9 for qemu-devel@nongnu.org; Fri, 18 Dec 2020 15:54: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-499-e48J-g-QO-eBp33GiNOWBg-1; Fri, 18 Dec 2020 15:54:16 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1C47A801AA9 for ; Fri, 18 Dec 2020 20:54:15 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B70542999F; Fri, 18 Dec 2020 20:54:14 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id EB2D411275ED; Fri, 18 Dec 2020 21:54:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608324890; 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=fNy72KJQm8NtDgfkUBo9YKJjmL7JjBTXL1LMq0uQRv8=; b=Mw6fv457fFcWdxKyM3yyLw3o5HrJetMbx7IGE6kzuRTghgI0Oa7H0YBXsBECHFyBZiI4qN 96lNer5/IZXdGQ0yD46uLYdsDeDEBc3Aut9HCcM6kFx3KXpr04A+uqIISrXbh+9jHwCPEM fu8ytJmen9r7PmDdn8CP/xzS7xiHX5Y= X-MC-Unique: e48J-g-QO-eBp33GiNOWBg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH 10/11] qapi/commands: Simplify command registry generation Date: Fri, 18 Dec 2020 21:54:06 +0100 Message-Id: <20201218205407.1326907-11-armbru@redhat.com> In-Reply-To: <20201218205407.1326907-1-armbru@redhat.com> References: <20201218205407.1326907-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: marcandre.lureau@redhat.com, jsnow@redhat.com, ehabkost@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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 --- 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..396485cc1a 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) -> 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 Tue Nov 18 07:46:13 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608325387; cv=none; d=zohomail.com; s=zohoarc; b=gmPuxmtx6kZbrXS665u0q4EW5IXPBIN9Zbt6LzCNRORUoVJ5RKJNpG2k6Z0vy3PeV9T0Di5Ogw9E9gIl81fitAUg5+9R3WjAKbDyqhc5MNgve43T2/NczMPwPVAWP5240+1VEamNz202SErL3Snq/N1Z3g+Rs6O6aTpLm9UxRCI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608325387; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6/CuaJC7XFULyrISro1XcEU0d4RDqipklc12MycemEM=; b=BB8kLKOUeCGqgcwb+EhAATx+4tfAMYnh1INb1x57o22P4yQHsI6ZVrcarGXyQGHxKx5GVDacMDeOw+CX38ZmTpAE8nGNdHxzPqnaCsToyWMBaz1H9xmtNoL/2eGRGQFtuvJax5poriNBPhCeo4YNH/bh38UtZPKeeIn1jDxpAnY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1608325387548901.7406628180411; Fri, 18 Dec 2020 13:03:07 -0800 (PST) Received: from localhost ([::1]:49466 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqMu2-00043f-Ec for importer@patchew.org; Fri, 18 Dec 2020 16:03:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55634) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqMla-00012R-1w for qemu-devel@nongnu.org; Fri, 18 Dec 2020 15:54:22 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:44675) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqMlX-0002uw-6t for qemu-devel@nongnu.org; Fri, 18 Dec 2020 15:54:21 -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-7-JR4dTSJbO7irTv9BjlOM1Q-1; Fri, 18 Dec 2020 15:54:16 -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 286C610051AA for ; Fri, 18 Dec 2020 20:54:15 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ED9DC60C15; Fri, 18 Dec 2020 20:54:14 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id EE85511275F3; Fri, 18 Dec 2020 21:54:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608324858; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6/CuaJC7XFULyrISro1XcEU0d4RDqipklc12MycemEM=; b=ddK1AYTvuZqnASIgqcqtCUXvknoBP0RJOIdebxKXyZ/fibL0VhM94lbBxqciu06oN3ZuKv mAuXadPYbwqzlrWlLu1ZTYErTo7pdgYXX7To0H2kn7sJ1/Fgvz8FSrc2Tp225kyH7RrwyR 4EsEL43vmd7cT+kFC3WRxDy9oavOE6E= X-MC-Unique: JR4dTSJbO7irTv9BjlOM1Q-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH 11/11] qapi/gen: Drop support for QAPIGen without a file name Date: Fri, 18 Dec 2020 21:54:07 +0100 Message-Id: <20201218205407.1326907-12-armbru@redhat.com> In-Reply-To: <20201218205407.1326907-1-armbru@redhat.com> References: <20201218205407.1326907-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: marcandre.lureau@redhat.com, jsnow@redhat.com, ehabkost@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The previous commit removed the only user of QAPIGen(None). Tighten the type hint. Signed-off-by: Markus Armbruster --- scripts/qapi/gen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index cb00229f5d..8716689450 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -37,7 +37,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 '' --=20 2.26.2