From nobody Sun Feb 8 23:05:09 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571916328; cv=none; d=zoho.com; s=zohoarc; b=INp3EwPo4OYar7oIg6eSICZ6sIX1vYU/Uch+WVmFLPHzDlmgFmj2A96yzW87fSsekTP6f1vxy/tSgAMFbqnmrY1dbn9VPkl6eCbxNHN6ZgQ/1X1R/xk/QciWZc1PdowVp0uLhspq3QN7rvu8daALv3PyzB8ydIjKI5Ff/8s1bno= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571916328; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HNo8W5kBLPXth+ISSC7U9Yf3Hu3WHiltTwo4vNi9h2Q=; b=K57QlSf8kVc4OFYyjiJYQVHYNVOYvBoGMikrK/WdCJxIIsUAKhr3Jzclci7RzJmL8Lc+iP/9d//neRY+8XleDUotPxj5mI4ZAfL/YbypX1ulVRIAi5XoUBR4H9zUIle/ATsjExV9ns/T8RKy0UHOb2gZxXVw95pNroGFLSYlwIs= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571916328265464.3821551494194; Thu, 24 Oct 2019 04:25:28 -0700 (PDT) Received: from localhost ([::1]:39792 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNbF8-0002Bx-Uq for importer@patchew.org; Thu, 24 Oct 2019 07:25:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59341) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNatL-0000zo-0v for qemu-devel@nongnu.org; Thu, 24 Oct 2019 07:02:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNatE-0004qe-Ky for qemu-devel@nongnu.org; Thu, 24 Oct 2019 07:02:54 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:29323 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNatE-0004od-9T for qemu-devel@nongnu.org; Thu, 24 Oct 2019 07:02:48 -0400 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-158-8iBBIsdTP_qKRAsWWt5p0w-1; Thu, 24 Oct 2019 07:02:43 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 60883107AD35; Thu, 24 Oct 2019 11:02:42 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.36.118.123]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0605752DD; Thu, 24 Oct 2019 11:02:42 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 843041130348; Thu, 24 Oct 2019 13:02:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571914967; 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=HNo8W5kBLPXth+ISSC7U9Yf3Hu3WHiltTwo4vNi9h2Q=; b=Qy3rJJS2yWn5996N7bTkawpsllkOSTvb9FVKMCK8hOLlckh1/2UdovkbL3aVojGv5EP56m WTCxuIaOsCS6TvEvxdNNDx+PPEGDNs3pWOd6hYozAW0FPMa43JfR91JSHfKcFQiEDRusIF GYscBAQWSWZs5KinEfkxiBqbDOqSyDY= From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH 17/19] qapi: Lift features into QAPISchemaEntity Date: Thu, 24 Oct 2019 13:02:35 +0200 Message-Id: <20191024110237.30963-18-armbru@redhat.com> In-Reply-To: <20191024110237.30963-1-armbru@redhat.com> References: <20191024110237.30963-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: 8iBBIsdTP_qKRAsWWt5p0w-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 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: kwolf@redhat.com, pkrempa@redhat.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Commit 6a8c0b5102 "qapi: Add feature flags to struct types" added features to QAPISchemaObjectType. Commit a95daa5093 "qapi: Add feature flags to commands in qapi" added them to QAPISchemaCommand, duplicating the code. Tolerable, but the duplication will only get worse as we add features to more definitions. To de-duplicate, lift features from QAPISchemaObjectType and QAPISchemaCommand into QAPISchemaEntity. Signed-off-by: Markus Armbruster --- scripts/qapi/schema.py | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index ee510f129b..bdea9482fc 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -27,8 +27,11 @@ from qapi.parser import QAPISchemaParser class QAPISchemaEntity(object): meta =3D None =20 - def __init__(self, name, info, doc, ifcond=3DNone): + def __init__(self, name, info, doc, ifcond=3DNone, features=3DNone): assert name is None or isinstance(name, str) + for f in features or []: + assert isinstance(f, QAPISchemaFeature) + f.set_defined_in(name) self.name =3D name self._module =3D None # For explicitly defined entities, info points to the (explicit) @@ -39,6 +42,7 @@ class QAPISchemaEntity(object): self.info =3D info self.doc =3D doc self._ifcond =3D ifcond or [] + self.features =3D features or [] self._checked =3D False =20 def c_name(self): @@ -49,6 +53,10 @@ class QAPISchemaEntity(object): if self.info: self._module =3D os.path.relpath(self.info.fname, os.path.dirname(schema.fname)) + seen =3D {} + for f in self.features: + f.check_clash(self.info, seen) + self._checked =3D True =20 def connect_doc(self, doc=3DNone): @@ -307,7 +315,7 @@ class QAPISchemaObjectType(QAPISchemaType): # struct has local_members, optional base, and no variants # flat union has base, variants, and no local_members # simple union has local_members, variants, and no base - QAPISchemaType.__init__(self, name, info, doc, ifcond) + QAPISchemaType.__init__(self, name, info, doc, ifcond, features) self.meta =3D 'union' if variants else 'struct' assert base is None or isinstance(base, str) for m in local_members: @@ -316,15 +324,11 @@ class QAPISchemaObjectType(QAPISchemaType): if variants is not None: assert isinstance(variants, QAPISchemaObjectTypeVariants) variants.set_defined_in(name) - for f in features: - assert isinstance(f, QAPISchemaFeature) - f.set_defined_in(name) self._base_name =3D base self.base =3D None self.local_members =3D local_members self.variants =3D variants self.members =3D None - self.features =3D features =20 def check(self, schema): # This calls another type T's .check() exactly when the C @@ -362,11 +366,6 @@ class QAPISchemaObjectType(QAPISchemaType): self.variants.check(schema, seen) self.variants.check_clash(self.info, seen) =20 - # Features are in a name space separate from members - seen =3D {} - for f in self.features: - f.check_clash(self.info, seen) - self.members =3D members # mark completed =20 # Check that the members of this type do not cause duplicate JSON memb= ers, @@ -678,12 +677,9 @@ class QAPISchemaCommand(QAPISchemaEntity): def __init__(self, name, info, doc, ifcond, arg_type, ret_type, gen, success_response, boxed, allow_oob, allow_preconfig, features): - QAPISchemaEntity.__init__(self, name, info, doc, ifcond) + QAPISchemaEntity.__init__(self, name, info, doc, ifcond, features) assert not arg_type or isinstance(arg_type, str) assert not ret_type or isinstance(ret_type, str) - for f in features: - assert isinstance(f, QAPISchemaFeature) - f.set_defined_in(name) self._arg_type_name =3D arg_type self.arg_type =3D None self._ret_type_name =3D ret_type @@ -693,7 +689,6 @@ class QAPISchemaCommand(QAPISchemaEntity): self.boxed =3D boxed self.allow_oob =3D allow_oob self.allow_preconfig =3D allow_preconfig - self.features =3D features =20 def check(self, schema): QAPISchemaEntity.check(self, schema) @@ -723,11 +718,6 @@ class QAPISchemaCommand(QAPISchemaEntity): "command's 'returns' cannot take %s" % self.ret_type.describe()) =20 - # Features are in a name space separate from members - seen =3D {} - for f in self.features: - f.check_clash(self.info, seen) - def connect_doc(self, doc=3DNone): doc =3D doc or self.doc if doc: --=20 2.21.0