From nobody Tue Feb 10 10:18:55 2026 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=1682488720; cv=none; d=zohomail.com; s=zohoarc; b=fzkp1WmSyRU/MeLVqp+QWSgRpyybs1P7keCT/h8w/9RvknZjCuaX7XTHzkOhMi/Jkb8tmKUBvZHXYQzIxzcGKMkgbvhH7RBo3giZoIqIfG16QvIiJllmbh78r9MKe9nOWl9//394R7weFzNHOvQ2dwgc9KWsL8YbCZb4p+CAGlQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682488720; 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=4Hz9ZJyOHb7HeMMGGGjq9hemFWL+7NMJVM41BZbVF+U=; b=bFxLiDEfuisp6/HsoZa/eCQNKgFu2IFo3d2HWJi4v79T3uZLas2Td2P68VzxwFR1jLYXu0kmSKy6JpRh9X6bCqHR2PqAeWfZ3aghrr4P79bHudK2SivAGbQXN+TjReE2Tn4CTyYd3YMTv26G1QL+BynUtj/Y025WIak7QTiV7Jw= 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 1682488720822267.42200444609125; Tue, 25 Apr 2023 22:58:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prYAB-00068n-GY; Wed, 26 Apr 2023 01:57:59 -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 1prYA5-000650-2a for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:53 -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 1prYA1-0002l8-Sk for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:52 -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-111-VY1c3qtyMhCCTrJ_ToMP6Q-1; Wed, 26 Apr 2023 01:57:45 -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 5CF2885C069; Wed, 26 Apr 2023 05:57:45 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3B80640C6E67; Wed, 26 Apr 2023 05:57:45 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 1FD0B21F1674; Wed, 26 Apr 2023 07:57:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682488669; 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=4Hz9ZJyOHb7HeMMGGGjq9hemFWL+7NMJVM41BZbVF+U=; b=CDUq313j2IT5QN2YL/GEgrJBcc1l4laBhg9DegdPz7ZJurMsW6czN4VhwSGs7BL+dPeywy eUjow2BOgQV0Eq0EYBTdoRAuXzqfl6E7YkZyG2rjvTH8T2ztv86Iw8fG/267OsZjWAvScJ RGuAIgxDDIrYCP98FPulM0UNb5FMo3I= X-MC-Unique: VY1c3qtyMhCCTrJ_ToMP6Q-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, Eric Blake Subject: [PULL 01/17] qapi: Fix error message format regression Date: Wed, 26 Apr 2023 07:57:28 +0200 Message-Id: <20230426055744.1041930-2-armbru@redhat.com> In-Reply-To: <20230426055744.1041930-1-armbru@redhat.com> References: <20230426055744.1041930-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.129.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, 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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1682488722333100003 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 Message-Id: <20230316071325.492471-2-armbru@redhat.com> 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 Tue Feb 10 10:18:55 2026 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=1682488755; cv=none; d=zohomail.com; s=zohoarc; b=G24DNO3/dHrY4wrkPN+xPQ0fgS56H7Pk3lWkHxFjCIG9mjY2HVvXix4iuZhIrFEiFh5wD6alP6AId2UljAWfRLTuioF5gRRLc6WDrrQIQbIKCZHSOuZZod3jw8GHkjkQebrqgxRneWR8EtO5lxzckpgvyMW8PBV/Q/OEyauBbgE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682488755; 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=HkFgjMWt5KNaHGBR9CmQxE75XwMh5eMqRnxwnsHCttM=; b=ipwrrQGsAc7BuX2y4BEO6cq5RnscJ7KqhU9Ac+O62AmIFfPOWNWjGQDceEJY1/9CUnJ0hB5WOY/jAtgasDeaRNpi8u00hAuomfVd2Vyz+HSG4GJBz61KeCXWTdlLW0pIzE/D1MJIYSjFaiZzryYS6Ud9B1HeQ4rA/ZNJKAxjULQ= 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 168248875583697.47099813725674; Tue, 25 Apr 2023 22:59:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prYA6-00065k-UD; Wed, 26 Apr 2023 01:57: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 1prYA3-00064m-D8 for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:51 -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 1prYA0-0002kc-Lo for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:51 -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-652-ESpqf9EbPLihiwjWtMEz6Q-1; Wed, 26 Apr 2023 01:57:45 -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 5C829811E7C; Wed, 26 Apr 2023 05:57:45 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3B48E2027043; Wed, 26 Apr 2023 05:57:45 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 21EC321F1675; Wed, 26 Apr 2023 07:57:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682488667; 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=HkFgjMWt5KNaHGBR9CmQxE75XwMh5eMqRnxwnsHCttM=; b=LZxU53zPZUcN3msbHNrz9PYSlVIvCIdA3klA/mz5nFfNzYaP9PLXhlKaG6scNs2AC2lM+h 9AkeLGtreqeBgKqoo5qSZ8dC0jaYvgN8w/fB6Jkmi8MszHWB8hzXOHyyeoK3Hc69GYHf1P M0WsY3GQZunjtoCt2ewqztwzpnbmXdQ= X-MC-Unique: ESpqf9EbPLihiwjWtMEz6Q-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 02/17] qapi/schema: Use super() Date: Wed, 26 Apr 2023 07:57:29 +0200 Message-Id: <20230426055744.1041930-3-armbru@redhat.com> In-Reply-To: <20230426055744.1041930-1-armbru@redhat.com> References: <20230426055744.1041930-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.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.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, 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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1682488756989100001 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 Message-Id: <20230316071325.492471-3-armbru@redhat.com> 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 Tue Feb 10 10:18:55 2026 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=1682488769; cv=none; d=zohomail.com; s=zohoarc; b=gz6rv6xy7jzNsLLgCBwZjC9VdURKvos1oxSKxZPc4FJV1k4A3U3o3V5Ce3+HHCrTK5yiYvLpph66v11ZzO44HzQ5fxXDIXjiajvS+tSgRGpJmaBF+B2YU0ivL9sLNkm+nkkww+W2gRPk5OoGu6zbbHVQ1S4HrRPujg2U6IQRpdw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682488769; 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=/XCpp4IYNlBe2hK/DlBvjTYh2CD/7uH6PGvRz7XzWdw=; b=ZmSadXVmMwKVyz1zzUzZ4KwMmSWZkGCXn7dqkBFctVyKpk3n4oPHKz2RkUYWkPkxnggG3tB8cHHmL0tID8xZtWtX0G64mBd7XZL+K2xnJI6KvKdVC7if/wu6fut0wR0ualP7TOng9tbRwPSARvrW7ETlRMNy9Jeq3GslwH4WqDU= 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 168248876924457.900247799490444; Tue, 25 Apr 2023 22:59:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prYA6-000651-3B; Wed, 26 Apr 2023 01:57: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 1prYA3-00064Z-2p for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:51 -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 1prYA0-0002kY-DC for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:50 -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-652-QX121gQHMkqy7CFl0a8aRw-1; Wed, 26 Apr 2023 01:57:45 -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 6154B101A531; Wed, 26 Apr 2023 05:57:45 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3BA3C14171B8; Wed, 26 Apr 2023 05:57:45 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 2424E21F1678; Wed, 26 Apr 2023 07:57:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682488667; 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=/XCpp4IYNlBe2hK/DlBvjTYh2CD/7uH6PGvRz7XzWdw=; b=FCD/vfnm+uPyBcZBm0tLWATzc70O/UKjY21TDeCONrcDv8mu0pmRDsGtaOUwnZUM6t6tV/ B/4zUfV8fH/oyNQW9HB0wu+Y04N4dMie/m+jMJHY4F7nRW7g1pAkqAsHR10IERjfRioqvW wMDl+lMV9SNxa8mItLMfBu6z04XOcDU= X-MC-Unique: QX121gQHMkqy7CFl0a8aRw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, Eric Blake Subject: [PULL 03/17] qapi: Clean up after removal of simple unions Date: Wed, 26 Apr 2023 07:57:30 +0200 Message-Id: <20230426055744.1041930-4-armbru@redhat.com> In-Reply-To: <20230426055744.1041930-1-armbru@redhat.com> References: <20230426055744.1041930-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.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, 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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1682488771117100003 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 Message-Id: <20230316071325.492471-4-armbru@redhat.com> 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 Tue Feb 10 10:18:55 2026 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=1682488794; cv=none; d=zohomail.com; s=zohoarc; b=h0auaYAGigrgF/C7DnvvlWm4yxRHHuS9MTx3pNf78IZlJPjB1VhiCiWSJlFoun7ed/zfDkbrB1S6xB5Nr8DhlyJC0UrAHd326zbRoGNTcOx8ptS4KirbsFnOGeSkn4cdsXWBUDJqGWPz4auFxsVFtciBDwfAbBUGCrvaOleLf0U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682488794; 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=EzV7jMDO/oPYTIZ3Q5bzgIZeimLue6BIglf8wNAP8IM=; b=EyQE7qc6IlypvyVYV8n31xm3oRyvrN1GayDUzqkxAU4lOqKfhgZtqLOn/BgzxnGPtPyavqe8SFL/oclfBrSI4zY3eh6vjrrILeUOuTUq2b8IUtVP9oVV3q/QvVp+S3qDnsV7oO7obVzRgNqJFS//kHicEnA0do4GtZpuJXQWfkE= 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 1682488794095792.6064187013449; Tue, 25 Apr 2023 22:59:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prYAK-0006BK-7G; Wed, 26 Apr 2023 01:58:09 -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 1prYA5-00065Y-LY for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:53 -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 1prYA1-0002l6-RM for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:53 -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-111-i7KBhvuqOOCGTo607IdrZA-1; Wed, 26 Apr 2023 01:57:45 -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 780523855561; Wed, 26 Apr 2023 05:57:45 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3B83F40C6E68; Wed, 26 Apr 2023 05:57:45 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 2666221F167A; Wed, 26 Apr 2023 07:57:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682488669; 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=EzV7jMDO/oPYTIZ3Q5bzgIZeimLue6BIglf8wNAP8IM=; b=WgRzH8AVBzfgEspIDTj2iC6/IYXYUX12v5YIC/uXF7xu9KyomSqgfLZA54LH0JAxlF05qt MviF12vSFq8HW7/OWb05bBhNVigLKMuAx+Mq+/03mAwt8kz0IaNNKorx5TWapeKHuX4YNo ataFI0dNbfkRlEorfGM9JxASAzDzc/I= X-MC-Unique: i7KBhvuqOOCGTo607IdrZA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, Eric Blake Subject: [PULL 04/17] qapi: Split up check_type() Date: Wed, 26 Apr 2023 07:57:31 +0200 Message-Id: <20230426055744.1041930-5-armbru@redhat.com> In-Reply-To: <20230426055744.1041930-1-armbru@redhat.com> References: <20230426055744.1041930-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.129.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, 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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1682488794719100003 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_array(), and 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 Message-Id: <20230316071325.492471-5-armbru@redhat.com> Reviewed-by: Eric Blake [Commit message corrected] --- 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 Tue Feb 10 10:18:55 2026 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=1682488798; cv=none; d=zohomail.com; s=zohoarc; b=gpXdXxWqEi1jQAMZ8lepSUF386trhJ5Nc7MwgfgPAnrcIC88J1UNbg/LvyDMDh4UJcq9dw33bSipWzWnGEB+IrMcKJWb9hNhxWDHpE9T310tmSXJQsoXPp6UAgjSHPj8w0WIThtjGCIqiJcbPoqweNebddDlztoKcAiTTjfyQuI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682488798; 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=sHaz+ZyHxDWMdvVqCZzu28yAU4wKDL37BtKh3S/IF5A=; b=DEggLg3btK2UQEFzcD6wY4nyYDeND2Nx++Tkz0GsWCZWhMmKl82Pe9dtQHVDOg7an7+GhICoUYI+qkDC9VqNjoNnEtw5vl8VCUhzzrqYElZlvxxZ1oUVjm1ddpuPQFpbQ8RjwTUC+Oimq7JhDrCB8RxOntWJGb3cp+3PLDuu1bc= 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 1682488798635925.9474471157698; Tue, 25 Apr 2023 22:59:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prYAU-0006FU-TZ; Wed, 26 Apr 2023 01:58:18 -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 1prYA7-00066P-3V for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:55 -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 1prYA3-0002lt-Rq for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:54 -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-654-O8KR1VNKMeuA4mB2R9qwTw-1; Wed, 26 Apr 2023 01:57:46 -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 6F72787A9E3; Wed, 26 Apr 2023 05:57:46 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4E0CB2027043; Wed, 26 Apr 2023 05:57:46 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 28D7421F167D; Wed, 26 Apr 2023 07:57:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682488671; 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=sHaz+ZyHxDWMdvVqCZzu28yAU4wKDL37BtKh3S/IF5A=; b=C7iyrsYFkP/4G6mVD79fvyTtmPZt/mHW/reH39Y1GyCxZSenUn/plJ3/y1G2yUujMs3ALk 81gFf3vu3zMfPY68oFgFW5jngjUsoy3UBXDOGRt7Of/PQ7HytfApAhraCrBkPSGLiDnoHH xsxIieP8/h8UHGemVLvsDFjuNZBVPi4= X-MC-Unique: O8KR1VNKMeuA4mB2R9qwTw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 05/17] qapi: Improve error message for unexpected array types Date: Wed, 26 Apr 2023 07:57:32 +0200 Message-Id: <20230426055744.1041930-6-armbru@redhat.com> In-Reply-To: <20230426055744.1041930-1-armbru@redhat.com> References: <20230426055744.1041930-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.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.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, 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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1682488799046100001 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 Message-Id: <20230316071325.492471-6-armbru@redhat.com> 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 Tue Feb 10 10:18:55 2026 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=1682488879; cv=none; d=zohomail.com; s=zohoarc; b=Go07crv8knanwEi2gwTeHf/YdySXpmnBk3vQ94oB8SnvslPQl6ztbY5caSk1QsxWHPX7cyLlQcs2uPGBR9GcF0kTa+pKBdOR15vAGkGieXOMMVKO7AUEQ6RMfqVAGzJYOROiJWoOnipzbxf60B5bWQbYrobZO7gowmfSVDgVmLQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682488879; 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=EfVOpdOcACxPelROUMNVfG6Dk0nhCSJlthNzV395Cto=; b=n2ch59Mo9FaJkqPyqYX3HQ3QJB2+bTXGiw89mm0LgN9LuiYE4ENvcfYS1nqNdTyF7LxkaPFdmEW5XCFWcj7j8aeVyh5/SjfZXc2AV0OHG44gZMC+wL/al7NMVy1TGDzRLUbbvdji30fq1p8OvsFyXre4URZh2sKUEkmIIF8k67c= 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 1682488879285519.1038908590268; Tue, 25 Apr 2023 23:01:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prYAA-00068U-BB; Wed, 26 Apr 2023 01:57:58 -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 1prYA3-00064p-PM for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:52 -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 1prYA0-0002kl-U2 for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:51 -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-121-72fMW6U-OcCHnxdJwis6Cw-1; Wed, 26 Apr 2023 01:57:46 -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 72CEE85A5A3; Wed, 26 Apr 2023 05:57:46 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4F75B14171B8; Wed, 26 Apr 2023 05:57:46 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 2B03D21F9814; Wed, 26 Apr 2023 07:57:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682488668; 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=EfVOpdOcACxPelROUMNVfG6Dk0nhCSJlthNzV395Cto=; b=Cz4seb7+HKDrLGECpO5v/fuje96nJgFBYCRExUXogE9uKaKlVm/hZ7fDdOyGq1o+9pNYx7 SEkvt9KpoRt5PzUPQevnHW0h4lyVAkf35Joau8X7WK/Ol0f9wRCVZgrJK1mgDsgMM7cgLF GWmjM2Aw1KZNSU3fcHWY5keL011oQFo= X-MC-Unique: 72fMW6U-OcCHnxdJwis6Cw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, Eric Blake Subject: [PULL 06/17] qapi: Simplify code a bit after previous commits Date: Wed, 26 Apr 2023 07:57:33 +0200 Message-Id: <20230426055744.1041930-7-armbru@redhat.com> In-Reply-To: <20230426055744.1041930-1-armbru@redhat.com> References: <20230426055744.1041930-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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, 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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1682488879730100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Message-Id: <20230316071325.492471-7-armbru@redhat.com> Reviewed-by: Eric Blake [Commit message corrected] --- 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 Tue Feb 10 10:18:55 2026 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=1682488714; cv=none; d=zohomail.com; s=zohoarc; b=PE1XL8vjADneYCzPRji7wODggFK3xBfzVqifk6sCK1P8oXR1GHSNhVe0/yWTUMfNkoE5YXyeqPc7w7GZie98W8qoT5sySxayJ2MbxUyABYOW6XF3mQbH2sgTO7UESPwui3zoQKHF4Ef1c7VkYmdqcB34tLQpiL5eepjBJmncx3Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682488714; 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=jWUz8T+lNSx/aWm5bkx5op9IQO0lB55ipCHPbpWrDvw=; b=Lve39xJAhflSVp5G1k9Pnspty1wMl96oFnPoUekl32Epb4nDlrld43vLPyeQFY4bHiahMH22UalLuzNZtQkZUPhD9FONgWI5/8gIlPUO66pCobTRTUGu9DtL+GwqfYNY1IO6oc017NqbdTNt9QwdL/2loS3ZxeA+5A74l4FvzKM= 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 1682488714649382.0510193646883; Tue, 25 Apr 2023 22:58:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prYAB-00068m-Gh; Wed, 26 Apr 2023 01:57:59 -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 1prYA3-00064w-Un for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:52 -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 1prYA1-0002kq-6L for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:51 -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-654-kAe1fMceP2a76K3V3lYaWw-1; Wed, 26 Apr 2023 01:57:46 -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 6F770185A792; Wed, 26 Apr 2023 05:57:46 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4E116C15BA0; Wed, 26 Apr 2023 05:57:46 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 2D48621F9816; Wed, 26 Apr 2023 07:57:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682488668; 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=jWUz8T+lNSx/aWm5bkx5op9IQO0lB55ipCHPbpWrDvw=; b=hVMk1zePfOSnLQIJgF5ZYttGFzl2+CtLlCNBBEzvnKmm/cDANdhK6+VRSdxhtLb7qGCoiy dQ3NHeARzYWDAe6L2DvTtwvFOjdTDBYxpyRe+S7077m9gI2e8KLhYongxtmGZkpVvOQLeG Ljsw6Lm6hZJfMmJWIqiE/vCH8mxzrdI= X-MC-Unique: kAe1fMceP2a76K3V3lYaWw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, Eric Blake Subject: [PULL 07/17] qapi: Fix error message when type name or array is expected Date: Wed, 26 Apr 2023 07:57:34 +0200 Message-Id: <20230426055744.1041930-8-armbru@redhat.com> In-Reply-To: <20230426055744.1041930-1-armbru@redhat.com> References: <20230426055744.1041930-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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, 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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1682488715943100007 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 Message-Id: <20230316071325.492471-8-armbru@redhat.com> 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 Tue Feb 10 10:18:55 2026 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=1682488696; cv=none; d=zohomail.com; s=zohoarc; b=jvsVuucCEv5uutA4jX+aIzFdmAqNoymRxx9HUDsJvlGJiHbFb08lWVVdQskEPFUyI+Odc/Wt8efNPvvn7E5PjbGz8u1pp1cboeZL4FwqDX+75ufir5izIspf98Xkcy4V2wf2DkzjBvOc/wO5PF2QWnmmCHzDiQf8odOzG/ukhz4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682488696; 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=6xWPqYOxbMMcQQ0xbZRErVJpecR93so7hYbagKc2EfA=; b=fbVLfz+p0IwQPHCHxRomesCyBGOepxnxNXBLfQZccsYae1lJY/12CCKFLJSZn26er2/xmFzyQJdMOT2iGT6kYSxpmfFUQJOZTM3/WNXwgz9UmlZzZ/mHvnUvJcj/cCGHQuj/oHXnulAMnxnvs0m4v8p8/KGjuvQQSXcamf/7Cqc= 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 16824886964915.021206118046507; Tue, 25 Apr 2023 22:58:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prYA9-00068S-4T; Wed, 26 Apr 2023 01:57:58 -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 1prYA3-00064x-Vg for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:52 -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 1prYA1-0002kp-5U for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:51 -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-508-nKHmebk0PCWVRSb-dtXn3Q-1; Wed, 26 Apr 2023 01:57:46 -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 8942E3C0C89F; Wed, 26 Apr 2023 05:57:46 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4D1F540C2064; Wed, 26 Apr 2023 05:57:46 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 2F89C21F9817; Wed, 26 Apr 2023 07:57:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682488668; 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=6xWPqYOxbMMcQQ0xbZRErVJpecR93so7hYbagKc2EfA=; b=fM0qPO543V3spLTMejw6IuJivM8DO29gWE6BFHBgW6iH434WJWsE/F/Nn0P8ibDnwu30sm IQ/wA6oMYxsvBFUBjDSV/KIssoO9mVK0yACCqoJWX+sYKKWmdlyIYQmtWTtSOcr91NTZni 3SHlGseo0vhJFKMmwpF+1ev3duu0XKk= X-MC-Unique: nKHmebk0PCWVRSb-dtXn3Q-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, Eric Blake Subject: [PULL 08/17] qapi: Fix to reject 'data': 'mumble' in struct Date: Wed, 26 Apr 2023 07:57:35 +0200 Message-Id: <20230426055744.1041930-9-armbru@redhat.com> In-Reply-To: <20230426055744.1041930-1-armbru@redhat.com> References: <20230426055744.1041930-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.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, 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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1682488698087100001 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: factor check_type_implicit() out of check_type_name_or_implicit(), and switch check_struct() to use it instead. Also add a test case. Signed-off-by: Markus Armbruster Message-Id: <20230316071325.492471-9-armbru@redhat.com> Reviewed-by: Eric Blake [More detailed commit message] --- 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 Tue Feb 10 10:18:55 2026 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=1682488818; cv=none; d=zohomail.com; s=zohoarc; b=ZYvj5e/C4ubm59MhsAGjZZD+dPh647JH739vU2wE528EQuTkDczKYQ6WTxqLDKXlTFqt4REWpTKnjWzMtLDxDK0bKCRhompX5OLq9nSHYSRHsUfffBxz9/bPd5ZRaGbqLB9QTO5G3LVcPn58uwe0clBTTunGd0kGOCzY4r25t+o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682488818; 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=TwSYfDyBRyKjYd0qorhEVRpu+/fW7H3hiS6a+ZmTNO8=; b=anfMRbX3E/UgMwXraJ1eFLen2bfYpC0iaZ/4pSHuM1AphNv3nPKIVpfSAWibhYNNF0fkFkHN/KiUDBaOWZGsTMh3/IIy8kgsYeI4IeGdcqSs1j95G2zWEWNTXio7AzWhDyLr4wbZoDGMJzCgnwlvZHEDf27NBJQQZvPAPp1eEIw= 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 1682488818750918.4910641553545; Tue, 25 Apr 2023 23:00:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prYAZ-0006LR-4r; Wed, 26 Apr 2023 01:58:23 -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 1prYA6-00065t-F1 for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:54 -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 1prYA3-0002lm-Ax for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:54 -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-61-RO7iImjANg-daR-jRfXUwg-1; Wed, 26 Apr 2023 01:57:46 -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 6D04987A9E2; Wed, 26 Apr 2023 05:57:46 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4D25C2166B41; Wed, 26 Apr 2023 05:57:46 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 31BC121F9818; Wed, 26 Apr 2023 07:57:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682488670; 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=TwSYfDyBRyKjYd0qorhEVRpu+/fW7H3hiS6a+ZmTNO8=; b=FlzbeMSVtfKQZdlrO+I+cX6Mo/Wsx9NvXtPB9bjwyhWyLZ7GLaHsIjkI6RyIbz07NkDi9Z LhuiZpDBdFlORrx6x/fIKz3sVpm5UJ3mkbfRIGtMt0SyveaBIUWfPdlG3sA6O9WIH1Lo0b N/USKE1C1CSQ1ozB3ExczOf1L2c3vkM= X-MC-Unique: RO7iImjANg-daR-jRfXUwg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, Eric Blake Subject: [PULL 09/17] tests/qapi-schema: Improve union discriminator coverage Date: Wed, 26 Apr 2023 07:57:36 +0200 Message-Id: <20230426055744.1041930-10-armbru@redhat.com> In-Reply-To: <20230426055744.1041930-1-armbru@redhat.com> References: <20230426055744.1041930-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.129.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, 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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1682488819256100001 Content-Type: text/plain; charset="utf-8" A union's 'discriminator' must name 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 Message-Id: <20230316071325.492471-10-armbru@redhat.com Reviewed-by: Eric Blake [Commit message typo fixed] --- 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 Tue Feb 10 10:18:55 2026 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=1682488810; cv=none; d=zohomail.com; s=zohoarc; b=EdrGIoHW7YGiG71CuNLZLB1IzTARkBzv5U+eIqXprCJbcSbr4lJOXcfjYrbdvUTLxLItik+de5/MNq2zc3GDAvP0Pm78jz5Ubct2f9yv0EXblHwi4L0FZxdnFfG+5r/+SbAPyXS5m6LhHmVTqz87EQ+3sg3oFfUKjzT+XiRh+3g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682488810; 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=QRjMZQEXdxF4CzJQgIaBMTANYHhrLpii6yXZoilbytQ=; b=eHrh5QZ4DXMAua7+8scygsbGiikUU8wbd8giwQVCDj6pBKQZtDEaaaLK/MHWZr3T5LGIRA7X9RZxLNaF+NRc7+zcQjvGTlFiZApoFVurSGcJVG/MERXZBlb/XUhKuWtO4LAUaQngXRZbbf2RFCejT6SGSTX5pXo8O/HRg7QIVJg= 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 1682488810981924.1813243128291; Tue, 25 Apr 2023 23:00:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prYAV-0006Hl-HR; Wed, 26 Apr 2023 01:58:19 -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 1prYA6-000663-Kr for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:54 -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 1prYA2-0002lL-3h for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:54 -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-361-pVHS90PbO5ScvKyp7xfQWQ-1; Wed, 26 Apr 2023 01:57:46 -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 8D52D3855569; Wed, 26 Apr 2023 05:57:46 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4E5874C83A; Wed, 26 Apr 2023 05:57:46 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 3403421F981C; Wed, 26 Apr 2023 07:57:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682488669; 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=QRjMZQEXdxF4CzJQgIaBMTANYHhrLpii6yXZoilbytQ=; b=cpYk0a6RFdy0DccMFDw7Z8aEbc4Chc+KyRD7JYqXCGFHr+rBM+c55+K3Oo5k31lVhQLaty vUr6ml2yB4+Sm1lPJuNYlnYmwi/RlI7aiZVGPLCVq19I8GD+E6AN1k89kTiovTlZhtOWac s7GcrKI5t99VKllyt9gJ2RwPY7odGIg= X-MC-Unique: pVHS90PbO5ScvKyp7xfQWQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 10/17] tests/qapi-schema: Rename a few conditionals Date: Wed, 26 Apr 2023 07:57:37 +0200 Message-Id: <20230426055744.1041930-11-armbru@redhat.com> In-Reply-To: <20230426055744.1041930-1-armbru@redhat.com> References: <20230426055744.1041930-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.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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, 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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1682488812814100003 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 Message-Id: <20230316071325.492471-11-armbru@redhat.com> 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 Tue Feb 10 10:18:55 2026 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=1682488789; cv=none; d=zohomail.com; s=zohoarc; b=WlmNc1Od2ZUwjLDk1plVRLCpozpJKTZRtlfUJvzWOnX5Eb0eaFUAR+f35UjtmkLAuO8S/VUS0c7C/PChCRr/CnQMeajcOhdDpHPL+yLNmUfxoyS3TigdpRbRBVeEDV/AfzwGGKC5jy0tPw3/GaRHhbelYjS58ptwNwo30SBFysI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682488789; 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=jRk1nFbnqOhorbVjQ1hQZKVhXqGBVGhh4vs3W09hBcI=; b=ZRg5+a+jr+H0m6V0LCD9/wPTbNrc1OUyoU9jS53Ekor6NRBpp8EaJXbCZFHXRtKhBLnHBCt+Oq2AmItEOz/OHRIped84Yf3+8GFJpT/KxoXHD+tDLXSrhm8Sx7iT1hxgQDJrnJWVRkhHaFmZkU0Fz/W2pGOpcfolIoVGuHjfKx0= 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 1682488789080266.86776910158244; Tue, 25 Apr 2023 22:59:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prYAW-0006Jg-Sx; Wed, 26 Apr 2023 01:58:20 -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 1prYA4-00064y-B3 for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:52 -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 1prYA1-0002ko-CM for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:51 -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-121-ndPmPqqxPaCrocgvqVcDiw-1; Wed, 26 Apr 2023 01:57:46 -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 805401C06EDE; Wed, 26 Apr 2023 05:57:46 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5F7452027045; Wed, 26 Apr 2023 05:57:46 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 3636421F9821; Wed, 26 Apr 2023 07:57:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682488668; 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=jRk1nFbnqOhorbVjQ1hQZKVhXqGBVGhh4vs3W09hBcI=; b=gXm7AkJ+QNccwmY226zx1bPEGsw9ue657brvyyRu+gYAL2OJhY/OBQFPrwmlBG8gGw9gJR 8tc66JW8vFZbgo+MEJ2BFHjAUD7M9xcwXBceOpPhJ+Wg2FmaVTVhgvsxv/NQnwYlJkxxxF ksG5ebISyUO/Pk9ylT7FJncp9BH2yvo= X-MC-Unique: ndPmPqqxPaCrocgvqVcDiw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, Eric Blake Subject: [PULL 11/17] tests/qapi-schema: Clean up positive test for conditionals Date: Wed, 26 Apr 2023 07:57:38 +0200 Message-Id: <20230426055744.1041930-12-armbru@redhat.com> In-Reply-To: <20230426055744.1041930-1-armbru@redhat.com> References: <20230426055744.1041930-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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, 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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1682488790983100003 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_UNION 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 Message-Id: <20230316071325.492471-12-armbru@redhat.com> Reviewed-by: Eric Blake [Commit message corrected] --- 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 Tue Feb 10 10:18:55 2026 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=1682488849; cv=none; d=zohomail.com; s=zohoarc; b=jAbv6z0wzwo4esl6YS6UfiI9e4CYBJoYMOcfb7R1+5faZOq0ogxU1EFhXlXwFLN2A/vW/jOe8UcfzH+yCvmFSpCHsmZ9fUYPf8CRWdBIjjwLpW+x+s8Ptc1fepNU2QwICob7gScJ4Jko8HwJeaq8gW0OSQxYY3UilrLyOZikSAI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682488849; 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=nVDfzAF6LV/svDWG8x3EvjcEqX00xRmByzKi14lXILc=; b=LyPbK6Wq8qylA0biVX/QyGqS9LgM2yoU7p5BDJe6T/ZQby8HI2zjeNfs+MPTiUiKOwwjpV7duHgMyl9I3dUKJjKv36IKPRy6yJgXK1JdKvnFs+PlCtWe3yLdQVAkKwychgS80MtWPF+YFqf6YgoDEqqGD4/END/p0BVCfnQoz7Q= 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 1682488849960143.40578341862488; Tue, 25 Apr 2023 23:00:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prYAY-0006L3-8o; Wed, 26 Apr 2023 01:58:22 -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 1prYA7-00067i-L5 for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:55 -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 1prYA4-0002m2-Dq for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:55 -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-361-1xofCn7XOF6LMvegbhd8RQ-1; Wed, 26 Apr 2023 01:57:46 -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 80769185A791; Wed, 26 Apr 2023 05:57:46 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 60412492B0F; Wed, 26 Apr 2023 05:57:46 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 3871A21F9824; Wed, 26 Apr 2023 07:57:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682488671; 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=nVDfzAF6LV/svDWG8x3EvjcEqX00xRmByzKi14lXILc=; b=Ue9Ayi9kCfnyAkY2LGi0CPtv5W9J/JOnLABLQGPr+js3BxFVSEoDY7Q+RjgoaZONrDz7Bb Qhnx9VE9xLlWLJEisjpRiYgV1jNh6f6vyxrEjmY94DtZpXxnCgEVOg2Or4DdoDPT5b/R+k kQUO8pHEfd+nO/dg808eiDgf6PEMd9k= X-MC-Unique: 1xofCn7XOF6LMvegbhd8RQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 12/17] tests/qapi-schema: Cover optional conditional struct member Date: Wed, 26 Apr 2023 07:57:39 +0200 Message-Id: <20230426055744.1041930-13-armbru@redhat.com> In-Reply-To: <20230426055744.1041930-1-armbru@redhat.com> References: <20230426055744.1041930-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.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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, 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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1682488851629100001 Signed-off-by: Markus Armbruster Message-Id: <20230316071325.492471-13-armbru@redhat.com> 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 Tue Feb 10 10:18:55 2026 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=1682488699; cv=none; d=zohomail.com; s=zohoarc; b=FTleOgCxuRji4b7XXm4vm2tMfK1IV2gL/MF4S57HsMBHUBEyigHNe0dj0UfB1O1otDkjDQ8Jzx5Fm/tFWj3Z+vC6TxF1yqja/ChaZiHVJabPTdkCemfxg9JPkYw8V+vcM7fP/z4fjr11hDjG2MiVJ0y30ZPIJjj616b6MomBGug= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682488699; 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=McAUM5sEvTPlGnUQIPBBdFR/Oxsek/scSFXeyPQ8Mc0=; b=WyhiTO7gUvsO7iHozw6jdcEgUblPuNNcrLSSBqRldMFwUWY1NEE2lIQxN0TDQi0jzk78jSOgK7IbrUG85cNlfm1TVWE1PNfqe7zmX9stUA6d0eX9qBFVkJzQpXCmRZk6YTByZt9dgJ6w/vAOfID//ziY8gPYC15tlr6+iC30owI= 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 1682488699719561.7221750169234; Tue, 25 Apr 2023 22:58:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prYA9-00068Q-3X; Wed, 26 Apr 2023 01:57:58 -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 1prYA5-000657-7A for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:53 -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 1prYA1-0002lB-TF for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:52 -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-361-TZwypoyKNP6KmEoh1F_h3A-1; Wed, 26 Apr 2023 01:57:46 -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 81728858F0E; Wed, 26 Apr 2023 05:57:46 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 60DF62027046; Wed, 26 Apr 2023 05:57:46 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 3AB6621F9829; Wed, 26 Apr 2023 07:57:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682488669; 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=McAUM5sEvTPlGnUQIPBBdFR/Oxsek/scSFXeyPQ8Mc0=; b=XRz/VbJIu2JVk8lY8dhK0IZ+0+sdMf/3eNZavP8HE5BzsbPP5srnZHLg6MfZldyL59xyFL j5RJK0eGlaN8IvVwWnEeZ09ntYuhOvqmDOn4EvzH8iZZSfNAciRrfa4Rfa+0Ajl+9W63Km 7r1UiEqg2hSaYVMf5/nZh1Bh6WS91yY= X-MC-Unique: TZwypoyKNP6KmEoh1F_h3A-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eric Blake Subject: [PULL 13/17] qapi: Fix code generated for optional conditional struct member Date: Wed, 26 Apr 2023 07:57:40 +0200 Message-Id: <20230426055744.1041930-14-armbru@redhat.com> In-Reply-To: <20230426055744.1041930-1-armbru@redhat.com> References: <20230426055744.1041930-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.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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, 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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1682488701646100003 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) { ---> 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 Message-Id: <20230316071325.492471-14-armbru@redhat.com> Reviewed-by: Eric Blake --- 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 Tue Feb 10 10:18:55 2026 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=1682488785; cv=none; d=zohomail.com; s=zohoarc; b=lzjckdepT0OTaHjhkqpic3knr4uog/tSsa8aVtNqHx5UJT6WSS9pLsM7wy13UrI7yy+FnImDv6qcUjgoY/ilP0rVswb+hQoYLf5nMqXbpR/t2zo7aND1iXFXCI0+ra78mUx1vcB7whtunlp5Nk7K65ld8L59K5RTQGypRdk27Q4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682488785; 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=oSd0shBxJx5hPVORsFhN2W+nr7mL/xfgq19PsYAwITI=; b=WvPfepXy3bmCRi8DtmyKSwIXeCV7wS1hoXwoDEcTFPOlszEpAluNcD+zvy4LEzQR+wYZJxP/Dq9kcVAjUgSw9CgzbuQ6+fjct9WV1eUnwGtoXfoJAmW+yVj8zfbkhlAtN6x0z1PHlEoQcBaD0wXUblNAyx9CScbYVSA718tTEYg= 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 1682488785703134.12084954021952; Tue, 25 Apr 2023 22:59:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prYAU-0006Dy-2W; Wed, 26 Apr 2023 01:58:18 -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 1prYA5-00065X-LC for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:53 -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 1prYA1-0002l0-He for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:53 -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-121-mKWkiQKIMzW7o16DV6yl9Q-1; Wed, 26 Apr 2023 01:57:47 -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 014F83855561; Wed, 26 Apr 2023 05:57:47 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9E54C40C6E67; Wed, 26 Apr 2023 05:57:46 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 3CFBD21F9831; Wed, 26 Apr 2023 07:57:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682488668; 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=oSd0shBxJx5hPVORsFhN2W+nr7mL/xfgq19PsYAwITI=; b=gK1Zb1bcyRr1s3sZUpcr3CI1sCatV784uw3eBmZZJ/Rr38KuNnFGUbwdz83wgJ6lkasZDp bZh4DOYEb+fNQYqE9YVuBvDYX9g2CjOe/TOd59vc5AJXF7IPlcB+v0TfxapYdwz0sDm+d6 e7dCrjTo0Z6egcA3arkN4DTmBHAidxE= X-MC-Unique: mKWkiQKIMzW7o16DV6yl9Q-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, Eric Blake Subject: [PULL 14/17] qapi: Require boxed for conditional command and event arguments Date: Wed, 26 Apr 2023 07:57:41 +0200 Message-Id: <20230426055744.1041930-15-armbru@redhat.com> In-Reply-To: <20230426055744.1041930-1-armbru@redhat.com> References: <20230426055744.1041930-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.129.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, 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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1682488787026100003 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 Message-Id: <20230316071325.492471-15-armbru@redhat.com> 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 a079378d1b..d1fdf4182c 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -66,6 +66,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 From nobody Tue Feb 10 10:18:55 2026 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=1682488748; cv=none; d=zohomail.com; s=zohoarc; b=h2xG6C/bwKo5rcKrC59StiUqR5pCWeGwAsZk2P9at3u8nkdYAIJiOdH+KV/b8TobEzEHa9JSI8O3dD492sGDvuvc3Sg6Nev/iY6UFBDkbjr0y4IFEW+/GhT4cedVqjtfatP08PYvvpmEjz+bPE3L1VZ2yYuliDFjkdRL8S9MkIc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682488748; 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=Oj6VNxOw6ZUrjXHVwuTvB4feiL9lqrETGgo/kHGM4qI=; b=WrUs39XXeJTNGZweyp7oQtOlUKCxAsr0E1zwvLTHsV/Elj/14NfgaWw+Yhz5ewYDlADS5IUnd9VRW1VXu07NPsPUaO/UspubSrnrLD0EkpS3Hm3r4HSCUCld9Gdxey7188KHEFjFnFVU2AZMFjUhgsFKS4zNIJvvvunZqo/4jJU= 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 1682488748058702.0284554668358; Tue, 25 Apr 2023 22:59:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prYAP-0006C9-Oo; Wed, 26 Apr 2023 01:58:13 -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 1prYA7-00066N-2x for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:55 -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 1prYA4-0002m4-6R for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:54 -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-618-tLlBozATOdify8bcBMEUlA-1; Wed, 26 Apr 2023 01:57:47 -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 745C3185A79C; Wed, 26 Apr 2023 05:57:47 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5490D2166B3A; Wed, 26 Apr 2023 05:57:47 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 3F4F621F9835; Wed, 26 Apr 2023 07:57:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682488671; 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=Oj6VNxOw6ZUrjXHVwuTvB4feiL9lqrETGgo/kHGM4qI=; b=Z2wU8XApFoZztqBBsHPljCh4+E8Z5q8KEkyqOf5mYgAzubvXQHcvgmeVdPCcMMlRyCM4iP 5DlzcOtGLgcc23yJLIkBJ3oGTITKlwe91ELeqGS+vmHdpoMxtfnT0deRWN7vPT+upSqrsQ qXptkjO9UR7X14STg9UabYrmFwZNdkA= X-MC-Unique: tLlBozATOdify8bcBMEUlA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PULL 15/17] qapi: support updating expected test output via make Date: Wed, 26 Apr 2023 07:57:42 +0200 Message-Id: <20230426055744.1041930-16-armbru@redhat.com> In-Reply-To: <20230426055744.1041930-1-armbru@redhat.com> References: <20230426055744.1041930-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.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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, 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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1682488748903100003 From: Daniel P. Berrang=C3=A9 It is possible to pass --update to tests/qapi-schema/test-qapi.py to make it update the output files on error. This is inconvenient to achieve though when test-qapi.py is run indirectly by make/meson. Instead simply allow for an env variable to be set: $ QAPI_TEST_UPDATE=3D make check-qapi-schema Signed-off-by: Daniel P. Berrang=C3=A9 Message-Id: <20230420102619.348173-2-berrange@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- tests/qapi-schema/test-qapi.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index 2160cef082..d58c31f539 100755 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -206,6 +206,7 @@ def main(argv): parser.add_argument('-d', '--dir', action=3D'store', default=3D'', help=3D"directory containing tests") parser.add_argument('-u', '--update', action=3D'store_true', + default=3D'QAPI_TEST_UPDATE' in os.environ, help=3D"update expected test results") parser.add_argument('tests', nargs=3D'*', metavar=3D'TEST', action=3D'= store') args =3D parser.parse_args() --=20 2.39.2 From nobody Tue Feb 10 10:18:55 2026 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=1682488824; cv=none; d=zohomail.com; s=zohoarc; b=LfRz2pr//UDqCxs50VXgsSR5pKhOSYcgBWxJEETooXz1KfEzkPsxmY1teWmVOiJryHQrXGrRHVAsOFch4+QsqsunjzG9dqcP/VQ47EHvletKdffFo6p4Vmu+im2J8jvlhCeF1LmlZoJsFYWkHXW/tHTPKrL7Y6z50zD3Niqc9vI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682488824; 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=4ZP0gwr8BfrslPu6vxIFua5vdD1mL2kgjqf89nE5odg=; b=KpicpelkSwP+BeaP5gACuxpHkAQ3m6HPsgWET532w8gXn+g2ueQ0HWYpVis/y13Nu5oRKH2Ai4JbjFjXPMrsUONYwT+df8WklvmfJ0EIJgmA4AF82wEV9TdV+WNguN3Z/SCiw+aRrRS3YPyTM0z5f2FhcpLRHM2pWfrvH654Hyc= 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 168248882476742.53614889086282; Tue, 25 Apr 2023 23:00:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prYAC-0006AN-M9; Wed, 26 Apr 2023 01:58:02 -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 1prYA5-00065Z-M1 for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:53 -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 1prYA1-0002lE-WA for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:53 -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-224-83EWB18PNIK57gEMEubsbg-1; Wed, 26 Apr 2023 01:57:47 -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 76AC329AA39C; Wed, 26 Apr 2023 05:57:47 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 55FA11121314; Wed, 26 Apr 2023 05:57:47 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 4185221F9836; Wed, 26 Apr 2023 07:57:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682488669; 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=4ZP0gwr8BfrslPu6vxIFua5vdD1mL2kgjqf89nE5odg=; b=VuSoQ9BxzuFMbXNe+VDnuv7Q1mmE6qt4R7iLVyOUscs6R6C/BK1DmrjoFZYa3q5VkOrRu2 Ds2sqBnTofMWNudBGFkHqwJZ6AbF0sOLAQN5waFdIEYMNyn39N99q5NcLFtcCfk21DsWpS Fjkc9sZZenPflLXFD9N+SZDmGVitlmQ= X-MC-Unique: 83EWB18PNIK57gEMEubsbg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Subject: [PULL 16/17] qapi: Improve specificity of type/member descriptions Date: Wed, 26 Apr 2023 07:57:43 +0200 Message-Id: <20230426055744.1041930-17-armbru@redhat.com> In-Reply-To: <20230426055744.1041930-1-armbru@redhat.com> References: <20230426055744.1041930-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.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: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, 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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1682488826362100001 Error messages describe object members, enumeration values, features, and variants like ROLE 'NAME', where ROLE is "member", "value", "feature", or "branch", respectively. When the member is defined in another type, e.g. inherited from a base type, we add "of type 'TYPE'". Example: test case struct-base-clash-deep reports a member of type 'Sub' clashing with a member of its base type 'Base' as struct-base-clash-deep.json: In struct 'Sub': struct-base-clash-deep.json:10: member 'name' collides with member 'nam= e' of type 'Base' Members of implicitly defined types need special treatment. We don't want to add "of type 'TYPE'" for them, because their named are made up and mean nothing to the user. Instead, we describe members of an implicitly defined base type as "base member 'NAME'", and command and event parameters as "parameter 'NAME'". Example: test case union-bad-base reports member of a variant's type clashing with a member of its implicitly defined base type as union-bad-base.json: In union 'TestUnion': union-bad-base.json:8: member 'string' of type 'TestTypeA' collides wit= h base member 'string' The next commit will permit unions as variant types. "base member 'NAME' would then be ambigious: is it the union's base, or is it the union's variant's base? One of its test cases would report a clash between two such bases as "base member 'type' collides with base member 'type'". Confusing. Refine the special treatment: add "of TYPE" even for implicitly defined types, but massage TYPE and ROLE so they make sense for the user. Message-Id: <20230420102619.348173-3-berrange@redhat.com> Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Markus Armbruster --- scripts/qapi/schema.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 8f31f8832f..27e336577f 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -701,6 +701,7 @@ def connect_doc(self, doc): =20 def describe(self, info): role =3D self.role + meta =3D 'type' defined_in =3D self.defined_in assert defined_in =20 @@ -712,13 +713,17 @@ def describe(self, info): # Implicit type created for a command's dict 'data' assert role =3D=3D 'member' role =3D 'parameter' + meta =3D 'command' + defined_in =3D defined_in[:-4] elif defined_in.endswith('-base'): # Implicit type created for a union's dict 'base' role =3D 'base ' + role + defined_in =3D defined_in[:-5] else: assert False - elif defined_in !=3D info.defn_name: - return "%s '%s' of type '%s'" % (role, self.name, defined_in) + + if defined_in !=3D info.defn_name: + return "%s '%s' of %s '%s'" % (role, self.name, meta, defined_= in) return "%s '%s'" % (role, self.name) =20 =20 --=20 2.39.2 From nobody Tue Feb 10 10:18:55 2026 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=1682488712; cv=none; d=zohomail.com; s=zohoarc; b=ZdMDWgO8E5T+sJqwgybzduwevwffA2J/KKxXispR52b83c+igQqefhFbOLR4h6aCbpkCMAnosrxJJqe0UTOYrDHurbY6ze6LI9/96cZAyMwsKB7VgGSrS4Kuu47pXBb09mCyN0TQnqACuV/k8bjDZZhcWzadKwarrMvz3Hl2x9Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682488712; 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=ALtEZBWvyinZG0dfPm6FOHx/NNWiaTe4U5wY2dfDQSA=; b=BR70o/EvCYQ85GOTw4NByhX7myPg4xRM0Y8EZdGp84t+AQAq2DWHx5BDtck07co/q6LtpW0WJPjBwL7Eq4gNroWlNFNF3VgHWYC/oi+MpKX8iQQ92UaIomvt0tL/FntR0ZKvBGjobIW4FseQxiMZQRWVrTP+y1JBZfbEnBhG9cw= 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 1682488712206817.4882156147274; Tue, 25 Apr 2023 22:58:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prYAZ-0006LZ-SO; Wed, 26 Apr 2023 01:58:23 -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 1prYA8-00068P-LA for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:56 -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 1prYA4-0002mQ-Lv for qemu-devel@nongnu.org; Wed, 26 Apr 2023 01:57:56 -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-224-9Bf9q7W6MM-xX_AWvTCyHQ-1; Wed, 26 Apr 2023 01:57:48 -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 B5C1885C06D; Wed, 26 Apr 2023 05:57:47 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5917F14171B8; Wed, 26 Apr 2023 05:57:47 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 43F3F21F983A; Wed, 26 Apr 2023 07:57:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682488671; 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=ALtEZBWvyinZG0dfPm6FOHx/NNWiaTe4U5wY2dfDQSA=; b=BJyOELPl8wQw3woGryZYPXmty2fL2BhVNwoESw71xnyldZCH5MImPkxsKsAl2WTuzmZnLq XSWeUPES+IaoITv2LvtlznRVh0Q+sWeNnx950bIdYuW/1EOp3fxciGEstnv/u1wKYrxPNE /Qn2D3cdmPZEUURfsHMyJ9YaEAZraF4= X-MC-Unique: 9Bf9q7W6MM-xX_AWvTCyHQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PULL 17/17] qapi: allow unions to contain further unions Date: Wed, 26 Apr 2023 07:57:44 +0200 Message-Id: <20230426055744.1041930-18-armbru@redhat.com> In-Reply-To: <20230426055744.1041930-1-armbru@redhat.com> References: <20230426055744.1041930-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.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.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, 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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1682488712944100001 From: Daniel P. Berrang=C3=A9 This extends the QAPI schema validation to permit unions inside unions, provided the checks for clashing fields pass. Reviewed-by: Markus Armbruster Signed-off-by: Daniel P. Berrang=C3=A9 Message-Id: <20230420102619.348173-4-berrange@redhat.com> Signed-off-by: Markus Armbruster --- tests/unit/test-qobject-input-visitor.c | 47 +++++++++++++++ tests/unit/test-qobject-output-visitor.c | 58 +++++++++++++++++++ scripts/qapi/schema.py | 6 +- tests/qapi-schema/meson.build | 2 + tests/qapi-schema/qapi-schema-test.json | 32 ++++++++++ tests/qapi-schema/qapi-schema-test.out | 29 ++++++++++ .../union-invalid-union-subfield.err | 2 + .../union-invalid-union-subfield.json | 30 ++++++++++ .../union-invalid-union-subfield.out | 0 .../union-invalid-union-subtype.err | 2 + .../union-invalid-union-subtype.json | 29 ++++++++++ .../union-invalid-union-subtype.out | 0 12 files changed, 234 insertions(+), 3 deletions(-) create mode 100644 tests/qapi-schema/union-invalid-union-subfield.err create mode 100644 tests/qapi-schema/union-invalid-union-subfield.json create mode 100644 tests/qapi-schema/union-invalid-union-subfield.out create mode 100644 tests/qapi-schema/union-invalid-union-subtype.err create mode 100644 tests/qapi-schema/union-invalid-union-subtype.json create mode 100644 tests/qapi-schema/union-invalid-union-subtype.out diff --git a/tests/unit/test-qobject-input-visitor.c b/tests/unit/test-qobj= ect-input-visitor.c index 77fbf985be..9b3e2dbe14 100644 --- a/tests/unit/test-qobject-input-visitor.c +++ b/tests/unit/test-qobject-input-visitor.c @@ -706,6 +706,51 @@ static void test_visitor_in_union_flat(TestInputVisito= rData *data, g_assert(&base->enum1 =3D=3D &tmp->enum1); } =20 +static void test_visitor_in_union_in_union(TestInputVisitorData *data, + const void *unused) +{ + Visitor *v; + g_autoptr(TestUnionInUnion) tmp =3D NULL; + + v =3D visitor_input_test_init(data, + "{ 'type': 'value-a', " + " 'type-a': 'value-a1', " + " 'integer': 2, " + " 'name': 'fish' }"); + + visit_type_TestUnionInUnion(v, NULL, &tmp, &error_abort); + g_assert_cmpint(tmp->type, =3D=3D, TEST_UNION_ENUM_VALUE_A); + g_assert_cmpint(tmp->u.value_a.type_a, =3D=3D, TEST_UNION_ENUMA_VALUE_= A1); + g_assert_cmpint(tmp->u.value_a.u.value_a1.integer, =3D=3D, 2); + g_assert_cmpint(strcmp(tmp->u.value_a.u.value_a1.name, "fish"), =3D=3D= , 0); + + qapi_free_TestUnionInUnion(tmp); + + v =3D visitor_input_test_init(data, + "{ 'type': 'value-a', " + " 'type-a': 'value-a2', " + " 'integer': 1729, " + " 'size': 87539319 }"); + + visit_type_TestUnionInUnion(v, NULL, &tmp, &error_abort); + g_assert_cmpint(tmp->type, =3D=3D, TEST_UNION_ENUM_VALUE_A); + g_assert_cmpint(tmp->u.value_a.type_a, =3D=3D, TEST_UNION_ENUMA_VALUE_= A2); + g_assert_cmpint(tmp->u.value_a.u.value_a2.integer, =3D=3D, 1729); + g_assert_cmpint(tmp->u.value_a.u.value_a2.size, =3D=3D, 87539319); + + qapi_free_TestUnionInUnion(tmp); + + v =3D visitor_input_test_init(data, + "{ 'type': 'value-b', " + " 'integer': 1729, " + " 'onoff': true }"); + + visit_type_TestUnionInUnion(v, NULL, &tmp, &error_abort); + g_assert_cmpint(tmp->type, =3D=3D, TEST_UNION_ENUM_VALUE_B); + g_assert_cmpint(tmp->u.value_b.integer, =3D=3D, 1729); + g_assert_cmpint(tmp->u.value_b.onoff, =3D=3D, true); +} + static void test_visitor_in_alternate(TestInputVisitorData *data, const void *unused) { @@ -1216,6 +1261,8 @@ int main(int argc, char **argv) NULL, test_visitor_in_null); input_visitor_test_add("/visitor/input/union-flat", NULL, test_visitor_in_union_flat); + input_visitor_test_add("/visitor/input/union-in-union", + NULL, test_visitor_in_union_in_union); input_visitor_test_add("/visitor/input/alternate", NULL, test_visitor_in_alternate); input_visitor_test_add("/visitor/input/errors", diff --git a/tests/unit/test-qobject-output-visitor.c b/tests/unit/test-qob= ject-output-visitor.c index 7f054289fe..1535b3ad17 100644 --- a/tests/unit/test-qobject-output-visitor.c +++ b/tests/unit/test-qobject-output-visitor.c @@ -352,6 +352,62 @@ static void test_visitor_out_union_flat(TestOutputVisi= torData *data, qapi_free_UserDefFlatUnion(tmp); } =20 +static void test_visitor_out_union_in_union(TestOutputVisitorData *data, + const void *unused) +{ + QDict *qdict; + + TestUnionInUnion *tmp =3D g_new0(TestUnionInUnion, 1); + tmp->type =3D TEST_UNION_ENUM_VALUE_A; + tmp->u.value_a.type_a =3D TEST_UNION_ENUMA_VALUE_A1; + tmp->u.value_a.u.value_a1.integer =3D 42; + tmp->u.value_a.u.value_a1.name =3D g_strdup("fish"); + + visit_type_TestUnionInUnion(data->ov, NULL, &tmp, &error_abort); + qdict =3D qobject_to(QDict, visitor_get(data)); + g_assert(qdict); + g_assert_cmpstr(qdict_get_str(qdict, "type"), =3D=3D, "value-a"); + g_assert_cmpstr(qdict_get_str(qdict, "type-a"), =3D=3D, "value-a1"); + g_assert_cmpint(qdict_get_int(qdict, "integer"), =3D=3D, 42); + g_assert_cmpstr(qdict_get_str(qdict, "name"), =3D=3D, "fish"); + + qapi_free_TestUnionInUnion(tmp); + + + visitor_reset(data); + tmp =3D g_new0(TestUnionInUnion, 1); + tmp->type =3D TEST_UNION_ENUM_VALUE_A; + tmp->u.value_a.type_a =3D TEST_UNION_ENUMA_VALUE_A2; + tmp->u.value_a.u.value_a2.integer =3D 1729; + tmp->u.value_a.u.value_a2.size =3D 87539319; + + visit_type_TestUnionInUnion(data->ov, NULL, &tmp, &error_abort); + qdict =3D qobject_to(QDict, visitor_get(data)); + g_assert(qdict); + g_assert_cmpstr(qdict_get_str(qdict, "type"), =3D=3D, "value-a"); + g_assert_cmpstr(qdict_get_str(qdict, "type-a"), =3D=3D, "value-a2"); + g_assert_cmpint(qdict_get_int(qdict, "integer"), =3D=3D, 1729); + g_assert_cmpint(qdict_get_int(qdict, "size"), =3D=3D, 87539319); + + qapi_free_TestUnionInUnion(tmp); + + + visitor_reset(data); + tmp =3D g_new0(TestUnionInUnion, 1); + tmp->type =3D TEST_UNION_ENUM_VALUE_B; + tmp->u.value_b.integer =3D 1729; + tmp->u.value_b.onoff =3D true; + + visit_type_TestUnionInUnion(data->ov, NULL, &tmp, &error_abort); + qdict =3D qobject_to(QDict, visitor_get(data)); + g_assert(qdict); + g_assert_cmpstr(qdict_get_str(qdict, "type"), =3D=3D, "value-b"); + g_assert_cmpint(qdict_get_int(qdict, "integer"), =3D=3D, 1729); + g_assert_cmpint(qdict_get_bool(qdict, "onoff"), =3D=3D, true); + + qapi_free_TestUnionInUnion(tmp); +} + static void test_visitor_out_alternate(TestOutputVisitorData *data, const void *unused) { @@ -586,6 +642,8 @@ int main(int argc, char **argv) &out_visitor_data, test_visitor_out_list_qapi_= free); output_visitor_test_add("/visitor/output/union-flat", &out_visitor_data, test_visitor_out_union_flat= ); + output_visitor_test_add("/visitor/output/union-in-union", + &out_visitor_data, test_visitor_out_union_in_u= nion); output_visitor_test_add("/visitor/output/alternate", &out_visitor_data, test_visitor_out_alternate); output_visitor_test_add("/visitor/output/null", diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 27e336577f..231ebf61ba 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -465,9 +465,10 @@ def check(self, schema): # on behalf of info, which is not necessarily self.info def check_clash(self, info, seen): assert self._checked - assert not self.variants # not implemented for m in self.members: m.check_clash(info, seen) + if self.variants: + self.variants.check_clash(info, seen) =20 def connect_doc(self, doc=3DNone): super().connect_doc(doc) @@ -656,8 +657,7 @@ def check(self, schema, seen): self.info, "branch '%s' is not a value of %s" % (v.name, self.tag_member.type.describe())) - if (not isinstance(v.type, QAPISchemaObjectType) - or v.type.variants): + if not isinstance(v.type, QAPISchemaObjectType): raise QAPISemError( self.info, "%s cannot use %s" diff --git a/tests/qapi-schema/meson.build b/tests/qapi-schema/meson.build index a06515ca17..af085f745d 100644 --- a/tests/qapi-schema/meson.build +++ b/tests/qapi-schema/meson.build @@ -197,6 +197,8 @@ schemas =3D [ 'union-invalid-data.json', 'union-invalid-discriminator.json', 'union-invalid-if-discriminator.json', + 'union-invalid-union-subfield.json', + 'union-invalid-union-subtype.json', 'union-no-base.json', 'union-optional-discriminator.json', 'union-string-discriminator.json', diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index 8bbf94834a..8ca977c49d 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -114,6 +114,38 @@ { 'struct': 'UserDefC', 'data': { 'string1': 'str', 'string2': 'str' } } =20 +# this tests that unions can contain other unions in their branches +{ 'enum': 'TestUnionEnum', + 'data': [ 'value-a', 'value-b' ] } + +{ 'enum': 'TestUnionEnumA', + 'data': [ 'value-a1', 'value-a2' ] } + +{ 'struct': 'TestUnionTypeA1', + 'data': { 'integer': 'int', + 'name': 'str'} } + +{ 'struct': 'TestUnionTypeA2', + 'data': { 'integer': 'int', + 'size': 'int' } } + +{ 'union': 'TestUnionTypeA', + 'base': { 'type-a': 'TestUnionEnumA' }, + 'discriminator': 'type-a', + 'data': { 'value-a1': 'TestUnionTypeA1', + 'value-a2': 'TestUnionTypeA2' } } + +{ 'struct': 'TestUnionTypeB', + 'data': { 'integer': 'int', + 'onoff': 'bool' } } + +{ 'union': 'TestUnionInUnion', + 'base': { 'type': 'TestUnionEnum' }, + 'discriminator': 'type', + 'data': { 'value-a': 'TestUnionTypeA', + 'value-b': 'TestUnionTypeB' } } + + # for testing use of 'number' within alternates { 'alternate': 'AltEnumBool', 'data': { 'e': 'EnumOne', 'b': 'bool' } } { 'alternate': 'AltEnumNum', 'data': { 'e': 'EnumOne', 'n': 'number' } } diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index cc34b422e6..e2f0981348 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -105,6 +105,35 @@ alternate UserDefAlternate object UserDefC member string1: str optional=3DFalse member string2: str optional=3DFalse +enum TestUnionEnum + member value-a + member value-b +enum TestUnionEnumA + member value-a1 + member value-a2 +object TestUnionTypeA1 + member integer: int optional=3DFalse + member name: str optional=3DFalse +object TestUnionTypeA2 + member integer: int optional=3DFalse + member size: int optional=3DFalse +object q_obj_TestUnionTypeA-base + member type-a: TestUnionEnumA optional=3DFalse +object TestUnionTypeA + base q_obj_TestUnionTypeA-base + tag type-a + case value-a1: TestUnionTypeA1 + case value-a2: TestUnionTypeA2 +object TestUnionTypeB + member integer: int optional=3DFalse + member onoff: bool optional=3DFalse +object q_obj_TestUnionInUnion-base + member type: TestUnionEnum optional=3DFalse +object TestUnionInUnion + base q_obj_TestUnionInUnion-base + tag type + case value-a: TestUnionTypeA + case value-b: TestUnionTypeB alternate AltEnumBool tag type case e: EnumOne diff --git a/tests/qapi-schema/union-invalid-union-subfield.err b/tests/qap= i-schema/union-invalid-union-subfield.err new file mode 100644 index 0000000000..91aa87bcd8 --- /dev/null +++ b/tests/qapi-schema/union-invalid-union-subfield.err @@ -0,0 +1,2 @@ +union-invalid-union-subfield.json: In union 'TestUnion': +union-invalid-union-subfield.json:25: member 'teeth' of type 'TestTypeFish= ' collides with base member 'teeth' diff --git a/tests/qapi-schema/union-invalid-union-subfield.json b/tests/qa= pi-schema/union-invalid-union-subfield.json new file mode 100644 index 0000000000..e1639d3a96 --- /dev/null +++ b/tests/qapi-schema/union-invalid-union-subfield.json @@ -0,0 +1,30 @@ +# Clash between common member and union variant's variant member +# Base's member 'teeth' clashes with TestTypeFish's + +{ 'enum': 'TestEnum', + 'data': [ 'animals', 'plants' ] } + +{ 'enum': 'TestAnimals', + 'data': [ 'fish', 'birds'] } + +{ 'struct': 'TestTypeFish', + 'data': { 'scales': 'int', 'teeth': 'int' } } + +{ 'struct': 'TestTypeBirds', + 'data': { 'feathers': 'int' } } + +{ 'union': 'TestTypeAnimals', + 'base': { 'atype': 'TestAnimals' }, + 'discriminator': 'atype', + 'data': { 'fish': 'TestTypeFish', + 'birds': 'TestTypeBirds' } } + +{ 'struct': 'TestTypePlants', + 'data': { 'integer': 'int' } } + +{ 'union': 'TestUnion', + 'base': { 'type': 'TestEnum', + 'teeth': 'int' }, + 'discriminator': 'type', + 'data': { 'animals': 'TestTypeAnimals', + 'plants': 'TestTypePlants' } } diff --git a/tests/qapi-schema/union-invalid-union-subfield.out b/tests/qap= i-schema/union-invalid-union-subfield.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/union-invalid-union-subtype.err b/tests/qapi= -schema/union-invalid-union-subtype.err new file mode 100644 index 0000000000..3538dc2e70 --- /dev/null +++ b/tests/qapi-schema/union-invalid-union-subtype.err @@ -0,0 +1,2 @@ +union-invalid-union-subtype.json: In union 'TestUnion': +union-invalid-union-subtype.json:25: base member 'type' of type 'TestTypeA= ' collides with base member 'type' diff --git a/tests/qapi-schema/union-invalid-union-subtype.json b/tests/qap= i-schema/union-invalid-union-subtype.json new file mode 100644 index 0000000000..ce1de51d8d --- /dev/null +++ b/tests/qapi-schema/union-invalid-union-subtype.json @@ -0,0 +1,29 @@ +# Clash between common member and union variant's common member +# Base's member 'type' clashes with TestTypeA's + +{ 'enum': 'TestEnum', + 'data': [ 'value-a', 'value-b' ] } + +{ 'enum': 'TestEnumA', + 'data': [ 'value-a1', 'value-a2' ] } + +{ 'struct': 'TestTypeA1', + 'data': { 'integer': 'int' } } + +{ 'struct': 'TestTypeA2', + 'data': { 'integer': 'int' } } + +{ 'union': 'TestTypeA', + 'base': { 'type': 'TestEnumA' }, + 'discriminator': 'type', + 'data': { 'value-a1': 'TestTypeA1', + 'value-a2': 'TestTypeA2' } } + +{ 'struct': 'TestTypeB', + 'data': { 'integer': 'int' } } + +{ 'union': 'TestUnion', + 'base': { 'type': 'TestEnum' }, + 'discriminator': 'type', + 'data': { 'value-a': 'TestTypeA', + 'value-b': 'TestTypeB' } } diff --git a/tests/qapi-schema/union-invalid-union-subtype.out b/tests/qapi= -schema/union-invalid-union-subtype.out new file mode 100644 index 0000000000..e69de29bb2 --=20 2.39.2