From patchwork Tue Jan 19 18:02:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 1428796 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=e6JyKjte; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DKy6Q5NWQz9sSs for ; Wed, 20 Jan 2021 05:36:30 +1100 (AEDT) Received: from localhost ([::1]:34502 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1vrg-00036f-Je for incoming@patchwork.ozlabs.org; Tue, 19 Jan 2021 13:36:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42510) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1vLQ-0007fG-Pd for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:53388) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l1vLM-0005Pi-VB for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611079383; 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=IZpWSM54xsimG0B6tYdsDuXcPSLAIK/STHFzgm6mKZU=; b=e6JyKjteMxVAFYeRBjOHAKgz+jwrmNV61fnOYvvqUFPaodJ8BLrhnZJVBHYSTtQFpgIyNq ibgbfB2k1SQ46CBbiu0pf1HiD46wVnVR3kqKJkNhk3+78zDLNq6R8fvd2IxRvenfMmcvSf k+tH44lPXurr8zYx9YiX8l4gCGzdkUo= 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-487-gGxsc5ZlM8q26Jc8P7P6Tg-1; Tue, 19 Jan 2021 13:03:01 -0500 X-MC-Unique: gGxsc5ZlM8q26Jc8P7P6Tg-1 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 437E7180A094 for ; Tue, 19 Jan 2021 18:02:50 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-151.rdu2.redhat.com [10.10.120.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C6145D9DD; Tue, 19 Jan 2021 18:02:46 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v3 01/17] qapi/commands: assert arg_type is not None Date: Tue, 19 Jan 2021 13:02:26 -0500 Message-Id: <20210119180242.1570753-2-jsnow@redhat.com> In-Reply-To: <20210119180242.1570753-1-jsnow@redhat.com> References: <20210119180242.1570753-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.195, 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: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- scripts/qapi/commands.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index 50978090b44..71744f48a35 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -126,6 +126,9 @@ def gen_marshal(name: str, boxed: bool, ret_type: Optional[QAPISchemaType]) -> str: have_args = boxed or (arg_type and not arg_type.is_empty()) + if have_args: + assert arg_type is not None + arg_type_c_name = arg_type.c_name() ret = mcgen(''' @@ -147,7 +150,7 @@ def gen_marshal(name: str, ret += mcgen(''' %(c_name)s arg = {0}; ''', - c_name=arg_type.c_name()) + c_name=arg_type_c_name) ret += mcgen(''' @@ -163,7 +166,7 @@ def gen_marshal(name: str, ok = visit_check_struct(v, errp); } ''', - c_arg_type=arg_type.c_name()) + c_arg_type=arg_type_c_name) else: ret += mcgen(''' ok = visit_check_struct(v, errp); @@ -193,7 +196,7 @@ def gen_marshal(name: str, ret += mcgen(''' visit_type_%(c_arg_type)s_members(v, &arg, NULL); ''', - c_arg_type=arg_type.c_name()) + c_arg_type=arg_type_c_name) ret += mcgen(''' visit_end_struct(v, NULL); From patchwork Tue Jan 19 18:02:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 1428803 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=KjLKoQNQ; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DKyNp1Gn6z9s24 for ; Wed, 20 Jan 2021 05:48:58 +1100 (AEDT) Received: from localhost ([::1]:49272 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1w3k-0001ZW-1f for incoming@patchwork.ozlabs.org; Tue, 19 Jan 2021 13:48:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42630) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1vLW-0007kY-3k for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:14 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:36648) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l1vLT-0005RG-Em for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611079390; 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=GG76/Nd6SkwPrzWo+WM1kldD4e/+xCkc9xSouGuiJ+w=; b=KjLKoQNQVte8V2bYtUDQd0OeZuaw0ssFEvzGxDnCM4PHlvTIgRknM+aUXmDMHV27P+OwAc FJ8t24AWG3KBVy4EYtV/8AUuEq4L/9t51Iaf5O5dvu46cRWQgl5QvfG42AXOrjFfhuSKoo LmiNgC8fRGZ8r1CJR2P34RP8Gu3bQ98= 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-310-avljdWpdM2qKWF0VY_O6jA-1; Tue, 19 Jan 2021 13:03:09 -0500 X-MC-Unique: avljdWpdM2qKWF0VY_O6jA-1 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 53EFF107AD39 for ; Tue, 19 Jan 2021 18:02:51 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-151.rdu2.redhat.com [10.10.120.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D2915D9DD; Tue, 19 Jan 2021 18:02:50 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v3 02/17] qapi/events: fix visit_event typing Date: Tue, 19 Jan 2021 13:02:27 -0500 Message-Id: <20210119180242.1570753-3-jsnow@redhat.com> In-Reply-To: <20210119180242.1570753-1-jsnow@redhat.com> References: <20210119180242.1570753-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.195, 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: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Actually, the arg_type can indeed be Optional. Signed-off-by: John Snow --- scripts/qapi/events.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index 599f3d1f564..9851653b9d1 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -12,7 +12,7 @@ See the COPYING file in the top-level directory. """ -from typing import List +from typing import List, Optional from .common import c_enum_const, c_name, mcgen from .gen import QAPISchemaModularCVisitor, build_params, ifcontext @@ -27,7 +27,7 @@ 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, def gen_event_send_decl(name: str, - arg_type: QAPISchemaObjectType, + arg_type: Optional[QAPISchemaObjectType], boxed: bool) -> str: return mcgen(''' @@ -78,7 +78,7 @@ def gen_param_var(typ: QAPISchemaObjectType) -> str: 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=build_event_send_proto(name, arg_type, boxed)) if have_args: + assert arg_type is not None ret += mcgen(''' QObject *obj; Visitor *v; @@ -114,6 +115,7 @@ def gen_event_send(name: str, name=name) if have_args: + assert arg_type is not None ret += mcgen(''' v = qobject_output_visitor_new(&obj); ''') @@ -214,7 +216,7 @@ def visit_event(self, info: QAPISourceInfo, ifcond: List[str], features: List[QAPISchemaFeature], - arg_type: QAPISchemaObjectType, + arg_type: Optional[QAPISchemaObjectType], boxed: bool) -> None: with ifcontext(ifcond, self._genh, self._genc): self._genh.add(gen_event_send_decl(name, arg_type, boxed)) From patchwork Tue Jan 19 18:02:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 1428792 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=JXN6KDgr; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DKy113B15z9sSs for ; Wed, 20 Jan 2021 05:31:49 +1100 (AEDT) Received: from localhost ([::1]:53838 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1vn9-0007eA-BA for incoming@patchwork.ozlabs.org; Tue, 19 Jan 2021 13:31:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42482) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1vLO-0007dz-Tm for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:06 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:47056) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l1vLM-0005Pc-8E for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611079383; 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=UWlRvp04PP8y4awj0DstdIy0uVKYQOYQ4hnvF2zD2T8=; b=JXN6KDgrIdFSjhAdxO7J2NIxuTd0gE6e8YYknA5yxNsBVSE/d5P3L9P2K3Vp5vy/tugziH kd/7685KUKCth6nEZLHhhp1gORUQkHlls30ciyhRYJQ9emu6HqRlUUBs+ZeLkQdqdHuHqG JOe69P+DDLkofe0wt46Z/THv+sZlNlg= 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-413--iqOFrKlOyiaIBC0bTVlIg-1; Tue, 19 Jan 2021 13:03:01 -0500 X-MC-Unique: -iqOFrKlOyiaIBC0bTVlIg-1 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 ABC71180A0A9 for ; Tue, 19 Jan 2021 18:02:52 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-151.rdu2.redhat.com [10.10.120.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 805505D9DD; Tue, 19 Jan 2021 18:02:51 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v3 03/17] qapi/main: handle theoretical None-return from re.match() Date: Tue, 19 Jan 2021 13:02:28 -0500 Message-Id: <20210119180242.1570753-4-jsnow@redhat.com> In-Reply-To: <20210119180242.1570753-1-jsnow@redhat.com> References: <20210119180242.1570753-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.195, 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: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Mypy cannot understand that this match can never be None, so help it along. Signed-off-by: John Snow --- scripts/qapi/main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/qapi/main.py b/scripts/qapi/main.py index 42517210b80..703e7ed1ed5 100644 --- a/scripts/qapi/main.py +++ b/scripts/qapi/main.py @@ -23,6 +23,8 @@ def invalid_prefix_char(prefix: str) -> Optional[str]: match = 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() != len(prefix): return prefix[match.end()] return None From patchwork Tue Jan 19 18:02:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 1428807 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=G8NjZ9J8; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DKyZq6DPjz9s24 for ; Wed, 20 Jan 2021 05:57:39 +1100 (AEDT) Received: from localhost ([::1]:60780 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1wC9-0007Kw-K5 for incoming@patchwork.ozlabs.org; Tue, 19 Jan 2021 13:57:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42670) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1vLY-0007li-7M for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:39267) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l1vLU-0005Rd-02 for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611079391; 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=60shrPKSBq0N3xI/dJVvfPA+/FHrHJZ5f+BtRl689cI=; b=G8NjZ9J8c0Xd9NxXhgjMABC56RIqXLEoGlsV8nOuCuRxtpHQkSn83e50Slwue5emV9kXjo Ec4tBbdP4hFniG93W5dVBUasvK6QA6tEUT3S+jhrf3a/wOiP/GZTrG0Zah3km4FV+KBgLg rzfqCS8391MYBZeVuukIa9jEpKA8K0M= 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-482-7m1rkeMMPs6ZOCMFCpNQ-A-1; Tue, 19 Jan 2021 13:03:09 -0500 X-MC-Unique: 7m1rkeMMPs6ZOCMFCpNQ-A-1 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 3F7B9107AD41 for ; Tue, 19 Jan 2021 18:02:54 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-151.rdu2.redhat.com [10.10.120.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 011BC5D9DD; Tue, 19 Jan 2021 18:02:52 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v3 04/17] qapi/gen: inline _wrap_ifcond into end_if() Date: Tue, 19 Jan 2021 13:02:29 -0500 Message-Id: <20210119180242.1570753-5-jsnow@redhat.com> In-Reply-To: <20210119180242.1570753-1-jsnow@redhat.com> References: <20210119180242.1570753-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.195, 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: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- scripts/qapi/gen.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index b40f18eee3c..3d81b90ab71 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -130,15 +130,12 @@ def start_if(self, ifcond: List[str]) -> None: self._start_if = (ifcond, self._body, self._preamble) def end_if(self) -> None: - assert self._start_if - self._wrap_ifcond() - self._start_if = None - - def _wrap_ifcond(self) -> None: + assert self._start_if is not None self._body = _wrap_ifcond(self._start_if[0], self._start_if[1], self._body) self._preamble = _wrap_ifcond(self._start_if[0], self._start_if[2], self._preamble) + self._start_if = None def get_content(self) -> str: assert self._start_if is None From patchwork Tue Jan 19 18:02:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 1428804 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ceZxgV/2; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DKySV149zz9sBy for ; Wed, 20 Jan 2021 05:52:08 +1100 (AEDT) Received: from localhost ([::1]:52062 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1w6n-0002pj-Mf for incoming@patchwork.ozlabs.org; Tue, 19 Jan 2021 13:52:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42580) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1vLU-0007iG-DA for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:12 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:39178) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l1vLQ-0005QV-HG for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611079387; 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=4xS66eQmUSx23VphivHbGiAaJMJlWm78y/k8iMgru4s=; b=ceZxgV/29kEjkx4bi87t/yjuK13DSuqe1XgdOiTVY+f6u1iWBDm3KoxiJHeHfG0dxN3wH5 5rJcKb39m41bAy7WxYvuidlZyfcNmC3cyqgjDrKXNSborFFISPcnjlB+4bZq2jM4qtA8Y2 RPJzdUjCcjAtevMPm+Rg/9KBhdRn4q0= 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-114-w0QbyEm4MdO4xH9UYnCtaQ-1; Tue, 19 Jan 2021 13:03:01 -0500 X-MC-Unique: w0QbyEm4MdO4xH9UYnCtaQ-1 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 7E71B8018A4 for ; Tue, 19 Jan 2021 18:02:55 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-151.rdu2.redhat.com [10.10.120.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 846145D9DD; Tue, 19 Jan 2021 18:02:54 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v3 05/17] qapi: pass QAPISchemaModule to visit_module instead of str Date: Tue, 19 Jan 2021 13:02:30 -0500 Message-Id: <20210119180242.1570753-6-jsnow@redhat.com> In-Reply-To: <20210119180242.1570753-1-jsnow@redhat.com> References: <20210119180242.1570753-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.195, 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: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Modify visit_module to pass the module itself instead of just its name. This allows for future patches to centralize some module-interrogation behavior within the QAPISchemaModule class itself, cutting down on duplication between gen.py and schema.py. Signed-off-by: John Snow --- docs/sphinx/qapidoc.py | 8 ++++---- scripts/qapi/gen.py | 16 ++++++++++------ scripts/qapi/schema.py | 4 ++-- tests/qapi-schema/test-qapi.py | 4 ++-- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/docs/sphinx/qapidoc.py b/docs/sphinx/qapidoc.py index e03abcbb959..f754f675d66 100644 --- a/docs/sphinx/qapidoc.py +++ b/docs/sphinx/qapidoc.py @@ -463,11 +463,11 @@ def __init__(self, env, qapidir): self._env = env self._qapidir = qapidir - def visit_module(self, name): - if name is not None: - qapifile = self._qapidir + '/' + name + def visit_module(self, module): + if module.name: + qapifile = self._qapidir + '/' + module.name self._env.note_dependency(os.path.abspath(qapifile)) - super().visit_module(name) + super().visit_module(module) class QAPIDocDirective(Directive): diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index 3d81b90ab71..e73d3d61aac 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -31,7 +31,11 @@ guardstart, mcgen, ) -from .schema import QAPISchemaObjectType, QAPISchemaVisitor +from .schema import ( + QAPISchemaModule, + QAPISchemaObjectType, + QAPISchemaVisitor, +) from .source import QAPISourceInfo @@ -304,19 +308,19 @@ def _begin_system_module(self, name: None) -> None: def _begin_user_module(self, name: str) -> None: pass - def visit_module(self, name: Optional[str]) -> None: - if name is None: + def visit_module(self, module: QAPISchemaModule) -> None: + if module.name is None: if self._builtin_blurb: self._add_system_module(None, self._builtin_blurb) - self._begin_system_module(name) + self._begin_system_module(module.name) else: # The built-in module has not been created. No code may # be generated. self._genc = None self._genh = None else: - self._add_user_module(name, self._user_blurb) - self._begin_user_module(name) + self._add_user_module(module.name, self._user_blurb) + self._begin_user_module(module.name) def visit_include(self, name: str, info: QAPISourceInfo) -> None: relname = os.path.relpath(self._module_filename(self._what, name), diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 720449feee4..69ba722c084 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -97,7 +97,7 @@ def visit_begin(self, schema): def visit_end(self): pass - def visit_module(self, name): + def visit_module(self, module): pass def visit_needed(self, entity): @@ -145,7 +145,7 @@ def add_entity(self, ent): self._entity_list.append(ent) def visit(self, visitor): - visitor.visit_module(self.name) + visitor.visit_module(self) for entity in self._entity_list: if visitor.visit_needed(entity): entity.visit(visitor) diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index e8db9d09d91..bec1ebff3db 100755 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -24,8 +24,8 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor): - def visit_module(self, name): - print('module %s' % name) + def visit_module(self, module): + print('module %s' % module.name) def visit_include(self, name, info): print('include %s' % name) From patchwork Tue Jan 19 18:02:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 1428801 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=UetQMcLA; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DKyKC616Sz9sBy for ; Wed, 20 Jan 2021 05:45:51 +1100 (AEDT) Received: from localhost ([::1]:43380 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1w0j-0007Hq-OO for incoming@patchwork.ozlabs.org; Tue, 19 Jan 2021 13:45:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42550) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1vLT-0007hA-AA for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:11 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:52563) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l1vLQ-0005QM-HJ for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611079387; 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=1Ai/VlO/RNcCgVu+JEISrd3kFfJr9+Mv+vSzaYWMrxw=; b=UetQMcLAtbjOnQ3RtviIi4H/qF9wYFvUJTPd52WEXe4i9ayK11nveO9ZH2zM922s8j3vSj ZKOA7+UW1ZG+5EFg7vTonXKTR4e06foEIUiSG/zhvT6NMDCCYx87dkoxO4x+68uVJfy6CW WTBdeSjXv/A04Mlnkw7NAjUgRXm6fLs= 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-296-fOzfxlioPFy8DAygVepY_g-1; Tue, 19 Jan 2021 13:03:01 -0500 X-MC-Unique: fOzfxlioPFy8DAygVepY_g-1 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 D2595180A0AE for ; Tue, 19 Jan 2021 18:02:56 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-151.rdu2.redhat.com [10.10.120.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB8C75D9DD; Tue, 19 Jan 2021 18:02:55 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v3 06/17] qapi: centralize is_[user|system|builtin]_module methods Date: Tue, 19 Jan 2021 13:02:31 -0500 Message-Id: <20210119180242.1570753-7-jsnow@redhat.com> In-Reply-To: <20210119180242.1570753-1-jsnow@redhat.com> References: <20210119180242.1570753-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.195, 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: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- docs/sphinx/qapidoc.py | 2 +- scripts/qapi/gen.py | 21 +++++++-------------- scripts/qapi/schema.py | 28 ++++++++++++++++++++++++++-- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/docs/sphinx/qapidoc.py b/docs/sphinx/qapidoc.py index f754f675d66..08b9439de2b 100644 --- a/docs/sphinx/qapidoc.py +++ b/docs/sphinx/qapidoc.py @@ -464,7 +464,7 @@ def __init__(self, env, qapidir): self._qapidir = qapidir def visit_module(self, module): - if module.name: + if module.user_module: qapifile = self._qapidir + '/' + module.name self._env.note_dependency(os.path.abspath(qapifile)) super().visit_module(module) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index e73d3d61aac..3b7eddc1c21 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -250,21 +250,14 @@ def __init__(self, self._main_module: Optional[str] = None @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 '' def _module_basename(self, what: str, name: Optional[str]) -> str: - ret = '' if self._is_builtin_module(name) else self._prefix - if self._is_user_module(name): + ret = '' if QAPISchemaModule.is_builtin_module(name) else self._prefix + if QAPISchemaModule.is_user_module(name): basename = os.path.basename(name) ret += what if name != self._main_module: @@ -286,7 +279,7 @@ def _add_module(self, name: Optional[str], blurb: str) -> None: self._genc, self._genh = self._module[name] 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 = name self._add_module(name, blurb) @@ -296,7 +289,7 @@ def _add_system_module(self, name: Optional[str], blurb: str) -> None: def write(self, output_dir: str, opt_builtins: bool = 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_builtins: continue (genc, genh) = self._module[name] genc.write(output_dir) @@ -309,7 +302,7 @@ def _begin_user_module(self, name: str) -> None: pass def visit_module(self, module: QAPISchemaModule) -> None: - if module.name is None: + if module.system_module: if self._builtin_blurb: self._add_system_module(None, self._builtin_blurb) self._begin_system_module(module.name) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 69ba722c084..44a9232c881 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -141,6 +141,30 @@ def __init__(self, name): self.name = name self._entity_list = [] + @classmethod + def is_system_module(cls, name: Optional[str]) -> bool: + return name is None or name.startswith('./') + + @classmethod + def is_user_module(cls, name: Optional[str]) -> bool: + return not cls.is_system_module(name) + + @classmethod + def is_builtin_module(cls, name: str) -> bool: + return name == './builtin' + + @property + def system_module(self) -> bool: + return self.is_system_module(self.name) + + @property + def user_module(self) -> bool: + return self.is_user_module(self.name) + + @property + def builtin_module(self) -> bool: + return self.is_builtin_module(self.name) + def add_entity(self, ent): self._entity_list.append(ent) @@ -871,8 +895,8 @@ def resolve_type(self, name, info, what): return typ 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) def _make_module(self, fname): From patchwork Tue Jan 19 18:02:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 1428802 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=hj+/v75Z; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DKyM34XMwz9sBy for ; Wed, 20 Jan 2021 05:47:27 +1100 (AEDT) Received: from localhost ([::1]:45734 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1w2H-0008LL-Gj for incoming@patchwork.ozlabs.org; Tue, 19 Jan 2021 13:47:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42614) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1vLV-0007ji-DJ for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:13 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:53486) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l1vLT-0005RF-Ek for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611079390; 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=4BZcb8KNqwK0gahDQWfoq7j5v/5e8ewZXJZ319ijxO0=; b=hj+/v75ZgmD7F+7PiHXKdw/C41u9i3KCJmYOcFHvHQwRMH/WvNMd7rLtNAoryPIJp8/DYy ZwxqYiemwc068YQnU3cmf4XUx7PK1Nn9nDl9tqF5vJiMspw8yU3liIYaNu+FPosbGP/qkD 1XFrK9PCQT6tfHqpvyDz1CGMnem5boA= 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-310-2ejfURv6NTGd2tTcZIYjDg-1; Tue, 19 Jan 2021 13:03:09 -0500 X-MC-Unique: 2ejfURv6NTGd2tTcZIYjDg-1 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 2552E107AD47 for ; Tue, 19 Jan 2021 18:02:58 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-151.rdu2.redhat.com [10.10.120.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 22CF95D9DD; Tue, 19 Jan 2021 18:02:56 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v3 07/17] qapi/gen: Replace ._begin_system_module() Date: Tue, 19 Jan 2021 13:02:32 -0500 Message-Id: <20210119180242.1570753-8-jsnow@redhat.com> In-Reply-To: <20210119180242.1570753-1-jsnow@redhat.com> References: <20210119180242.1570753-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.195, 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: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Markus Armbruster QAPISchemaModularCVisitor._begin_system_module() is actually just for the builtin module. Rename it to ._begin_builtin_module() and drop its useless @name parameter. Signed-off-by: Markus Armbruster Signed-off-by: John Snow --- 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 3b7eddc1c21..9f850d23646 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -295,7 +295,7 @@ def write(self, output_dir: str, opt_builtins: bool = False) -> None: genc.write(output_dir) genh.write(output_dir) - def _begin_system_module(self, name: None) -> None: + def _begin_builtin_module(self) -> None: pass def _begin_user_module(self, name: str) -> None: @@ -305,7 +305,7 @@ def visit_module(self, module: QAPISchemaModule) -> None: if module.system_module: if self._builtin_blurb: self._add_system_module(None, self._builtin_blurb) - self._begin_system_module(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 2b4916cdaa1..dbf58c0b91d 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -271,7 +271,7 @@ def __init__(self, prefix: str): prefix, 'qapi-types', ' * Schema-defined QAPI types', ' * Built-in QAPI types', __doc__) - def _begin_system_module(self, name: None) -> None: + def _begin_builtin_module(self) -> None: self._genc.preamble_add(mcgen(''' #include "qemu/osdep.h" #include "qapi/dealloc-visitor.h" diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 339f1521524..568ba35592c 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -305,7 +305,7 @@ def __init__(self, prefix: str): prefix, 'qapi-visit', ' * Schema-defined QAPI visitors', ' * Built-in QAPI visitors', __doc__) - 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" From patchwork Tue Jan 19 18:02:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 1428779 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=FjqF93ez; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DKxcl6rWhz9sB4 for ; Wed, 20 Jan 2021 05:14:15 +1100 (AEDT) Received: from localhost ([::1]:50066 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1vW9-0000H3-SF for incoming@patchwork.ozlabs.org; Tue, 19 Jan 2021 13:14:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42548) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1vLS-0007gU-Vd for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:11 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:47374) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l1vLQ-0005QR-H2 for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611079387; 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=NVTzjiFRodxmIdATxFHaTkf+ppb0zaHWEF0Y7bI4Ops=; b=FjqF93ez1jv3/ZflaoikTaZUfeobm2OkTRR2UL25W1WRye4EhS6y5FLqCgkCPkM5Hb1Yzg 0G91jVJIljWIT/1Owyj7vEcsNVk/Qj5HiQH8VJXxZlFjlNQ6ECiq1RZa/12C7IbcUrpXMw RoLczuZzsLPc5x7iE9iswbOA6r0DvwI= 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-280-tgapuW6ePN2RC7y5X9ObfQ-1; Tue, 19 Jan 2021 13:03:05 -0500 X-MC-Unique: tgapuW6ePN2RC7y5X9ObfQ-1 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 EE6221005504 for ; Tue, 19 Jan 2021 18:03:04 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-151.rdu2.redhat.com [10.10.120.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 54EC95D9DD; Tue, 19 Jan 2021 18:02:58 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v3 08/17] qapi: use explicitly internal module names Date: Tue, 19 Jan 2021 13:02:33 -0500 Message-Id: <20210119180242.1570753-9-jsnow@redhat.com> In-Reply-To: <20210119180242.1570753-1-jsnow@redhat.com> References: <20210119180242.1570753-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.195, 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: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Use ./emit and ./init explicitly instead of "emit" and "init". Add assertions that enforce this. Signed-off-by: John Snow --- scripts/qapi/commands.py | 2 +- scripts/qapi/events.py | 2 +- scripts/qapi/gen.py | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index 71744f48a35..fc5fe27c472 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -286,7 +286,7 @@ def _begin_user_module(self, name: str) -> None: types=types)) 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" diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index 9851653b9d1..26faa829898 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -191,7 +191,7 @@ def _begin_user_module(self, name: str) -> None: types=types)) 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 9f850d23646..18b72dd06c8 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -285,7 +285,8 @@ def _add_user_module(self, name: str, blurb: str) -> None: self._add_module(name, blurb) 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) def write(self, output_dir: str, opt_builtins: bool = False) -> None: for name in self._module: From patchwork Tue Jan 19 18:02:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 1428814 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=c25wTD2x; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DKysl4x8Gz9s2g for ; Wed, 20 Jan 2021 06:10:35 +1100 (AEDT) Received: from localhost ([::1]:49822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1wOf-0006bX-Lm for incoming@patchwork.ozlabs.org; Tue, 19 Jan 2021 14:10:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42708) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1vLb-0007nq-99 for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:25699) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l1vLT-0005RR-NC for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611079391; 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=uGlYLy4/E4QNJ/liZFOvaLcj2OGPSvFe5u2L/4n7lvU=; b=c25wTD2x1BoaBjjGzP0Yhss1/0tlwa1r9dN/W2RacNGd52FpAbvpUTQW1a562YBUm20BJC ptcHMoH+SNBdSRazv5ld2ybQZDzjgh2BWz7gPV+K6jP15PmHbV6hoF5rPNNhSQlVKucyPh dkI0E0eRRsi8crqYhtHHT5PA1onLu8Y= 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-160--GiWtg5-OJCBXv716naKpQ-1; Tue, 19 Jan 2021 13:03:09 -0500 X-MC-Unique: -GiWtg5-OJCBXv716naKpQ-1 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 EA1DB107ACFB for ; Tue, 19 Jan 2021 18:03:05 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-151.rdu2.redhat.com [10.10.120.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 279845D9DD; Tue, 19 Jan 2021 18:03:05 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v3 09/17] qapi: use './builtin' as the built-in module name Date: Tue, 19 Jan 2021 13:02:34 -0500 Message-Id: <20210119180242.1570753-10-jsnow@redhat.com> In-Reply-To: <20210119180242.1570753-1-jsnow@redhat.com> References: <20210119180242.1570753-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.195, 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: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- scripts/qapi/gen.py | 18 +++++++++--------- scripts/qapi/schema.py | 14 +++++++------- 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, 24 insertions(+), 24 deletions(-) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index 18b72dd06c8..55acd7e080d 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -246,16 +246,16 @@ def __init__(self, self._pydoc = pydoc self._genc: Optional[QAPIGenC] = None self._genh: Optional[QAPIGenH] = None - self._module: Dict[Optional[str], Tuple[QAPIGenC, QAPIGenH]] = {} + self._module: Dict[str, Tuple[QAPIGenC, QAPIGenH]] = {} self._main_module: Optional[str] = None @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 '' - def _module_basename(self, what: str, name: Optional[str]) -> str: + def _module_basename(self, what: str, name: str) -> str: ret = '' if QAPISchemaModule.is_builtin_module(name) else self._prefix if QAPISchemaModule.is_user_module(name): basename = os.path.basename(name) @@ -263,15 +263,15 @@ def _module_basename(self, what: str, name: Optional[str]) -> str: if name != self._main_module: ret += '-' + os.path.splitext(basename)[0] else: - name = name[2:] if name else 'builtin' - ret += re.sub(r'-', '-' + name + '-', what) + assert QAPISchemaModule.is_system_module(name) + ret += re.sub(r'-', '-' + name[2:] + '-', what) return ret - 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)) - def _add_module(self, name: Optional[str], blurb: str) -> None: + def _add_module(self, name: str, blurb: str) -> None: basename = self._module_filename(self._what, name) genc = QAPIGenC(basename + '.c', blurb, self._pydoc) genh = QAPIGenH(basename + '.h', blurb, self._pydoc) @@ -284,7 +284,7 @@ def _add_user_module(self, name: str, blurb: str) -> None: self._main_module = name self._add_module(name, blurb) - 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) @@ -305,7 +305,7 @@ def _begin_user_module(self, name: str) -> None: def visit_module(self, module: QAPISchemaModule) -> None: if module.system_module: if self._builtin_blurb: - self._add_system_module(None, self._builtin_blurb) + self._add_system_module(module.name, self._builtin_blurb) self._begin_builtin_module() else: # The built-in module has not been created. No code may diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 44a9232c881..c519c18a5ec 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -68,7 +68,8 @@ def check_doc(self): def _set_module(self, schema, info): assert self._checked - self._module = schema.module_by_fname(info and info.fname) + fname = info.fname if info else './builtin' + self._module = schema.module_by_fname(fname) self._module.add_entity(self) def set_module(self, schema): @@ -142,11 +143,11 @@ def __init__(self, name): self._entity_list = [] @classmethod - def is_system_module(cls, name: Optional[str]) -> bool: - return name is None or name.startswith('./') + def is_system_module(cls, name: str) -> bool: + return name.startswith('./') @classmethod - def is_user_module(cls, name: Optional[str]) -> bool: + def is_user_module(cls, name: str) -> bool: return not cls.is_system_module(name) @classmethod @@ -849,7 +850,7 @@ def __init__(self, fname): self._entity_dict = {} self._module_dict = OrderedDict() self._schema_dir = os.path.dirname(fname) - self._make_module(None) # built-ins + self._make_module('./builtin') # built-ins self._make_module(fname) self._predefining = True self._def_predefineds() @@ -894,7 +895,7 @@ def resolve_type(self, name, info, what): info, "%s uses unknown type '%s'" % (what, name)) return typ - 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) @@ -907,7 +908,6 @@ def _make_module(self, fname): def module_by_fname(self, fname): name = self._module_name(fname) - assert name in self._module_dict return self._module_dict[name] def _def_include(self, expr, info, doc): diff --git a/tests/qapi-schema/comments.out b/tests/qapi-schema/comments.out index 273f0f54e16..ce4f6a4f0f5 100644 --- a/tests/qapi-schema/comments.out +++ b/tests/qapi-schema/comments.out @@ -1,4 +1,4 @@ -module None +module ./builtin object q_empty enum QType prefix QTYPE diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out index 419284dae29..715b0bbc1af 100644 --- a/tests/qapi-schema/doc-good.out +++ b/tests/qapi-schema/doc-good.out @@ -1,4 +1,4 @@ -module None +module ./builtin object q_empty enum QType prefix QTYPE diff --git a/tests/qapi-schema/empty.out b/tests/qapi-schema/empty.out index 69666c39ad2..3feb3f69d3d 100644 --- a/tests/qapi-schema/empty.out +++ b/tests/qapi-schema/empty.out @@ -1,4 +1,4 @@ -module None +module ./builtin object q_empty enum QType prefix QTYPE diff --git a/tests/qapi-schema/event-case.out b/tests/qapi-schema/event-case.out index 42ae519656d..9ae44052ac4 100644 --- a/tests/qapi-schema/event-case.out +++ b/tests/qapi-schema/event-case.out @@ -1,4 +1,4 @@ -module None +module ./builtin object q_empty enum QType prefix QTYPE diff --git a/tests/qapi-schema/include-repetition.out b/tests/qapi-schema/include-repetition.out index 0b654ddebb6..16dbd9b8194 100644 --- a/tests/qapi-schema/include-repetition.out +++ b/tests/qapi-schema/include-repetition.out @@ -1,4 +1,4 @@ -module None +module ./builtin object q_empty enum QType prefix QTYPE diff --git a/tests/qapi-schema/include-simple.out b/tests/qapi-schema/include-simple.out index 061f81e5090..48e923bfbc8 100644 --- a/tests/qapi-schema/include-simple.out +++ b/tests/qapi-schema/include-simple.out @@ -1,4 +1,4 @@ -module None +module ./builtin object q_empty enum QType prefix QTYPE diff --git a/tests/qapi-schema/indented-expr.out b/tests/qapi-schema/indented-expr.out index 04356775cd1..6a30ded3fa6 100644 --- a/tests/qapi-schema/indented-expr.out +++ b/tests/qapi-schema/indented-expr.out @@ -1,4 +1,4 @@ -module None +module ./builtin object q_empty enum QType prefix QTYPE diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qapi-schema-test.out index 8868ca0dca9..3b1387d9f18 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -1,4 +1,4 @@ -module None +module ./builtin object q_empty enum QType prefix QTYPE From patchwork Tue Jan 19 18:02:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 1428784 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Rp9XaGru; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DKxlt1lt1z9sT6 for ; Wed, 20 Jan 2021 05:20:26 +1100 (AEDT) Received: from localhost ([::1]:59096 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1vc8-00056T-6o for incoming@patchwork.ozlabs.org; Tue, 19 Jan 2021 13:20:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42634) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1vLW-0007kZ-48 for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:14 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:41116) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l1vLT-0005RK-FL for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611079390; 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=e6aiH8zm1YUPRAyeHaBmqcArttEwHHHXEPxZD/0Y0wE=; b=Rp9XaGru+z93IPcRmA/HqkSAQmHT0/ZRhUvgdNt6/2v+BmYxT3zzGVcxk4PaUmZdGo+gq+ Y1EAI9nwiuvqSpNWuSFuiAn/H8h1YEkUIUSrWkrZmraRMD1kmVUrwASMz6W8Qw4Vxu1frE jLS+vAnJoHtdogSbluq1F42a8hHrGZg= 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-160-xst1rdZqMg2bR8_EdtjQTQ-1; Tue, 19 Jan 2021 13:03:09 -0500 X-MC-Unique: xst1rdZqMg2bR8_EdtjQTQ-1 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 E5C14107AD4C for ; Tue, 19 Jan 2021 18:03:06 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-151.rdu2.redhat.com [10.10.120.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 21D935D9DD; Tue, 19 Jan 2021 18:03:06 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v3 10/17] qapi/gen: Combine ._add_[user|system]_module Date: Tue, 19 Jan 2021 13:02:35 -0500 Message-Id: <20210119180242.1570753-11-jsnow@redhat.com> In-Reply-To: <20210119180242.1570753-1-jsnow@redhat.com> References: <20210119180242.1570753-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.195, 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: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Markus Armbruster 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(). Signed-off-by: Markus Armbruster Signed-off-by: John Snow --- scripts/qapi/commands.py | 2 +- scripts/qapi/events.py | 2 +- scripts/qapi/gen.py | 20 +++++++------------- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index fc5fe27c472..49111663394 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -286,7 +286,7 @@ def _begin_user_module(self, name: str) -> None: types=types)) 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" diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index 26faa829898..079c666ec69 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -191,7 +191,7 @@ def _begin_user_module(self, name: str) -> None: types=types)) 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 55acd7e080d..b5505685e6e 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -272,22 +272,15 @@ def _module_filename(self, what: str, name: str) -> str: self._module_basename(what, name)) def _add_module(self, name: str, blurb: str) -> None: + if QAPISchemaModule.is_user_module(name): + if self._main_module is None: + self._main_module = name basename = self._module_filename(self._what, name) genc = QAPIGenC(basename + '.c', blurb, self._pydoc) genh = QAPIGenH(basename + '.h', blurb, self._pydoc) self._module[name] = (genc, genh) self._genc, self._genh = self._module[name] - 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 = 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 = False) -> None: for name in self._module: if QAPISchemaModule.is_builtin_module(name) and not opt_builtins: @@ -303,9 +296,9 @@ def _begin_user_module(self, name: str) -> None: pass def visit_module(self, module: QAPISchemaModule) -> None: - if module.system_module: + if module.builtin_module: if self._builtin_blurb: - self._add_system_module(module.name, self._builtin_blurb) + self._add_module(module.name, self._builtin_blurb) self._begin_builtin_module() else: # The built-in module has not been created. No code may @@ -313,7 +306,8 @@ def visit_module(self, module: QAPISchemaModule) -> None: self._genc = None self._genh = None else: - self._add_user_module(module.name, self._user_blurb) + assert module.user_module, "Unexpected system module" + self._add_module(module.name, self._user_blurb) self._begin_user_module(module.name) def visit_include(self, name: str, info: QAPISourceInfo) -> None: From patchwork Tue Jan 19 18:02:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 1428786 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=gXgIUsrb; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DKxs91vQRz9sSs for ; Wed, 20 Jan 2021 05:25:01 +1100 (AEDT) Received: from localhost ([::1]:39478 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1vgZ-0001U8-6b for incoming@patchwork.ozlabs.org; Tue, 19 Jan 2021 13:24:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42654) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1vLW-0007kw-RG for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:16 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:28109) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l1vLT-0005RM-KQ for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611079390; 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=+4djVAJuJxG9JDMBfsIoZrWqekj/Y5ucXQee7MNLfE8=; b=gXgIUsrbq8jLbb1K06xGFv0fQ0o+wUlC97/zjL+dqqRdMrrzBnV702sPRiE0COsnSFTUiJ 0wpunrR0Bywcign6rQsuYR7WBlTSSmBniBXfe+TTU4nAbODj3XAQ/xWQ1SqAwwmZRTkhya +bBBhudj6ZEFlhG+ges8T0b7QUVutSY= 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-130-VNGToKc7Mu68pcAZDYOqFw-1; Tue, 19 Jan 2021 13:03:08 -0500 X-MC-Unique: VNGToKc7Mu68pcAZDYOqFw-1 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 DFE71BBEE1 for ; Tue, 19 Jan 2021 18:03:07 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-151.rdu2.redhat.com [10.10.120.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1C94B5D9DD; Tue, 19 Jan 2021 18:03:07 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v3 11/17] qapi: centralize the built-in module name definition Date: Tue, 19 Jan 2021 13:02:36 -0500 Message-Id: <20210119180242.1570753-12-jsnow@redhat.com> In-Reply-To: <20210119180242.1570753-1-jsnow@redhat.com> References: <20210119180242.1570753-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.195, 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: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Use a constant to make it obvious we're referring to a very specific thing. Signed-off-by: John Snow --- scripts/qapi/schema.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index c519c18a5ec..887a1c82c6f 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -68,7 +68,7 @@ def check_doc(self): def _set_module(self, schema, info): assert self._checked - fname = info.fname if info else './builtin' + fname = info.fname if info else QAPISchemaModule.BUILTIN_MODULE_NAME self._module = schema.module_by_fname(fname) self._module.add_entity(self) @@ -138,6 +138,9 @@ def visit_event(self, name, info, ifcond, features, arg_type, boxed): class QAPISchemaModule: + + BUILTIN_MODULE_NAME = './builtin' + def __init__(self, name): self.name = name self._entity_list = [] @@ -152,7 +155,7 @@ def is_user_module(cls, name: str) -> bool: @classmethod def is_builtin_module(cls, name: str) -> bool: - return name == './builtin' + return name == cls.BUILTIN_MODULE_NAME @property def system_module(self) -> bool: @@ -850,7 +853,7 @@ def __init__(self, fname): self._entity_dict = {} self._module_dict = OrderedDict() self._schema_dir = os.path.dirname(fname) - self._make_module('./builtin') # built-ins + self._make_module(QAPISchemaModule.BUILTIN_MODULE_NAME) # built-ins self._make_module(fname) self._predefining = True self._def_predefineds() From patchwork Tue Jan 19 18:02:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 1428810 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=K4jo1mFX; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DKyjm3wjfz9rx8 for ; Wed, 20 Jan 2021 06:03:40 +1100 (AEDT) Received: from localhost ([::1]:41280 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1wHy-0002jg-FP for incoming@patchwork.ozlabs.org; Tue, 19 Jan 2021 14:03:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42700) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1vLb-0007me-5q for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:25022) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l1vLX-0005Sf-Sg for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611079394; 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=DXthwzTGPV8NROKpyvQC4SOqtS8Z5EE8TjfysGXtoI4=; b=K4jo1mFXdmRC0wfghRvsRcxui/yuF6M1oeTsyB49/Qdfd2xpwR+lJMrQut5/KIa8WnerGa UgYC5L3M7DTQCHXkbT4sfHUlvcZTlUkAho2IEsLpKdise3Q0osw8MliILj5jnzm9NbgIoW EKu/hkKKLeQu6Ed8iuomMzBtYBKvA+A= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-572-3vpKrEisNTGZXCBxUHhJyA-1; Tue, 19 Jan 2021 13:03:12 -0500 X-MC-Unique: 3vpKrEisNTGZXCBxUHhJyA-1 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 AFE0E10054FF for ; Tue, 19 Jan 2021 18:03:11 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-151.rdu2.redhat.com [10.10.120.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 17FA85D9DD; Tue, 19 Jan 2021 18:03:07 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v3 12/17] qapi/gen: write _genc/_genh access shims Date: Tue, 19 Jan 2021 13:02:37 -0500 Message-Id: <20210119180242.1570753-13-jsnow@redhat.com> In-Reply-To: <20210119180242.1570753-1-jsnow@redhat.com> References: <20210119180242.1570753-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.195, 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: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- 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 b5505685e6e..4b5d3ea3a5b 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -244,11 +244,20 @@ def __init__(self, self._user_blurb = user_blurb self._builtin_blurb = builtin_blurb self._pydoc = pydoc - self._genc: Optional[QAPIGenC] = None - self._genh: Optional[QAPIGenH] = None + self._current_module: Optional[str] = None self._module: Dict[str, Tuple[QAPIGenC, QAPIGenH]] = {} self._main_module: Optional[str] = None + @property + def _genc(self) -> QAPIGenC: + assert self._current_module is not None + return self._module[self._current_module][0] + + @property + def _genh(self) -> QAPIGenH: + assert self._current_module is not None + return self._module[self._current_module][1] + @staticmethod def _module_dirname(name: str) -> str: if QAPISchemaModule.is_user_module(name): @@ -279,7 +288,7 @@ def _add_module(self, name: str, blurb: str) -> None: genc = QAPIGenC(basename + '.c', blurb, self._pydoc) genh = QAPIGenH(basename + '.h', blurb, self._pydoc) self._module[name] = (genc, genh) - self._genc, self._genh = self._module[name] + self._current_module = name def write(self, output_dir: str, opt_builtins: bool = False) -> None: for name in self._module: @@ -303,8 +312,7 @@ def visit_module(self, module: QAPISchemaModule) -> None: else: # The built-in module has not been created. No code may # be generated. - self._genc = None - self._genh = None + self._current_module = None else: assert module.user_module, "Unexpected system module" self._add_module(module.name, self._user_blurb) From patchwork Tue Jan 19 18:02:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 1428790 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=WCXXt7Ut; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DKxwy29rcz9sVy for ; Wed, 20 Jan 2021 05:28:18 +1100 (AEDT) Received: from localhost ([::1]:48452 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1vjk-0005PQ-1f for incoming@patchwork.ozlabs.org; Tue, 19 Jan 2021 13:28:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42736) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1vLd-0007oY-3c for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:21 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:46174) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l1vLb-0005TW-GI for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611079398; 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=vbkfW/5FHbt4kV4zbz6lvbzg2zNEEUQdO380g35ehGs=; b=WCXXt7UtK6zDS7yx1plAvdOwI/QTkRffQGb0dtRIMe796J6fZDjs0CGAlVx+kP5W/Nm/Eo OosXHIeUxoA2mwYADYqqG8rAC5xfQWgVrZaPrdIzWTzmZEWJWNH/hMXXYBTyBFNq/hXP5+ G8EDt6n7q05H9GlaFmHpmcTdaMYFoVs= 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-230-cBQxEgOfOFKxpnaMPrxAtg-1; Tue, 19 Jan 2021 13:03:16 -0500 X-MC-Unique: cBQxEgOfOFKxpnaMPrxAtg-1 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 997D959 for ; Tue, 19 Jan 2021 18:03:15 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-151.rdu2.redhat.com [10.10.120.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB1F85D9DD; Tue, 19 Jan 2021 18:03:11 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v3 13/17] qapi/gen: Support for switching to another module temporarily Date: Tue, 19 Jan 2021 13:02:38 -0500 Message-Id: <20210119180242.1570753-14-jsnow@redhat.com> In-Reply-To: <20210119180242.1570753-1-jsnow@redhat.com> References: <20210119180242.1570753-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.195, 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: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Markus Armbruster Signed-off-by: Markus Armbruster Signed-off-by: John Snow --- scripts/qapi/gen.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index 4b5d3ea3a5b..86abdabb57a 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -290,6 +290,13 @@ def _add_module(self, name: str, blurb: str) -> None: self._module[name] = (genc, genh) self._current_module = name + @contextmanager + def _temp_module(self, name: str) -> Iterator[None]: + old_module = self._current_module + self._current_module = name + yield + self._current_module = old_module + def write(self, output_dir: str, opt_builtins: bool = False) -> None: for name in self._module: if QAPISchemaModule.is_builtin_module(name) and not opt_builtins: From patchwork Tue Jan 19 18:02:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 1428816 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=GMWODmnJ; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DKyyb1Hbtz9sWH for ; Wed, 20 Jan 2021 06:14:47 +1100 (AEDT) Received: from localhost ([::1]:56120 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1wSj-0000yz-4m for incoming@patchwork.ozlabs.org; Tue, 19 Jan 2021 14:14:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42764) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1vLf-0007pl-3S for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:39807) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l1vLc-0005Tv-TO for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611079400; 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=8Z3bad5yWvdxkBc5j9NZ8zF1uyAhF+f5gWUrQmcvKlQ=; b=GMWODmnJZeW8mgrGgMKEhm9TEbo7n1uKjlGnv8c98PFMaD3Bn836TRLlZQm5NZ/dp/J5Qp bWPvmc35Z/7FM+zYPXn9XsRri/hE8nYniIiUZVv/8Co8beZ0QJgbV2Y6edoQ0z3pC64tA+ NTvTMPOSYFhHy+nVbmqBfdLpjI9hnfA= 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-137-FSv7bGfENIOd_LwCCJF7_A-1; Tue, 19 Jan 2021 13:03:17 -0500 X-MC-Unique: FSv7bGfENIOd_LwCCJF7_A-1 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 9EA75106C060 for ; Tue, 19 Jan 2021 18:03:16 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-151.rdu2.redhat.com [10.10.120.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id C4B295D9DD; Tue, 19 Jan 2021 18:03:15 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v3 14/17] qapi/commands: Simplify command registry generation Date: Tue, 19 Jan 2021 13:02:39 -0500 Message-Id: <20210119180242.1570753-15-jsnow@redhat.com> In-Reply-To: <20210119180242.1570753-1-jsnow@redhat.com> References: <20210119180242.1570753-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.195, 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: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Markus Armbruster QAPISchemaGenCommandVisitor.visit_command() needs to generate the marshalling function into the current module, and also generate its registration into the ./init system module. The latter is done somewhat awkwardly: .__init__() creates a QAPIGenCCode that will not be written out, each .visit_command() adds its registration to it, and .visit_end() copies its contents into the ./init module it creates. Instead provide the means to temporarily switch to another module. Create the ./init module in .visit_begin(), and generate its initial part. Add registrations to it in .visit_command(). Finish it in .visit_end(). Signed-off-by: Markus Armbruster Signed-off-by: John Snow --- scripts/qapi/commands.py | 49 ++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index 49111663394..13a9dcaf894 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -23,7 +23,6 @@ from .common import c_name, mcgen from .gen import ( QAPIGenC, - QAPIGenCCode, QAPISchemaModularCVisitor, build_params, ifcontext, @@ -237,28 +236,11 @@ def gen_register_command(name: str, return ret -def gen_registry(registry: str, prefix: str) -> str: - ret = mcgen(''' - -void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds) -{ - QTAILQ_INIT(cmds); - -''', - c_prefix=c_name(prefix, protect=False)) - ret += registry - ret += 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 = QAPIGenCCode(None) self._visited_ret_types: Dict[QAPIGenC, Set[QAPISchemaType]] = {} def _begin_user_module(self, name: str) -> None: @@ -285,7 +267,7 @@ def _begin_user_module(self, name: str) -> None: ''', types=types)) - def visit_end(self) -> None: + def visit_begin(self, schema: QAPISchema) -> None: self._add_module('./init', ' * QAPI Commands initialization') self._genh.add(mcgen(''' #include "qapi/qmp/dispatch.h" @@ -293,13 +275,24 @@ def visit_end(self) -> None: void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds); ''', c_prefix=c_name(self._prefix, protect=False))) - 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=self._prefix)) - self._genc.add(gen_registry(self._regy.get_content(), self._prefix)) + prefix=self._prefix, + c_prefix=c_name(self._prefix, protect=False))) + + def visit_end(self) -> None: + with self._temp_module('./init'): + self._genc.add(mcgen(''' +} +''')) def visit_command(self, name: str, @@ -324,15 +317,17 @@ def visit_command(self, if ret_type and ret_type not in self._visited_ret_types[self._genc]: self._visited_ret_types[self._genc].add(ret_type) with ifcontext(ret_type.ifcond, - self._genh, self._genc, self._regy): + self._genh, self._genc): self._genc.add(gen_marshal_output(ret_type)) - with ifcontext(ifcond, self._genh, self._genc, self._regy): + with ifcontext(ifcond, self._genh, self._genc): self._genh.add(gen_command_decl(name, arg_type, boxed, ret_type)) 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_preconfig, + coroutine)) def gen_commands(schema: QAPISchema, From patchwork Tue Jan 19 18:02:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 1428795 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ZG4wRe7Y; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DKy374h3Nz9sSs for ; Wed, 20 Jan 2021 05:33:39 +1100 (AEDT) Received: from localhost ([::1]:57348 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1voo-0000jK-Qc for incoming@patchwork.ozlabs.org; Tue, 19 Jan 2021 13:33:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42766) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1vLf-0007q9-DF for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:31150) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l1vLd-0005U0-AR for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611079400; 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=pLrunFLCoJk0GtHTxxoch3fmksJsTJwZSJiudioWPto=; b=ZG4wRe7YAZTM3INW4GoOQ/U6TE+6p861iKAX3Zq0sFSsQiMCpA77v/+qVF2WOpBWm8cZi3 Nmzx93J05y97mmsaTcRQnKagflBau8J/wtzWCJlSfWTvaSBQs2/0J1QarM1PmdgkqLonDy ERoyeie2LBtjSkVbsOSFQwZFRrH6JzM= 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-5-nPTFNboCNZigeyA_xVjvgQ-1; Tue, 19 Jan 2021 13:03:18 -0500 X-MC-Unique: nPTFNboCNZigeyA_xVjvgQ-1 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 A5BC31005504 for ; Tue, 19 Jan 2021 18:03:17 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-151.rdu2.redhat.com [10.10.120.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id CC3A95D9DD; Tue, 19 Jan 2021 18:03:16 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v3 15/17] qapi/gen: Drop support for QAPIGen without a file name Date: Tue, 19 Jan 2021 13:02:40 -0500 Message-Id: <20210119180242.1570753-16-jsnow@redhat.com> In-Reply-To: <20210119180242.1570753-1-jsnow@redhat.com> References: <20210119180242.1570753-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.195, 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: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Markus Armbruster The previous commit removed the only user of QAPIGen(None). Tighten the type hint. Signed-off-by: Markus Armbruster Signed-off-by: John Snow --- 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 86abdabb57a..87074335e6c 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -40,7 +40,7 @@ class QAPIGen: - def __init__(self, fname: Optional[str]): + def __init__(self, fname: str): self.fname = fname self._preamble = '' self._body = '' @@ -125,7 +125,7 @@ def build_params(arg_type: Optional[QAPISchemaObjectType], 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]] = None From patchwork Tue Jan 19 18:02:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 1428805 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=cWYHaizd; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DKyVx0FMDz9s24 for ; Wed, 20 Jan 2021 05:54:17 +1100 (AEDT) Received: from localhost ([::1]:54386 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1w8s-0004Pc-KC for incoming@patchwork.ozlabs.org; Tue, 19 Jan 2021 13:54:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42786) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1vLh-0007s0-04 for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:36603) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l1vLe-0005UK-Qn for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611079401; 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=PKk0LP3oG7EtlOgLwNnDNvhlYco8mw/JkKzSj9qCvps=; b=cWYHaizdhkdlvo4vMJhUcyhE8skaJz9HlcwWQi40n8XkO2vJAp6JJk/zrPACF7L/Nl6Eny SztZeO5RUoDyJieOB5UNemdcuGHJf1pVy1MzbF05EDKVWVg8rOxuHYpowG/CJy5zPhfLTZ Ou9GHUFVrxPdWzLRC0QQyFoWompQrpg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-496-jBTUnacCORiTTjKaDeaz5A-1; Tue, 19 Jan 2021 13:03:19 -0500 X-MC-Unique: jBTUnacCORiTTjKaDeaz5A-1 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 9F259BBEE1 for ; Tue, 19 Jan 2021 18:03:18 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-151.rdu2.redhat.com [10.10.120.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id CEF345D9DD; Tue, 19 Jan 2021 18:03:17 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v3 16/17] qapi: type 'info' as Optional[QAPISourceInfo] Date: Tue, 19 Jan 2021 13:02:41 -0500 Message-Id: <20210119180242.1570753-17-jsnow@redhat.com> In-Reply-To: <20210119180242.1570753-1-jsnow@redhat.com> References: <20210119180242.1570753-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.195, 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: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- scripts/qapi/commands.py | 2 +- scripts/qapi/events.py | 2 +- scripts/qapi/gen.py | 2 +- scripts/qapi/types.py | 2 +- scripts/qapi/visit.py | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index 13a9dcaf894..54af519f44d 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -296,7 +296,7 @@ def visit_end(self) -> None: def visit_command(self, name: str, - info: QAPISourceInfo, + info: Optional[QAPISourceInfo], ifcond: List[str], features: List[QAPISchemaFeature], arg_type: Optional[QAPISchemaObjectType], diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index 079c666ec69..8c57deb2b89 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -213,7 +213,7 @@ def visit_end(self) -> None: 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 87074335e6c..f3f4d2b011e 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -325,7 +325,7 @@ def visit_module(self, module: QAPISchemaModule) -> None: self._add_module(module.name, self._user_blurb) self._begin_user_module(module.name) - def visit_include(self, name: str, info: QAPISourceInfo) -> None: + def visit_include(self, name: str, info: Optional[QAPISourceInfo]) -> None: relname = os.path.relpath(self._module_filename(self._what, name), os.path.dirname(self._genh.fname)) self._genh.preamble_add(mcgen(''' diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index dbf58c0b91d..2bdd6268476 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -350,7 +350,7 @@ def visit_object_type(self, def visit_alternate_type(self, name: str, - info: QAPISourceInfo, + info: Optional[QAPISourceInfo], ifcond: List[str], features: List[QAPISchemaFeature], variants: QAPISchemaVariants) -> None: diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 568ba35592c..22e62df9017 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -336,7 +336,7 @@ def _begin_user_module(self, name: str) -> None: def visit_enum_type(self, name: str, - info: QAPISourceInfo, + info: Optional[QAPISourceInfo], ifcond: List[str], features: List[QAPISchemaFeature], members: List[QAPISchemaEnumMember], @@ -378,7 +378,7 @@ def visit_object_type(self, def visit_alternate_type(self, name: str, - info: QAPISourceInfo, + info: Optional[QAPISourceInfo], ifcond: List[str], features: List[QAPISchemaFeature], variants: QAPISchemaVariants) -> None: From patchwork Tue Jan 19 18:02:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 1428808 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=SWxEKUFj; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DKyby3znWz9s24 for ; Wed, 20 Jan 2021 05:58:38 +1100 (AEDT) Received: from localhost ([::1]:34854 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1wD6-0008JG-DW for incoming@patchwork.ozlabs.org; Tue, 19 Jan 2021 13:58:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42788) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1vLh-0007sN-R8 for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:40243) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l1vLf-0005UP-FU for qemu-devel@nongnu.org; Tue, 19 Jan 2021 13:03:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611079402; 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=s5opNEmjkiJr+km2yMFbUbb4Ju/cuOKo5wovOyY19nc=; b=SWxEKUFjfhK/B/zztFtJQyP+nBKP3kAHZNXRuElTjkGGaLfyqIXO/XdwBQcadOeeYYoLsL 5RY1T74wznKyBI7f0zG6qeb7a8ci9dVI4sM53A7WdyhCe+1iL5+dt+9iIS9C3hX+qUihGw S663uSSSLNg7GUL3WhqaC+2bbmvhWCM= 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-188-SR0rGFz-O0i33Q9IEiNaQA-1; Tue, 19 Jan 2021 13:03:21 -0500 X-MC-Unique: SR0rGFz-O0i33Q9IEiNaQA-1 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 2AA9E1005513 for ; Tue, 19 Jan 2021 18:03:20 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-151.rdu2.redhat.com [10.10.120.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id E71825D9E2; Tue, 19 Jan 2021 18:03:18 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v3 17/17] qapi: enable strict-optional checks Date: Tue, 19 Jan 2021 13:02:42 -0500 Message-Id: <20210119180242.1570753-18-jsnow@redhat.com> In-Reply-To: <20210119180242.1570753-1-jsnow@redhat.com> References: <20210119180242.1570753-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.195, 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: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- scripts/qapi/mypy.ini | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/qapi/mypy.ini b/scripts/qapi/mypy.ini index 74fc6c82153..04bd5db5278 100644 --- a/scripts/qapi/mypy.ini +++ b/scripts/qapi/mypy.ini @@ -1,6 +1,5 @@ [mypy] strict = True -strict_optional = False disallow_untyped_calls = False python_version = 3.6