From nobody Thu Apr 25 18:03:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1678950847; cv=none; d=zohomail.com; s=zohoarc; b=XNF6uslzDA1T3Bb0XRRlFPAN1lTKc5fNtpxSUu/eYnkaUXwFDZoeM3VUnAhbPJyR/c8EDHO4S8fKKVTdvi/3qv17a9WFu9+OHDhSHn0mBOGpjdHTtP0g7CMdVGEpm9UPMWs11IM1wpcg2x4rPMs6y/fKThAs8ffEtnF1QrvUCMw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678950847; 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=aTx7L55fpeKIMQLSdfD4nXtyc19FXlrBhBi+qVAuLZU=; b=NwQz904KVWGokmezDMOK0Di91YUFuXruJpQVWANsSA83DdYRgxLi/ALztA38GcdRrI0LF+TbnesKzWaVVU+v1iOhRfUaJN4ERxXvV3G1LGBXW4wAkH1R1l3ifbtpxbDrZjfZn7JKqTpgQvMDRJJ4LNYMuQWkntV7aH1w8li9G+M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1678950847132263.75992688090366; Thu, 16 Mar 2023 00:14:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pchnw-0003lq-Oz; Thu, 16 Mar 2023 03:13:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pchns-0003j8-Tc for qemu-devel@nongnu.org; Thu, 16 Mar 2023 03:13:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pchno-0004YS-Lv for qemu-devel@nongnu.org; Thu, 16 Mar 2023 03:13:36 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-240-FB5bn1caPNmvSvuZwm5pww-1; Thu, 16 Mar 2023 03:13:27 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 190353C0F23C; Thu, 16 Mar 2023 07:13:27 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.52]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EE1AA492C3E; Thu, 16 Mar 2023 07:13:26 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id E86D321E6606; Thu, 16 Mar 2023 08:13:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678950810; 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=aTx7L55fpeKIMQLSdfD4nXtyc19FXlrBhBi+qVAuLZU=; b=YqxrpEedsqniEWS6ZzRKUibVrXY+XpVQD63yG9io/pUowfFJjgXk0GXHaob8YokMblm6eb jIa28Qp8COgMFQlKL8qLA1q8rwwO9AcaPdPeeqzsHZFyu3m9zuRnqH83GQfYbmcOLQDbfy DsjnklWKD+kmzirZAppIyqbK3n3Nt24= X-MC-Unique: FB5bn1caPNmvSvuZwm5pww-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: michael.roth@amd.com, marcandre.lureau@redhat.com, berrange@redhat.com, eblake@redhat.com, jsnow@redhat.com Subject: [PATCH 01/14] qapi: Fix error message format regression Date: Thu, 16 Mar 2023 08:13:12 +0100 Message-Id: <20230316071325.492471-2-armbru@redhat.com> In-Reply-To: <20230316071325.492471-1-armbru@redhat.com> References: <20230316071325.492471-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1678950848708100003 Content-Type: text/plain; charset="utf-8" Commit 52a474180ae3 changed reporting of errors connected to a source location without mentioning it in the commit message. For instance, $ python scripts/qapi-gen.py tests/qapi-schema/unknown-escape.json tests/qapi-schema/unknown-escape.json:3:21: unknown escape \x became scripts/qapi-gen.py: tests/qapi-schema/unknown-escape.json:3:21: unknow= n escape \x This is not how compilers report such errors, and Emacs doesn't recognize the format. Revert this change. Fixes: 52a474180ae3 (qapi-gen: Separate arg-parsing from generation) Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- scripts/qapi/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qapi/main.py b/scripts/qapi/main.py index fc216a53d3..316736b6a2 100644 --- a/scripts/qapi/main.py +++ b/scripts/qapi/main.py @@ -98,6 +98,6 @@ def main() -> int: builtins=3Dargs.builtins, gen_tracing=3Dnot args.suppress_tracing) except QAPIError as err: - print(f"{sys.argv[0]}: {str(err)}", file=3Dsys.stderr) + print(err, file=3Dsys.stderr) return 1 return 0 --=20 2.39.2 From nobody Thu Apr 25 18:03:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1678950974; cv=none; d=zohomail.com; s=zohoarc; b=a5PPQ8U8UNcSu11AXAQl7Y5N5CXFU+aMuRHP83GxMQ3BCOw2QGQHAsUCGyy+YsanxGPQk1vKmHIoUYbItNgRUY+kSTO0wIS8zz4RdURIYdFwrsHMM3OHO4RcD9j3nGLFccQLHNlT43I6NF/w4SOgl2tSAzmObw2nacJCYqEeP48= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678950974; 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=3345eteHKXxbPiz948AHTUx8tRH+sdWWNeaVU7BajRA=; b=Xdy6J0ZYiORgMPlPfyZBx7mUrOPRC+HJC9raOmQJbL6pmz/VqCekwiXRwzuhHfPOuL+L0moMpSA2EzWAiYpkyMd5urh+/8o2xt2P39rauQwz1KQ68LwyXSfcp76b+sZnLqBbuPHGDDDpz7vjn/6wzlaoy3JssVMKI8uP4zIzw3U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 167895097435491.58193233644079; Thu, 16 Mar 2023 00:16:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pcho6-0003nd-VC; Thu, 16 Mar 2023 03:13:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pchns-0003j6-R0 for qemu-devel@nongnu.org; Thu, 16 Mar 2023 03:13:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pchno-0004YV-Sf for qemu-devel@nongnu.org; Thu, 16 Mar 2023 03:13:36 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-360-uYC6OI4LPWiUvAOaMf_A6w-1; Thu, 16 Mar 2023 03:13:27 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 20B583813F44; Thu, 16 Mar 2023 07:13:27 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.52]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F380EC15BA0; Thu, 16 Mar 2023 07:13:26 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id EABDA21E6608; Thu, 16 Mar 2023 08:13:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678950811; 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=3345eteHKXxbPiz948AHTUx8tRH+sdWWNeaVU7BajRA=; b=PxNuIi9EsXgWBU27vc3z1WQIMWej8/aGkVXjRdorlDpiFzFLGpeqB54w1e6sXPZSRbKe3G DxSOLUtzniyGtTrvPWKT/AZTXncvs5LQpatKEhtdXU3f0FFztjwSQIkufOPCxDwl9ygK5Y 683uN04dUBVUOcz2XtioaMMIL39+Szs= X-MC-Unique: uYC6OI4LPWiUvAOaMf_A6w-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: michael.roth@amd.com, marcandre.lureau@redhat.com, berrange@redhat.com, eblake@redhat.com, jsnow@redhat.com Subject: [PATCH 02/14] qapi/schema: Use super() Date: Thu, 16 Mar 2023 08:13:13 +0100 Message-Id: <20230316071325.492471-3-armbru@redhat.com> In-Reply-To: <20230316071325.492471-1-armbru@redhat.com> References: <20230316071325.492471-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1678950975169100006 Content-Type: text/plain; charset="utf-8" Commit 2cae67bcb5e (qapi: Use super() now we have Python 3) converted the code to super(). Shortly after, commit f965e8fea6a (qapi: New special feature flag "deprecated") neglected to use super(). Convert it now. Signed-off-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- scripts/qapi/schema.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 207e4d71f3..719152fe49 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -259,7 +259,7 @@ def need_has_if_optional(self): return not self.c_type().endswith(POINTER_SUFFIX) =20 def check(self, schema): - QAPISchemaEntity.check(self, schema) + super().check(schema) for feat in self.features: if feat.is_special(): raise QAPISemError( --=20 2.39.2 From nobody Thu Apr 25 18:03:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1678950847; cv=none; d=zohomail.com; s=zohoarc; b=SvRCKVvwysgpzk1xYa8FKFT1eo4Bomlaqd9HSyUO31fOnnJr2zIqM/wi65lwsdKIgxTPs5lCnMryRQCb/BaPeVLyypX3WEcRTlozLQl3ZbBYgCc+voiEf/iET5WP7xRMbL1G1OHmYBJBKlcpl7AOV1XDJvvgec8nobmKfyDbfGs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678950847; 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=dCyon08GZNuo71GqM0P29omWjbczDKsa5uy94+fjclw=; b=VX2qpuPRb50M0PO4Uu2RtmXbsXZTcAi8M55LeU5ewoXCsv7d1KRn2EoXUlLxaxXBYy63g5UsmXJglby+enZjvteeqdqZr20ElvT+efE2ndy1Hloo4YRFeFVEJVPqQE3R7Yv/pLtUy+Eh4Jwt0A0Qfc3n1eN4dATWYtSXms0cac0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1678950847673184.03458972529813; Thu, 16 Mar 2023 00:14:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pchoA-0003pF-8B; Thu, 16 Mar 2023 03:13:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pchns-0003j9-UD for qemu-devel@nongnu.org; Thu, 16 Mar 2023 03:13:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pchno-0004Xr-5u for qemu-devel@nongnu.org; Thu, 16 Mar 2023 03:13:36 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-240-2OF3R9vdOuilIN1xo1VRIQ-1; Thu, 16 Mar 2023 03:13:27 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 20BF02A5955B; Thu, 16 Mar 2023 07:13:27 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.52]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F359740C6E67; Thu, 16 Mar 2023 07:13:26 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id ED07D21E66EF; Thu, 16 Mar 2023 08:13:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678950809; 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=dCyon08GZNuo71GqM0P29omWjbczDKsa5uy94+fjclw=; b=Jv+Oy4/jupKSEbUixULfK9KJfQnJqhIn4ljzzBEptaXBnV/50mxGsZi+6lWkKO584pBFbm AiZFVfoq+DowBqTwaSwxjkKSYSscaK8n1g4hKuzRauSHhLf7y2k+SQWc4PAgD13PWTYN1P vtNHphTVRK98sw0skIGUnaC1xHz7vIM= X-MC-Unique: 2OF3R9vdOuilIN1xo1VRIQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: michael.roth@amd.com, marcandre.lureau@redhat.com, berrange@redhat.com, eblake@redhat.com, jsnow@redhat.com Subject: [PATCH 03/14] qapi: Clean up after removal of simple unions Date: Thu, 16 Mar 2023 08:13:14 +0100 Message-Id: <20230316071325.492471-4-armbru@redhat.com> In-Reply-To: <20230316071325.492471-1-armbru@redhat.com> References: <20230316071325.492471-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1678950848707100002 Content-Type: text/plain; charset="utf-8" Commit 4e99f4b12c0 (qapi: Drop simple unions) missed a bit of code dealing with simple union branches. Drop it. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- scripts/qapi/expr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index ca01ea6f4a..59bdd86024 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -518,7 +518,7 @@ def check_union(expr: QAPIExpression) -> None: source =3D "'data' member '%s'" % key check_keys(value, info, source, ['type'], ['if']) check_if(value, info, source) - check_type(value['type'], info, source, allow_array=3Dnot base) + check_type(value['type'], info, source) =20 =20 def check_alternate(expr: QAPIExpression) -> None: --=20 2.39.2 From nobody Thu Apr 25 18:03:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1678950929; cv=none; d=zohomail.com; s=zohoarc; b=CADukXSWP3S0Sao241aXsNvv86O58dE0B3SOKlcNzLm/d2XvszhTwVEY86wvrUtntO+x3X/imSf7vHBcFZYJspyNbWyIi79gX6j5BNdvjMJSqIQMleX8mDPZctmymlrlQFdza202wDgHb9pwGX59FkRkaLGYjsTuBoq31yfTjiQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678950929; 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=BC4ChxiWp8BemgmqKQbdUo68On4aRvL0LpimWfx2uuo=; b=hQalahhvN0zvZMU+Ek63zn41duJT7JI79dRS17cd/xrtxCQT/LH3SRZi17/7AYTK4ecTtGye7oPbSgSse/9ysbOTzwm0PuVYnJ0T1bvrxzc/NwDQq8oAclz6n6aLQiA8tRFsmb4t5DoRAm31ErLN8UWMmFNGiuSualCFYbfzcvs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1678950929512597.713659117199; Thu, 16 Mar 2023 00:15:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pchoC-0003qJ-55; Thu, 16 Mar 2023 03:13:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pchnw-0003lt-O9 for qemu-devel@nongnu.org; Thu, 16 Mar 2023 03:13:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pchnq-0004Ye-1W for qemu-devel@nongnu.org; Thu, 16 Mar 2023 03:13:40 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-329-52cFFazyOxuwSeQ8vhOjhg-1; Thu, 16 Mar 2023 03:13:27 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3B97E101A551; Thu, 16 Mar 2023 07:13:27 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.52]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F32A4202701E; Thu, 16 Mar 2023 07:13:26 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id EF55C21E660B; Thu, 16 Mar 2023 08:13:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678950811; 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=BC4ChxiWp8BemgmqKQbdUo68On4aRvL0LpimWfx2uuo=; b=HUjhs0TNv44rOLYOkPYqCIkImDinW3Owv7MnRXGdf5r/sd+sp4/Pg0TJsQiD2bXvlCi2jy 1/SWnPJNHy9ed5P+oNz4GfPO8mLspzLU6SqzTq/67jDotgGEfFxH7kB49E0VvCPiaEbPXd vmzza56UeWlGA3tN5qTC/AbMtV27Ceg= X-MC-Unique: 52cFFazyOxuwSeQ8vhOjhg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: michael.roth@amd.com, marcandre.lureau@redhat.com, berrange@redhat.com, eblake@redhat.com, jsnow@redhat.com Subject: [PATCH 04/14] qapi: Split up check_type() Date: Thu, 16 Mar 2023 08:13:15 +0100 Message-Id: <20230316071325.492471-5-armbru@redhat.com> In-Reply-To: <20230316071325.492471-1-armbru@redhat.com> References: <20230316071325.492471-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1678950930903100001 Content-Type: text/plain; charset="utf-8" check_type() can check type names, arrays, and implicit struct types. Callers pass flags to select from this menu. This makes the function somewhat hard to read. Moreover, a few minor bugs are hiding in there, as we'll see shortly. Split it into check_type_name(), check_type_name_or_implicit(). Each of them is a copy of the original specialized to a certain set of flags. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- scripts/qapi/expr.py | 116 +++++++++++++++++++++++++------------------ 1 file changed, 67 insertions(+), 49 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 59bdd86024..bc04bf34c2 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -333,62 +333,74 @@ def normalize_members(members: object) -> None: members[key] =3D {'type': arg} =20 =20 -def check_type(value: Optional[object], - info: QAPISourceInfo, - source: str, - allow_array: bool =3D False, - allow_dict: Union[bool, str] =3D False) -> None: - """ - Normalize and validate the QAPI type of ``value``. - - Python types of ``str`` or ``None`` are always allowed. - - :param value: The value to check. - :param info: QAPI schema source file information. - :param source: Error string describing this ``value``. - :param allow_array: - Allow a ``List[str]`` of length 1, which indicates an array of - the type named by the list element. - :param allow_dict: - Allow a dict. Its members can be struct type members or union - branches. When the value of ``allow_dict`` is in pragma - ``member-name-exceptions``, the dict's keys may violate the - member naming rules. The dict members are normalized in place. - - :raise QAPISemError: When ``value`` fails validation. - :return: None, ``value`` is normalized in-place as needed. - """ +def check_type_name(value: Optional[object], + info: QAPISourceInfo, source: str) -> None: + if value is None: + return + + if isinstance(value, str): + return + + if isinstance(value, list): + raise QAPISemError(info, "%s cannot be an array" % source) + + raise QAPISemError(info, "%s should be a type name" % source) + + +def check_type_name_or_array(value: Optional[object], + info: QAPISourceInfo, source: str) -> None: if value is None: return =20 - # Type name if isinstance(value, str): return =20 - # Array type if isinstance(value, list): - if not allow_array: - raise QAPISemError(info, "%s cannot be an array" % source) if len(value) !=3D 1 or not isinstance(value[0], str): raise QAPISemError(info, "%s: array type must contain single type na= me" % source) return =20 - # Anonymous type + raise QAPISemError(info, + "%s should be a type name" % source) =20 - if not allow_dict: - raise QAPISemError(info, "%s should be a type name" % source) + +def check_type_name_or_implicit(value: Optional[object], + info: QAPISourceInfo, source: str, + parent_name: Optional[str]) -> None: + """ + Normalize and validate an optional implicit struct type. + + Accept ``None``, ``str``, or a ``dict`` defining an implicit + struct type. The latter is normalized in place. + + :param value: The value to check. + :param info: QAPI schema source file information. + :param source: Error string describing this ``value``. + :param parent_name: + When the value of ``parent_name`` is in pragma + ``member-name-exceptions``, an implicit struct type may + violate the member naming rules. + + :raise QAPISemError: When ``value`` fails validation. + :return: None + """ + if value is None: + return + + if isinstance(value, str): + return + + if isinstance(value, list): + raise QAPISemError(info, "%s cannot be an array" % source) =20 if not isinstance(value, dict): raise QAPISemError(info, "%s should be an object or type name" % source) =20 - permissive =3D False - if isinstance(allow_dict, str): - permissive =3D allow_dict in info.pragma.member_name_exceptions + permissive =3D parent_name in info.pragma.member_name_exceptions =20 - # value is a dictionary, check that each member is okay for (key, arg) in value.items(): key_source =3D "%s member '%s'" % (source, key) if key.startswith('*'): @@ -401,7 +413,7 @@ def check_type(value: Optional[object], check_keys(arg, info, key_source, ['type'], ['if', 'features']) check_if(arg, info, key_source) check_features(arg.get('features'), info) - check_type(arg['type'], info, key_source, allow_array=3DTrue) + check_type_name_or_array(arg['type'], info, key_source) =20 =20 def check_features(features: Optional[object], @@ -489,8 +501,8 @@ def check_struct(expr: QAPIExpression) -> None: name =3D cast(str, expr['struct']) # Checked in check_exprs members =3D expr['data'] =20 - check_type(members, expr.info, "'data'", allow_dict=3Dname) - check_type(expr.get('base'), expr.info, "'base'") + check_type_name_or_implicit(members, expr.info, "'data'", name) + check_type_name(expr.get('base'), expr.info, "'base'") =20 =20 def check_union(expr: QAPIExpression) -> None: @@ -508,7 +520,7 @@ def check_union(expr: QAPIExpression) -> None: members =3D expr['data'] info =3D expr.info =20 - check_type(base, info, "'base'", allow_dict=3Dname) + check_type_name_or_implicit(base, info, "'base'", name) check_name_is_str(discriminator, info, "'discriminator'") =20 if not isinstance(members, dict): @@ -518,7 +530,7 @@ def check_union(expr: QAPIExpression) -> None: source =3D "'data' member '%s'" % key check_keys(value, info, source, ['type'], ['if']) check_if(value, info, source) - check_type(value['type'], info, source) + check_type_name(value['type'], info, source) =20 =20 def check_alternate(expr: QAPIExpression) -> None: @@ -544,7 +556,7 @@ def check_alternate(expr: QAPIExpression) -> None: check_name_lower(key, info, source) check_keys(value, info, source, ['type'], ['if']) check_if(value, info, source) - check_type(value['type'], info, source, allow_array=3DTrue) + check_type_name_or_array(value['type'], info, source) =20 =20 def check_command(expr: QAPIExpression) -> None: @@ -560,10 +572,13 @@ def check_command(expr: QAPIExpression) -> None: rets =3D expr.get('returns') boxed =3D expr.get('boxed', False) =20 - if boxed and args is None: - raise QAPISemError(expr.info, "'boxed': true requires 'data'") - check_type(args, expr.info, "'data'", allow_dict=3Dnot boxed) - check_type(rets, expr.info, "'returns'", allow_array=3DTrue) + if boxed: + if args is None: + raise QAPISemError(expr.info, "'boxed': true requires 'data'") + check_type_name(args, expr.info, "'data'") + else: + check_type_name_or_implicit(args, expr.info, "'data'", None) + check_type_name_or_array(rets, expr.info, "'returns'") =20 =20 def check_event(expr: QAPIExpression) -> None: @@ -578,9 +593,12 @@ def check_event(expr: QAPIExpression) -> None: args =3D expr.get('data') boxed =3D expr.get('boxed', False) =20 - if boxed and args is None: - raise QAPISemError(expr.info, "'boxed': true requires 'data'") - check_type(args, expr.info, "'data'", allow_dict=3Dnot boxed) + if boxed: + if args is None: + raise QAPISemError(expr.info, "'boxed': true requires 'data'") + check_type_name(args, expr.info, "'data'") + else: + check_type_name_or_implicit(args, expr.info, "'data'", None) =20 =20 def check_exprs(exprs: List[QAPIExpression]) -> List[QAPIExpression]: --=20 2.39.2 From nobody Thu Apr 25 18:03:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1678950914; cv=none; d=zohomail.com; s=zohoarc; b=Ekb0EJz4UFGNBAn2xLivXdLWj2vcTrbHeMD/3tkY99ctkMBIbuGDnDOqQEc9+iSxG3XlcH+sVdiqkxvc3LKpjrhuGDzaRIn1VM7RFG+EjxMywGodOqEKdeDap3NOKtNEgsXUpwCpDesVg8WaeccYQx93o17AMb8Vf//LA5xSOzg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678950914; 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=NcyB48MUTsNeYNzfdaDmyRLIeBWZB+Bt/g8SlJWXkEg=; b=n8sJWytpM1qeU7haSzbZWH/xx+Z/Zk/ouBouQeh2Hgz0pw1aFhdL6rNZBbQhcKUB+pLjBmvezMQN/9S03R6bUzfWdw7izzC0m5kW8AtZWzvaAxFmOeVrznmZwoovbDXsTFBxVGkE+cFelC+eP0furEkCMI1h+RFbNjrTv/sDXn0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1678950914806330.4221377535647; Thu, 16 Mar 2023 00:15:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pcho0-0003mW-C0; Thu, 16 Mar 2023 03:13:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pchns-0003j4-Po for qemu-devel@nongnu.org; Thu, 16 Mar 2023 03:13:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pchno-0004YD-CO for qemu-devel@nongnu.org; Thu, 16 Mar 2023 03:13:36 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-353-OvqlNSxCNTKtOJKLb8AZig-1; Thu, 16 Mar 2023 03:13:28 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 25CE33C0F236; Thu, 16 Mar 2023 07:13:28 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.52]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0474235454; Thu, 16 Mar 2023 07:13:28 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id F1DF421E5A75; Thu, 16 Mar 2023 08:13:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678950810; 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=NcyB48MUTsNeYNzfdaDmyRLIeBWZB+Bt/g8SlJWXkEg=; b=dnuEv4rb/PUm6GK7suhgiavutqUXpEN6IP+HeADqiSuTniIV+8SLPBgOhV9P79N9t0sepe /g++SrA6KJTHOWaHH4zV+SgcwMCJKMoHWb5MFHmQb4bxTOnU0H6cRWMQ+wm6DDFKowZ2iw bSCjUTHPV0LLUyoj95VlSL90eJHkn4s= X-MC-Unique: OvqlNSxCNTKtOJKLb8AZig-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: michael.roth@amd.com, marcandre.lureau@redhat.com, berrange@redhat.com, eblake@redhat.com, jsnow@redhat.com Subject: [PATCH 05/14] qapi: Improve error message for unexpected array types Date: Thu, 16 Mar 2023 08:13:16 +0100 Message-Id: <20230316071325.492471-6-armbru@redhat.com> In-Reply-To: <20230316071325.492471-1-armbru@redhat.com> References: <20230316071325.492471-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1678950916665100001 Content-Type: text/plain; charset="utf-8" We reject array types in certain places with "cannot be an array". Deleting this check improves the error message to "should be a type name" or "should be an object or type name", depending on context, so do that. Signed-off-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- scripts/qapi/expr.py | 6 ------ tests/qapi-schema/bad-data.err | 2 +- tests/qapi-schema/union-array-branch.err | 2 +- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index bc04bf34c2..5abeaa19dd 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -341,9 +341,6 @@ def check_type_name(value: Optional[object], if isinstance(value, str): return =20 - if isinstance(value, list): - raise QAPISemError(info, "%s cannot be an array" % source) - raise QAPISemError(info, "%s should be a type name" % source) =20 =20 @@ -392,9 +389,6 @@ def check_type_name_or_implicit(value: Optional[object], if isinstance(value, str): return =20 - if isinstance(value, list): - raise QAPISemError(info, "%s cannot be an array" % source) - if not isinstance(value, dict): raise QAPISemError(info, "%s should be an object or type name" % source) diff --git a/tests/qapi-schema/bad-data.err b/tests/qapi-schema/bad-data.err index 7991c8898d..a987df4108 100644 --- a/tests/qapi-schema/bad-data.err +++ b/tests/qapi-schema/bad-data.err @@ -1,2 +1,2 @@ bad-data.json: In command 'oops': -bad-data.json:2: 'data' cannot be an array +bad-data.json:2: 'data' should be an object or type name diff --git a/tests/qapi-schema/union-array-branch.err b/tests/qapi-schema/u= nion-array-branch.err index 5db9c17481..2aa146261a 100644 --- a/tests/qapi-schema/union-array-branch.err +++ b/tests/qapi-schema/union-array-branch.err @@ -1,2 +1,2 @@ union-array-branch.json: In union 'TestUnion': -union-array-branch.json:8: 'data' member 'value1' cannot be an array +union-array-branch.json:8: 'data' member 'value1' should be a type name --=20 2.39.2 From nobody Thu Apr 25 18:03:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1678950864; cv=none; d=zohomail.com; s=zohoarc; b=SPfBdgOj9pvdJRxGOfiDg3NT2Ju+nq8OF3j9f55wUc8HUHJCaU8EcBBRWfitImRuOyLvdXpXdd7vPNAvN7ffoDWkZ9iSK9XX0yXGwipL1uMRjglRxx0aTBtUDe69vs7dVp7XTNpq6YsUtBzDo74PR3W7iPF+VylgzAVva1OtKa8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678950864; 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=VOa9B6AXBverozFLWZBZwC08lAjb4Su+j9azeXkAwgg=; b=Olt8SsvTahIIFbhjlom/pP3+C7KRX64PXy47ruwEnBbmtX6SDenlYYsBMe/tYOXRwFBMGaKmtNy8s4vlhzxnHj80+NdQI2tEZzi2mrt6U+wbmZyoeUKQ0QsV0tyAT82eKTUtp+tyc/DXCsq/KkeuY7+xBA7JK75zqEfBl2xi7EA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1678950864102876.59378412912; Thu, 16 Mar 2023 00:14:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pcho4-0003nN-VJ; Thu, 16 Mar 2023 03:13:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pchnu-0003kz-Hz for qemu-devel@nongnu.org; Thu, 16 Mar 2023 03:13:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pchnp-0004Yq-Bj for qemu-devel@nongnu.org; Thu, 16 Mar 2023 03:13:38 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-522-di3TaPT2NaCAo573pm_OkQ-1; Thu, 16 Mar 2023 03:13:28 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1D9BA185A790; Thu, 16 Mar 2023 07:13:28 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.52]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F25D61121314; Thu, 16 Mar 2023 07:13:27 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id F422B21E5A0C; Thu, 16 Mar 2023 08:13:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678950811; 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=VOa9B6AXBverozFLWZBZwC08lAjb4Su+j9azeXkAwgg=; b=EvEgaRTXI1lm7RbXksJWKVV1bbGzfIFzJ7W9+TCh3HlckptxQG4J5d3r6YYdorxrp1xx27 PFwywey/okzVoMjVeis9xAnmL2pmXSS0TXstgx4qeeD8pjCtMUfoZsRsnVO+zwaabxkqmw xEUipY4VEy5jOPeZh1UFGjj1tCfEf5Y= X-MC-Unique: di3TaPT2NaCAo573pm_OkQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: michael.roth@amd.com, marcandre.lureau@redhat.com, berrange@redhat.com, eblake@redhat.com, jsnow@redhat.com Subject: [PATCH 06/14] qapi: Simplify code a bit after previous commit Date: Thu, 16 Mar 2023 08:13:17 +0100 Message-Id: <20230316071325.492471-7-armbru@redhat.com> In-Reply-To: <20230316071325.492471-1-armbru@redhat.com> References: <20230316071325.492471-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1678950864460100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- scripts/qapi/expr.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 5abeaa19dd..8a8de9e3aa 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -335,21 +335,13 @@ def normalize_members(members: object) -> None: =20 def check_type_name(value: Optional[object], info: QAPISourceInfo, source: str) -> None: - if value is None: - return - - if isinstance(value, str): - return - - raise QAPISemError(info, "%s should be a type name" % source) + if value is not None and not isinstance(value, str): + raise QAPISemError(info, "%s should be a type name" % source) =20 =20 def check_type_name_or_array(value: Optional[object], info: QAPISourceInfo, source: str) -> None: - if value is None: - return - - if isinstance(value, str): + if value is None or isinstance(value, str): return =20 if isinstance(value, list): --=20 2.39.2 From nobody Thu Apr 25 18:03:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1678950910; cv=none; d=zohomail.com; s=zohoarc; b=MCh0a8X1EJeitvQOLZNavPLLkSfGRKpGTQ8wmy2t0pOQquomZnMH/Mo/bdsau0PU3kjl+1uR/MSgA8nUP5y69anQJh2Lw2i501QeypQ3L6r9ak45O1KBF8+KbZaF1dX/5Cp5twdOvZcdGHEnqr4wjOzLbHAOR/+uFa4XlfpQM0I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678950910; 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=EzIn+EN9FBJ/yTMAkgP33aMDYuc17XmEnemZLe3fTb4=; b=nSSZKynySGw5ejZhkp3KiOkOjD2mH9Mxg6mRtxQH6J3fx9dRiqlwKgV3nslxNnbVaBRaB4RBWumEahtJr+3YCPhJVf1aVYB5/lYVriHwlW8Ad1aQEyDokw8nNU372993x6QgivijKAumCzMjPg+EkxHFiDasvB+8WTf8UKmkJ7A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1678950910704438.89794166880006; Thu, 16 Mar 2023 00:15:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pchoD-0003rW-BD; Thu, 16 Mar 2023 03:13:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pchnu-0003l3-My for qemu-devel@nongnu.org; Thu, 16 Mar 2023 03:13:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pchnp-0004Yt-BA for qemu-devel@nongnu.org; Thu, 16 Mar 2023 03:13:38 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-473-RcKP6MRnPwyta9FXGZwHbQ-1; Thu, 16 Mar 2023 03:13:28 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 20F8E85A5A3; Thu, 16 Mar 2023 07:13:28 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.52]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 00646202701F; Thu, 16 Mar 2023 07:13:28 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 0257621E4AA7; Thu, 16 Mar 2023 08:13:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678950811; 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=EzIn+EN9FBJ/yTMAkgP33aMDYuc17XmEnemZLe3fTb4=; b=KIRN+ru+pabqNpB+vScGkKDJNSDA06RWl/FoeNNnKxl3vXl676wPIrlMYPZmmn5ADjIKZq zuko+xRiVLqtK8jb5XTJnQCtz2P0HSRY7vg901ip1pSls+b0079zbGgfnRpzbyXaBzRYca X/i1OmAnL5uw1TMU26qoHZixxIWAzOU= X-MC-Unique: RcKP6MRnPwyta9FXGZwHbQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: michael.roth@amd.com, marcandre.lureau@redhat.com, berrange@redhat.com, eblake@redhat.com, jsnow@redhat.com Subject: [PATCH 07/14] qapi: Fix error message when type name or array is expected Date: Thu, 16 Mar 2023 08:13:18 +0100 Message-Id: <20230316071325.492471-8-armbru@redhat.com> In-Reply-To: <20230316071325.492471-1-armbru@redhat.com> References: <20230316071325.492471-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1678950912663100001 Content-Type: text/plain; charset="utf-8" We incorrectly report "FOO should be a type name" when it could also be an array. Fix that. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- scripts/qapi/expr.py | 15 +++++++-------- tests/qapi-schema/event-nest-struct.err | 2 +- tests/qapi-schema/nested-struct-data.err | 2 +- tests/qapi-schema/returns-dict.err | 2 +- tests/qapi-schema/struct-member-invalid.err | 2 +- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 8a8de9e3aa..9bae500a7d 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -344,15 +344,14 @@ def check_type_name_or_array(value: Optional[object], if value is None or isinstance(value, str): return =20 - if isinstance(value, list): - if len(value) !=3D 1 or not isinstance(value[0], str): - raise QAPISemError(info, - "%s: array type must contain single type na= me" % - source) - return + if not isinstance(value, list): + raise QAPISemError(info, + "%s should be a type name or array" % source) =20 - raise QAPISemError(info, - "%s should be a type name" % source) + if len(value) !=3D 1 or not isinstance(value[0], str): + raise QAPISemError(info, + "%s: array type must contain single type name" % + source) =20 =20 def check_type_name_or_implicit(value: Optional[object], diff --git a/tests/qapi-schema/event-nest-struct.err b/tests/qapi-schema/ev= ent-nest-struct.err index 8c5f6ed311..15fc1406f8 100644 --- a/tests/qapi-schema/event-nest-struct.err +++ b/tests/qapi-schema/event-nest-struct.err @@ -1,2 +1,2 @@ event-nest-struct.json: In event 'EVENT_A': -event-nest-struct.json:1: 'data' member 'a' should be a type name +event-nest-struct.json:1: 'data' member 'a' should be a type name or array diff --git a/tests/qapi-schema/nested-struct-data.err b/tests/qapi-schema/n= ested-struct-data.err index c7258a0182..7dc5c7cb2d 100644 --- a/tests/qapi-schema/nested-struct-data.err +++ b/tests/qapi-schema/nested-struct-data.err @@ -1,2 +1,2 @@ nested-struct-data.json: In command 'foo': -nested-struct-data.json:2: 'data' member 'a' should be a type name +nested-struct-data.json:2: 'data' member 'a' should be a type name or array diff --git a/tests/qapi-schema/returns-dict.err b/tests/qapi-schema/returns= -dict.err index 9b2d90c010..bf160e754b 100644 --- a/tests/qapi-schema/returns-dict.err +++ b/tests/qapi-schema/returns-dict.err @@ -1,2 +1,2 @@ returns-dict.json: In command 'oops': -returns-dict.json:2: 'returns' should be a type name +returns-dict.json:2: 'returns' should be a type name or array diff --git a/tests/qapi-schema/struct-member-invalid.err b/tests/qapi-schem= a/struct-member-invalid.err index 7e01a41d7c..3130d69d9f 100644 --- a/tests/qapi-schema/struct-member-invalid.err +++ b/tests/qapi-schema/struct-member-invalid.err @@ -1,2 +1,2 @@ struct-member-invalid.json: In struct 'Foo': -struct-member-invalid.json:1: 'data' member 'a' should be a type name +struct-member-invalid.json:1: 'data' member 'a' should be a type name or a= rray --=20 2.39.2 From nobody Thu Apr 25 18:03:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1678950881; cv=none; d=zohomail.com; s=zohoarc; b=I1Ce/35dASlpWUvaVAmBPHj/4YenbNS0hnjsCGCLjslSd7DmrImdz+TgFz9rujT/SlIFZnRn/chootu4iZZHgl1YbB0h+DvjZGoz7A1JHaAS6M3AGHn7dDCAs3S+La5ce3GLiUPzd6p4WE41pYHgdCv91+n+vQW2Mhn/qfsN6tc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678950881; 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=M0fj5pOWzxFBQFdmDJzDYU6gnKmvzNCNk58+rvBvOjw=; b=FWL323g+1oZO7MA+S58w3xlTZvc0WVVV6ui4YFrzNbNkAwiBT5RCaCPlxa7YfZ8GKr55ZopcyDbVoCLFvRk8R2Tt+9XWET1pnDjmSqn+PGwch9EHpo0FaQrcuQaz32oFgRV/QFY8v8P+fZsz0cY53WGH6/u3ziQ0a1jI4eLq6Cs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1678950881162225.30974230573588; Thu, 16 Mar 2023 00:14:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pchoB-0003pz-T5; Thu, 16 Mar 2023 03:13:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pchnt-0003jE-2x for qemu-devel@nongnu.org; Thu, 16 Mar 2023 03:13:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pchno-0004YR-G7 for qemu-devel@nongnu.org; Thu, 16 Mar 2023 03:13:36 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-8-O7IE0CJKPuSg6Wb88bdLpA-1; Thu, 16 Mar 2023 03:13:28 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3C2E996DC83; Thu, 16 Mar 2023 07:13:28 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.52]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 025802166B29; Thu, 16 Mar 2023 07:13:28 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 049B221E4AA8; Thu, 16 Mar 2023 08:13:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678950810; 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=M0fj5pOWzxFBQFdmDJzDYU6gnKmvzNCNk58+rvBvOjw=; b=Fp30SRnu7C6iq0Auv7l9dbAHzRPw4gt2J5Eif+sNIE4s6qu/ciFitzVrhzQwepxW67UNbQ Vb0AhiTV+ngAorLo0EXs/NHj1dV7eHpiC2dDrACzYFYfnG6NCE/aWogBsgGzoZK8F8JJkQ IrWg6uguXjmvw6+3f2rg4QyObV5xHWs= X-MC-Unique: O7IE0CJKPuSg6Wb88bdLpA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: michael.roth@amd.com, marcandre.lureau@redhat.com, berrange@redhat.com, eblake@redhat.com, jsnow@redhat.com Subject: [PATCH 08/14] qapi: Fix to reject 'data': 'mumble' in struct Date: Thu, 16 Mar 2023 08:13:19 +0100 Message-Id: <20230316071325.492471-9-armbru@redhat.com> In-Reply-To: <20230316071325.492471-1-armbru@redhat.com> References: <20230316071325.492471-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1678950882557100001 Content-Type: text/plain; charset="utf-8" A struct's 'data' must be a JSON object defining the struct's members. The QAPI code generator incorrectly accepts a JSON string instead, and then crashes in QAPISchema._make_members() called from ._def_struct_type(). Fix to reject it, and add a test case. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- scripts/qapi/expr.py | 24 +++++++++++++-------- tests/qapi-schema/meson.build | 1 + tests/qapi-schema/struct-data-typename.err | 2 ++ tests/qapi-schema/struct-data-typename.json | 2 ++ tests/qapi-schema/struct-data-typename.out | 0 5 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 tests/qapi-schema/struct-data-typename.err create mode 100644 tests/qapi-schema/struct-data-typename.json create mode 100644 tests/qapi-schema/struct-data-typename.out diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 9bae500a7d..cae0a08359 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -354,14 +354,14 @@ def check_type_name_or_array(value: Optional[object], source) =20 =20 -def check_type_name_or_implicit(value: Optional[object], - info: QAPISourceInfo, source: str, - parent_name: Optional[str]) -> None: +def check_type_implicit(value: Optional[object], + info: QAPISourceInfo, source: str, + parent_name: Optional[str]) -> None: """ Normalize and validate an optional implicit struct type. =20 - Accept ``None``, ``str``, or a ``dict`` defining an implicit - struct type. The latter is normalized in place. + Accept ``None`` or a ``dict`` defining an implicit struct type. + The latter is normalized in place. =20 :param value: The value to check. :param info: QAPI schema source file information. @@ -377,9 +377,6 @@ def check_type_name_or_implicit(value: Optional[object], if value is None: return =20 - if isinstance(value, str): - return - if not isinstance(value, dict): raise QAPISemError(info, "%s should be an object or type name" % source) @@ -401,6 +398,15 @@ def check_type_name_or_implicit(value: Optional[object= ], check_type_name_or_array(arg['type'], info, key_source) =20 =20 +def check_type_name_or_implicit(value: Optional[object], + info: QAPISourceInfo, source: str, + parent_name: Optional[str]) -> None: + if value is None or isinstance(value, str): + return + + check_type_implicit(value, info, source, parent_name) + + def check_features(features: Optional[object], info: QAPISourceInfo) -> None: """ @@ -486,7 +492,7 @@ def check_struct(expr: QAPIExpression) -> None: name =3D cast(str, expr['struct']) # Checked in check_exprs members =3D expr['data'] =20 - check_type_name_or_implicit(members, expr.info, "'data'", name) + check_type_implicit(members, expr.info, "'data'", name) check_type_name(expr.get('base'), expr.info, "'base'") =20 =20 diff --git a/tests/qapi-schema/meson.build b/tests/qapi-schema/meson.build index d85b14f28c..f88110bddf 100644 --- a/tests/qapi-schema/meson.build +++ b/tests/qapi-schema/meson.build @@ -164,6 +164,7 @@ schemas =3D [ 'struct-base-clash-deep.json', 'struct-base-clash.json', 'struct-data-invalid.json', + 'struct-data-typename.json', 'struct-member-if-invalid.json', 'struct-member-invalid-dict.json', 'struct-member-invalid.json', diff --git a/tests/qapi-schema/struct-data-typename.err b/tests/qapi-schema= /struct-data-typename.err new file mode 100644 index 0000000000..8fbfe99a42 --- /dev/null +++ b/tests/qapi-schema/struct-data-typename.err @@ -0,0 +1,2 @@ +struct-data-typename.json: In struct 'Stru2': +struct-data-typename.json:2: 'data' should be an object or type name diff --git a/tests/qapi-schema/struct-data-typename.json b/tests/qapi-schem= a/struct-data-typename.json new file mode 100644 index 0000000000..70fbad0ee4 --- /dev/null +++ b/tests/qapi-schema/struct-data-typename.json @@ -0,0 +1,2 @@ +{ 'struct': 'Stru1', 'data': {} } +{ 'struct': 'Stru2', 'data': 'Stru1' } diff --git a/tests/qapi-schema/struct-data-typename.out b/tests/qapi-schema= /struct-data-typename.out new file mode 100644 index 0000000000..e69de29bb2 --=20 2.39.2 From nobody Thu Apr 25 18:03:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1678950974; cv=none; d=zohomail.com; s=zohoarc; b=JYXy8IQaIIRKzlhmgzgUJSrMMp4ohAmATD+WL02tRR01xz19ZSjbfkunKFeFfGgDPbeMVu4sInWR9FRIaDfhA/0wGfSSUvk1jK1kGcUXKBdtHeygvyhT7IzBMVTrPRsnYHiI3HgTN1p9KJH65amLoTlifOGpBNggRtSaXzJdIE4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678950974; 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=nngGE3EOQWa1ao4eWS6VZ/buG97D+phPC51W5Tj9TJg=; b=biPAcYPFn36xbn5tMwViLt9qyGyK7jyzuXIs6sC0X0hTOO7C9Q3iovv1SBa3rWHl3uKzfg1y63XwQ+rLVejXkqaiS6S7ycEzpt6oXnpyTCqrHzaCiqn441Nd7TFyHtwi1kHkk6v8PKP45hiPhvL3JbnjkP7bdLxxdXL02lwsdFg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1678950974632993.5096266329324; Thu, 16 Mar 2023 00:16:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pcho6-0003nQ-7U; Thu, 16 Mar 2023 03:13:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pchnu-0003lD-No for qemu-devel@nongnu.org; Thu, 16 Mar 2023 03:13:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pchno-0004YL-Gd for qemu-devel@nongnu.org; Thu, 16 Mar 2023 03:13:38 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-473-aVHm0YGyO8Gn2J08VsRWcw-1; Thu, 16 Mar 2023 03:13:28 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 225C3811E7B; Thu, 16 Mar 2023 07:13:28 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.52]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 02CA3492C3E; Thu, 16 Mar 2023 07:13:28 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 06D6421E4AA9; Thu, 16 Mar 2023 08:13:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678950810; 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=nngGE3EOQWa1ao4eWS6VZ/buG97D+phPC51W5Tj9TJg=; b=RX3AZXmpVOIMF8uGw8M7nxHxVphZofn15/U5Ca6HcumTppTIXuRI6iy+9jmDiZNlo8HSdH 3ZYed5WQgZret2+ZF8MviPch8bqmCLFg3Nu07PeXtlwjEDku2ESZUtLiWeYnDiWCM1EANd D52ctHj43Nvd/A0xJyxBzMWP9jpdmCU= X-MC-Unique: aVHm0YGyO8Gn2J08VsRWcw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: michael.roth@amd.com, marcandre.lureau@redhat.com, berrange@redhat.com, eblake@redhat.com, jsnow@redhat.com Subject: [PATCH 09/14] tests/qapi-schema: Improve union discriminator coverage Date: Thu, 16 Mar 2023 08:13:20 +0100 Message-Id: <20230316071325.492471-10-armbru@redhat.com> In-Reply-To: <20230316071325.492471-1-armbru@redhat.com> References: <20230316071325.492471-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1678950975167100005 Content-Type: text/plain; charset="utf-8" A union's 'discriminator' must name a one of the common members. QAPISchemaVariants.check() looks it up by its c_name(), then checks the name matches exactly (because c_name() is not injective). Tests union-base-empty and union-invalid-discriminator both cover the case where lookup fails. Repurpose the latter to cover the case where it succeeds and the name check fails. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- tests/qapi-schema/union-invalid-discriminator.err | 2 +- tests/qapi-schema/union-invalid-discriminator.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/qapi-schema/union-invalid-discriminator.err b/tests/qapi= -schema/union-invalid-discriminator.err index 38efb24b98..6bd774c156 100644 --- a/tests/qapi-schema/union-invalid-discriminator.err +++ b/tests/qapi-schema/union-invalid-discriminator.err @@ -1,2 +1,2 @@ union-invalid-discriminator.json: In union 'TestUnion': -union-invalid-discriminator.json:10: discriminator 'enum_wrong' is not a m= ember of 'base' +union-invalid-discriminator.json:10: discriminator 'type_tag' is not a mem= ber of 'base' diff --git a/tests/qapi-schema/union-invalid-discriminator.json b/tests/qap= i-schema/union-invalid-discriminator.json index c4fce97362..f315f36e37 100644 --- a/tests/qapi-schema/union-invalid-discriminator.json +++ b/tests/qapi-schema/union-invalid-discriminator.json @@ -8,7 +8,7 @@ 'data': { 'integer': 'int' } } =20 { 'union': 'TestUnion', - 'base': { 'enum1': 'TestEnum' }, - 'discriminator': 'enum_wrong', + 'base': { 'type-tag': 'TestEnum' }, + 'discriminator': 'type_tag', 'data': { 'value1': 'TestTypeA', 'value2': 'TestTypeB' } } --=20 2.39.2 From nobody Thu Apr 25 18:03:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1678950947; cv=none; d=zohomail.com; s=zohoarc; b=kMh0RwKFPIwLSmVXl38N6PreEzHNsd2jLv6Czz89FcKWtmFENriidk78p1y0q+WQRN38zBv1mu/7CnRIId7UQl//bMztmhIU4KKaw84aEyFUFyUd34C2XjVZoVtbM1dhcWzOK+NWaOttMq9i8qvY+JdKDAtf5XurTcGNYmN+g7Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678950947; 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=6AfFzV5B9lGJ6or40+GPBARbOc+NqTh7f4yEJp/sx9o=; b=iXmiIws6dpQZj3yFiBwSKIUoBkjMV/e5QfH+x0fhFyNz0PXRpAGLwFJmUU0rZDvwiBmzVXa4VJPzhnMPx08iwkUSq+MzEGsLIgvqx/VMv7k7TGZYANMlbA1CizcqZwhd8T6bFW+/B4fHtAmwXZOZD0N/XbRxzz/cT0LA4Q1ptSg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1678950947518613.4948683985698; Thu, 16 Mar 2023 00:15:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pcho7-0003oH-QV; Thu, 16 Mar 2023 03:13:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pchnw-0003ls-O9 for qemu-devel@nongnu.org; Thu, 16 Mar 2023 03:13:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pchnq-0004ZU-9b for qemu-devel@nongnu.org; Thu, 16 Mar 2023 03:13:40 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-399-bO1DifA1M3KJ6zV6tS7NFA-1; Thu, 16 Mar 2023 03:13:29 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 47F6A101A531; Thu, 16 Mar 2023 07:13:28 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.52]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0C2DC4042AC2; Thu, 16 Mar 2023 07:13:28 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 0909621E479B; Thu, 16 Mar 2023 08:13:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678950813; 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=6AfFzV5B9lGJ6or40+GPBARbOc+NqTh7f4yEJp/sx9o=; b=UFUUp2WeEwlrZyvJZ5CqEMzNqtt9o+lTSixp4VU0Wh6ELXL1xodoIoVExhnbb7sZEyqdxx YUI0jN9O01b6gML0WUbtxL4GxlD3TGi62NYv1/99NPTXuCn82jc41mEU/lH/TkEQ0UCtAs WX2kxpa3bpDknpWqSokKn4Cg6l4xQL4= X-MC-Unique: bO1DifA1M3KJ6zV6tS7NFA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: michael.roth@amd.com, marcandre.lureau@redhat.com, berrange@redhat.com, eblake@redhat.com, jsnow@redhat.com Subject: [PATCH 10/14] tests/qapi-schema: Rename a few conditionals Date: Thu, 16 Mar 2023 08:13:21 +0100 Message-Id: <20230316071325.492471-11-armbru@redhat.com> In-Reply-To: <20230316071325.492471-1-armbru@redhat.com> References: <20230316071325.492471-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1678950949029100002 Content-Type: text/plain; charset="utf-8" Positive test case { 'enum': 'TestIfEnum', 'data': [ 'foo', { 'name' : 'bar', 'if': 'TEST_IF_ENUM_BAR' } ], 'if': 'TEST_IF_ENUM' } generates #if defined(TEST_IF_ENUM) typedef enum TestIfEnum { TEST_IF_ENUM_FOO, #if defined(TEST_IF_ENUM_BAR) TEST_IF_ENUM_BAR, #endif /* defined(TEST_IF_ENUM_BAR) */ TEST_IF_ENUM__MAX, } TestIfEnum; Macro TEST_IF_ENUM_BAR clashes with the enumeration constant. Wouldn't compile with -DTEST_IF_BAR. Rename the macro to TEST_IF_ENUM_MEMBER. For consistency, rename similar macros elsewhere as well. Signed-off-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- tests/qapi-schema/qapi-schema-test.json | 12 ++++++------ tests/qapi-schema/qapi-schema-test.out | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index ba7302f42b..5728d4de38 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -220,18 +220,18 @@ =20 { 'struct': 'TestIfStruct', 'data': { 'foo': 'int', - 'bar': { 'type': 'int', 'if': 'TEST_IF_STRUCT_BAR'} }, + 'bar': { 'type': 'int', 'if': 'TEST_IF_STRUCT_MEMBER'} }, 'if': 'TEST_IF_STRUCT' } =20 { 'enum': 'TestIfEnum', - 'data': [ 'foo', { 'name' : 'bar', 'if': 'TEST_IF_ENUM_BAR' } ], + 'data': [ 'foo', { 'name' : 'bar', 'if': 'TEST_IF_ENUM_MEMBER' } ], 'if': 'TEST_IF_ENUM' } =20 { 'union': 'TestIfUnion', 'base': { 'type': 'TestIfEnum' }, 'discriminator': 'type', 'data': { 'foo': 'TestStruct', - 'bar': { 'type': 'UserDefZero', 'if': 'TEST_IF_ENUM_BAR'} }, + 'bar': { 'type': 'UserDefZero', 'if': 'TEST_IF_ENUM_MEMBER'} }, 'if': { 'all': ['TEST_IF_UNION', 'TEST_IF_STRUCT'] } } =20 { 'command': 'test-if-union-cmd', @@ -240,7 +240,7 @@ =20 { 'alternate': 'TestIfAlternate', 'data': { 'foo': 'int', - 'bar': { 'type': 'TestStruct', 'if': 'TEST_IF_ALT_BAR'} }, + 'bar': { 'type': 'TestStruct', 'if': 'TEST_IF_ALT_MEMBER'} }, 'if': { 'all': ['TEST_IF_ALT', 'TEST_IF_STRUCT'] } } =20 { 'command': 'test-if-alternate-cmd', @@ -250,7 +250,7 @@ { 'command': 'test-if-cmd', 'data': { 'foo': 'TestIfStruct', - 'bar': { 'type': 'TestIfEnum', 'if': 'TEST_IF_CMD_BAR' } }, + 'bar': { 'type': 'TestIfEnum', 'if': 'TEST_IF_CMD_ARG' } }, 'returns': 'UserDefThree', 'if': { 'all': ['TEST_IF_CMD', 'TEST_IF_STRUCT'] } } =20 @@ -258,7 +258,7 @@ =20 { 'event': 'TEST_IF_EVENT', 'data': { 'foo': 'TestIfStruct', - 'bar': { 'type': ['TestIfEnum'], 'if': 'TEST_IF_EVT_BAR' } }, + 'bar': { 'type': ['TestIfEnum'], 'if': 'TEST_IF_EVT_ARG' } }, 'if': { 'all': ['TEST_IF_EVT', 'TEST_IF_STRUCT'] } } =20 { 'event': 'TEST_IF_EVENT2', 'data': {}, diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 043d75c655..cbd96f0b24 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -246,12 +246,12 @@ command __org.qemu_x-command q_obj___org.qemu_x-comma= nd-arg -> None object TestIfStruct member foo: int optional=3DFalse member bar: int optional=3DFalse - if TEST_IF_STRUCT_BAR + if TEST_IF_STRUCT_MEMBER if TEST_IF_STRUCT enum TestIfEnum member foo member bar - if TEST_IF_ENUM_BAR + if TEST_IF_ENUM_MEMBER if TEST_IF_ENUM object q_obj_TestIfUnion-base member type: TestIfEnum optional=3DFalse @@ -261,7 +261,7 @@ object TestIfUnion tag type case foo: TestStruct case bar: UserDefZero - if TEST_IF_ENUM_BAR + if TEST_IF_ENUM_MEMBER if {'all': ['TEST_IF_UNION', 'TEST_IF_STRUCT']} object q_obj_test-if-union-cmd-arg member union-cmd-arg: TestIfUnion optional=3DFalse @@ -273,7 +273,7 @@ alternate TestIfAlternate tag type case foo: int case bar: TestStruct - if TEST_IF_ALT_BAR + if TEST_IF_ALT_MEMBER if {'all': ['TEST_IF_ALT', 'TEST_IF_STRUCT']} object q_obj_test-if-alternate-cmd-arg member alt-cmd-arg: TestIfAlternate optional=3DFalse @@ -284,7 +284,7 @@ command test-if-alternate-cmd q_obj_test-if-alternate-c= md-arg -> None object q_obj_test-if-cmd-arg member foo: TestIfStruct optional=3DFalse member bar: TestIfEnum optional=3DFalse - if TEST_IF_CMD_BAR + if TEST_IF_CMD_ARG if {'all': ['TEST_IF_CMD', 'TEST_IF_STRUCT']} command test-if-cmd q_obj_test-if-cmd-arg -> UserDefThree gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse @@ -296,7 +296,7 @@ array TestIfEnumList TestIfEnum object q_obj_TEST_IF_EVENT-arg member foo: TestIfStruct optional=3DFalse member bar: TestIfEnumList optional=3DFalse - if TEST_IF_EVT_BAR + if TEST_IF_EVT_ARG if {'all': ['TEST_IF_EVT', 'TEST_IF_STRUCT']} event TEST_IF_EVENT q_obj_TEST_IF_EVENT-arg boxed=3DFalse --=20 2.39.2 From nobody Thu Apr 25 18:03:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1678950948; cv=none; d=zohomail.com; s=zohoarc; b=aE/Go4WPId94R1U9Ve4upJDKtfT3T164CxclDRzPOF2LFYMfTQnSOpZEIo0ndlxOAvcEh2hLo+DeaZ4FjhX3X8uTDGqboOPB1xLcCRco7c+FhmExAopFKpQhYeiFHrPvcMCJF3X1n445yH1AvjRmLgIhNpHpfa70knM+g/39EXE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678950948; 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=bw693/5+zEmbAtqd6hWLlQEBYhJ+xeFumdoRWRorwd4=; b=OBeqNU6mvklS5AVsRHwRtkOltFXiW73zyFDILHxNFIAdKhNRoeiYY5Bkd7Ty5iWhG0n2qt+jML/SOjRUryxGOV6f6R6X0yO4zp8UtWXOIOvD8UI6V83oaZe3r+jhHLQ02Uhz7uT7ZL8jBcMtijOfIs1nNcHvAe1T0asXfIkTXdU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1678950948633218.45915445766195; Thu, 16 Mar 2023 00:15:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pchnu-0003kj-I0; Thu, 16 Mar 2023 03:13:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pchnq-0003h2-UN for qemu-devel@nongnu.org; Thu, 16 Mar 2023 03:13:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pchno-0004YJ-CE for qemu-devel@nongnu.org; Thu, 16 Mar 2023 03:13:34 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-8-oCYnbcGTMUSmbtGYNpfQpQ-1; Thu, 16 Mar 2023 03:13:28 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2A9EE800B23; Thu, 16 Mar 2023 07:13:28 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.52]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0A9C135453; Thu, 16 Mar 2023 07:13:28 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 0B49B21E479C; Thu, 16 Mar 2023 08:13:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678950810; 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=bw693/5+zEmbAtqd6hWLlQEBYhJ+xeFumdoRWRorwd4=; b=HUWYVBNIQkG+TjURJuEek+Maz/pLCYTt/38aTYQzP1h1nDKzcrhfoAWOnS4Ltetlsnfwgq i4bA3Ym/9mnyYKWjVFL1uEqZqO28//Qq8xwkd18Jji29LHTqKEUQ877J8lPTlhlvmaOJ4x b3lZqBh7w4uwnmPpFrQPd9N/oSZpBak= X-MC-Unique: oCYnbcGTMUSmbtGYNpfQpQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: michael.roth@amd.com, marcandre.lureau@redhat.com, berrange@redhat.com, eblake@redhat.com, jsnow@redhat.com Subject: [PATCH 11/14] tests/qapi-schema: Clean up positive test for conditionals Date: Thu, 16 Mar 2023 08:13:22 +0100 Message-Id: <20230316071325.492471-12-armbru@redhat.com> In-Reply-To: <20230316071325.492471-1-armbru@redhat.com> References: <20230316071325.492471-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1678950949026100001 Content-Type: text/plain; charset="utf-8" Union TestIfUnion is conditional on macros TEST_IF_UNION and TEST_IF_STRUCT. It uses TestIfEnum, which is conditional on macro TEST_IF_ENUM. If TEST_IF_ENUM and TEST_IF_STRUCT are defined, but TEST_IF_ENUM isn't, the generated code won't compile. Command test-if-cmd is conditional an macros TEST_IF_CMD and TEST_IF_STRUCT, and uses TestIfEnum. Similar issue. Event TEST_IF_EVENT is conditional an macros TEST_IF_EVT and TEST_IF_STRUCT, and uses TestIfEnum. Similar issue. Replace the uses of TestIfEnum in the latter two by str. TestIfUnion is now TestIfEnum's only user. Change TestIfEnum's condition to TEST_IF_UNION. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- tests/qapi-schema/qapi-schema-test.json | 6 +++--- tests/qapi-schema/qapi-schema-test.out | 8 +++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index 5728d4de38..8f0ee95d23 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -225,7 +225,7 @@ =20 { 'enum': 'TestIfEnum', 'data': [ 'foo', { 'name' : 'bar', 'if': 'TEST_IF_ENUM_MEMBER' } ], - 'if': 'TEST_IF_ENUM' } + 'if': 'TEST_IF_UNION' } =20 { 'union': 'TestIfUnion', 'base': { 'type': 'TestIfEnum' }, @@ -250,7 +250,7 @@ { 'command': 'test-if-cmd', 'data': { 'foo': 'TestIfStruct', - 'bar': { 'type': 'TestIfEnum', 'if': 'TEST_IF_CMD_ARG' } }, + 'bar': { 'type': 'str', 'if': 'TEST_IF_CMD_ARG' } }, 'returns': 'UserDefThree', 'if': { 'all': ['TEST_IF_CMD', 'TEST_IF_STRUCT'] } } =20 @@ -258,7 +258,7 @@ =20 { 'event': 'TEST_IF_EVENT', 'data': { 'foo': 'TestIfStruct', - 'bar': { 'type': ['TestIfEnum'], 'if': 'TEST_IF_EVT_ARG' } }, + 'bar': { 'type': ['str'], 'if': 'TEST_IF_EVT_ARG' } }, 'if': { 'all': ['TEST_IF_EVT', 'TEST_IF_STRUCT'] } } =20 { 'event': 'TEST_IF_EVENT2', 'data': {}, diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index cbd96f0b24..715f3a3f23 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -252,7 +252,7 @@ enum TestIfEnum member foo member bar if TEST_IF_ENUM_MEMBER - if TEST_IF_ENUM + if TEST_IF_UNION object q_obj_TestIfUnion-base member type: TestIfEnum optional=3DFalse if {'all': ['TEST_IF_UNION', 'TEST_IF_STRUCT']} @@ -283,7 +283,7 @@ command test-if-alternate-cmd q_obj_test-if-alternate-c= md-arg -> None if {'all': ['TEST_IF_ALT', 'TEST_IF_STRUCT']} object q_obj_test-if-cmd-arg member foo: TestIfStruct optional=3DFalse - member bar: TestIfEnum optional=3DFalse + member bar: str optional=3DFalse if TEST_IF_CMD_ARG if {'all': ['TEST_IF_CMD', 'TEST_IF_STRUCT']} command test-if-cmd q_obj_test-if-cmd-arg -> UserDefThree @@ -291,11 +291,9 @@ command test-if-cmd q_obj_test-if-cmd-arg -> UserDefTh= ree if {'all': ['TEST_IF_CMD', 'TEST_IF_STRUCT']} command test-cmd-return-def-three None -> UserDefThree gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse -array TestIfEnumList TestIfEnum - if TEST_IF_ENUM object q_obj_TEST_IF_EVENT-arg member foo: TestIfStruct optional=3DFalse - member bar: TestIfEnumList optional=3DFalse + member bar: strList optional=3DFalse if TEST_IF_EVT_ARG if {'all': ['TEST_IF_EVT', 'TEST_IF_STRUCT']} event TEST_IF_EVENT q_obj_TEST_IF_EVENT-arg --=20 2.39.2 From nobody Thu Apr 25 18:03:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1678950916; cv=none; d=zohomail.com; s=zohoarc; b=FBkSrDiVnJPyoHDjBJpXqJjXU3QW12Fvz0+dYwM2qyoW+xJo6J52y3fSCkKtwpkUFr5xIKSTYQ46VqjyNyIFS7W+/jjZfvDLplyKA4mtgSHW0yevj+uYPq1K42LLCxuzJuyTR92d7xOjCqu2+VhcmFFVPodZhcjr1fM5salW4N0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678950916; 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=y3RGgon6mQxy3kqt5Bg8manIx6MhIABbBysqLNQDdBU=; b=T/2ElnIkCHSuP8htpj6wLT4nVas4B8iBF+Rr2zCvu247oMkkaRv5XH6zep/DmeC/0cNcca7Us7MbXIOL8FfI1CYyMwd5muoYQ9U35TYrfRkA44Jas0hS9WYTb6yaSraD+jNfUGT+6DkddT6W3KMvtYGfFn25aqFvCyBieMyooe4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1678950916922177.64073545506983; Thu, 16 Mar 2023 00:15:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pchoC-0003qr-KT; Thu, 16 Mar 2023 03:13:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pchnu-0003l6-Ly for qemu-devel@nongnu.org; Thu, 16 Mar 2023 03:13:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pchnp-0004Z7-DG for qemu-devel@nongnu.org; Thu, 16 Mar 2023 03:13:38 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-473-65CMKaNEOwGrPDqms6Nqbg-1; Thu, 16 Mar 2023 03:13:28 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2F53D85A5B1; Thu, 16 Mar 2023 07:13:28 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.52]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0F39C140E95F; Thu, 16 Mar 2023 07:13:28 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 0D84F21F4F7D; Thu, 16 Mar 2023 08:13:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678950812; 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=y3RGgon6mQxy3kqt5Bg8manIx6MhIABbBysqLNQDdBU=; b=J/StTzxCaDhc4MbAotek/7PVDFRrDV4i8RLTxaXZvyGABbo3d/c78zyz7xGHjjubJvm1qM 0MnmIJySfo6T6ObdWvBPviQOrQkJ5Fhj/0AN2zJZLP5997XxAWHn1RaN3GhDgLjb08/h/e FtN4XjTNUXaJaSD3c3NyIPph1P9VN4E= X-MC-Unique: 65CMKaNEOwGrPDqms6Nqbg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: michael.roth@amd.com, marcandre.lureau@redhat.com, berrange@redhat.com, eblake@redhat.com, jsnow@redhat.com Subject: [PATCH 12/14] tests/qapi-schema: Cover optional conditional struct member Date: Thu, 16 Mar 2023 08:13:23 +0100 Message-Id: <20230316071325.492471-13-armbru@redhat.com> In-Reply-To: <20230316071325.492471-1-armbru@redhat.com> References: <20230316071325.492471-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1678950918668100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- tests/qapi-schema/qapi-schema-test.json | 3 ++- tests/qapi-schema/qapi-schema-test.out | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index 8f0ee95d23..f1f742d38c 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -220,7 +220,8 @@ =20 { 'struct': 'TestIfStruct', 'data': { 'foo': 'int', - 'bar': { 'type': 'int', 'if': 'TEST_IF_STRUCT_MEMBER'} }, + 'bar': { 'type': 'int', 'if': 'TEST_IF_STRUCT_MEMBER'}, + '*baz': { 'type': 'str', 'if': 'TEST_IF_STRUCT_MEMBER'} }, 'if': 'TEST_IF_STRUCT' } =20 { 'enum': 'TestIfEnum', diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 715f3a3f23..cee92c0d2e 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -247,6 +247,8 @@ object TestIfStruct member foo: int optional=3DFalse member bar: int optional=3DFalse if TEST_IF_STRUCT_MEMBER + member baz: str optional=3DTrue + if TEST_IF_STRUCT_MEMBER if TEST_IF_STRUCT enum TestIfEnum member foo --=20 2.39.2 From nobody Thu Apr 25 18:03:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1678950891; cv=none; d=zohomail.com; s=zohoarc; b=Q/RYEDzsrEhnSmmKdhkAhxnIVqn5Xficw1b0qS1DXQ+/lakdlaf4F62oh8pHEFp7F/D4iLehP4vU1e+3gEYxOVa6LmOYvgQusy2rGRfJb87gKrHceNL7Okl2fiPvJCpNntCPoLTnsLNNkzuedHxl/ZAn8PHYB8Lf6pKfAaekGWw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678950891; 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=hga3dak1FpksB7KppTghhWlEjpc6iM+ozQUOoK6T4Wo=; b=Ys4EG02z1UqFZAEZ4YSkNONlX9w4kvypWO0eizz6kpDCjI7yNF/Xe3ahMq1Liof9tJF3fU07aeiynlKoTFYn78/s/szEndDCopy1IKV4MV0H5gyMZ9qvWRfIKR+0pBTdbZDELLoWymUiie5r9ycCoi1FfSD6JkzHf4uxqE+gsto= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1678950891923363.08282979791477; Thu, 16 Mar 2023 00:14:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pchns-0003ii-AY; Thu, 16 Mar 2023 03:13:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pchnq-0003gy-Ml for qemu-devel@nongnu.org; Thu, 16 Mar 2023 03:13:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pchno-0004YE-7Q for qemu-devel@nongnu.org; Thu, 16 Mar 2023 03:13:34 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-8-9IUMfOEoPz-geboU31xfRw-1; Thu, 16 Mar 2023 03:13:28 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 411463813F3F; Thu, 16 Mar 2023 07:13:28 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.52]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 21AAAC15BA0; Thu, 16 Mar 2023 07:13:28 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 0FE2921F4F7F; Thu, 16 Mar 2023 08:13:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678950810; 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=hga3dak1FpksB7KppTghhWlEjpc6iM+ozQUOoK6T4Wo=; b=FiGirW/TjGM+doAOpi5iARtu1IQ3jqA8xwl1pgtrbm/0aOE/rSfb/vfF2PaOg6TGMD6ewl HdrgF+FXiQGI5i0kRxeteKmxHE7JG793Tf1U1CuBJjHJ8KvQ/TF3yCOuGc3Qjuj91iZZkD BlZ/M+Os8W+oe7WCjcA8ncVzAuazf5c= X-MC-Unique: 9IUMfOEoPz-geboU31xfRw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: michael.roth@amd.com, marcandre.lureau@redhat.com, berrange@redhat.com, eblake@redhat.com, jsnow@redhat.com Subject: [PATCH 13/14] qapi: Fix code generated for optional conditional struct member Date: Thu, 16 Mar 2023 08:13:24 +0100 Message-Id: <20230316071325.492471-14-armbru@redhat.com> In-Reply-To: <20230316071325.492471-1-armbru@redhat.com> References: <20230316071325.492471-1-armbru@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1678950892608100001 The generated member visit neglects to emit #if around a conditional struct member's has_ variable. For instance, tests/qapi-schema/qapi-schema-test.json generates #if defined(TEST_IF_STRUCT) bool visit_type_TestIfStruct_members(Visitor *v, TestIfStruct *obj, Err= or **errp) { Reviewed-by: Eric Blake ---> bool has_baz =3D !!obj->baz; if (!visit_type_int(v, "foo", &obj->foo, errp)) { return false; } #if defined(TEST_IF_STRUCT_MEMBER) if (!visit_type_int(v, "bar", &obj->bar, errp)) { return false; } #endif /* defined(TEST_IF_STRUCT_MEMBER) */ #if defined(TEST_IF_STRUCT_MEMBER) if (visit_optional(v, "baz", &has_baz)) { if (!visit_type_str(v, "baz", &obj->baz, errp)) { return false; } } #endif /* defined(TEST_IF_STRUCT_MEMBER) */ return true; } [...] #endif /* defined(TEST_IF_STRUCT) */ Won't compile when TEST_IF_STRUCT is defined and TEST_IF_STRUCT_MEMBER isn't. Fix that the obvious way: #if defined(TEST_IF_STRUCT_MEMBER) bool has_baz =3D !!obj->baz; #endif /* defined(TEST_IF_STRUCT_MEMBER) */ Fixes: 44ea9d9be33c (qapi: Start to elide redundant has_FOO in generated C) Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Markus Armbruster --- scripts/qapi/visit.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 26a584ee4c..c56ea4d724 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -74,11 +74,13 @@ def gen_visit_object_members(name: str, sep =3D '' for memb in members: if memb.optional and not memb.need_has(): + ret +=3D memb.ifcond.gen_if() ret +=3D mcgen(''' bool has_%(c_name)s =3D !!obj->%(c_name)s; ''', c_name=3Dc_name(memb.name)) sep =3D '\n' + ret +=3D memb.ifcond.gen_endif() ret +=3D sep =20 if base: --=20 2.39.2 From nobody Thu Apr 25 18:03:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1678950971; cv=none; d=zohomail.com; s=zohoarc; b=FtGa933pq8EVWjhHxOZaVg7iEJV+73yBNLzBfKzw38WuWZUYtIamApciBQgPxcirpgRThvAdF9y6+X4gFFLrmDB7STy2U63T+om/SdtDFngbMtsQzeDttnhI0jXrjNYDMKXmZCL1RSfZTXxwn2lYaUP2cPEOPcDjg1H1AQUTpWM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678950971; 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=dZ2fStG5njIzMXbN8tsZ7HYsDWx0m0FLBdQ7wL65gv8=; b=E9aRTsGNKqE13aodIOxUMISIL0/F7EuKU3HhfKQ+Z+5yswuuBeibGIIWgMvNPLCHTMwVsdndbExbyWl6lFNlLeeykHhjvRKXlmCCAJ2rvahNAI9f9O+Vjt8PvSV1buqXMG66em/Qzjry9cq0LegZLXPW57TrB63nISSrU3RvJ1o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1678950971233171.28648437271374; Thu, 16 Mar 2023 00:16:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pchoA-0003pW-Uu; Thu, 16 Mar 2023 03:13:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pchnv-0003lp-9v for qemu-devel@nongnu.org; Thu, 16 Mar 2023 03:13:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pchnp-0004Z3-Ce for qemu-devel@nongnu.org; Thu, 16 Mar 2023 03:13:38 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-475-Es6lMMNqOy-1DMAjVkUS7g-1; Thu, 16 Mar 2023 03:13:28 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 83A753813F3C; Thu, 16 Mar 2023 07:13:28 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.52]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2C891492B00; Thu, 16 Mar 2023 07:13:28 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 1243E21D2080; Thu, 16 Mar 2023 08:13:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678950812; 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=dZ2fStG5njIzMXbN8tsZ7HYsDWx0m0FLBdQ7wL65gv8=; b=iALCx4k+JjznMo8lbkoPdOnrfGt7dpR/M9/IJuKIpn6leq5ni8l2y4M31Oey9S6hTYc9/a JtkhzibofGpsxZhZ0Hsp/lux6lmv8FBsSWXtctMbaZc8X8jA5g1MMKqBMGoP/VJhXyAhIy YBgIcicrTmRdyhdKXff8eftJXk0HAg8= X-MC-Unique: Es6lMMNqOy-1DMAjVkUS7g-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: michael.roth@amd.com, marcandre.lureau@redhat.com, berrange@redhat.com, eblake@redhat.com, jsnow@redhat.com Subject: [PATCH 14/14] qapi: Require boxed for conditional command and event arguments Date: Thu, 16 Mar 2023 08:13:25 +0100 Message-Id: <20230316071325.492471-15-armbru@redhat.com> In-Reply-To: <20230316071325.492471-1-armbru@redhat.com> References: <20230316071325.492471-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1678950973198100003 Content-Type: text/plain; charset="utf-8" The C code generator fails to honor 'if' conditions of command and event arguments. For instance, tests/qapi-schema/qapi-schema-test.json has { 'event': 'TEST_IF_EVENT', 'data': { 'foo': 'TestIfStruct', 'bar': { 'type': ['str'], 'if': 'TEST_IF_EVT_ARG' } }, 'if': { 'all': ['TEST_IF_EVT', 'TEST_IF_STRUCT'] } } Generated tests/test-qapi-events.h fails to honor the TEST_IF_EVT_ARG condition: #if defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT) void qapi_event_send_test_if_event(TestIfStruct *foo, strList *bar); #endif /* defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT) */ Only uses so far are in tests/. We could fix the generator to emit something like #if defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT) void qapi_event_send_test_if_event(TestIfStruct *foo #if defined(TEST_IF_EVT_ARG) , strList *bar #endif ); #endif /* defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT) */ Ugly. Calls become similarly ugly. Not worth fixing. Conditional arguments work fine with 'boxed': true, simply because complex types with conditional members work fine. Not worth breaking. Reject conditional arguments unless boxed. Move the tests cases covering unboxed conditional arguments out of tests/qapi-schema/qapi-schema-test.json. Cover boxed conditional arguments there instead. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- docs/devel/qapi-code-gen.rst | 5 ++--- scripts/qapi/commands.py | 1 + scripts/qapi/gen.py | 1 + scripts/qapi/schema.py | 14 ++++++++++++++ tests/qapi-schema/args-if-implicit.err | 2 ++ tests/qapi-schema/args-if-implicit.json | 4 ++++ tests/qapi-schema/args-if-implicit.out | 0 tests/qapi-schema/args-if-unboxed.err | 2 ++ tests/qapi-schema/args-if-unboxed.json | 6 ++++++ tests/qapi-schema/args-if-unboxed.out | 0 tests/qapi-schema/event-args-if-unboxed.err | 2 ++ tests/qapi-schema/event-args-if-unboxed.json | 4 ++++ tests/qapi-schema/event-args-if-unboxed.out | 0 tests/qapi-schema/meson.build | 2 ++ tests/qapi-schema/qapi-schema-test.json | 9 ++++----- tests/qapi-schema/qapi-schema-test.out | 18 ++++-------------- 16 files changed, 48 insertions(+), 22 deletions(-) create mode 100644 tests/qapi-schema/args-if-implicit.err create mode 100644 tests/qapi-schema/args-if-implicit.json create mode 100644 tests/qapi-schema/args-if-implicit.out create mode 100644 tests/qapi-schema/args-if-unboxed.err create mode 100644 tests/qapi-schema/args-if-unboxed.json create mode 100644 tests/qapi-schema/args-if-unboxed.out create mode 100644 tests/qapi-schema/event-args-if-unboxed.err create mode 100644 tests/qapi-schema/event-args-if-unboxed.json create mode 100644 tests/qapi-schema/event-args-if-unboxed.out diff --git a/docs/devel/qapi-code-gen.rst b/docs/devel/qapi-code-gen.rst index 23e7f2fb1c..879a649e8c 100644 --- a/docs/devel/qapi-code-gen.rst +++ b/docs/devel/qapi-code-gen.rst @@ -805,9 +805,8 @@ gets its generated code guarded like this:: ... generated code ... #endif /* defined(HAVE_BAR) && defined(CONFIG_FOO) */ =20 -Individual members of complex types, commands arguments, and -event-specific data can also be made conditional. This requires the -longhand form of MEMBER. +Individual members of complex types can also be made conditional. +This requires the longhand form of MEMBER. =20 Example: a struct type with unconditional member 'foo' and conditional member 'bar' :: diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index 79c5e5c3a9..bda6896076 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -64,6 +64,7 @@ def gen_call(name: str, elif arg_type: assert not arg_type.variants for memb in arg_type.members: + assert not memb.ifcond.is_present() if memb.need_has(): argstr +=3D 'arg.has_%s, ' % c_name(memb.name) argstr +=3D 'arg.%s, ' % c_name(memb.name) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index b5a8d03e8e..8f8f784f4a 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -119,6 +119,7 @@ def build_params(arg_type: Optional[QAPISchemaObjectTyp= e], elif arg_type: assert not arg_type.variants for memb in arg_type.members: + assert not memb.ifcond.is_present() ret +=3D sep sep =3D ', ' if memb.need_has(): diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 719152fe49..8f31f8832f 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -486,6 +486,10 @@ def is_empty(self): assert self.members is not None return not self.members and not self.variants =20 + def has_conditional_members(self): + assert self.members is not None + return any(m.ifcond.is_present() for m in self.members) + def c_name(self): assert self.name !=3D 'q_empty' return super().c_name() @@ -817,6 +821,11 @@ def check(self, schema): self.info, "command's 'data' can take %s only with 'boxed': true" % self.arg_type.describe()) + self.arg_type.check(schema) + if self.arg_type.has_conditional_members() and not self.boxed: + raise QAPISemError( + self.info, + "conditional command arguments require 'boxed': true") if self._ret_type_name: self.ret_type =3D schema.resolve_type( self._ret_type_name, self.info, "command's 'returns'") @@ -872,6 +881,11 @@ def check(self, schema): self.info, "event's 'data' can take %s only with 'boxed': true" % self.arg_type.describe()) + self.arg_type.check(schema) + if self.arg_type.has_conditional_members() and not self.boxed: + raise QAPISemError( + self.info, + "conditional event arguments require 'boxed': true") =20 def connect_doc(self, doc=3DNone): super().connect_doc(doc) diff --git a/tests/qapi-schema/args-if-implicit.err b/tests/qapi-schema/arg= s-if-implicit.err new file mode 100644 index 0000000000..da2447d397 --- /dev/null +++ b/tests/qapi-schema/args-if-implicit.err @@ -0,0 +1,2 @@ +args-if-implicit.json: In command 'test-if-cmd': +args-if-implicit.json:1: conditional command arguments require 'boxed': tr= ue diff --git a/tests/qapi-schema/args-if-implicit.json b/tests/qapi-schema/ar= gs-if-implicit.json new file mode 100644 index 0000000000..1eda39cb1e --- /dev/null +++ b/tests/qapi-schema/args-if-implicit.json @@ -0,0 +1,4 @@ +{ 'command': 'test-if-cmd', + 'data': { + 'foo': 'int', + 'bar': { 'type': 'str', 'if': 'TEST_IF_CMD_ARG' } } } diff --git a/tests/qapi-schema/args-if-implicit.out b/tests/qapi-schema/arg= s-if-implicit.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/args-if-unboxed.err b/tests/qapi-schema/args= -if-unboxed.err new file mode 100644 index 0000000000..3d2fc836ef --- /dev/null +++ b/tests/qapi-schema/args-if-unboxed.err @@ -0,0 +1,2 @@ +args-if-unboxed.json: In command 'test-if-cmd': +args-if-unboxed.json:5: conditional command arguments require 'boxed': true diff --git a/tests/qapi-schema/args-if-unboxed.json b/tests/qapi-schema/arg= s-if-unboxed.json new file mode 100644 index 0000000000..6e04c13e72 --- /dev/null +++ b/tests/qapi-schema/args-if-unboxed.json @@ -0,0 +1,6 @@ +{ 'struct': 'TestIfCmdArgs', + 'data': { + 'foo': 'int', + 'bar': { 'type': 'str', 'if': 'TEST_IF_CMD_ARG' } } } +{ 'command': 'test-if-cmd', + 'data': 'TestIfCmdArgs' } diff --git a/tests/qapi-schema/args-if-unboxed.out b/tests/qapi-schema/args= -if-unboxed.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/event-args-if-unboxed.err b/tests/qapi-schem= a/event-args-if-unboxed.err new file mode 100644 index 0000000000..41ac64c6f3 --- /dev/null +++ b/tests/qapi-schema/event-args-if-unboxed.err @@ -0,0 +1,2 @@ +tests/qapi-schema/event-args-if-unboxed.json: In event 'TEST_IF_EVENT': +tests/qapi-schema/event-args-if-unboxed.json:1: event's 'data' members may= have 'if' conditions only with 'boxed': true diff --git a/tests/qapi-schema/event-args-if-unboxed.json b/tests/qapi-sche= ma/event-args-if-unboxed.json new file mode 100644 index 0000000000..ca42a74e3a --- /dev/null +++ b/tests/qapi-schema/event-args-if-unboxed.json @@ -0,0 +1,4 @@ + { 'event': 'TEST_IF_EVENT', + 'data': { + 'foo': 'int', + 'bar': { 'type': 'str', 'if': 'TEST_IF_CMD_ARG' } } } diff --git a/tests/qapi-schema/event-args-if-unboxed.out b/tests/qapi-schem= a/event-args-if-unboxed.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/meson.build b/tests/qapi-schema/meson.build index f88110bddf..a06515ca17 100644 --- a/tests/qapi-schema/meson.build +++ b/tests/qapi-schema/meson.build @@ -27,6 +27,8 @@ schemas =3D [ 'args-bad-boxed.json', 'args-boxed-anon.json', 'args-boxed-string.json', + 'args-if-implicit.json', + 'args-if-unboxed.json', 'args-int.json', 'args-invalid.json', 'args-member-array-bad.json', diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index f1f742d38c..8bbf94834a 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -249,17 +249,16 @@ 'if': { 'all': ['TEST_IF_ALT', 'TEST_IF_STRUCT'] } } =20 { 'command': 'test-if-cmd', - 'data': { - 'foo': 'TestIfStruct', - 'bar': { 'type': 'str', 'if': 'TEST_IF_CMD_ARG' } }, + 'boxed': true, + 'data': 'TestIfStruct', 'returns': 'UserDefThree', 'if': { 'all': ['TEST_IF_CMD', 'TEST_IF_STRUCT'] } } =20 { 'command': 'test-cmd-return-def-three', 'returns': 'UserDefThree' } =20 { 'event': 'TEST_IF_EVENT', - 'data': { 'foo': 'TestIfStruct', - 'bar': { 'type': ['str'], 'if': 'TEST_IF_EVT_ARG' } }, + 'boxed': true, + 'data': 'TestIfStruct', 'if': { 'all': ['TEST_IF_EVT', 'TEST_IF_STRUCT'] } } =20 { 'event': 'TEST_IF_EVENT2', 'data': {}, diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index cee92c0d2e..cc34b422e6 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -283,23 +283,13 @@ object q_obj_test-if-alternate-cmd-arg command test-if-alternate-cmd q_obj_test-if-alternate-cmd-arg -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse if {'all': ['TEST_IF_ALT', 'TEST_IF_STRUCT']} -object q_obj_test-if-cmd-arg - member foo: TestIfStruct optional=3DFalse - member bar: str optional=3DFalse - if TEST_IF_CMD_ARG - if {'all': ['TEST_IF_CMD', 'TEST_IF_STRUCT']} -command test-if-cmd q_obj_test-if-cmd-arg -> UserDefThree - gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse +command test-if-cmd TestIfStruct -> UserDefThree + gen=3DTrue success_response=3DTrue boxed=3DTrue oob=3DFalse preconfig= =3DFalse if {'all': ['TEST_IF_CMD', 'TEST_IF_STRUCT']} command test-cmd-return-def-three None -> UserDefThree gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse -object q_obj_TEST_IF_EVENT-arg - member foo: TestIfStruct optional=3DFalse - member bar: strList optional=3DFalse - if TEST_IF_EVT_ARG - if {'all': ['TEST_IF_EVT', 'TEST_IF_STRUCT']} -event TEST_IF_EVENT q_obj_TEST_IF_EVENT-arg - boxed=3DFalse +event TEST_IF_EVENT TestIfStruct + boxed=3DTrue if {'all': ['TEST_IF_EVT', 'TEST_IF_STRUCT']} event TEST_IF_EVENT2 None boxed=3DFalse --=20 2.39.2