From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569328682; cv=none; d=zoho.com; s=zohoarc; b=b3KahTOvedWHiv6kG5U159cAiX1f6CqrBqFQdnAF/bbAjVvPAZjXaPeXGZqkX7lUFHu2VPUJDk5+L4jIY4cFiq5NpA12WUdaOXWbAZOx5swm5bc9gO0bLmkmVoutu1Xq6+5ufRQcEQ6lOlA/ywriQOlWIdGvUHMS+tevxkg1NBQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569328682; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=UAK/+ZpR0fNPdjrp+1uHdGnL0+ntIFMNZfci4b4Z/po=; b=Rzp+BotMzOlNO+MiSwABpTm2OG6k5MOwcDIFIQA/9/JdU2a+4v2O5EmCX3mYtnHlIHDFpk1Wm99QCoe9kvRYJdlHcg8xEha5Uxi+gytMQ+57PEj+6szsoQMDRb7LAkAZdW/ZrobkP43nrFDJvAGSVUIwumSPP6KT3ICbRuUCMBc= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15693286828311005.0271443061876; Tue, 24 Sep 2019 05:38:02 -0700 (PDT) Received: from localhost ([::1]:45176 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk4n-0003RQ-DW for importer@patchew.org; Tue, 24 Sep 2019 08:37:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50374) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0i-0001ID-N3 for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0g-0006s4-1w for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44162) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0f-0006qy-Sy for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:38 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1332188305 for ; Tue, 24 Sep 2019 12:33:36 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D77E41001938; Tue, 24 Sep 2019 12:33:35 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 382CE113865F; Tue, 24 Sep 2019 14:33:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 01/37] qapi: Make visit_next_list()'s comment less confusing Date: Tue, 24 Sep 2019 14:32:58 +0200 Message-Id: <20190924123334.30645-2-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 24 Sep 2019 12:33:36 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" visit_next_list() returns non-null on success, null on failure. The comment's phrasing "until NULL return or error occurs" is needlessly confusing. Scratch the "or error occurs" part. Signed-off-by: Markus Armbruster Message-Id: <20190802122325.16520-1-armbru@redhat.com> Reviewed-by: Eric Blake --- include/qapi/visitor.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h index 5b2ed3f202..c5b23851a1 100644 --- a/include/qapi/visitor.h +++ b/include/qapi/visitor.h @@ -364,10 +364,10 @@ void visit_start_list(Visitor *v, const char *name, G= enericList **list, * @tail must not be NULL; on the first call, @tail is the value of * *list after visit_start_list(), and on subsequent calls @tail must * be the previously returned value. Should be called in a loop until - * a NULL return or error occurs; for each non-NULL return, the caller - * then calls the appropriate visit_type_*() for the element type of - * the list, with that function's name parameter set to NULL and obj - * set to the address of @tail->value. + * a NULL return; for each non-NULL return, the caller then calls the + * appropriate visit_type_*() for the element type of the list, with + * that function's name parameter set to NULL and obj set to the + * address of @tail->value. */ GenericList *visit_next_list(Visitor *v, GenericList *tail, size_t size); =20 --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569328676; cv=none; d=zoho.com; s=zohoarc; b=EtN9me+iGgI1ILkubONHXTDnCib/mshhOUvUDvYzn2ftoCzU2rnhCe73/tpCnKb71FNs+1Hn+eTxwh+ZTj8nBjhdcUNsjoBDSrRwvo4Ys5d3XJyxSDs16Ib7dG3qD1x81iX2p4vzPGNbZx3b4s6TiGn3Aa1mkxhVAMgwWekARFs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569328676; h=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:ARC-Authentication-Results; bh=dIF4LbYDjRszsGPbabUMxwlMh3GKhANUSMUZJQHVcA4=; b=hQvPsGR8MUs8bGqO3LQTHFFx9wOrTwwMZzPSBQO45hPFYXco/TwJ6UhVOl7Ff/7GB+S2b21ePUEyvk7xp7oh47rYs3tsb0/sUXL5SVaqFjsRsibdFjx9FvN/u6YTTfC0qWCRorKOcRrl9L66Tb1W/HKWD0hDNM5LaGbnWa1LNgI= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569328676071700.9501693993433; Tue, 24 Sep 2019 05:37:56 -0700 (PDT) Received: from localhost ([::1]:45178 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk4n-0003TL-He for importer@patchew.org; Tue, 24 Sep 2019 08:37:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50377) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0i-0001IG-Ea for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0g-0006sH-58 for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39081) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0f-0006rM-T7 for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:38 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6654218C8914; Tue, 24 Sep 2019 12:33:36 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D75825C1B2; Tue, 24 Sep 2019 12:33:35 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 42B1F1138660; Tue, 24 Sep 2019 14:33:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 02/37] make check-unit: use after free in test-opts-visitor Date: Tue, 24 Sep 2019 14:32:59 +0200 Message-Id: <20190924123334.30645-3-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.70]); Tue, 24 Sep 2019 12:33:36 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrey Shinkevich Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Andrey Shinkevich In the struct OptsVisitor, the 'repeated_opts' member points to a list in the 'unprocessed_opts' hash table after the list has been destroyed. A subsequent call to visit_type_int() references the deleted list. It results in use-after-free issue reproduced by running the test case under the Valgrind: valgrind tests/test-opts-visitor. A new mode ListMode::LM_TRAVERSED is declared to mark the list traversal completed. Suggested-by: Markus Armbruster Signed-off-by: Andrey Shinkevich Message-Id: <1565024586-387112-1-git-send-email-andrey.shinkevich@virtuozzo= .com> --- qapi/opts-visitor.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c index 324b197495..5fe0276c1c 100644 --- a/qapi/opts-visitor.c +++ b/qapi/opts-visitor.c @@ -24,7 +24,8 @@ enum ListMode { LM_NONE, /* not traversing a list of repeated options */ =20 - LM_IN_PROGRESS, /* opts_next_list() ready to be called. + LM_IN_PROGRESS, /* + * opts_next_list() ready to be called. * * Generating the next list link will consume the= most * recently parsed QemuOpt instance of the repeat= ed @@ -36,7 +37,8 @@ enum ListMode * LM_UNSIGNED_INTERVAL. */ =20 - LM_SIGNED_INTERVAL, /* opts_next_list() has been called. + LM_SIGNED_INTERVAL, /* + * opts_next_list() has been called. * * Generating the next list link will consume the= most * recently stored element from the signed interv= al, @@ -48,7 +50,14 @@ enum ListMode * next element of the signed interval. */ =20 - LM_UNSIGNED_INTERVAL /* Same as above, only for an unsigned interval. = */ + LM_UNSIGNED_INTERVAL, /* Same as above, only for an unsigned interval.= */ + + LM_TRAVERSED /* + * opts_next_list() has been called. + * + * No more QemuOpt instance in the list. + * The traversal has been completed. + */ }; =20 typedef enum ListMode ListMode; @@ -238,6 +247,8 @@ opts_next_list(Visitor *v, GenericList *tail, size_t si= ze) OptsVisitor *ov =3D to_ov(v); =20 switch (ov->list_mode) { + case LM_TRAVERSED: + return NULL; case LM_SIGNED_INTERVAL: case LM_UNSIGNED_INTERVAL: if (ov->list_mode =3D=3D LM_SIGNED_INTERVAL) { @@ -258,6 +269,8 @@ opts_next_list(Visitor *v, GenericList *tail, size_t si= ze) opt =3D g_queue_pop_head(ov->repeated_opts); if (g_queue_is_empty(ov->repeated_opts)) { g_hash_table_remove(ov->unprocessed_opts, opt->name); + ov->repeated_opts =3D NULL; + ov->list_mode =3D LM_TRAVERSED; return NULL; } break; @@ -289,7 +302,8 @@ opts_end_list(Visitor *v, void **obj) =20 assert(ov->list_mode =3D=3D LM_IN_PROGRESS || ov->list_mode =3D=3D LM_SIGNED_INTERVAL || - ov->list_mode =3D=3D LM_UNSIGNED_INTERVAL); + ov->list_mode =3D=3D LM_UNSIGNED_INTERVAL || + ov->list_mode =3D=3D LM_TRAVERSED); ov->repeated_opts =3D NULL; ov->list_mode =3D LM_NONE; } @@ -306,6 +320,10 @@ lookup_scalar(const OptsVisitor *ov, const char *name,= Error **errp) list =3D lookup_distinct(ov, name, errp); return list ? g_queue_peek_tail(list) : NULL; } + if (ov->list_mode =3D=3D LM_TRAVERSED) { + error_setg(errp, "Fewer list elements than expected"); + return NULL; + } assert(ov->list_mode =3D=3D LM_IN_PROGRESS); return g_queue_peek_head(ov->repeated_opts); } --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569329213; cv=none; d=zoho.com; s=zohoarc; b=MaUgffQLaT7PK7o+Mz6G/B26Z6NfHmVDpOeQMvDTKq1B7EG6z2uiSBXOLYMOnzDTEumR9QwflLYXGvv/QOGtw3Lr/fsTKaL5xFSfIS6b0nA4yvwXr1bTUPhLPA23REcNEx5XsjFgF/MYVB0GuwiV91jyvKUiII/ABj8Cc56xWvQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569329213; 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:ARC-Authentication-Results; bh=F3oh4ZbbJivonAWS9LPBp/nVCdFlSqDl7oNZY5h4Ll0=; b=nm1/HuGWIEHUpbxZuD5hnS2NLGYNEVIQlF+ErSjXNf9eFb042yQL0jk4EJXie+fD9FfVyOTMN5h/GBDIV9EhJrK8BBP6w3AxL/SChHv2pkl/FwgM2JhUfFj4OfrCCD81SD1cApMcz4V8PmbOy35zDfAfa6+MGDMUNfhqdp2smbs= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569329213968460.9489427772917; Tue, 24 Sep 2019 05:46:53 -0700 (PDT) Received: from localhost ([::1]:45270 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCkDT-000382-LL for importer@patchew.org; Tue, 24 Sep 2019 08:46:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50554) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0o-0001KH-8P for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0k-0006yo-D1 for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52922) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0j-0006w9-V1 for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:42 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CC76310C0936 for ; Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D20C15D9D5; Tue, 24 Sep 2019 12:33:35 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 4B0031138661; Tue, 24 Sep 2019 14:33:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 03/37] scripts/git.orderfile: Match QAPI schema more precisely Date: Tue, 24 Sep 2019 14:33:00 +0200 Message-Id: <20190924123334.30645-4-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.66]); Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Pattern *.json also matches the tests/qapi-schema/*.json. Separates them from the tests/qapi-schema/*.{err,exit,out} in diffs. I hate that. Change the pattern to match just the "real" QAPI schemata. Signed-off-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20190913201349.24332-2-armbru@redhat.com> --- scripts/git.orderfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/git.orderfile b/scripts/git.orderfile index ac699700b1..e89790941c 100644 --- a/scripts/git.orderfile +++ b/scripts/git.orderfile @@ -19,11 +19,11 @@ Makefile* *.mak =20 # qapi schema -*.json +qapi/*.json +qga/*.json =20 # headers *.h =20 # code *.c - --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569328682; cv=none; d=zoho.com; s=zohoarc; b=eUI2WMqtun5iPTOZugcqs0P1cyrIsI5GR60aarprZ21SiWrzwLflJpeYPRXQV3R4vi4CR/x+YmLgC7t2K4xeLVDfJ57XRhtnaofjkGQAdVBhtruhjkHOMVLOjRjwvxaZoTgcMqDzUCbwYSmcxkDWrtAeuWy5Olf2YYBsGXWcJYA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569328682; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=F/3KpOelSilKfLDQBx/jkz+ENWrdp5+ybvnhv5O0wCk=; b=lzhHbH/GHR64pnpHOfgbeApa+rJzE8WIGpIBWsmcY4J6tL8/rGHKhNC9blMB7uJhE64nUFugDyI8sDWAffPVy88k9iVPnpIR2AbTCv9arVHb0bdTj+YEr3GDkcUDEhNsocJoTToI5J9JWxrXpTeYBL6qEGmlRt92OK/wkJaqGiY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569328682310635.9078346051863; Tue, 24 Sep 2019 05:38:02 -0700 (PDT) Received: from localhost ([::1]:45174 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk4k-0003PU-6a for importer@patchew.org; Tue, 24 Sep 2019 08:37:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50375) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0i-0001IE-ET for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0g-0006sN-5f for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49338) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0f-0006r2-TA for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:38 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3ABA080F91 for ; Tue, 24 Sep 2019 12:33:36 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D761D194B2; Tue, 24 Sep 2019 12:33:35 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5104D11386A6; Tue, 24 Sep 2019 14:33:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 04/37] qapi: Drop check_type()'s redundant parameter @allow_optional Date: Tue, 24 Sep 2019 14:33:01 +0200 Message-Id: <20190924123334.30645-5-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 24 Sep 2019 12:33:36 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" check_type() uses @allow_optional only when @value is a dictionary and @allow_dict is True. All callers that pass allow_dict=3DTrue also pass allow_optional=3DTrue. Therefore, @allow_optional is always True when check_type() uses it. Drop the redundant parameter. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20190913201349.24332-3-armbru@redhat.com> --- scripts/qapi/common.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index d61bfdc526..9aefcfe015 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -783,9 +783,8 @@ def check_if(expr, info): check_if_str(ifcond, info) =20 =20 -def check_type(info, source, value, allow_array=3DFalse, - allow_dict=3DFalse, allow_optional=3DFalse, - allow_metas=3D[]): +def check_type(info, source, value, + allow_array=3DFalse, allow_dict=3DFalse, allow_metas=3D[]): global all_names =20 if value is None: @@ -821,7 +820,7 @@ def check_type(info, source, value, allow_array=3DFalse, # value is a dictionary, check that each member is okay for (key, arg) in value.items(): check_name(info, "Member of %s" % source, key, - allow_optional=3Dallow_optional) + allow_optional=3DTrue) if c_name(key, False) =3D=3D 'u' or c_name(key, False).startswith(= 'has_'): raise QAPISemError(info, "Member of %s uses reserved name '%s'" % (source, key)) @@ -843,14 +842,14 @@ def check_command(expr, info): if boxed: args_meta +=3D ['union', 'alternate'] check_type(info, "'data' for command '%s'" % name, - expr.get('data'), allow_dict=3Dnot boxed, allow_optional=3D= True, + expr.get('data'), allow_dict=3Dnot boxed, allow_metas=3Dargs_meta) returns_meta =3D ['union', 'struct'] if name in returns_whitelist: returns_meta +=3D ['built-in', 'alternate', 'enum'] check_type(info, "'returns' for command '%s'" % name, expr.get('returns'), allow_array=3DTrue, - allow_optional=3DTrue, allow_metas=3Dreturns_meta) + allow_metas=3Dreturns_meta) =20 =20 def check_event(expr, info): @@ -861,7 +860,7 @@ def check_event(expr, info): if boxed: meta +=3D ['union', 'alternate'] check_type(info, "'data' for event '%s'" % name, - expr.get('data'), allow_dict=3Dnot boxed, allow_optional=3D= True, + expr.get('data'), allow_dict=3Dnot boxed, allow_metas=3Dmeta) =20 =20 @@ -889,7 +888,7 @@ def check_union(expr, info): else: # The object must have a string or dictionary 'base'. check_type(info, "'base' for union '%s'" % name, - base, allow_dict=3DTrue, allow_optional=3DTrue, + base, allow_dict=3DTrue, allow_metas=3D['struct']) if not base: raise QAPISemError(info, "Flat union '%s' must have a base" @@ -1012,7 +1011,7 @@ def check_struct(expr, info): features =3D expr.get('features') =20 check_type(info, "'data' for struct '%s'" % name, members, - allow_dict=3DTrue, allow_optional=3DTrue) + allow_dict=3DTrue) check_type(info, "'base' for struct '%s'" % name, expr.get('base'), allow_metas=3D['struct']) =20 --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569329210; cv=none; d=zoho.com; s=zohoarc; b=f2btN141a8Ol/0fz6/R4eQttEHHvn8Hjdd2fj9rHiuPNSbKj0g5L9884l80zQJl4wgT4A395UQj6IHIzV9arOL77f7DAsKF2lrQhZsl0nN0ByJ4lGJDmIvul5P7r5+s5c6iZc2S2/iG6eHPfUWzJX0sQmCwhIE4YGXTLQ0TH1to= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569329210; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=GnZ8bM/xLQXVjqOWLfILFd3MIlbI9zpzPnCpA1hlz1s=; b=Gmgmn2cKjHo7E6rA3pBhPfkm+maFDBUEMPYqxBQMl6sFrQfa4qBc0cpzZQc/EtCFNFoSDqa97Yl/ngzxh4nLkLmswhDbYbXcNOCHkEWzBhm2MTlyHJpznxTSz1DR8kC+JDmxVmi+OihviJ3LNh/FXF9S5mV91d/OtlpS5F9lm20= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569329210277348.75590886681437; Tue, 24 Sep 2019 05:46:50 -0700 (PDT) Received: from localhost ([::1]:45262 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCkDL-0002tS-SH for importer@patchew.org; Tue, 24 Sep 2019 08:46:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50418) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0j-0001IT-JI for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0g-0006t6-NX for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55460) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0g-0006rs-Ec for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:38 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B3A152BF73 for ; Tue, 24 Sep 2019 12:33:37 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5B2F95D721; Tue, 24 Sep 2019 12:33:37 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 567B911386A7; Tue, 24 Sep 2019 14:33:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 05/37] qapi: Drop support for boxed alternate arguments Date: Tue, 24 Sep 2019 14:33:02 +0200 Message-Id: <20190924123334.30645-6-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 24 Sep 2019 12:33:37 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Commands and events can define their argument type inline (default) or by referring to another type ('boxed': true, since commit c818408e44 "qapi: Implement boxed types for commands/events", v2.7.0). The unboxed inline definition is an (anonymous) struct type. The boxed type may be a struct, union, or alternate type. The latter is problematic: docs/interop/qemu-spec.txt requires the value of the 'data' key to be a json-object, but any non-degenerate alternate type has at least one branch that isn't. Fortunately, we haven't made use of alternates in this context outside tests/. Drop support for them. QAPISchemaAlternateType.is_empty() is now unused. Drop it, too. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20190913201349.24332-4-armbru@redhat.com> --- docs/devel/qapi-code-gen.txt | 12 ++++++------ scripts/qapi/common.py | 15 ++++----------- tests/qapi-schema/qapi-schema-test.json | 2 +- tests/qapi-schema/qapi-schema-test.out | 2 +- 4 files changed, 12 insertions(+), 19 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index e8ec8ac1de..3d3931fb7a 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -612,9 +612,9 @@ the command. Normally, 'data' is a dictionary for an a= nonymous type, or names a struct type (possibly empty, but not a union), and its members are passed as separate arguments to this function. If the command definition includes a key 'boxed' with the boolean value true, -then 'data' is instead the name of any non-empty complex type -(struct, union, or alternate), and a pointer to that QAPI type is -passed as a single argument. +then 'data' is instead the name of any non-empty complex type (struct +or union), and a pointer to that QAPI type is passed as a single +argument. =20 The generator also emits a marshalling function that extracts arguments for the user's function out of an input QDict, calls the @@ -714,9 +714,9 @@ The generator emits a function to send the event. Norm= ally, 'data' is a dictionary for an anonymous type, or names a struct type (possibly empty, but not a union), and its members are passed as separate arguments to this function. If the event definition includes a key -'boxed' with the boolean value true, then 'data' is instead the name of -any non-empty complex type (struct, union, or alternate), and a -pointer to that QAPI type is passed as a single argument. +'boxed' with the boolean value true, then 'data' is instead the name +of any non-empty complex type (struct or union), and a pointer to that +QAPI type is passed as a single argument. =20 =20 =3D=3D=3D Features =3D=3D=3D diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 9aefcfe015..54d02458b5 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -840,7 +840,7 @@ def check_command(expr, info): =20 args_meta =3D ['struct'] if boxed: - args_meta +=3D ['union', 'alternate'] + args_meta +=3D ['union'] check_type(info, "'data' for command '%s'" % name, expr.get('data'), allow_dict=3Dnot boxed, allow_metas=3Dargs_meta) @@ -858,7 +858,7 @@ def check_event(expr, info): =20 meta =3D ['struct'] if boxed: - meta +=3D ['union', 'alternate'] + meta +=3D ['union'] check_type(info, "'data' for event '%s'" % name, expr.get('data'), allow_dict=3Dnot boxed, allow_metas=3Dmeta) @@ -1690,9 +1690,6 @@ class QAPISchemaAlternateType(QAPISchemaType): visitor.visit_alternate_type(self.name, self.info, self.ifcond, self.variants) =20 - def is_empty(self): - return False - =20 class QAPISchemaCommand(QAPISchemaEntity): def __init__(self, name, info, doc, ifcond, arg_type, ret_type, @@ -1714,15 +1711,13 @@ class QAPISchemaCommand(QAPISchemaEntity): QAPISchemaEntity.check(self, schema) if self._arg_type_name: self.arg_type =3D schema.lookup_type(self._arg_type_name) - assert (isinstance(self.arg_type, QAPISchemaObjectType) or - isinstance(self.arg_type, QAPISchemaAlternateType)) + assert isinstance(self.arg_type, QAPISchemaObjectType) self.arg_type.check(schema) if self.boxed: if self.arg_type.is_empty(): raise QAPISemError(self.info, "Cannot use 'boxed' with empty type= ") else: - assert not isinstance(self.arg_type, QAPISchemaAlternateTy= pe) assert not self.arg_type.variants elif self.boxed: raise QAPISemError(self.info, "Use of 'boxed' requires 'data'") @@ -1750,15 +1745,13 @@ class QAPISchemaEvent(QAPISchemaEntity): QAPISchemaEntity.check(self, schema) if self._arg_type_name: self.arg_type =3D schema.lookup_type(self._arg_type_name) - assert (isinstance(self.arg_type, QAPISchemaObjectType) or - isinstance(self.arg_type, QAPISchemaAlternateType)) + assert isinstance(self.arg_type, QAPISchemaObjectType) self.arg_type.check(schema) if self.boxed: if self.arg_type.is_empty(): raise QAPISemError(self.info, "Cannot use 'boxed' with empty type= ") else: - assert not isinstance(self.arg_type, QAPISchemaAlternateTy= pe) assert not self.arg_type.variants elif self.boxed: raise QAPISemError(self.info, "Use of 'boxed' requires 'data'") diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index c6d59acc3e..0fadb4ddd7 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -180,7 +180,7 @@ { 'event': 'EVENT_D', 'data': { 'a' : 'EventStructOne', 'b' : 'str', '*c': 'str', '*enum3': 'E= numOne' } } { 'event': 'EVENT_E', 'boxed': true, 'data': 'UserDefZero' } -{ 'event': 'EVENT_F', 'boxed': true, 'data': 'UserDefAlternate' } +{ 'event': 'EVENT_F', 'boxed': true, 'data': 'UserDefFlatUnion' } =20 # test that we correctly compile downstream extensions, as well as munge # ticklish names diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 85d510bc00..5470a525f5 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -252,7 +252,7 @@ event EVENT_D q_obj_EVENT_D-arg boxed=3DFalse event EVENT_E UserDefZero boxed=3DTrue -event EVENT_F UserDefAlternate +event EVENT_F UserDefFlatUnion boxed=3DTrue enum __org.qemu_x-Enum member __org.qemu_x-value --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569328682; cv=none; d=zoho.com; s=zohoarc; b=a0MwFmWLYwINlwJHMbRxIPa1woB83WqMvzIh5sYVR2xf/KdY9cnjPu5BvmvnFfNHhhB8EZdruvvxnXyq5G2uqOi5yC5g58W4ggJCesXbvLcSZBWhX4IUwXNAvra6khp/lezHXyNkpNvG7FWRj2Ek/wc2YtyLuZHZSEtc6fnKiiI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569328682; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=h+J6hOoMVOcffMtOMtcpUIXbb50PE/JCRxfbP87G5KY=; b=JC5ETLD/Eza4YDWNnXb3z3CL70c4OdqCdmgoe7UX0PKUQkkBJDHYLoWT4A4C9q3mD1VWrflEviI78pATTdf79nvfmuAaAOT7b1+SO87JKNDBUzajZHcK7IiddfdQPslO3XbknLpxgoSikk6Kq+RjQB3xZSk6rAVCs1F25lcwRxo= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569328682938125.13890316979519; Tue, 24 Sep 2019 05:38:02 -0700 (PDT) Received: from localhost ([::1]:45182 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk4r-0003Wg-Li for importer@patchew.org; Tue, 24 Sep 2019 08:37:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50417) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0j-0001IS-GR for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0g-0006sz-Mh for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39114) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0g-0006ru-DM for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:38 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B784C800DF4 for ; Tue, 24 Sep 2019 12:33:37 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5CD825C1B2; Tue, 24 Sep 2019 12:33:37 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5CBAC11386A8; Tue, 24 Sep 2019 14:33:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 06/37] docs/devel/qapi-code-gen: Minor specification fixes Date: Tue, 24 Sep 2019 14:33:03 +0200 Message-Id: <20190924123334.30645-7-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.67]); Tue, 24 Sep 2019 12:33:37 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The specification claims "Each expression that isn't an include directive may be preceded by a documentation block", but the code also rejects them for pragma directives. The code is correct. Fix the specification. The specification reserves member names starting with 'has_', but the code also reserves name 'u'. Fix the specification. The specification claims "The string 'max' is not allowed as an enum value". Untrue. Fix the specification. While there, delete the naming advice, because it's redundant with the naming rules in section "Schema overview" The specification claims "No branch of the union can be named 'max', as this would collide with the implicit enum". Untrue. Fix the specification. The specification claims "It is not allowed to name an event 'MAX', since the generator also produces a C enumeration of all event names with a generated _MAX value at the end." Untrue. Fix the specification. The specification claims "All branches of the union must be complex types", but the code permits only struct types. The code is correct. Fix the specification. The specification claims a command's return type "must be the string name of a complex or built-in type, a one-element array containing the name of a complex or built-in type" unless the command is in pragma 'returns-whitelist'. The code does not permit built-in types. Fix the specification. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20190913201349.24332-5-armbru@redhat.com> --- docs/devel/qapi-code-gen.txt | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index 3d3931fb7a..4ce67752a7 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -117,9 +117,9 @@ Example: =20 =3D=3D=3D=3D Expression documentation =3D=3D=3D=3D =20 -Each expression that isn't an include directive may be preceded by a -documentation block. Such blocks are called expression documentation -blocks. +Expressions other than include and pragma directives may be preceded +by a documentation block. Such blocks are called expression +documentation blocks. =20 When documentation is required (see pragma 'doc-required'), expression documentation blocks are mandatory. @@ -243,8 +243,9 @@ underscore. =20 Event names should be ALL_CAPS with words separated by underscore. =20 -Member names starting with 'has-' or 'has_' are reserved for the -generator, which uses them for tracking optional members. +Member name 'u' and names starting with 'has-' or 'has_' are reserved +for the generator, which uses them for unions and for tracking +optional members. =20 Any name (command, event, type, member, or enum value) beginning with "x-" is marked experimental, and may be withdrawn or changed @@ -460,15 +461,14 @@ discriminator value, as in these examples: =20 The generated C code uses a struct containing a union. Additionally, an implicit C enum 'NameKind' is created, corresponding to the union -'Name', for accessing the various branches of the union. No branch of -the union can be named 'max', as this would collide with the implicit -enum. The value for each branch can be of any type. +'Name', for accessing the various branches of the union. The value +for each branch can be of any type. =20 A flat union definition avoids nesting on the wire, and specifies a set of common members that occur in all variants of the union. The 'base' key must specify either a type name (the type must be a struct, not a union), or a dictionary representing an anonymous type. -All branches of the union must be complex types, and the top-level +All branches of the union must be struct types, and the top-level members of the union dictionary on the wire will be combination of members from both the base type and the appropriate branch type (when merging two dictionaries, there must be no keys in common). The @@ -578,8 +578,8 @@ The 'returns' member describes what will appear in the = "return" member of a Client JSON Protocol reply on successful completion of a command. The member is optional from the command declaration; if absent, the "return" member will be an empty dictionary. If 'returns' is present, -it must be the string name of a complex or built-in type, a -one-element array containing the name of a complex or built-in type. +it must be the string name of a complex type, or a +one-element array containing the name of a complex type. To return anything else, you have to list the command in pragma 'returns-whitelist'. If you do this, the command cannot be extended to return additional information in the future. Use of @@ -691,13 +691,11 @@ started with --preconfig. Usage: { 'event': STRING, '*data': COMPLEX-TYPE-NAME-OR-DICT, '*boxed': true } =20 -Events are defined with the keyword 'event'. It is not allowed to -name an event 'MAX', since the generator also produces a C enumeration -of all event names with a generated _MAX value at the end. When -'data' is also specified, additional info will be included in the -event, with similar semantics to a 'struct' expression. Finally there -will be C API generated in qapi-events.h; when called by QEMU code, a -message with timestamp will be emitted on the wire. +Events are defined with the keyword 'event'. When 'data' is also +specified, additional info will be included in the event, with similar +semantics to a 'struct' expression. Finally there will be C API +generated in qapi-events.h; when called by QEMU code, a message with +timestamp will be emitted on the wire. =20 An example event is: =20 --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569328933; cv=none; d=zoho.com; s=zohoarc; b=PwIIVfhm5HFgCvFIlZz1LmEkySWF14DsxuZeYgmuMMLrFf16LH4JAcA24BXuq2gSakml9ge9ux6dG0umA+36z/MH6dY8x6yzdXN24svAKDg6AQ+uQ4iGf7SGlei4PgT6TEOTyZR5DWLSes7wYybNAzPqmCksbPwvr0WvkgGauvk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569328933; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=gHz+jSbI7++jrrjVZrSF/lJUhiYKrI4hgAfNKkCT5YA=; b=KBDCtIQ3ZMDvcAR1M8bpRexhKx+63O/S69XyeGxpNal6y94QT8tchEmaDGpdNrMvUefW3H1rGJrpMBHy+yqeixQfNLzoLQf1VBaE4X9A4uHEaHcHc7Zd+vnNMH0n6FWdZL8+QbkAjD3i7UJr27CS/zTK5TlSTg1odCZN0wCFFPU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569328933420747.6453157697309; Tue, 24 Sep 2019 05:42:13 -0700 (PDT) Received: from localhost ([::1]:45224 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk8x-0007Kv-7n for importer@patchew.org; Tue, 24 Sep 2019 08:42:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50395) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0i-0001IQ-Ke for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0h-0006tJ-3N for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52902) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0g-0006sc-P4 for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:38 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0FEEF10C0936 for ; Tue, 24 Sep 2019 12:33:38 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 79E245B6A5; Tue, 24 Sep 2019 12:33:37 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 6359E11385FD; Tue, 24 Sep 2019 14:33:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 07/37] tests/qapi-schema: Demonstrate bad reporting of funny characters Date: Tue, 24 Sep 2019 14:33:04 +0200 Message-Id: <20190924123334.30645-8-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.66]); Tue, 24 Sep 2019 12:33:38 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Invalid name 'not\\possible' is reported as 'not\possible'. Control characters (quoted or not) are even more confusing. Mark FIXME. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20190913201349.24332-6-armbru@redhat.com> --- tests/qapi-schema/enum-bad-name.err | 2 +- tests/qapi-schema/enum-bad-name.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/qapi-schema/enum-bad-name.err b/tests/qapi-schema/enum-b= ad-name.err index 9c3c1002b7..26a09f84ad 100644 --- a/tests/qapi-schema/enum-bad-name.err +++ b/tests/qapi-schema/enum-bad-name.err @@ -1 +1 @@ -tests/qapi-schema/enum-bad-name.json:2: Member of enum 'MyEnum' uses inval= id name 'not^possible' +tests/qapi-schema/enum-bad-name.json:3: Member of enum 'MyEnum' uses inval= id name 'not\possible' diff --git a/tests/qapi-schema/enum-bad-name.json b/tests/qapi-schema/enum-= bad-name.json index 8506562b31..1c4620edda 100644 --- a/tests/qapi-schema/enum-bad-name.json +++ b/tests/qapi-schema/enum-bad-name.json @@ -1,2 +1,3 @@ # we ensure all enum names can map to C -{ 'enum': 'MyEnum', 'data': [ 'not^possible' ] } +# FIXME reports 'not\possible' instead of 'not\\possible' +{ 'enum': 'MyEnum', 'data': [ 'not\\possible' ] } --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569330207; cv=none; d=zoho.com; s=zohoarc; b=Q+wOMyzZdSlDmdgLM4vjK8L2FkC5PEbRl8X4PbIgB/VKs7MUatGGTBy5PZi9oO1kGR9XkffXGrKtOTrcQDmS2D24DHKE4eJs5M8Qsg3Wyedbvkdw3HWlhjJyL2I5gZm+rDpCQhnHCG65cmSYBWtje8KGJd8w+BtwbVSWUo+taow= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569330207; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=uGVPNMHF0AcPd7aDaLN2zQWekcTlus4oMOf4u5V3OpM=; b=JJFrTuKm9/B+c9XgjHeSTOurxmtOax54mtnZjhrdVseWzw7sTLaY3ACbCV1fE+ZCwqcHPjCStThZmFdU7hAb6DlPOjkAUTItlw3JJARmm4Gt+mAWpcnrDZJnwkWfUGISajWQsJUV/oj5sNiAyEcbWy2wcZfE6WPGN9kPivu8o5Q= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 156933020715636.51595054161521; Tue, 24 Sep 2019 06:03:27 -0700 (PDT) Received: from localhost ([::1]:45368 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCkTU-0000DF-BA for importer@patchew.org; Tue, 24 Sep 2019 09:03:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50599) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0p-0001Le-IJ for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0j-0006y3-P9 for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38434) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0j-0006v5-3j for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:41 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 39E8A300D243 for ; Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8883560BFB; Tue, 24 Sep 2019 12:33:37 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 6A65D113860E; Tue, 24 Sep 2019 14:33:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 08/37] qapi: Restrict strings to printable ASCII Date: Tue, 24 Sep 2019 14:33:05 +0200 Message-Id: <20190924123334.30645-9-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" RFC 8259 on string contents: All Unicode characters may be placed within the quotation marks, except for the characters that MUST be escaped: quotation mark, reverse solidus, and the control characters (U+0000 through U+001F). The QAPI schema parser accepts both less and more than JSON: it accepts only ASCII with \u (less), and accepts control characters other than LF (new line) unescaped. How it treats unescaped non-ASCII input differs between Python 2 and Python 3. Make it accept strictly less: require printable ASCII. Drop support for \b, \f, \n, \r, \t. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20190913201349.24332-7-armbru@redhat.com> --- scripts/qapi/common.py | 28 ++++++++----------- tests/Makefile.include | 3 +- tests/qapi-schema/string-code-point-127.err | 1 + ...de-str.exit =3D> string-code-point-127.exit} | 0 tests/qapi-schema/string-code-point-127.json | 2 ++ ...code-str.out =3D> string-code-point-127.out} | 0 tests/qapi-schema/string-code-point-31.err | 1 + tests/qapi-schema/string-code-point-31.exit | 1 + tests/qapi-schema/string-code-point-31.json | 2 ++ tests/qapi-schema/string-code-point-31.out | 0 tests/qapi-schema/unicode-str.err | 1 - tests/qapi-schema/unicode-str.json | 2 -- 12 files changed, 20 insertions(+), 21 deletions(-) create mode 100644 tests/qapi-schema/string-code-point-127.err rename tests/qapi-schema/{unicode-str.exit =3D> string-code-point-127.exit= } (100%) create mode 100644 tests/qapi-schema/string-code-point-127.json rename tests/qapi-schema/{unicode-str.out =3D> string-code-point-127.out} = (100%) create mode 100644 tests/qapi-schema/string-code-point-31.err create mode 100644 tests/qapi-schema/string-code-point-31.exit create mode 100644 tests/qapi-schema/string-code-point-31.json create mode 100644 tests/qapi-schema/string-code-point-31.out delete mode 100644 tests/qapi-schema/unicode-str.err delete mode 100644 tests/qapi-schema/unicode-str.json diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 54d02458b5..539b50f9ac 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -515,6 +515,7 @@ class QAPISchemaParser(object): elif self.tok in '{}:,[]': return elif self.tok =3D=3D "'": + # Note: we accept only printable ASCII string =3D '' esc =3D False while True: @@ -523,17 +524,9 @@ class QAPISchemaParser(object): if ch =3D=3D '\n': raise QAPIParseError(self, 'Missing terminating "\= '"') if esc: - if ch =3D=3D 'b': - string +=3D '\b' - elif ch =3D=3D 'f': - string +=3D '\f' - elif ch =3D=3D 'n': - string +=3D '\n' - elif ch =3D=3D 'r': - string +=3D '\r' - elif ch =3D=3D 't': - string +=3D '\t' - elif ch =3D=3D 'u': + # Note: we don't recognize escape sequences + # for control characters + if ch =3D=3D 'u': value =3D 0 for _ in range(0, 4): ch =3D self.src[self.cursor] @@ -552,20 +545,21 @@ class QAPISchemaParser(object): 'For now, \\u escape ' 'only supports non-ze= ro ' 'values up to \\u007f= ') - string +=3D chr(value) - elif ch in '\\/\'"': - string +=3D ch - else: + ch =3D chr(value) + elif ch not in '\\/\'"': raise QAPIParseError(self, "Unknown escape \\%s" % c= h) esc =3D False elif ch =3D=3D '\\': esc =3D True + continue elif ch =3D=3D "'": self.val =3D string return - else: - string +=3D ch + if ord(ch) < 32 or ord(ch) >=3D 127: + raise QAPIParseError( + self, "Funny character in string") + string +=3D ch elif self.src.startswith('true', self.pos): self.val =3D True self.cursor +=3D 3 diff --git a/tests/Makefile.include b/tests/Makefile.include index 479664f899..393cfd78f0 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -451,6 +451,8 @@ qapi-schema +=3D returns-array-bad.json qapi-schema +=3D returns-dict.json qapi-schema +=3D returns-unknown.json qapi-schema +=3D returns-whitelist.json +qapi-schema +=3D string-code-point-31.json +qapi-schema +=3D string-code-point-127.json qapi-schema +=3D struct-base-clash-deep.json qapi-schema +=3D struct-base-clash.json qapi-schema +=3D struct-data-invalid.json @@ -462,7 +464,6 @@ qapi-schema +=3D type-bypass-bad-gen.json qapi-schema +=3D unclosed-list.json qapi-schema +=3D unclosed-object.json qapi-schema +=3D unclosed-string.json -qapi-schema +=3D unicode-str.json qapi-schema +=3D union-base-empty.json qapi-schema +=3D union-base-no-discriminator.json qapi-schema +=3D union-branch-case.json diff --git a/tests/qapi-schema/string-code-point-127.err b/tests/qapi-schem= a/string-code-point-127.err new file mode 100644 index 0000000000..c310910c23 --- /dev/null +++ b/tests/qapi-schema/string-code-point-127.err @@ -0,0 +1 @@ +tests/qapi-schema/string-code-point-127.json:2:14: Funny character in stri= ng diff --git a/tests/qapi-schema/unicode-str.exit b/tests/qapi-schema/string-= code-point-127.exit similarity index 100% rename from tests/qapi-schema/unicode-str.exit rename to tests/qapi-schema/string-code-point-127.exit diff --git a/tests/qapi-schema/string-code-point-127.json b/tests/qapi-sche= ma/string-code-point-127.json new file mode 100644 index 0000000000..480318a69f --- /dev/null +++ b/tests/qapi-schema/string-code-point-127.json @@ -0,0 +1,2 @@ +# We accept printable ASCII: code points 32..126. Test code point 127: +{ 'command': '=7F' } diff --git a/tests/qapi-schema/unicode-str.out b/tests/qapi-schema/string-c= ode-point-127.out similarity index 100% rename from tests/qapi-schema/unicode-str.out rename to tests/qapi-schema/string-code-point-127.out diff --git a/tests/qapi-schema/string-code-point-31.err b/tests/qapi-schema= /string-code-point-31.err new file mode 100644 index 0000000000..45797928d9 --- /dev/null +++ b/tests/qapi-schema/string-code-point-31.err @@ -0,0 +1 @@ +tests/qapi-schema/string-code-point-31.json:2:14: Funny character in string diff --git a/tests/qapi-schema/string-code-point-31.exit b/tests/qapi-schem= a/string-code-point-31.exit new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/qapi-schema/string-code-point-31.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/string-code-point-31.json b/tests/qapi-schem= a/string-code-point-31.json new file mode 100644 index 0000000000..f186cbd720 --- /dev/null +++ b/tests/qapi-schema/string-code-point-31.json @@ -0,0 +1,2 @@ +# We accept printable ASCII: code points 32..126. Test code point 127: +{ 'command': '=1F' } diff --git a/tests/qapi-schema/string-code-point-31.out b/tests/qapi-schema= /string-code-point-31.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/unicode-str.err b/tests/qapi-schema/unicode-= str.err deleted file mode 100644 index f621cd6448..0000000000 --- a/tests/qapi-schema/unicode-str.err +++ /dev/null @@ -1 +0,0 @@ -tests/qapi-schema/unicode-str.json:2: 'command' uses invalid name '=C3=A9' diff --git a/tests/qapi-schema/unicode-str.json b/tests/qapi-schema/unicode= -str.json deleted file mode 100644 index 5253a1b9f3..0000000000 --- a/tests/qapi-schema/unicode-str.json +++ /dev/null @@ -1,2 +0,0 @@ -# we don't support full Unicode strings, yet -{ 'command': '=C3=A9' } --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569330446; cv=none; d=zoho.com; s=zohoarc; b=KIqcGazhIu0uskNs0VqbIYQRdQ+I3KPjDsqahZsNvMQRoQ0LGuQFQBPkWK1jSHRFWtE3BLOvcLYRDbQn8zYLULsg3aNgDTEg82Hg5UdMiE48kZ+O/SLatAz7Gyhva9fV5WPJnbnq4nofo2kORN8WLWie6F0JTin7RxY3ZHvmEgQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569330446; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=x4I6fnFyapg1AqYf/RJAaQzmRQ6XSzjenKpN93sSXMI=; b=D4bKwEQlYPFgVBJqoFbdaRY2zgMZUh9obcbS9UZZxN/x/Gz0C3tVQahMnPAs3SyhwQo3iCjFhllcUtfZUbhnx9qqDPWA0yZWU880G4kTHnL7Q41b2HoXfCEtejp20bYHC6kqDJAkUGz/nnePP63HtuSyhpvW4EUUEQnGQ/esxOo= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569330446864376.17691538711813; Tue, 24 Sep 2019 06:07:26 -0700 (PDT) Received: from localhost ([::1]:45396 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCkXN-00030A-58 for importer@patchew.org; Tue, 24 Sep 2019 09:07:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50466) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0l-0001Ic-2w for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0h-0006tV-6e for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42746) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0g-0006sD-NJ for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:38 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 01026307D844 for ; Tue, 24 Sep 2019 12:33:38 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9C02260C63; Tue, 24 Sep 2019 12:33:37 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 7279411385A7; Tue, 24 Sep 2019 14:33:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 09/37] qapi: Drop support for escape sequences other than \\ Date: Tue, 24 Sep 2019 14:33:06 +0200 Message-Id: <20190924123334.30645-10-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 24 Sep 2019 12:33:38 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Since the previous commit restricted strings to printable ASCII, \uXXXX's only use is obfuscation. Drop it. This leaves \\, \/, \', and \". Since QAPI schema strings are all names, and names are restricted to ASCII letters, digits, hyphen, and underscore, none of them is useful. The latter three have no test coverage. Drop them. Keep \\ to avoid (more) gratuitous incompatibility with JSON. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20190913201349.24332-8-armbru@redhat.com> --- scripts/qapi/common.py | 26 +++----------------- tests/Makefile.include | 3 --- tests/qapi-schema/escape-outside-string.err | 1 - tests/qapi-schema/escape-outside-string.exit | 1 - tests/qapi-schema/escape-outside-string.json | 3 --- tests/qapi-schema/escape-outside-string.out | 0 tests/qapi-schema/escape-too-big.err | 1 - tests/qapi-schema/escape-too-big.exit | 1 - tests/qapi-schema/escape-too-big.json | 3 --- tests/qapi-schema/escape-too-big.out | 0 tests/qapi-schema/escape-too-short.err | 1 - tests/qapi-schema/escape-too-short.exit | 1 - tests/qapi-schema/escape-too-short.json | 3 --- tests/qapi-schema/escape-too-short.out | 0 tests/qapi-schema/ident-with-escape.err | 1 + tests/qapi-schema/ident-with-escape.exit | 2 +- tests/qapi-schema/ident-with-escape.json | 2 +- tests/qapi-schema/ident-with-escape.out | 16 ------------ tests/qapi-schema/unknown-escape.json | 2 +- 19 files changed, 7 insertions(+), 60 deletions(-) delete mode 100644 tests/qapi-schema/escape-outside-string.err delete mode 100644 tests/qapi-schema/escape-outside-string.exit delete mode 100644 tests/qapi-schema/escape-outside-string.json delete mode 100644 tests/qapi-schema/escape-outside-string.out delete mode 100644 tests/qapi-schema/escape-too-big.err delete mode 100644 tests/qapi-schema/escape-too-big.exit delete mode 100644 tests/qapi-schema/escape-too-big.json delete mode 100644 tests/qapi-schema/escape-too-big.out delete mode 100644 tests/qapi-schema/escape-too-short.err delete mode 100644 tests/qapi-schema/escape-too-short.exit delete mode 100644 tests/qapi-schema/escape-too-short.json delete mode 100644 tests/qapi-schema/escape-too-short.out diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 539b50f9ac..0fb1d1956a 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -524,29 +524,9 @@ class QAPISchemaParser(object): if ch =3D=3D '\n': raise QAPIParseError(self, 'Missing terminating "\= '"') if esc: - # Note: we don't recognize escape sequences - # for control characters - if ch =3D=3D 'u': - value =3D 0 - for _ in range(0, 4): - ch =3D self.src[self.cursor] - self.cursor +=3D 1 - if ch not in '0123456789abcdefABCDEF': - raise QAPIParseError(self, - '\\u escape needs= 4 ' - 'hex digits') - value =3D (value << 4) + int(ch, 16) - # If Python 2 and 3 didn't disagree so much on - # how to handle Unicode, then we could allow - # Unicode string defaults. But most of QAPI is - # ASCII-only, so we aren't losing much for now. - if not value or value > 0x7f: - raise QAPIParseError(self, - 'For now, \\u escape ' - 'only supports non-ze= ro ' - 'values up to \\u007f= ') - ch =3D chr(value) - elif ch not in '\\/\'"': + # Note: we recognize only \\ because we have + # no use for funny characters in strings + if ch !=3D '\\': raise QAPIParseError(self, "Unknown escape \\%s" % c= h) esc =3D False diff --git a/tests/Makefile.include b/tests/Makefile.include index 393cfd78f0..8585e7ed26 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -374,9 +374,6 @@ qapi-schema +=3D enum-int-member.json qapi-schema +=3D enum-member-case.json qapi-schema +=3D enum-missing-data.json qapi-schema +=3D enum-wrong-data.json -qapi-schema +=3D escape-outside-string.json -qapi-schema +=3D escape-too-big.json -qapi-schema +=3D escape-too-short.json qapi-schema +=3D event-boxed-empty.json qapi-schema +=3D event-case.json qapi-schema +=3D event-member-invalid-dict.json diff --git a/tests/qapi-schema/escape-outside-string.err b/tests/qapi-schem= a/escape-outside-string.err deleted file mode 100644 index b9b8837fd2..0000000000 --- a/tests/qapi-schema/escape-outside-string.err +++ /dev/null @@ -1 +0,0 @@ -tests/qapi-schema/escape-outside-string.json:3:27: Stray "\" diff --git a/tests/qapi-schema/escape-outside-string.exit b/tests/qapi-sche= ma/escape-outside-string.exit deleted file mode 100644 index d00491fd7e..0000000000 --- a/tests/qapi-schema/escape-outside-string.exit +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/tests/qapi-schema/escape-outside-string.json b/tests/qapi-sche= ma/escape-outside-string.json deleted file mode 100644 index 482f79554b..0000000000 --- a/tests/qapi-schema/escape-outside-string.json +++ /dev/null @@ -1,3 +0,0 @@ -# escape sequences are permitted only inside strings -# { 'command': 'foo', 'data': {} } -{ 'command': 'foo', 'data'\u003a{} } diff --git a/tests/qapi-schema/escape-outside-string.out b/tests/qapi-schem= a/escape-outside-string.out deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/qapi-schema/escape-too-big.err b/tests/qapi-schema/escap= e-too-big.err deleted file mode 100644 index d9aeb5dc38..0000000000 --- a/tests/qapi-schema/escape-too-big.err +++ /dev/null @@ -1 +0,0 @@ -tests/qapi-schema/escape-too-big.json:3:14: For now, \u escape only suppor= ts non-zero values up to \u007f diff --git a/tests/qapi-schema/escape-too-big.exit b/tests/qapi-schema/esca= pe-too-big.exit deleted file mode 100644 index d00491fd7e..0000000000 --- a/tests/qapi-schema/escape-too-big.exit +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/tests/qapi-schema/escape-too-big.json b/tests/qapi-schema/esca= pe-too-big.json deleted file mode 100644 index 62bcecd557..0000000000 --- a/tests/qapi-schema/escape-too-big.json +++ /dev/null @@ -1,3 +0,0 @@ -# we don't support full Unicode strings, yet -# { 'command': '=C3=A9' } -{ 'command': '\u00e9' } diff --git a/tests/qapi-schema/escape-too-big.out b/tests/qapi-schema/escap= e-too-big.out deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/qapi-schema/escape-too-short.err b/tests/qapi-schema/esc= ape-too-short.err deleted file mode 100644 index 934de598ee..0000000000 --- a/tests/qapi-schema/escape-too-short.err +++ /dev/null @@ -1 +0,0 @@ -tests/qapi-schema/escape-too-short.json:3:14: \u escape needs 4 hex digits diff --git a/tests/qapi-schema/escape-too-short.exit b/tests/qapi-schema/es= cape-too-short.exit deleted file mode 100644 index d00491fd7e..0000000000 --- a/tests/qapi-schema/escape-too-short.exit +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/tests/qapi-schema/escape-too-short.json b/tests/qapi-schema/es= cape-too-short.json deleted file mode 100644 index 6cb1dec8f7..0000000000 --- a/tests/qapi-schema/escape-too-short.json +++ /dev/null @@ -1,3 +0,0 @@ -# the \u escape requires 4 hex digits -# { 'command': 'a' } -{ 'command': '\u61' } diff --git a/tests/qapi-schema/escape-too-short.out b/tests/qapi-schema/esc= ape-too-short.out deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/qapi-schema/ident-with-escape.err b/tests/qapi-schema/id= ent-with-escape.err index e69de29bb2..5517dcb4b1 100644 --- a/tests/qapi-schema/ident-with-escape.err +++ b/tests/qapi-schema/ident-with-escape.err @@ -0,0 +1 @@ +tests/qapi-schema/ident-with-escape.json:3:3: Unknown escape \u diff --git a/tests/qapi-schema/ident-with-escape.exit b/tests/qapi-schema/i= dent-with-escape.exit index 573541ac97..d00491fd7e 100644 --- a/tests/qapi-schema/ident-with-escape.exit +++ b/tests/qapi-schema/ident-with-escape.exit @@ -1 +1 @@ -0 +1 diff --git a/tests/qapi-schema/ident-with-escape.json b/tests/qapi-schema/i= dent-with-escape.json index 56617501e7..76b4503d95 100644 --- a/tests/qapi-schema/ident-with-escape.json +++ b/tests/qapi-schema/ident-with-escape.json @@ -1,4 +1,4 @@ -# we allow escape sequences in strings, if they map back to ASCII +# we don't recognize any \ escapes other than \\ (tested elsewhere) # { 'command': 'fooA', 'data': { 'bar1': 'str' } } { 'c\u006fmmand': '\u0066\u006f\u006FA', 'd\u0061ta': { '\u0062\u0061\u00721': '\u0073\u0074\u0072' } } diff --git a/tests/qapi-schema/ident-with-escape.out b/tests/qapi-schema/id= ent-with-escape.out index 39754eba8c..e69de29bb2 100644 --- a/tests/qapi-schema/ident-with-escape.out +++ b/tests/qapi-schema/ident-with-escape.out @@ -1,16 +0,0 @@ -module None -object q_empty -enum QType - prefix QTYPE - member none - member qnull - member qnum - member qstring - member qdict - member qlist - member qbool -module ident-with-escape.json -object q_obj_fooA-arg - member bar1: str optional=3DFalse -command fooA q_obj_fooA-arg -> None - gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse diff --git a/tests/qapi-schema/unknown-escape.json b/tests/qapi-schema/unkn= own-escape.json index 8e6891e52a..8372e8024f 100644 --- a/tests/qapi-schema/unknown-escape.json +++ b/tests/qapi-schema/unknown-escape.json @@ -1,3 +1,3 @@ -# we only recognize JSON escape sequences, plus our \' extension (no \x) +# we only recognize \\ # { 'command': 'foo', 'data': {} } { 'command': 'foo', 'dat\x61':{} } --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569330680; cv=none; d=zoho.com; s=zohoarc; b=nYj8Hx1fsIxjR5KtdJ7vsEbSEqCNfhjcMXcV0LQ70apKfAEsJNtfOQg9D3K/2pb2NmkZilTfl+oeCOpmj5Al1b6lguhJwgQoNljpm3pDE9dvC0A1ZkTT8dvIlSVTHFKN6HU+bl4wutajQO8zqKRYkh0H9ao4oVsOiA/Zz2tJwxA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569330680; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=VNmZ5iBW+ljuBVe2I/oBgl3qfR5hyeg9LXlXBVBwv9I=; b=PAfQB7gTQVz0k5WDf6yIk8HPzgpxGW3g7A9IE/Tj8pkf4ROR3VPIvlsokeVKJU4DOQ6gD58QLihRQpdlo3p2sxV0sh+4+FyMi9xMrUFICGWq/MFx108uZmhDjbj1E7svSmhU4cOGZVF2SGfWuC5HX4xLpUcy3ozhV3CliknIv/s= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569330680195827.817189980883; Tue, 24 Sep 2019 06:11:20 -0700 (PDT) Received: from localhost ([::1]:45450 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCkb5-000779-TQ for importer@patchew.org; Tue, 24 Sep 2019 09:11:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50448) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0k-0001Ia-Ke for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0h-0006ts-9f for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39886) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0g-0006sS-O5 for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:39 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 08E922A09A1 for ; Tue, 24 Sep 2019 12:33:38 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A4BA760C80; Tue, 24 Sep 2019 12:33:37 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 7A36811385CB; Tue, 24 Sep 2019 14:33:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 10/37] qapi: Permit 'boxed' with empty type Date: Tue, 24 Sep 2019 14:33:07 +0200 Message-Id: <20190924123334.30645-11-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 24 Sep 2019 12:33:38 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" We reject empty types with 'boxed': true. We don't really need that to work, but making it work is actually simpler than rejecting it, so do that. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20190913201349.24332-9-armbru@redhat.com> --- tests/test-qmp-cmds.c | 4 ++++ scripts/qapi/commands.py | 4 ++-- scripts/qapi/common.py | 14 ++------------ scripts/qapi/events.py | 10 +++++----- tests/Makefile.include | 1 - tests/qapi-schema/args-boxed-empty.err | 1 - tests/qapi-schema/args-boxed-empty.exit | 1 - tests/qapi-schema/args-boxed-empty.json | 3 --- tests/qapi-schema/args-boxed-empty.out | 0 tests/qapi-schema/qapi-schema-test.json | 2 ++ tests/qapi-schema/qapi-schema-test.out | 4 ++++ 11 files changed, 19 insertions(+), 25 deletions(-) delete mode 100644 tests/qapi-schema/args-boxed-empty.err delete mode 100644 tests/qapi-schema/args-boxed-empty.exit delete mode 100644 tests/qapi-schema/args-boxed-empty.json delete mode 100644 tests/qapi-schema/args-boxed-empty.out diff --git a/tests/test-qmp-cmds.c b/tests/test-qmp-cmds.c index ab389f42da..36fdf5b115 100644 --- a/tests/test-qmp-cmds.c +++ b/tests/test-qmp-cmds.c @@ -97,6 +97,10 @@ void qmp_boxed_union(UserDefListUnion *arg, Error **errp) { } =20 +void qmp_boxed_empty(Empty1 *arg, Error **errp) +{ +} + __org_qemu_x_Union1 *qmp___org_qemu_x_command(__org_qemu_x_EnumList *a, __org_qemu_x_StructList *b, __org_qemu_x_Union2 *c, diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index b929e07be4..7e3dd1068a 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -30,7 +30,7 @@ def gen_call(name, arg_type, boxed, ret_type): =20 argstr =3D '' if boxed: - assert arg_type and not arg_type.is_empty() + assert arg_type argstr =3D '&arg, ' elif arg_type: assert not arg_type.variants @@ -96,7 +96,7 @@ def gen_marshal_decl(name): =20 =20 def gen_marshal(name, arg_type, boxed, ret_type): - have_args =3D arg_type and not arg_type.is_empty() + have_args =3D boxed or (arg_type and not arg_type.is_empty()) =20 ret =3D mcgen(''' =20 diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 0fb1d1956a..c5c71287c3 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -1687,12 +1687,7 @@ class QAPISchemaCommand(QAPISchemaEntity): self.arg_type =3D schema.lookup_type(self._arg_type_name) assert isinstance(self.arg_type, QAPISchemaObjectType) self.arg_type.check(schema) - if self.boxed: - if self.arg_type.is_empty(): - raise QAPISemError(self.info, - "Cannot use 'boxed' with empty type= ") - else: - assert not self.arg_type.variants + assert not self.arg_type.variants or self.boxed elif self.boxed: raise QAPISemError(self.info, "Use of 'boxed' requires 'data'") if self._ret_type_name: @@ -1721,12 +1716,7 @@ class QAPISchemaEvent(QAPISchemaEntity): self.arg_type =3D schema.lookup_type(self._arg_type_name) assert isinstance(self.arg_type, QAPISchemaObjectType) self.arg_type.check(schema) - if self.boxed: - if self.arg_type.is_empty(): - raise QAPISemError(self.info, - "Cannot use 'boxed' with empty type= ") - else: - assert not self.arg_type.variants + assert not self.arg_type.variants or self.boxed elif self.boxed: raise QAPISemError(self.info, "Use of 'boxed' requires 'data'") =20 diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index b732581046..e0abfef7b0 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -65,6 +65,8 @@ def gen_event_send(name, arg_type, boxed, event_enum_name= , event_emit): # practice, we can rename our local variables with a leading _ prefix, # or split the code into a wrapper function that creates a boxed # 'param' object then calls another to do the real work. + have_args =3D boxed or (arg_type and not arg_type.is_empty()) + ret =3D mcgen(''' =20 %(proto)s @@ -73,15 +75,13 @@ def gen_event_send(name, arg_type, boxed, event_enum_na= me, event_emit): ''', proto=3Dbuild_event_send_proto(name, arg_type, boxed)) =20 - if arg_type and not arg_type.is_empty(): + if have_args: ret +=3D mcgen(''' QObject *obj; Visitor *v; ''') if not boxed: ret +=3D gen_param_var(arg_type) - else: - assert not boxed =20 ret +=3D mcgen(''' =20 @@ -90,7 +90,7 @@ def gen_event_send(name, arg_type, boxed, event_enum_name= , event_emit): ''', name=3Dname) =20 - if arg_type and not arg_type.is_empty(): + if have_args: ret +=3D mcgen(''' v =3D qobject_output_visitor_new(&obj); ''') @@ -121,7 +121,7 @@ def gen_event_send(name, arg_type, boxed, event_enum_na= me, event_emit): event_emit=3Devent_emit, c_enum=3Dc_enum_const(event_enum_name, name)) =20 - if arg_type and not arg_type.is_empty(): + if have_args: ret +=3D mcgen(''' visit_free(v); ''') diff --git a/tests/Makefile.include b/tests/Makefile.include index 8585e7ed26..2c3adb1530 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -311,7 +311,6 @@ qapi-schema +=3D args-array-empty.json qapi-schema +=3D args-array-unknown.json qapi-schema +=3D args-bad-boxed.json qapi-schema +=3D args-boxed-anon.json -qapi-schema +=3D args-boxed-empty.json qapi-schema +=3D args-boxed-string.json qapi-schema +=3D args-int.json qapi-schema +=3D args-invalid.json diff --git a/tests/qapi-schema/args-boxed-empty.err b/tests/qapi-schema/arg= s-boxed-empty.err deleted file mode 100644 index 039603e85c..0000000000 --- a/tests/qapi-schema/args-boxed-empty.err +++ /dev/null @@ -1 +0,0 @@ -tests/qapi-schema/args-boxed-empty.json:3: Cannot use 'boxed' with empty t= ype diff --git a/tests/qapi-schema/args-boxed-empty.exit b/tests/qapi-schema/ar= gs-boxed-empty.exit deleted file mode 100644 index d00491fd7e..0000000000 --- a/tests/qapi-schema/args-boxed-empty.exit +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/tests/qapi-schema/args-boxed-empty.json b/tests/qapi-schema/ar= gs-boxed-empty.json deleted file mode 100644 index 52717e065f..0000000000 --- a/tests/qapi-schema/args-boxed-empty.json +++ /dev/null @@ -1,3 +0,0 @@ -# 'boxed' requires a non-empty type -{ 'struct': 'Empty', 'data': {} } -{ 'command': 'foo', 'boxed': true, 'data': 'Empty' } diff --git a/tests/qapi-schema/args-boxed-empty.out b/tests/qapi-schema/arg= s-boxed-empty.out deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index 0fadb4ddd7..e6dbbbd328 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -149,6 +149,7 @@ { 'command': 'guest-sync', 'data': { 'arg': 'any' }, 'returns': 'any' } { 'command': 'boxed-struct', 'boxed': true, 'data': 'UserDefZero' } { 'command': 'boxed-union', 'data': 'UserDefListUnion', 'boxed': true } +{ 'command': 'boxed-empty', 'boxed': true, 'data': 'Empty1' } =20 # Smoke test on out-of-band and allow-preconfig-test { 'command': 'test-flags-command', 'allow-oob': true, 'allow-preconfig': t= rue } @@ -181,6 +182,7 @@ 'data': { 'a' : 'EventStructOne', 'b' : 'str', '*c': 'str', '*enum3': 'E= numOne' } } { 'event': 'EVENT_E', 'boxed': true, 'data': 'UserDefZero' } { 'event': 'EVENT_F', 'boxed': true, 'data': 'UserDefFlatUnion' } +{ 'event': 'EVENT_G', 'boxed': true, 'data': 'Empty1' } =20 # test that we correctly compile downstream extensions, as well as munge # ticklish names diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 5470a525f5..fb00a21996 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -221,6 +221,8 @@ command boxed-struct UserDefZero -> None gen=3DTrue success_response=3DTrue boxed=3DTrue oob=3DFalse preconfig= =3DFalse command boxed-union UserDefListUnion -> None gen=3DTrue success_response=3DTrue boxed=3DTrue oob=3DFalse preconfig= =3DFalse +command boxed-empty Empty1 -> None + gen=3DTrue success_response=3DTrue boxed=3DTrue oob=3DFalse preconfig= =3DFalse command test-flags-command None -> None gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DTrue preconfig= =3DTrue object UserDefOptions @@ -254,6 +256,8 @@ event EVENT_E UserDefZero boxed=3DTrue event EVENT_F UserDefFlatUnion boxed=3DTrue +event EVENT_G Empty1 + boxed=3DTrue enum __org.qemu_x-Enum member __org.qemu_x-value object __org.qemu_x-Base --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569329204; cv=none; d=zoho.com; s=zohoarc; b=KSyKDPszDDkXOWvdRt2xEw2XydYwYR2LI6Dg+SwDxzdTA6VQWSV9g0kon4eCAl3J5aSpFjzph7o+Si751c1xT4vyUBo4mFeN9VAw3Ig6hW0a7FCLcurWP3u84+Xepfs2DtiFK7dak5UMF6u7slfmagpMheMdAz0fanzdLaZaQrU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569329204; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=LM2K3lbfLlTp6fXn+EqI6xqRcQ8QIlRBobAxLX767ps=; b=ir6NFglqvp9I8DJVQjkyrfzKT3fjD0EhY/dCOwJtfN57rl1fFelkddPmBCIA/1GDmT/WNiE+dyNANzy5fYZb7tz6R5Ti1hdSSxEHMpJQirYoQ+vqceV8IQL5xSPtIiuKhGoaChYHWYyXRN2BwBQCUXUEuzOH4uMjaiThIgV/4ec= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 156932920450670.05538027012426; Tue, 24 Sep 2019 05:46:44 -0700 (PDT) Received: from localhost ([::1]:45254 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCkDH-0002g1-Lu for importer@patchew.org; Tue, 24 Sep 2019 08:46:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50438) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0k-0001IX-CG for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0h-0006te-AQ for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37008) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0g-0006sR-Oj for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:39 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0A66410CC1EE for ; Tue, 24 Sep 2019 12:33:38 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A72695D9DC; Tue, 24 Sep 2019 12:33:37 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 813F211385D4; Tue, 24 Sep 2019 14:33:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 11/37] qapi: Permit alternates with just one branch Date: Tue, 24 Sep 2019 14:33:08 +0200 Message-Id: <20190924123334.30645-12-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.65]); Tue, 24 Sep 2019 12:33:38 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" A union or alternate without branches makes no sense and doesn't work: it can't be instantiated. A union or alternate with just one branch works, but is degenerate. We accept the former, but reject the latter. Weird. docs/devel/qapi-code-gen.txt doesn't mention the difference. It claims an alternate definition is "is similar to a simple union type". Permit degenerate alternates to make them consistent with unions. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20190913201349.24332-10-armbru@redhat.com> --- scripts/qapi/common.py | 6 ++---- tests/qapi-schema/alternate-empty.err | 2 +- tests/qapi-schema/alternate-empty.json | 4 ++-- tests/qapi-schema/qapi-schema-test.json | 4 +++- tests/qapi-schema/qapi-schema-test.out | 6 ++++-- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index c5c71287c3..99db18f3d6 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -920,11 +920,9 @@ def check_alternate(expr, info): members =3D expr['data'] types_seen =3D {} =20 - # Check every branch; require at least two branches - if len(members) < 2: + if len(members) =3D=3D 0: raise QAPISemError(info, - "Alternate '%s' should have at least two branch= es " - "in 'data'" % name) + "Alternate '%s' cannot have empty 'data'" % nam= e) for (key, value) in members.items(): check_name(info, "Member of alternate '%s'" % name, key) check_known_keys(info, diff --git a/tests/qapi-schema/alternate-empty.err b/tests/qapi-schema/alte= rnate-empty.err index bb06c5bfec..86dbc666eb 100644 --- a/tests/qapi-schema/alternate-empty.err +++ b/tests/qapi-schema/alternate-empty.err @@ -1 +1 @@ -tests/qapi-schema/alternate-empty.json:2: Alternate 'Alt' should have at l= east two branches in 'data' +tests/qapi-schema/alternate-empty.json:2: Alternate 'Alt' cannot have empt= y 'data' diff --git a/tests/qapi-schema/alternate-empty.json b/tests/qapi-schema/alt= ernate-empty.json index fff15baf16..9f445474e6 100644 --- a/tests/qapi-schema/alternate-empty.json +++ b/tests/qapi-schema/alternate-empty.json @@ -1,2 +1,2 @@ -# alternates must list at least two types to be useful -{ 'alternate': 'Alt', 'data': { 'i': 'int' } } +# alternates cannot be empty +{ 'alternate': 'Alt', 'data': { } } diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index e6dbbbd328..8b0d47c4ab 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -186,19 +186,21 @@ =20 # test that we correctly compile downstream extensions, as well as munge # ticklish names +# also test union and alternate with just one branch { 'enum': '__org.qemu_x-Enum', 'data': [ '__org.qemu_x-value' ] } { 'struct': '__org.qemu_x-Base', 'data': { '__org.qemu_x-member1': '__org.qemu_x-Enum' } } { 'struct': '__org.qemu_x-Struct', 'base': '__org.qemu_x-Base', 'data': { '__org.qemu_x-member2': 'str', '*wchar-t': 'int' } } { 'union': '__org.qemu_x-Union1', 'data': { '__org.qemu_x-branch': 'str' }= } +{ 'alternate': '__org.qemu_x-Alt1', 'data': { '__org.qemu_x-branch': 'str'= } } { 'struct': '__org.qemu_x-Struct2', 'data': { 'array': ['__org.qemu_x-Union1'] } } { 'union': '__org.qemu_x-Union2', 'base': '__org.qemu_x-Base', 'discriminator': '__org.qemu_x-member1', 'data': { '__org.qemu_x-value': '__org.qemu_x-Struct2' } } { 'alternate': '__org.qemu_x-Alt', - 'data': { '__org.qemu_x-branch': 'str', 'b': '__org.qemu_x-Base' } } + 'data': { '__org.qemu_x-branch': '__org.qemu_x-Base' } } { 'event': '__ORG.QEMU_X-EVENT', 'data': '__org.qemu_x-Struct' } { 'command': '__org.qemu_x-command', 'data': { 'a': ['__org.qemu_x-Enum'], 'b': ['__org.qemu_x-Struct'], diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index fb00a21996..bea7976bbb 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -274,6 +274,9 @@ object __org.qemu_x-Union1 member type: __org.qemu_x-Union1Kind optional=3DFalse tag type case __org.qemu_x-branch: q_obj_str-wrapper +alternate __org.qemu_x-Alt1 + tag type + case __org.qemu_x-branch: str array __org.qemu_x-Union1List __org.qemu_x-Union1 object __org.qemu_x-Struct2 member array: __org.qemu_x-Union1List optional=3DFalse @@ -283,8 +286,7 @@ object __org.qemu_x-Union2 case __org.qemu_x-value: __org.qemu_x-Struct2 alternate __org.qemu_x-Alt tag type - case __org.qemu_x-branch: str - case b: __org.qemu_x-Base + case __org.qemu_x-branch: __org.qemu_x-Base event __ORG.QEMU_X-EVENT __org.qemu_x-Struct boxed=3DFalse array __org.qemu_x-EnumList __org.qemu_x-Enum --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569330042; cv=none; d=zoho.com; s=zohoarc; b=CH+qWBnbCw+42Pk3Ikovwbqapx7Q/4qdj2cz51lyDLTriocibSxRX+qBsuNTRTHcRnlttcjjChqrKu2D2q2zRzLrjfj5UWNI7z9I8b2EiZbBhIPCd1+zI7I46hDXu4L7lzn5h7sqHwI9oyRnhexwg4zutKnJUf5wmCuwClXuT9s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569330042; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=pHTqX+vXUKjoxoYHC1/2hdeIUkLoVVi8uD/eXZJ6Arg=; b=Ca8FkUuiZmxyMeqa8wE9Mj12Du0ZjTUlCr8UHvvBnDOcnuZZmKYERe4N1NFvhULcCpLx0VeboEIAqVW/wMKW834ip19IRSFHKTYgN9FXVedv/b9E/QphHqNGyhaI/gDrVjKvFIMHaBT87rE+xvu/eCm1pdkLSHfuD7R29UT2Qu8= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569330042281182.7990971766252; Tue, 24 Sep 2019 06:00:42 -0700 (PDT) Received: from localhost ([::1]:45356 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCkQq-0007Fl-CX for importer@patchew.org; Tue, 24 Sep 2019 09:00:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50444) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0k-0001IZ-Gn for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0h-0006tj-6v for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55692) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0g-0006sg-OP for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:39 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 13C5F18CB8EF for ; Tue, 24 Sep 2019 12:33:38 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AAE0F194B2; Tue, 24 Sep 2019 12:33:37 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 8D46D11385D5; Tue, 24 Sep 2019 14:33:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 12/37] qapi: Permit omitting all flat union branches Date: Tue, 24 Sep 2019 14:33:09 +0200 Message-Id: <20190924123334.30645-13-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.63]); Tue, 24 Sep 2019 12:33:38 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Absent flat union branches default to the empty struct (since commit 800877bb16 "qapi: allow empty branches in flat unions"). But an attempt to omit all of them is rejected with "Union 'FOO' has no branches". Harmless oddity, but it's easy to avoid, so do that. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20190913201349.24332-11-armbru@redhat.com> [Commit message typo fixed] --- docs/devel/qapi-code-gen.txt | 3 +-- scripts/qapi/common.py | 16 ++++++++-------- tests/qapi-schema/flat-union-empty.err | 2 +- tests/qapi-schema/flat-union-empty.json | 2 +- tests/qapi-schema/qapi-schema-test.json | 5 +++++ tests/qapi-schema/qapi-schema-test.out | 9 +++++++++ tests/qapi-schema/union-empty.err | 2 +- tests/qapi-schema/union-empty.json | 2 +- 8 files changed, 27 insertions(+), 14 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index 4ce67752a7..ec2d374483 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -436,8 +436,7 @@ Union types are used to let the user choose between sev= eral different variants for an object. There are two flavors: simple (no discriminator or base), and flat (both discriminator and base). A union type is defined using a data dictionary as explained in the following -paragraphs. The data dictionary for either type of union must not -be empty. +paragraphs. Unions must have at least one branch. =20 A simple union type defines a mapping from automatic discriminator values to data types like in this example: diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 99db18f3d6..3393a049cc 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -852,7 +852,7 @@ def check_union(expr, info): =20 # With no discriminator it is a simple union. if discriminator is None: - enum_define =3D None + enum_values =3D members.keys() allow_metas =3D ['built-in', 'union', 'alternate', 'struct', 'enum= '] if base is not None: raise QAPISemError(info, "Simple union '%s' must not have a ba= se" % @@ -885,16 +885,17 @@ def check_union(expr, info): 'must not be conditional' % (base, discriminator, name)) enum_define =3D enum_types.get(discriminator_value['type']) - allow_metas =3D ['struct'] # Do not allow string discriminator if not enum_define: raise QAPISemError(info, "Discriminator '%s' must be of enumeration " "type" % discriminator) + enum_values =3D enum_get_names(enum_define) + allow_metas =3D ['struct'] + + if (len(enum_values) =3D=3D 0): + raise QAPISemError(info, "Union '%s' has no branches" % name) =20 - # Check every branch; don't allow an empty union - if len(members) =3D=3D 0: - raise QAPISemError(info, "Union '%s' cannot have empty 'data'" % n= ame) for (key, value) in members.items(): check_name(info, "Member of union '%s'" % name, key) =20 @@ -907,8 +908,8 @@ def check_union(expr, info): =20 # If the discriminator names an enum type, then all members # of 'data' must also be members of the enum type. - if enum_define: - if key not in enum_get_names(enum_define): + if discriminator is not None: + if key not in enum_values: raise QAPISemError(info, "Discriminator value '%s' is not found = in " "enum '%s'" @@ -1578,7 +1579,6 @@ class QAPISchemaObjectTypeVariants(object): assert bool(tag_member) !=3D bool(tag_name) assert (isinstance(tag_name, str) or isinstance(tag_member, QAPISchemaObjectTypeMember)) - assert len(variants) > 0 for v in variants: assert isinstance(v, QAPISchemaObjectTypeVariant) self._tag_name =3D tag_name diff --git a/tests/qapi-schema/flat-union-empty.err b/tests/qapi-schema/fla= t-union-empty.err index 15754f54eb..fedbc0d1cf 100644 --- a/tests/qapi-schema/flat-union-empty.err +++ b/tests/qapi-schema/flat-union-empty.err @@ -1 +1 @@ -tests/qapi-schema/flat-union-empty.json:4: Union 'Union' cannot have empty= 'data' +tests/qapi-schema/flat-union-empty.json:4: Union 'Union' has no branches diff --git a/tests/qapi-schema/flat-union-empty.json b/tests/qapi-schema/fl= at-union-empty.json index 77f1d9abfb..83e1cc7b96 100644 --- a/tests/qapi-schema/flat-union-empty.json +++ b/tests/qapi-schema/flat-union-empty.json @@ -1,4 +1,4 @@ -# flat unions cannot be empty +# flat union discriminator cannot be empty { 'enum': 'Empty', 'data': [ ] } { 'struct': 'Base', 'data': { 'type': 'Empty' } } { 'union': 'Union', 'base': 'Base', 'discriminator': 'type', 'data': { } } diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index 8b0d47c4ab..75c42eb0e3 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -25,6 +25,11 @@ { 'struct': 'Empty1', 'data': { } } { 'struct': 'Empty2', 'base': 'Empty1', 'data': { } } =20 +# Likewise for an empty flat union +{ 'union': 'Union', + 'base': { 'type': 'EnumOne' }, 'discriminator': 'type', + 'data': { } } + { 'command': 'user_def_cmd0', 'data': 'Empty2', 'returns': 'Empty2' } =20 # for testing override of default naming heuristic diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index bea7976bbb..98031da96f 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -23,6 +23,15 @@ enum MyEnum object Empty1 object Empty2 base Empty1 +object q_obj_Union-base + member type: EnumOne optional=3DFalse +object Union + base q_obj_Union-base + tag type + case value1: q_empty + case value2: q_empty + case value3: q_empty + case value4: q_empty command user_def_cmd0 Empty2 -> Empty2 gen=3DTrue success_response=3DTrue boxed=3DFalse oob=3DFalse preconfig= =3DFalse enum QEnumTwo diff --git a/tests/qapi-schema/union-empty.err b/tests/qapi-schema/union-em= pty.err index 12c20221bd..d4241a38a2 100644 --- a/tests/qapi-schema/union-empty.err +++ b/tests/qapi-schema/union-empty.err @@ -1 +1 @@ -tests/qapi-schema/union-empty.json:2: Union 'Union' cannot have empty 'dat= a' +tests/qapi-schema/union-empty.json:2: Union 'Union' has no branches diff --git a/tests/qapi-schema/union-empty.json b/tests/qapi-schema/union-e= mpty.json index 1f0b13ca21..df3e5e639a 100644 --- a/tests/qapi-schema/union-empty.json +++ b/tests/qapi-schema/union-empty.json @@ -1,2 +1,2 @@ -# unions cannot be empty +# simple unions cannot be empty { 'union': 'Union', 'data': { } } --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569329487; cv=none; d=zoho.com; s=zohoarc; b=d0aDldy/xkKa8hvG9QqVB76+r02pdWWYGQ6DtLPxrDM/g2Tzzn7sgSsLhFJt1775Siq3xhF3fbgLIiPKwyEeV/8rKVVTMhDxMtPOE1iWKayFbCUJzivKGpN0xuN2cVPbfWQRJKatz24wpxcB+F+LAjZkHYNv8vWI8xkiwwgaqzs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569329487; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=PQHMScX0COQq6U5UbuCuc597qhJ3FHdXOGkHLJ+Lgac=; b=cL29KCIW2alwRV4JbTZlmjEqIjJlEaR5gjsOpdyrSJapV34AGa9Yu2TKVkkUpsWnzB/vfcNMPq8g6Qhl3gjxd306Nnja9NGNDL9g2cLugZAswWKjiy1DT0X8xRZRYSm20Zw4lxcZzIOnanEXwX8DjODEB4auRC4Ol4MKSHweJ/g= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569329487350723.4085658454809; Tue, 24 Sep 2019 05:51:27 -0700 (PDT) Received: from localhost ([::1]:45304 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCkHt-0007If-Bd for importer@patchew.org; Tue, 24 Sep 2019 08:51:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50488) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0l-0001Is-ST for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0i-0006vH-G2 for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48540) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0i-0006uA-4D for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:40 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4C2D7308FFB1 for ; Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EA6AD60852; Tue, 24 Sep 2019 12:33:38 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 967E11138528; Tue, 24 Sep 2019 14:33:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 13/37] qapi: Adjust frontend errors to say enum value, not member Date: Tue, 24 Sep 2019 14:33:10 +0200 Message-Id: <20190924123334.30645-14-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" For consistency with docs/devel/qapi-code-gen.txt. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20190913201349.24332-12-armbru@redhat.com> --- scripts/qapi/common.py | 11 ++++++++--- scripts/qapi/events.py | 2 +- tests/qapi-schema/enum-clash-member.err | 2 +- tests/qapi-schema/enum-member-case.err | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 3393a049cc..a538d2f37c 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -1340,7 +1340,7 @@ class QAPISchemaEnumType(QAPISchemaType): def __init__(self, name, info, doc, ifcond, members, prefix): QAPISchemaType.__init__(self, name, info, doc, ifcond) for m in members: - assert isinstance(m, QAPISchemaMember) + assert isinstance(m, QAPISchemaEnumMember) m.set_owner(name) assert prefix is None or isinstance(prefix, str) self.members =3D members @@ -1551,6 +1551,10 @@ class QAPISchemaMember(object): return "'%s' %s" % (self.name, self._pretty_owner()) =20 =20 +class QAPISchemaEnumMember(QAPISchemaMember): + role =3D 'value' + + class QAPISchemaFeature(QAPISchemaMember): role =3D 'feature' =20 @@ -1807,7 +1811,8 @@ class QAPISchema(object): return [QAPISchemaFeature(f['name'], f.get('if')) for f in feature= s] =20 def _make_enum_members(self, values): - return [QAPISchemaMember(v['name'], v.get('if')) for v in values] + return [QAPISchemaEnumMember(v['name'], v.get('if')) + for v in values] =20 def _make_implicit_enum_type(self, name, info, ifcond, values): # See also QAPISchemaObjectTypeMember._pretty_owner() @@ -2223,7 +2228,7 @@ const QEnumLookup %(c_name)s_lookup =3D { =20 def gen_enum(name, members, prefix=3DNone): # append automatically generated _MAX value - enum_members =3D members + [QAPISchemaMember('_MAX')] + enum_members =3D members + [QAPISchemaEnumMember('_MAX')] =20 ret =3D mcgen(''' =20 diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index e0abfef7b0..7062553cf3 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -194,7 +194,7 @@ void %(event_emit)s(%(event_enum)s event, QDict *qdict); self._event_emit_name)) # Note: we generate the enum member regardless of @ifcond, to # keep the enumeration usable in target-independent code. - self._event_enum_members.append(QAPISchemaMember(name)) + self._event_enum_members.append(QAPISchemaEnumMember(name)) =20 =20 def gen_events(schema, output_dir, prefix): diff --git a/tests/qapi-schema/enum-clash-member.err b/tests/qapi-schema/en= um-clash-member.err index 5403c78507..8238d2e807 100644 --- a/tests/qapi-schema/enum-clash-member.err +++ b/tests/qapi-schema/enum-clash-member.err @@ -1 +1 @@ -tests/qapi-schema/enum-clash-member.json:2: 'one_two' (member of MyEnum) c= ollides with 'one-two' (member of MyEnum) +tests/qapi-schema/enum-clash-member.json:2: 'one_two' (value of MyEnum) co= llides with 'one-two' (value of MyEnum) diff --git a/tests/qapi-schema/enum-member-case.err b/tests/qapi-schema/enu= m-member-case.err index 3c67a3a067..5d689e92d5 100644 --- a/tests/qapi-schema/enum-member-case.err +++ b/tests/qapi-schema/enum-member-case.err @@ -1 +1 @@ -tests/qapi-schema/enum-member-case.json:4: 'Value' (member of NoWayThisWil= lGetWhitelisted) should not use uppercase +tests/qapi-schema/enum-member-case.json:4: 'Value' (value of NoWayThisWill= GetWhitelisted) should not use uppercase --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569331432; cv=none; d=zoho.com; s=zohoarc; b=bQbxcGmChM3H+P492l7CmAIUs9UCHtQctOInqmwirkXFgSBDfhdYiuL1xFFShlGVJTjmBU3ZfJCFpRINqWg1+0CZ6wukKlw9bfGjKr1jbGrOuJtyffaXw3PqH4Fqye0iveUZsTOwJPHVwl4zlaxckMtIWyv8dgRAKLlxdn8CZx4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569331432; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=IzgcwmNTLljML4xH/pEOgqnXlkdFDwSLFrQxS4DOS6o=; b=O1lq8benAYOSQ4KzQ3nawXhJLwBRR3+a1uuv3rzK5wYyuoTq3v90JMEyiEq0Vfs8ChwSEzTlc6g/65HmBiwdGnRTdo4HE4WeTCfVq8OkS2y/p//iXhMXMFq6AtvZ7Qm5/tS9j8FU4OzJl1jOLSmdWyARDb6kSzeIyLI4b2uU264= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569331432296846.1479201396398; Tue, 24 Sep 2019 06:23:52 -0700 (PDT) Received: from localhost ([::1]:45588 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCknG-0001hm-Ml for importer@patchew.org; Tue, 24 Sep 2019 09:23:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50623) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0q-0001Mf-O5 for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0i-0006vq-Nf for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15085) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0i-0006uT-C4 for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:40 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7B21D300DA70 for ; Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F1DA55C1B2; Tue, 24 Sep 2019 12:33:38 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 9CCA311384A9; Tue, 24 Sep 2019 14:33:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 14/37] docs/devel/qapi-code-gen: Reorder sections for readability Date: Tue, 24 Sep 2019 14:33:11 +0200 Message-Id: <20190924123334.30645-15-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Section "QMP/Guest agent schema" starts with a brief introduction, then subsection "Comments", then subsection "Schema overview" (more elaborate introduction), and only then talks about schema entities like types, commands, and so forth. Subsection "Comments" is long and tiring: almost 500 words, mostly about doc comments. Move the doc comment part to its own subsection "Documentation comments" at the very end of "QMP/Guest agent schema". Subsection "Schema overview" explains naming rules at considerable length: 250 words. Move this part to its own subsection "Naming rules and reserved names" right after the subsections on schema entities. Subsection "Enumeration types" is wedged between "Struct types" and "Union types". Move it before "Struct types". Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20190913201349.24332-13-armbru@redhat.com> --- docs/devel/qapi-code-gen.txt | 436 ++++++++++++++++++----------------- 1 file changed, 221 insertions(+), 215 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index ec2d374483..663ef10a56 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -50,147 +50,6 @@ schema requires the use of JSON numbers or null. Comments are allowed; anything between an unquoted # and the following newline is ignored. =20 -A multi-line comment that starts and ends with a '##' line is a -documentation comment. These are parsed by the documentation -generator, which recognizes certain markup detailed below. - - -=3D=3D=3D=3D Documentation markup =3D=3D=3D=3D - -Comment text starting with '=3D' is a section title: - - # =3D Section title - -Double the '=3D' for a subsection title: - - # =3D=3D Subsection title - -'|' denotes examples: - - # | Text of the example, may span - # | multiple lines - -'*' starts an itemized list: - - # * First item, may span - # multiple lines - # * Second item - -You can also use '-' instead of '*'. - -A decimal number followed by '.' starts a numbered list: - - # 1. First item, may span - # multiple lines - # 2. Second item - -The actual number doesn't matter. You could even use '*' instead of -'2.' for the second item. - -Lists can't be nested. Blank lines are currently not supported within -lists. - -Additional whitespace between the initial '#' and the comment text is -permitted. - -*foo* and _foo_ are for strong and emphasis styles respectively (they -do not work over multiple lines). @foo is used to reference a name in -the schema. - -Example: - -## -# =3D Section -# =3D=3D Subsection -# -# Some text foo with *strong* and _emphasis_ -# 1. with a list -# 2. like that -# -# And some code: -# | $ echo foo -# | -> do this -# | <- get that -# -## - - -=3D=3D=3D=3D Expression documentation =3D=3D=3D=3D - -Expressions other than include and pragma directives may be preceded -by a documentation block. Such blocks are called expression -documentation blocks. - -When documentation is required (see pragma 'doc-required'), expression -documentation blocks are mandatory. - -The documentation block consists of a first line naming the -expression, an optional overview, a description of each argument (for -commands and events) or member (for structs, unions and alternates), -and optional tagged sections. - -FIXME: the parser accepts these things in almost any order. - -Extensions added after the expression was first released carry a -'(since x.y.z)' comment. - -A tagged section starts with one of the following words: -"Note:"/"Notes:", "Since:", "Example"/"Examples", "Returns:", "TODO:". -The section ends with the start of a new section. - -A 'Since: x.y.z' tagged section lists the release that introduced the -expression. - -For example: - -## -# @BlockStats: -# -# Statistics of a virtual block device or a block backing device. -# -# @device: If the stats are for a virtual block device, the name -# corresponding to the virtual block device. -# -# @node-name: The node name of the device. (since 2.3) -# -# ... more members ... -# -# Since: 0.14.0 -## -{ 'struct': 'BlockStats', - 'data': {'*device': 'str', '*node-name': 'str', - ... more members ... } } - -## -# @query-blockstats: -# -# Query the @BlockStats for all virtual block devices. -# -# @query-nodes: If true, the command will query all the -# block nodes ... explain, explain ... (since 2.3) -# -# Returns: A list of @BlockStats for each virtual block devices. -# -# Since: 0.14.0 -# -# Example: -# -# -> { "execute": "query-blockstats" } -# <- { -# ... lots of output ... -# } -# -## -{ 'command': 'query-blockstats', - 'data': { '*query-nodes': 'bool' }, - 'returns': ['BlockStats'] } - -=3D=3D=3D=3D Free-form documentation =3D=3D=3D=3D - -A documentation block that isn't an expression documentation block is -a free-form documentation block. These may be used to provide -additional text and structuring content. - =20 =3D=3D=3D Schema overview =3D=3D=3D =20 @@ -217,43 +76,6 @@ refers to a single-dimension array of that type; multi-= dimension arrays are not directly supported (although an array of a complex struct that contains an array member is possible). =20 -All names must begin with a letter, and contain only ASCII letters, -digits, hyphen, and underscore. There are two exceptions: enum values -may start with a digit, and names that are downstream extensions (see -section Downstream extensions) start with underscore. - -Names beginning with 'q_' are reserved for the generator, which uses -them for munging QMP names that resemble C keywords or other -problematic strings. For example, a member named "default" in qapi -becomes "q_default" in the generated C code. - -Types, commands, and events share a common namespace. Therefore, -generally speaking, type definitions should always use CamelCase for -user-defined type names, while built-in types are lowercase. - -Type names ending with 'Kind' or 'List' are reserved for the -generator, which uses them for implicit union enums and array types, -respectively. - -Command names, and member names within a type, should be all lower -case with words separated by a hyphen. However, some existing older -commands and complex types use underscore; when extending such -expressions, consistency is preferred over blindly avoiding -underscore. - -Event names should be ALL_CAPS with words separated by underscore. - -Member name 'u' and names starting with 'has-' or 'has_' are reserved -for the generator, which uses them for unions and for tracking -optional members. - -Any name (command, event, type, member, or enum value) beginning with -"x-" is marked experimental, and may be withdrawn or changed -incompatibly in a future release. - -Pragma 'name-case-whitelist' lets you violate the rules on use of -upper and lower case. Use for new code is strongly discouraged. - In the rest of this document, usage lines are given for each expression type, with literal strings written in lower case and placeholders written in capitals. If a literal string includes a @@ -328,6 +150,43 @@ Pragma 'name-case-whitelist' takes a list of names tha= t may violate rules on use of upper- vs. lower-case letters. Default is none. =20 =20 +=3D=3D=3D Enumeration types =3D=3D=3D + +Usage: { 'enum': STRING, 'data': ARRAY-OF-STRING } + { 'enum': STRING, '*prefix': STRING, 'data': ARRAY-OF-STRING } + +An enumeration type is a dictionary containing a single 'data' key +whose value is a list of strings. An example enumeration is: + + { 'enum': 'MyEnum', 'data': [ 'value1', 'value2', 'value3' ] } + +Nothing prevents an empty enumeration, although it is probably not +useful. The list of strings should be lower case; if an enum name +represents multiple words, use '-' between words. The string 'max' is +not allowed as an enum value, and values should not be repeated. + +The enum constants will be named by using a heuristic to turn the +type name into a set of underscore separated words. For the example +above, 'MyEnum' will turn into 'MY_ENUM' giving a constant name +of 'MY_ENUM_VALUE1' for the first value. If the default heuristic +does not result in a desirable name, the optional 'prefix' member +can be used when defining the enum. + +The enumeration values are passed as strings over the Client JSON +Protocol, but are encoded as C enum integral values in generated code. +While the C code starts numbering at 0, it is better to use explicit +comparisons to enum values than implicit comparisons to 0; the C code +will also include a generated enum member ending in _MAX for tracking +the size of the enum, useful when using common functions for +converting between strings and enum values. Since the wire format +always passes by name, it is acceptable to reorder or add new +enumeration members in any location without breaking clients of Client +JSON Protocol; however, removing enum values would break +compatibility. For any struct that has a member that will only contain +a finite set of string values, using an enum type for that member is +better than open-coding the member to be type 'str'. + + =3D=3D=3D Struct types =3D=3D=3D =20 Usage: { 'struct': STRING, 'data': DICT, '*base': STRUCT-NAME } @@ -389,43 +248,6 @@ both members like this: "backing": "/some/place/my-backing-file" } =20 =20 -=3D=3D=3D Enumeration types =3D=3D=3D - -Usage: { 'enum': STRING, 'data': ARRAY-OF-STRING } - { 'enum': STRING, '*prefix': STRING, 'data': ARRAY-OF-STRING } - -An enumeration type is a dictionary containing a single 'data' key -whose value is a list of strings. An example enumeration is: - - { 'enum': 'MyEnum', 'data': [ 'value1', 'value2', 'value3' ] } - -Nothing prevents an empty enumeration, although it is probably not -useful. The list of strings should be lower case; if an enum name -represents multiple words, use '-' between words. The string 'max' is -not allowed as an enum value, and values should not be repeated. - -The enum constants will be named by using a heuristic to turn the -type name into a set of underscore separated words. For the example -above, 'MyEnum' will turn into 'MY_ENUM' giving a constant name -of 'MY_ENUM_VALUE1' for the first value. If the default heuristic -does not result in a desirable name, the optional 'prefix' member -can be used when defining the enum. - -The enumeration values are passed as strings over the Client JSON -Protocol, but are encoded as C enum integral values in generated code. -While the C code starts numbering at 0, it is better to use explicit -comparisons to enum values than implicit comparisons to 0; the C code -will also include a generated enum member ending in _MAX for tracking -the size of the enum, useful when using common functions for -converting between strings and enum values. Since the wire format -always passes by name, it is acceptable to reorder or add new -enumeration members in any location without breaking clients of Client -JSON Protocol; however, removing enum values would break -compatibility. For any struct that has a member that will only contain -a finite set of string values, using an enum type for that member is -better than open-coding the member to be type 'str'. - - =3D=3D=3D Union types =3D=3D=3D =20 Usage: { 'union': STRING, 'data': DICT } @@ -744,6 +566,46 @@ This expanded form is necessary if you want to make th= e feature conditional (see below in "Configuring the schema"). =20 =20 +=3D=3D=3D Naming rules and reserved names =3D=3D=3D + +All names must begin with a letter, and contain only ASCII letters, +digits, hyphen, and underscore. There are two exceptions: enum values +may start with a digit, and names that are downstream extensions (see +section Downstream extensions) start with underscore. + +Names beginning with 'q_' are reserved for the generator, which uses +them for munging QMP names that resemble C keywords or other +problematic strings. For example, a member named "default" in qapi +becomes "q_default" in the generated C code. + +Types, commands, and events share a common namespace. Therefore, +generally speaking, type definitions should always use CamelCase for +user-defined type names, while built-in types are lowercase. + +Type names ending with 'Kind' or 'List' are reserved for the +generator, which uses them for implicit union enums and array types, +respectively. + +Command names, and member names within a type, should be all lower +case with words separated by a hyphen. However, some existing older +commands and complex types use underscore; when extending such +expressions, consistency is preferred over blindly avoiding +underscore. + +Event names should be ALL_CAPS with words separated by underscore. + +Member name 'u' and names starting with 'has-' or 'has_' are reserved +for the generator, which uses them for unions and for tracking +optional members. + +Any name (command, event, type, member, or enum value) beginning with +"x-" is marked experimental, and may be withdrawn or changed +incompatibly in a future release. + +Pragma 'name-case-whitelist' lets you violate the rules on use of +upper and lower case. Use for new code is strongly discouraged. + + =3D=3D=3D Downstream extensions =3D=3D=3D =20 QAPI schema names that are externally visible, say in the Client JSON @@ -814,6 +676,150 @@ The presence of 'if' keys in the schema is reflected = through to the introspection output depending on the build configuration. =20 =20 +=3D=3D=3D Documentation comments =3D=3D=3D + +A multi-line comment that starts and ends with a '##' line is a +documentation comment. These are parsed by the documentation +generator, which recognizes certain markup detailed below. + + +=3D=3D=3D=3D Documentation markup =3D=3D=3D=3D + +Comment text starting with '=3D' is a section title: + + # =3D Section title + +Double the '=3D' for a subsection title: + + # =3D=3D Subsection title + +'|' denotes examples: + + # | Text of the example, may span + # | multiple lines + +'*' starts an itemized list: + + # * First item, may span + # multiple lines + # * Second item + +You can also use '-' instead of '*'. + +A decimal number followed by '.' starts a numbered list: + + # 1. First item, may span + # multiple lines + # 2. Second item + +The actual number doesn't matter. You could even use '*' instead of +'2.' for the second item. + +Lists can't be nested. Blank lines are currently not supported within +lists. + +Additional whitespace between the initial '#' and the comment text is +permitted. + +*foo* and _foo_ are for strong and emphasis styles respectively (they +do not work over multiple lines). @foo is used to reference a name in +the schema. + +Example: + +## +# =3D Section +# =3D=3D Subsection +# +# Some text foo with *strong* and _emphasis_ +# 1. with a list +# 2. like that +# +# And some code: +# | $ echo foo +# | -> do this +# | <- get that +# +## + + +=3D=3D=3D=3D Expression documentation =3D=3D=3D=3D + +Expressions other than include and pragma directives may be preceded +by a documentation block. Such blocks are called expression +documentation blocks. + +When documentation is required (see pragma 'doc-required'), expression +documentation blocks are mandatory. + +The documentation block consists of a first line naming the +expression, an optional overview, a description of each argument (for +commands and events) or member (for structs, unions and alternates), +and optional tagged sections. + +FIXME: the parser accepts these things in almost any order. + +Extensions added after the expression was first released carry a +'(since x.y.z)' comment. + +A tagged section starts with one of the following words: +"Note:"/"Notes:", "Since:", "Example"/"Examples", "Returns:", "TODO:". +The section ends with the start of a new section. + +A 'Since: x.y.z' tagged section lists the release that introduced the +expression. + +For example: + +## +# @BlockStats: +# +# Statistics of a virtual block device or a block backing device. +# +# @device: If the stats are for a virtual block device, the name +# corresponding to the virtual block device. +# +# @node-name: The node name of the device. (since 2.3) +# +# ... more members ... +# +# Since: 0.14.0 +## +{ 'struct': 'BlockStats', + 'data': {'*device': 'str', '*node-name': 'str', + ... more members ... } } + +## +# @query-blockstats: +# +# Query the @BlockStats for all virtual block devices. +# +# @query-nodes: If true, the command will query all the +# block nodes ... explain, explain ... (since 2.3) +# +# Returns: A list of @BlockStats for each virtual block devices. +# +# Since: 0.14.0 +# +# Example: +# +# -> { "execute": "query-blockstats" } +# <- { +# ... lots of output ... +# } +# +## +{ 'command': 'query-blockstats', + 'data': { '*query-nodes': 'bool' }, + 'returns': ['BlockStats'] } + +=3D=3D=3D=3D Free-form documentation =3D=3D=3D=3D + +A documentation block that isn't an expression documentation block is +a free-form documentation block. These may be used to provide +additional text and structuring content. + + =3D=3D Client JSON Protocol introspection =3D=3D =20 Clients of a Client JSON Protocol commonly need to figure out what --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569329212; cv=none; d=zoho.com; s=zohoarc; b=J1RFCgscazhGBza8y3X4IuB+zT42CspXpPBLp+zcJrrIYs4IDoJ7nT5RcX9ovBlW+d91DNJMntDMDA7kFA5pzlED1s52lm72ZIyH4wIrX2R67v/kOlJVGGMKqN3ViS/U7J4tVFBZAdCV7n4SEawItyUONr61v5AsRlG0l8a1bIo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569329212; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=FbjPaxpqVaL+Iud/+LHnx9pA4xgLzZVCwAfdqcL6gSU=; b=eFZMojEYVIxOdFHVrHZk/M6Zq3s1rHw1OdciQBtFcffZzUK2jFwfK/n/99PMx5iXhLm9dZi6YUJW5Ik4bdencb8zAMlK5JTNUlw3hDTugSQlk1BFWoz/gNzzZSGQf6R5Xk2cjrRgijFXnRx/zfksVpa3RCvPpZh45NAZhJm2r04= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569329212355760.2418408625427; Tue, 24 Sep 2019 05:46:52 -0700 (PDT) Received: from localhost ([::1]:45266 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCkDP-000300-RS for importer@patchew.org; Tue, 24 Sep 2019 08:46:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50518) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0n-0001Je-L0 for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0i-0006vP-Jc for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53422) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0i-0006uE-4g for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:40 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 546608AC6F9 for ; Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F31BF5C207; Tue, 24 Sep 2019 12:33:38 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id A34B311384AA; Tue, 24 Sep 2019 14:33:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 15/37] docs/devel/qapi-code-gen: Rewrite compatibility considerations Date: Tue, 24 Sep 2019 14:33:12 +0200 Message-Id: <20190924123334.30645-16-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]); Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" We have some compatibility advice buried in sections "Enumeration types" and "Struct types". Compatibility is actually about commands and events. It devolves to the types used there. All kinds of types, not just enumerations and structs. Replace the existing advice by a new section "Compatibility considerations". Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20190913201349.24332-14-armbru@redhat.com> [Squash in paragraph on invisible schema changes, as per Eric's review] --- docs/devel/qapi-code-gen.txt | 99 +++++++++++++++++++++++------------- 1 file changed, 64 insertions(+), 35 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index 663ef10a56..ac36ed34e3 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -178,14 +178,11 @@ While the C code starts numbering at 0, it is better = to use explicit comparisons to enum values than implicit comparisons to 0; the C code will also include a generated enum member ending in _MAX for tracking the size of the enum, useful when using common functions for -converting between strings and enum values. Since the wire format -always passes by name, it is acceptable to reorder or add new -enumeration members in any location without breaking clients of Client -JSON Protocol; however, removing enum values would break -compatibility. For any struct that has a member that will only contain -a finite set of string values, using an enum type for that member is -better than open-coding the member to be type 'str'. +converting between strings and enum values. =20 +For any struct that has a member that will only contain a finite set +of string values, using an enum type for that member is better than +open-coding the member to be type 'str'. =20 =3D=3D=3D Struct types =3D=3D=3D =20 @@ -203,34 +200,6 @@ name. An example of a struct is: The use of '*' as a prefix to the name means the member is optional in the corresponding JSON protocol usage. =20 -The default initialization value of an optional argument should not be cha= nged -between versions of QEMU unless the new default maintains backward -compatibility to the user-visible behavior of the old default. - -With proper documentation, this policy still allows some flexibility; for -example, documenting that a default of 0 picks an optimal buffer size allo= ws -one release to declare the optimal size at 512 while another release decla= res -the optimal size at 4096 - the user-visible behavior is not the bytes used= by -the buffer, but the fact that the buffer was optimal size. - -On input structures (only mentioned in the 'data' side of a command), chan= ging -from mandatory to optional is safe (older clients will supply the option, = and -newer clients can benefit from the default); changing from optional to -mandatory is backwards incompatible (older clients may be omitting the opt= ion, -and must continue to work). - -On output structures (only mentioned in the 'returns' side of a command), -changing from mandatory to optional is in general unsafe (older clients ma= y be -expecting the member, and could crash if it is missing), although it -can be done if the only way that the optional argument will be omitted -is when it is triggered by the presence of a new input flag to the -command that older clients don't know to send. Changing from optional -to mandatory is safe. - -A structure that is used in both input and output of various commands -must consider the backwards compatibility constraints of both directions -of use. - A struct definition can specify another struct as its base. In this case, the members of the base type are included as top-level membe= rs of the new struct's dictionary in the Client JSON Protocol wire @@ -1037,6 +1006,66 @@ the names of built-in types. Clients should examine= member "json-type" instead of hard-coding names of built-in types. =20 =20 +=3D=3D Compatibility considerations =3D=3D + +Maintaining backward compatibility at the Client JSON Protocol level +while evolving the schema requires some care. This section is about +syntactic compatibility, which is necessary, but not sufficient, for +actual compatibility. + +Clients send commands with argument data, and receive command +responses with return data and events with event data. + +Adding opt-in functionality to the send direction is backwards +compatible: adding commands, optional arguments, enumeration values, +union and alternate branches; turning an argument type into an +alternate of that type; making mandatory arguments optional. Clients +oblivious of the new functionality continue to work. + +Incompatible changes include removing commands, command arguments, +enumeration values, union and alternate branches, adding mandatory +command arguments, and making optional arguments mandatory. + +The specified behavior of an absent optional argument should remain +the same. With proper documentation, this policy still allows some +flexibility; for example, when an optional 'buffer-size' argument is +specified to default to a sensible buffer size, the actual default +value can still be changed. The specified default behavior is not the +exact size of the buffer, only that the default size is sensible. + +Adding functionality to the receive direction is generally backwards +compatible: adding events, adding return and event data members. +Clients are expected to ignore the ones they don't know. + +Removing "unreachable" stuff like events that can't be triggered +anymore, optional return or event data members that can't be sent +anymore, and return or event data member (enumeration) values that +can't be sent anymore makes no difference to clients, except for +introspection. The latter can conceivably confuse clients, so tread +carefully. + +Incompatible changes include removing return and event data members. + +Any change to a command definition's 'data' or one of the types used +there (recursively) needs to consider send direction compatibility. + +Any change to a command definition's 'return', an event definition's +'data', or one of the types used there (recursively) needs to consider +receive direction compatibility. + +Any change to types used in both contexts need to consider both. + +Members of enumeration types, complex types and alternate types may be +reordered freely. For enumerations and alternate types, this doesn't +affect the wire encoding. For complex types, this might make the +implementation emit JSON object members in a different order, which +the Client JSON Protocol permits. + +Since type names are not visible in the Client JSON Protocol, types +may be freely renamed. Even certain refactorings are invisible, such +as splitting members from one type into a common base type. + + =3D=3D Code generation =3D=3D =20 The QAPI code generator qapi-gen.py generates code and documentation --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569329593; cv=none; d=zoho.com; s=zohoarc; b=n6F5Q5vrfQDbT0vHPohoNTKNvpd0DwwAjKWonVHlsFdvlQIVLBEolhqQnoT2kQiDkAy9xjaAqTVhBygold0atdk1lGWUtGVW+ZSndI6t6xCW6xWe9PU+ihyRzRDhgl8BHpjRG5Ui8gC/59Oiql3lRPdthdgnriiAQrWp+bDkass= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569329593; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=jAiWfNT9kGuN1a4U7QD3nihAnMj92JyubhP3hplYeW0=; b=YMj29yqlTH121IKfaDMxP/nE9DhX884xmIT130M1J2cjV5A16q7hYr1ukcGkYuQPYdRhZhIDlUOisng5sKVpG1Jp/cv2lbUSpPO7dPdeMtmp5ym5gj1vnegygC5PM7sihtTKnE8yYGs21eOqlBUicuAV9YM3/p85g05UWpj3T2s= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569329593941680.755198881329; Tue, 24 Sep 2019 05:53:13 -0700 (PDT) Received: from localhost ([::1]:45310 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCkJZ-0000iA-T0 for importer@patchew.org; Tue, 24 Sep 2019 08:53:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50517) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0n-0001Jd-LH for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0i-0006vh-MP for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48544) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0i-0006uF-9U for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:40 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 551E63175282 for ; Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F380D60933; Tue, 24 Sep 2019 12:33:38 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id A971F11384D8; Tue, 24 Sep 2019 14:33:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 16/37] docs/devel/qapi-code-gen: Rewrite introduction to schema Date: Tue, 24 Sep 2019 14:33:13 +0200 Message-Id: <20190924123334.30645-17-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The introduction to the QAPI schema is somewhat rambling. Rewrite for clarity. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20190913201349.24332-15-armbru@redhat.com> --- docs/devel/qapi-code-gen.txt | 107 ++++++++++++++++------------------- 1 file changed, 48 insertions(+), 59 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index ac36ed34e3..d7bc79b48b 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -16,65 +16,54 @@ well as the QEMU Guest Agent (QGA) for communicating wi= th the guest. The remainder of this document uses "Client JSON Protocol" when referring to the wire contents of a QMP or QGA connection. =20 -To map Client JSON Protocol interfaces to the native C QAPI -implementations, a JSON-based schema is used to define types and -function signatures, and a set of scripts is used to generate types, -signatures, and marshaling/dispatch code. This document will describe -how the schemas, scripts, and resulting code are used. - - -=3D=3D QMP/Guest agent schema =3D=3D - -A QAPI schema file is designed to be loosely based on JSON -(http://www.ietf.org/rfc/rfc8259.txt) with changes for quoting style -and the use of comments; a QAPI schema file is then parsed by a python -code generation program. A valid QAPI schema consists of a series of -top-level expressions, with no commas between them. Where -dictionaries (JSON objects) are used, they are parsed as python -OrderedDicts so that ordering is preserved (for predictable layout of -generated C structs and parameter lists). Ordering doesn't matter -between top-level expressions or the keys within an expression, but -does matter within dictionary values for 'data' and 'returns' members -of a single expression. QAPI schema input is written using 'single -quotes' instead of JSON's "double quotes" (in contrast, Client JSON -Protocol uses no comments, and while input accepts 'single quotes' as -an extension, output is strict JSON using only "double quotes"). As -in JSON, trailing commas are not permitted in arrays or dictionaries. -Input must be ASCII (although QMP supports full Unicode strings, the -QAPI parser does not). At present, there is no place where a QAPI -schema requires the use of JSON numbers or null. - - -=3D=3D=3D Comments =3D=3D=3D - -Comments are allowed; anything between an unquoted # and the following -newline is ignored. - - -=3D=3D=3D Schema overview =3D=3D=3D - -The schema sets up a series of types, as well as commands and events -that will use those types. Forward references are allowed: the parser -scans in two passes, where the first pass learns all type names, and -the second validates the schema and generates the code. This allows -the definition of complex structs that can have mutually recursive -types, and allows for indefinite nesting of Client JSON Protocol that -satisfies the schema. A type name should not be defined more than -once. It is permissible for the schema to contain additional types -not used by any commands or events in the Client JSON Protocol, for -the side effect of generated C code used internally. - -There are eight top-level expressions recognized by the parser: -'include', 'pragma', 'command', 'struct', 'enum', 'union', -'alternate', and 'event'. There are several groups of types: simple -types (a number of built-in types, such as 'int' and 'str'; as well as -enumerations), complex types (structs and two flavors of unions), and -alternate types (a choice between other types). The 'command' and -'event' expressions can refer to existing types by name, or list an -anonymous type as a dictionary. Listing a type name inside an array -refers to a single-dimension array of that type; multi-dimension -arrays are not directly supported (although an array of a complex -struct that contains an array member is possible). +To map between Client JSON Protocol interfaces and the native C API, +we generate C code from a QAPI schema. This document describes the +QAPI schema language, and how it gets mapped to the Client JSON +Protocol and to C. It additionally provides guidance on maintaining +Client JSON Protocol compatibility. + + +=3D=3D The QAPI schema language =3D=3D + +The QAPI schema defines the Client JSON Protocol's commands and +events, as well as types used by them. Forward references are +allowed. + +It is permissible for the schema to contain additional types not used +by any commands or events, for the side effect of generated C code +used internally. + +There are several kinds of types: simple types (a number of built-in +types, such as 'int' and 'str'; as well as enumerations), arrays, +complex types (structs and two flavors of unions), and alternate types +(a choice between other types). + + +=3D=3D=3D Schema syntax =3D=3D=3D + +Syntax is loosely based on JSON (http://www.ietf.org/rfc/rfc8259.txt). +Differences: + +* Comments: start with a hash character (#) that is not part of a + string, and extend to the end of the line. + +* Strings are enclosed in 'single quotes', not "double quotes". + +* Strings are restricted to printable ASCII, and escape sequences to + just '\\'. + +* Numbers are not supported. + +A QAPI schema consists of a series of top-level expressions (JSON +objects). Code and documentation is generated in schema definition +order. Code order should not matter. + +The order of keys within JSON objects does not matter unless +explicitly noted. + +There are eight kinds of top-level expressions: 'include', 'pragma', +'command', 'struct', 'enum', 'union', 'alternate', and 'event'. These +are discussed in detail below. =20 In the rest of this document, usage lines are given for each expression type, with literal strings written in lower case and --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569331670; cv=none; d=zoho.com; s=zohoarc; b=jbQmW/elWIcGtCMI/W/EubWJ2YqSz2oTQ1/Bn0nnqH7Ova6fmmwglJh1aizp97T5FEEs/vnj0X80DAY4dRvqK60VVVdmLTMFo3I+tWnB6EjQcjOmJJwgptAnCRRl0D4BmcP6Fr1Iy9YDCusdVqRCYfVcTc6DoJND8V/s/f6+BqM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569331670; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=KY0qDy6FF1gQrQ/Vcs6NR2wx6gq47/1ZPV6AbibtofE=; b=k/V+Kkw+0qi+yr6IHSwSBnqLY0n2Kq5tZRNcbAaDWHjhTRxkaZFLMz32LcmJSbHZzy0a3haptvpfksYplmlXHhgc/UV/0pqLuSyqqng9TuBnZQsVUj5lN5pu8e7Zo1uN4NE7e2SpOaChpAVtMX2x4Kr1T8Ue/DokhhFDb3KHHKQ= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 156933167056275.35018403325444; Tue, 24 Sep 2019 06:27:50 -0700 (PDT) Received: from localhost ([::1]:45618 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCkr4-0006tC-MQ for importer@patchew.org; Tue, 24 Sep 2019 09:27:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50745) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0w-0001Rz-5s for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:34:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0j-0006xd-Lc for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42664) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0i-0006ui-HY for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:41 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AACAA309BF13 for ; Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 04A8E61559; Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id B08BA11384DA; Tue, 24 Sep 2019 14:33:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 17/37] docs/devel/qapi-code-gen: Improve QAPI schema language doc Date: Tue, 24 Sep 2019 14:33:14 +0200 Message-Id: <20190924123334.30645-18-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" We document the language by giving patterns of valid JSON objects. The patterns contain placeholders we don't define anywhere; their names have to speak for themselves. I guess they do, but I'd prefer a bit more rigor. Provide a grammar instead, and rework the text accordingly. Documentation for QAPI schema conditionals (commit 967c885108, 6cc32b0e14, 87adbbffd4..3e270dcacc) and feature flags (commit 6a8c0b5102) was bolted on. The sections documenting types, commands and events don't mention them. Section "Features" and "Configuring the schema" then provide additional syntax for types, commands and events. I hate that. Fix the sections documenting types, commands and events to provide accurate syntax, and point to "Features" and "Configuring the schema" for details. We talk about "(top-level) expressions other than include and pragma". Adopt more convenient terminology: a (top-level) expression is either a directive (include or pragma) or a definition (anything else). Avoid the terms "dictionary" and "key". Stick to JSON terminology "object" and "member name" instead. While there, make spacing more consistent. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20190913201349.24332-16-armbru@redhat.com> --- docs/devel/qapi-code-gen.txt | 596 ++++++++++++++++++++++------------- 1 file changed, 372 insertions(+), 224 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index d7bc79b48b..b12a5b4de8 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -4,12 +4,12 @@ Copyright IBM Corp. 2011 Copyright (C) 2012-2016 Red Hat, Inc. =20 This work is licensed under the terms of the GNU GPL, version 2 or -later. See the COPYING file in the top-level directory. +later. See the COPYING file in the top-level directory. =20 =3D=3D Introduction =3D=3D =20 QAPI is a native C API within QEMU which provides management-level -functionality to internal and external users. For external +functionality to internal and external users. For external users/processes, this interface is made available by a JSON-based wire format for the QEMU Monitor Protocol (QMP) for controlling qemu, as well as the QEMU Guest Agent (QGA) for communicating with the guest. @@ -54,24 +54,49 @@ Differences: =20 * Numbers are not supported. =20 -A QAPI schema consists of a series of top-level expressions (JSON -objects). Code and documentation is generated in schema definition -order. Code order should not matter. +A second layer of syntax defines the sequences of JSON texts that are +a correctly structured QAPI schema. We provide a grammar for this +syntax in an EBNF-like notation: =20 -The order of keys within JSON objects does not matter unless +* Production rules look like non-terminal =3D expression +* Concatenation: expression A B matches expression A, then B +* Alternation: expression A | B matches expression A or B +* Repetition: expression A... matches zero or more occurrences of + expression A +* Repetition: expression A, ... matches zero or more occurrences of + expression A separated by , +* Grouping: expression ( A ) matches expression A +* JSON's structural characters are terminals: { } [ ] : , +* JSON's literal names are terminals: false true null +* String literals enclosed in 'single quotes' are terminal, and match + this JSON string, with a leading '*' stripped off +* When JSON object member's name starts with '*', the member is + optional. +* The symbol STRING is a terminal, and matches any JSON string +* The symbol BOOL is a terminal, and matches JSON false or true +* ALL-CAPS words other than STRING are non-terminals + +The order of members within JSON objects does not matter unless explicitly noted. =20 -There are eight kinds of top-level expressions: 'include', 'pragma', -'command', 'struct', 'enum', 'union', 'alternate', and 'event'. These -are discussed in detail below. - -In the rest of this document, usage lines are given for each -expression type, with literal strings written in lower case and -placeholders written in capitals. If a literal string includes a -prefix of '*', that key/value pair can be omitted from the expression. -For example, a usage statement that includes '*base':STRUCT-NAME -means that an expression has an optional key 'base', which if present -must have a value that forms a struct name. +A QAPI schema consists of a series of top-level expressions: + + SCHEMA =3D TOP-LEVEL-EXPR... + +The top-level expressions are all JSON objects. Code and +documentation is generated in schema definition order. Code order +should not matter. + +A top-level expressions is either a directive or a definition: + + TOP-LEVEL-EXPR =3D DIRECTIVE | DEFINITION + +There are two kinds of directives and six kinds of definitions: + + DIRECTIVE =3D INCLUDE | PRAGMA + DEFINITION =3D ENUM | STRUCT | UNION | ALTERNATE | COMMAND | EVENT + +These are discussed in detail below. =20 =20 =3D=3D=3D Built-in Types =3D=3D=3D @@ -101,16 +126,16 @@ The following types are predefined, and map to C as f= ollows: =20 =3D=3D=3D Include directives =3D=3D=3D =20 -Usage: { 'include': STRING } +Syntax: + INCLUDE =3D { 'include': STRING } =20 The QAPI schema definitions can be modularized using the 'include' directi= ve: =20 { 'include': 'path/to/file.json' } =20 -The directive is evaluated recursively, and include paths are relative to = the -file using the directive. Multiple includes of the same file are -idempotent. No other keys should appear in the expression, and the include -value should be a string. +The directive is evaluated recursively, and include paths are relative +to the file using the directive. Multiple includes of the same file +are idempotent. =20 As a matter of style, it is a good idea to have all files be self-contained, but at the moment, nothing prevents an included file @@ -121,10 +146,12 @@ prevent incomplete include files. =20 =3D=3D=3D Pragma directives =3D=3D=3D =20 -Usage: { 'pragma': DICT } +Syntax: + PRAGMA =3D { 'pragma': { '*doc-required': BOOL, + '*returns-whitelist': [ STRING, ... ], + '*name-case-whitelist': [ STRING, ... ] } } =20 The pragma directive lets you control optional generator behavior. -The dictionary's entries are pragma names and values. =20 Pragma's scope is currently the complete schema. Setting the same pragma to different values in parts of the schema doesn't work. @@ -141,60 +168,95 @@ rules on use of upper- vs. lower-case letters. Defau= lt is none. =20 =3D=3D=3D Enumeration types =3D=3D=3D =20 -Usage: { 'enum': STRING, 'data': ARRAY-OF-STRING } - { 'enum': STRING, '*prefix': STRING, 'data': ARRAY-OF-STRING } +Syntax: + ENUM =3D { 'enum': STRING, + 'data': [ ENUM-VALUE, ... ], + '*prefix': STRING, + '*if': COND } + ENUM-VALUE =3D STRING + | { 'name': STRING, '*if': COND } =20 -An enumeration type is a dictionary containing a single 'data' key -whose value is a list of strings. An example enumeration is: +Member 'enum' names the enum type. + +Each member of the 'data' array defines a value of the enumeration +type. The form STRING is shorthand for { 'name': STRING }. The +'name' values must be be distinct. + +Example: =20 { 'enum': 'MyEnum', 'data': [ 'value1', 'value2', 'value3' ] } =20 Nothing prevents an empty enumeration, although it is probably not -useful. The list of strings should be lower case; if an enum name -represents multiple words, use '-' between words. The string 'max' is -not allowed as an enum value, and values should not be repeated. - -The enum constants will be named by using a heuristic to turn the -type name into a set of underscore separated words. For the example -above, 'MyEnum' will turn into 'MY_ENUM' giving a constant name -of 'MY_ENUM_VALUE1' for the first value. If the default heuristic -does not result in a desirable name, the optional 'prefix' member -can be used when defining the enum. - -The enumeration values are passed as strings over the Client JSON -Protocol, but are encoded as C enum integral values in generated code. -While the C code starts numbering at 0, it is better to use explicit -comparisons to enum values than implicit comparisons to 0; the C code -will also include a generated enum member ending in _MAX for tracking -the size of the enum, useful when using common functions for -converting between strings and enum values. - -For any struct that has a member that will only contain a finite set -of string values, using an enum type for that member is better than -open-coding the member to be type 'str'. +useful. + +On the wire, an enumeration type's value is represented by its +(string) name. In C, it's represented by an enumeration constant. +These are of the form PREFIX_NAME, where PREFIX is derived from the +enumeration type's name, and NAME from the value's name. For the +example above, the generator maps 'MyEnum' to MY_ENUM and 'value1' to +VALUE1, resulting in the enumeration constant MY_ENUM_VALUE1. The +optional 'prefix' member overrides PREFIX. + +The generated C enumeration constants have values 0, 1, ..., N-1 (in +QAPI schema order), where N is the number of values. There is an +additional enumeration constant PREFIX__MAX with value N. + +Do not use string or an integer type when an enumeration type can do +the job satisfactorily. + +The optional 'if' member specifies a conditional. See "Configuring +the schema" below for more on this. + + +=3D=3D=3D Type references and array types =3D=3D=3D + +Syntax: + TYPE-REF =3D STRING | ARRAY-TYPE + ARRAY-TYPE =3D [ STRING ] + +A string denotes the type named by the string. + +A one-element array containing a string denotes an array of the type +named by the string. Example: ['int'] denotes an array of 'int'. + =20 =3D=3D=3D Struct types =3D=3D=3D =20 -Usage: { 'struct': STRING, 'data': DICT, '*base': STRUCT-NAME } +Syntax: + STRUCT =3D { 'struct': STRING, + 'data': MEMBERS, + '*base': STRING, + '*if': COND, + '*features': FEATURES } + MEMBERS =3D { MEMBER, ... } + MEMBER =3D STRING : TYPE-REF + | STRING : { 'type': TYPE-REF, '*if': COND } =20 -A struct is a dictionary containing a single 'data' key whose value is -a dictionary; the dictionary may be empty. This corresponds to a -struct in C or an Object in JSON. Each value of the 'data' dictionary -must be the name of a type, or a one-element array containing a type -name. An example of a struct is: +Member 'struct' names the struct type. + +Each MEMBER of the 'data' object defines a member of the struct type. + +The MEMBER's STRING name consists of an optional '*' prefix and the +struct member name. If '*' is present, the member is optional. + +The MEMBER's value defines its properties, in particular its type. +The form TYPE-REF is shorthand for { 'type': TYPE-REF }. + +Example: =20 { 'struct': 'MyType', - 'data': { 'member1': 'str', 'member2': 'int', '*member3': 'str' } } + 'data': { 'member1': 'str', 'member2': ['int'], '*member3': 'str' } } =20 -The use of '*' as a prefix to the name means the member is optional in -the corresponding JSON protocol usage. +A struct type corresponds to a struct in C, and an object in JSON. +The C struct's members are generated in QAPI schema order. =20 -A struct definition can specify another struct as its base. -In this case, the members of the base type are included as top-level membe= rs -of the new struct's dictionary in the Client JSON Protocol wire -format. An example definition is: +The optional 'base' member names a struct type whose members are to be +included in this type. They go first in the C struct. =20 - { 'struct': 'BlockdevOptionsGenericFormat', 'data': { 'file': 'str' } } +Example: + + { 'struct': 'BlockdevOptionsGenericFormat', + 'data': { 'file': 'str' } } { 'struct': 'BlockdevOptionsGenericCOWFormat', 'base': 'BlockdevOptionsGenericFormat', 'data': { '*backing': 'str' } } @@ -205,18 +267,40 @@ both members like this: { "file": "/some/place/my-image", "backing": "/some/place/my-backing-file" } =20 +The optional 'if' member specifies a conditional. See "Configuring +the schema" below for more on this. + +The optional 'features' member specifies features. See "Features" +below for more on this. + =20 =3D=3D=3D Union types =3D=3D=3D =20 -Usage: { 'union': STRING, 'data': DICT } -or: { 'union': STRING, 'data': DICT, 'base': STRUCT-NAME-OR-DICT, - 'discriminator': ENUM-MEMBER-OF-BASE } - -Union types are used to let the user choose between several different -variants for an object. There are two flavors: simple (no -discriminator or base), and flat (both discriminator and base). A union -type is defined using a data dictionary as explained in the following -paragraphs. Unions must have at least one branch. +Syntax: + UNION =3D { 'union': STRING, + 'data': BRANCHES, + '*if': COND } + | { 'union': STRING, + 'data': BRANCHES, + 'base': ( MEMBERS | STRING ), + 'discriminator': STRING, + '*if': COND } + BRANCHES =3D { BRANCH, ... } + BRANCH =3D STRING : TYPE-REF + | STRING : { 'type': TYPE-REF, '*if': COND } + +Member 'union' names the union type. + +There are two flavors of union types: simple (no discriminator or +base), and flat (both discriminator and base). + +Each BRANCH of the 'data' object defines a branch of the union. A +union must have at least one branch. + +The BRANCH's STRING name is the branch name. + +The BRANCH's value defines the branch's properties, in particular its +type. The form TYPE-REF is shorthand for { 'type': TYPE-REF }. =20 A simple union type defines a mapping from automatic discriminator values to data types like in this example: @@ -229,8 +313,8 @@ values to data types like in this example: 'data': { 'file': 'BlockdevOptionsFile', 'qcow2': 'BlockdevOptionsQcow2' } } =20 -In the Client JSON Protocol, a simple union is represented by a -dictionary that contains the 'type' member as a discriminator, and a +In the Client JSON Protocol, a simple union is represented by an +object that contains the 'type' member as a discriminator, and a 'data' member that is of the specified data type corresponding to the discriminator value, as in these examples: =20 @@ -238,21 +322,27 @@ discriminator value, as in these examples: { "type": "qcow2", "data": { "backing": "/some/place/my-image", "lazy-refcounts": true } } =20 -The generated C code uses a struct containing a union. Additionally, +The generated C code uses a struct containing a union. Additionally, an implicit C enum 'NameKind' is created, corresponding to the union 'Name', for accessing the various branches of the union. The value for each branch can be of any type. =20 -A flat union definition avoids nesting on the wire, and specifies a -set of common members that occur in all variants of the union. The -'base' key must specify either a type name (the type must be a -struct, not a union), or a dictionary representing an anonymous type. -All branches of the union must be struct types, and the top-level -members of the union dictionary on the wire will be combination of -members from both the base type and the appropriate branch type (when -merging two dictionaries, there must be no keys in common). The -'discriminator' member must be the name of a non-optional enum-typed -member of the base struct. +Flat unions permit arbitrary common members that occur in all variants +of the union, not just a discriminator. Their discriminators need not +be named 'type'. They also avoid nesting on the wire. + +The 'base' member defines the common members. If it is a MEMBERS +object, it defines common members just like a struct type's 'data' +member defines struct type members. If it is a STRING, it names a +struct type whose members are the common members. + +All flat union branches must be of struct type. + +In the Client JSON Protocol, a flat union is represented by an object +with the common members (from the base type) and the selected branch's +members. The two sets of member names must be disjoint. Member +'discriminator' must name a non-optional enum-typed member of the base +struct. =20 The following example enhances the above simple union example by adding an optional common member 'read-only', renaming the @@ -276,12 +366,13 @@ Resulting in these JSON objects: Notice that in a flat union, the discriminator name is controlled by the user, but because it must map to a base member with enum type, the code generator ensures that branches match the existing values of the -enum. The order of the keys need not match the declaration of the enum. -The keys need not cover all possible enum values. Omitted enum values -are still valid branches that add no additional members to the data type. -In the resulting generated C data types, a flat union is -represented as a struct with the base members included directly, and -then a union of structures for each branch of the struct. +enum. The order of branches need not match the order of the enum +values. The branches need not cover all possible enum values. +Omitted enum values are still valid branches that add no additional +members to the data type. In the resulting generated C data types, a +flat union is represented as a struct with the base members in QAPI +schema order, and then a union of structures for each branch of the +struct. =20 A simple union can always be re-written as a flat union where the base class has a single member named 'type', and where each branch of the @@ -297,32 +388,47 @@ is identical on the wire to: { 'union': 'Flat': 'base': { 'type': 'Enum' }, 'discriminator': 'type', 'data': { 'one': 'Branch1', 'two': 'Branch2' } } =20 +The optional 'if' member specifies a conditional. See "Configuring +the schema" below for more on this. + =20 =3D=3D=3D Alternate types =3D=3D=3D =20 -Usage: { 'alternate': STRING, 'data': DICT } +Syntax: + ALTERNATE =3D { 'alternate': STRING, + 'data': ALTERNATIVES, + '*if': COND } + ALTERNATIVES =3D { ALTERNATIVE, ... } + ALTERNATIVE =3D STRING : TYPE-REF + | STRING : { 'type': STRING, '*if': COND } =20 -An alternate type is one that allows a choice between two or more JSON -data types (string, integer, number, or object, but currently not -array) on the wire. The definition is similar to a simple union type, -where each branch of the union names a QAPI type. For example: +Member 'alternate' names the alternate type. + +Each ALTERNATIVE of the 'data' object defines a branch of the +alternate. An alternate must have at least one branch. + +The ALTERNATIVE's STRING name is the branch name. + +The ALTERNATIVE's value defines the branch's properties, in particular +its type. The form STRING is shorthand for { 'type': STRING }. + +Example: =20 { 'alternate': 'BlockdevRef', 'data': { 'definition': 'BlockdevOptions', 'reference': 'str' } } =20 -Unlike a union, the discriminator string is never passed on the wire -for the Client JSON Protocol. Instead, the value's JSON type serves -as an implicit discriminator, which in turn means that an alternate -can only express a choice between types represented differently in -JSON. If a branch is typed as the 'bool' built-in, the alternate -accepts true and false; if it is typed as any of the various numeric +An alternate type is like a union type, except there is no +discriminator on the wire. Instead, the branch to use is inferred +from the value. An alternate can only express a choice between types +represented differently on the wire. + +If a branch is typed as the 'bool' built-in, the alternate accepts +true and false; if it is typed as any of the various numeric built-ins, it accepts a JSON number; if it is typed as a 'str' built-in or named enum type, it accepts a JSON string; if it is typed as the 'null' built-in, it accepts JSON null; and if it is typed as a -complex type (struct or union), it accepts a JSON object. Two -different complex types, for instance, aren't permitted, because both -are represented as a JSON object. +complex type (struct or union), it accepts a JSON object. =20 The example alternate declaration above allows using both of the following example objects: @@ -332,43 +438,52 @@ following example objects: "read-only": false, "filename": "/tmp/mydisk.qcow2" } } =20 +The optional 'if' member specifies a conditional. See "Configuring +the schema" below for more on this. + =20 =3D=3D=3D Commands =3D=3D=3D =20 ---- General Command Layout --- +Syntax: + COMMAND =3D { 'command': STRING, + ( + '*data': ( MEMBERS | STRING ), + | + 'data': STRING, + 'boxed': true, + ) + '*returns': TYPE-REF, + '*success-response': false, + '*gen': false, + '*allow-oob': true, + '*allow-preconfig': true, + '*if': COND } =20 -Usage: { 'command': STRING, '*data': COMPLEX-TYPE-NAME-OR-DICT, - '*returns': TYPE-NAME, '*boxed': true, - '*gen': false, '*success-response': false, - '*allow-oob': true, '*allow-preconfig': true } +Member 'command' names the command. =20 -Commands are defined by using a dictionary containing several members, -where three members are most common. The 'command' member is a -mandatory string, and determines the "execute" value passed in a -Client JSON Protocol command exchange. +Member 'data' defines the arguments. It defaults to an empty MEMBERS +object. =20 -The 'data' argument maps to the "arguments" dictionary passed in as -part of a Client JSON Protocol command. The 'data' member is optional -and defaults to {} (an empty dictionary). If present, it must be the -string name of a complex type, or a dictionary that declares an -anonymous type with the same semantics as a 'struct' expression. +If 'data' is a MEMBERS object, then MEMBERS defines arguments just +like a struct type's 'data' defines struct type members. =20 -The 'returns' member describes what will appear in the "return" member -of a Client JSON Protocol reply on successful completion of a command. -The member is optional from the command declaration; if absent, the -"return" member will be an empty dictionary. If 'returns' is present, -it must be the string name of a complex type, or a -one-element array containing the name of a complex type. -To return anything else, you have to list the command in pragma -'returns-whitelist'. If you do this, the command cannot be extended -to return additional information in the future. Use of +If 'data' is a STRING, then STRING names a complex type whose members +are the arguments. A union type requires 'boxed': true. + +Member 'returns' defines the command's return type. It defaults to an +empty struct type. It must normally be a complex type or an array of +a complex type. To return anything else, the command must be listed +in pragma 'returns-whitelist'. If you do this, extending the command +to return additional information will be harder. Use of 'returns-whitelist' for new commands is strongly discouraged. =20 -All commands in Client JSON Protocol use a dictionary to report -failure, with no way to specify that in QAPI. Where the error return -is different than the usual GenericError class in order to help the -client react differently to certain error conditions, it is worth -documenting this in the comments before the command declaration. +A command's error responses are not specified in the QAPI schema. +Error conditions should be documented in comments. + +In the Client JSON Protocol, the value of the "execute" or "exec-oob" +member is the command name. The value of the "arguments" member then +has to conform to the arguments, and the value of the success +response's "return" member will conform to the return type. =20 Some example commands: =20 @@ -386,23 +501,24 @@ which would validate this Client JSON Protocol transa= ction: =3D> { "execute": "my-second-command" } <=3D { "return": [ { "value": "one" }, { } ] } =20 -The generator emits a prototype for the user's function implementing -the command. Normally, 'data' is a dictionary for an anonymous type, -or names a struct type (possibly empty, but not a union), and its -members are passed as separate arguments to this function. If the -command definition includes a key 'boxed' with the boolean value true, -then 'data' is instead the name of any non-empty complex type (struct -or union), and a pointer to that QAPI type is passed as a single -argument. +The generator emits a prototype for the C function implementing the +command. The function itself needs to be written by hand. See +section "Code generated for commands" for examples. + +The function returns the return type. When member 'boxed' is absent, +it takes the command arguments as arguments one by one, in QAPI schema +order. Else it takes them wrapped in the C struct generated for the +complex argument type. It takes an additional Error ** argument in +either case. =20 The generator also emits a marshalling function that extracts arguments for the user's function out of an input QDict, calls the user's function, and if it succeeded, builds an output QObject from -its return value. +its return value. This is for use by the QMP monitor core. =20 In rare cases, QAPI cannot express a type-safe representation of a corresponding Client JSON Protocol command. You then have to suppress -generation of a marshalling function by including a key 'gen' with +generation of a marshalling function by including a member 'gen' with boolean value false, and instead write your own function. For example: =20 @@ -416,13 +532,12 @@ use type-safe unions. Normally, the QAPI schema is used to describe synchronous exchanges, where a response is expected. But in some cases, the action of a command is expected to change state in a way that a successful -response is not possible (although the command will still return a -normal dictionary error on failure). When a successful reply is not -possible, the command expression includes the optional key -'success-response' with boolean value false. So far, only QGA makes -use of this member. +response is not possible (although the command will still return an +error object on failure). When a successful reply is not possible, +the command definition includes the optional member 'success-response' +with boolean value false. So far, only QGA makes use of this member. =20 -Key 'allow-oob' declares whether the command supports out-of-band +Member 'allow-oob' declares whether the command supports out-of-band (OOB) execution. It defaults to false. For example: =20 { 'command': 'migrate_recover', @@ -455,8 +570,8 @@ other "slow" lock. =20 When in doubt, do not implement OOB execution support. =20 -Key 'allow-preconfig' declares whether the command is available before -the machine is built. It defaults to false. For example: +Member 'allow-preconfig' declares whether the command is available +before the machine is built. It defaults to false. For example: =20 { 'command': 'qmp_capabilities', 'data': { '*enable': [ 'QMPCapability' ] }, @@ -465,16 +580,33 @@ the machine is built. It defaults to false. For exa= mple: QMP is available before the machine is built only when QEMU was started with --preconfig. =20 +The optional 'if' member specifies a conditional. See "Configuring +the schema" below for more on this. + + =3D=3D=3D Events =3D=3D=3D =20 -Usage: { 'event': STRING, '*data': COMPLEX-TYPE-NAME-OR-DICT, - '*boxed': true } - -Events are defined with the keyword 'event'. When 'data' is also -specified, additional info will be included in the event, with similar -semantics to a 'struct' expression. Finally there will be C API -generated in qapi-events.h; when called by QEMU code, a message with -timestamp will be emitted on the wire. +Syntax: + EVENT =3D { 'event': STRING, + ( + '*data': ( MEMBERS | STRING ), + | + 'data': STRING, + 'boxed': true, + ) + '*if': COND } + +Member 'event' names the event. This is the event name used in the +Client JSON Protocol. + +Member 'data' defines the event-specific data. It defaults to an +empty MEMBERS object. + +If 'data' is a MEMBERS object, then MEMBERS defines event-specific +data just like a struct type's 'data' defines struct type members. + +If 'data' is a STRING, then STRING names a complex type whose members +are the event-specific data. A union type requires 'boxed': true. =20 An example event is: =20 @@ -487,42 +619,44 @@ Resulting in this JSON object: "data": { "b": "test string" }, "timestamp": { "seconds": 1267020223, "microseconds": 435656 } } =20 -The generator emits a function to send the event. Normally, 'data' is -a dictionary for an anonymous type, or names a struct type (possibly -empty, but not a union), and its members are passed as separate -arguments to this function. If the event definition includes a key -'boxed' with the boolean value true, then 'data' is instead the name -of any non-empty complex type (struct or union), and a pointer to that -QAPI type is passed as a single argument. +The generator emits a function to send the event. When member 'boxed' +is absent, it takes event-specific data one by one, in QAPI schema +order. Else it takes them wrapped in the C struct generated for the +complex type. See section "Code generated for events" for examples. + +The optional 'if' member specifies a conditional. See "Configuring +the schema" below for more on this. =20 =20 =3D=3D=3D Features =3D=3D=3D =20 +Syntax: + FEATURES =3D [ FEATURE, ... ] + FEATURE =3D STRING + | { 'name': STRING, '*if': COND } + Sometimes, the behaviour of QEMU changes compatibly, but without a -change in the QMP syntax (usually by allowing values or operations that -previously resulted in an error). QMP clients may still need to know -whether the extension is available. +change in the QMP syntax (usually by allowing values or operations +that previously resulted in an error). QMP clients may still need to +know whether the extension is available. =20 For this purpose, a list of features can be specified for a struct type. This is exposed to the client as a list of string, where each string signals that this build of QEMU shows a certain behaviour. =20 -In the schema, features can be specified as simple strings, for example: +Each member of the 'features' array defines a feature. It can either +be { 'name': STRING, '*if': COND }, or STRING, which is shorthand for +{ 'name': STRING }. + +The optional 'if' member specifies a conditional. See "Configuring +the schema" below for more on this. + +Example: =20 { 'struct': 'TestType', 'data': { 'number': 'int' }, 'features': [ 'allow-negative-numbers' ] } =20 -Another option is to specify features as dictionaries, where the key -'name' specifies the feature string to be exposed to clients: - -{ 'struct': 'TestType', - 'data': { 'number': 'int' }, - 'features': [ { 'name': 'allow-negative-numbers' } ] } - -This expanded form is necessary if you want to make the feature -conditional (see below in "Configuring the schema"). - =20 =3D=3D=3D Naming rules and reserved names =3D=3D=3D =20 @@ -546,9 +680,8 @@ respectively. =20 Command names, and member names within a type, should be all lower case with words separated by a hyphen. However, some existing older -commands and complex types use underscore; when extending such -expressions, consistency is preferred over blindly avoiding -underscore. +commands and complex types use underscore; when extending them, +consistency is preferred over blindly avoiding underscore. =20 Event names should be ALL_CAPS with words separated by underscore. =20 @@ -578,11 +711,14 @@ downstream command __com.redhat_drive-mirror. =20 =3D=3D=3D Configuring the schema =3D=3D=3D =20 -The 'struct', 'enum', 'union', 'alternate', 'command' and 'event' -top-level expressions can take an 'if' key. Its value must be a string -or a list of strings. A string is shorthand for a list containing just -that string. The code generated for the top-level expression will then -be guarded by #if COND for each COND in the list. +Syntax: + COND =3D STRING + | [ STRING, ... ] + +All definitions take an optional 'if' member. Its value must be a +string or a list of strings. A string is shorthand for a list +containing just that string. The code generated for the definition +will then be guarded by #if STRING for each STRING in the COND list. =20 Example: a conditional struct =20 @@ -597,29 +733,33 @@ gets its generated code guarded like this: #endif /* defined(HAVE_BAR) */ #endif /* defined(CONFIG_FOO) */ =20 -Where a member can be defined with a single string value for its type, -it is also possible to supply a dictionary instead with both 'type' -and 'if' keys. +Individual members of complex types, commands arguments, and +event-specific data can also be made conditional. This requires the +longhand form of MEMBER. =20 -Example: a conditional 'bar' member +Example: a struct type with unconditional member 'foo' and conditional +member 'bar' =20 { 'struct': 'IfStruct', 'data': { 'foo': 'int', 'bar': { 'type': 'int', 'if': 'defined(IFCOND)'} } } =20 -An enum value can be replaced by a dictionary with a 'name' and a 'if' -key. +A union's discriminator may not be conditional. =20 -Example: a conditional 'bar' enum member. +Likewise, individual enumeration values be conditional. This requires +the longhand form of ENUM-VALUE. + +Example: an enum type with unconditional value 'foo' and conditional +value 'bar' =20 { 'enum': 'IfEnum', 'data': [ 'foo', { 'name' : 'bar', 'if': 'defined(IFCOND)' } ] } =20 -Similarly, features can be specified as a dictionary with a 'name' and -an 'if' key. +Likewise, features can be conditional. This requires the longhand +form of FEATURE. =20 -Example: a conditional 'allow-negative-numbers' feature +Example: a struct with conditional feature 'allow-negative-numbers' =20 { 'struct': 'TestType', 'data': { 'number': 'int' }, @@ -628,17 +768,30 @@ Example: a conditional 'allow-negative-numbers' featu= re =20 Please note that you are responsible to ensure that the C code will compile with an arbitrary combination of conditions, since the -generators are unable to check it at this point. +generator is unable to check it at this point. =20 -The presence of 'if' keys in the schema is reflected through to the -introspection output depending on the build configuration. +The conditions apply to introspection as well, i.e. introspection +shows a conditional entity only when the condition is satisfied in +this particular build. =20 =20 =3D=3D=3D Documentation comments =3D=3D=3D =20 A multi-line comment that starts and ends with a '##' line is a -documentation comment. These are parsed by the documentation -generator, which recognizes certain markup detailed below. +documentation comment. + +If the documentation comment starts like + + ## + # @SYMBOL: + +it documents the definition if SYMBOL, else it's free-form +documentation. + +See below for more on definition documentation. + +Free-form documentation may be used to provide additional text and +structuring content. =20 =20 =3D=3D=3D=3D Documentation markup =3D=3D=3D=3D @@ -701,23 +854,24 @@ Example: ## =20 =20 -=3D=3D=3D=3D Expression documentation =3D=3D=3D=3D +=3D=3D=3D=3D Definition documentation =3D=3D=3D=3D =20 -Expressions other than include and pragma directives may be preceded -by a documentation block. Such blocks are called expression -documentation blocks. +Definition documentation, if present, must immediately precede the +definition it documents. =20 -When documentation is required (see pragma 'doc-required'), expression -documentation blocks are mandatory. +When documentation is required (see pragma 'doc-required'), every +definition must have documentation. =20 -The documentation block consists of a first line naming the -expression, an optional overview, a description of each argument (for -commands and events) or member (for structs, unions and alternates), -and optional tagged sections. +Definition documentation starts with a line naming the definition, +followed by an optional overview, a description of each argument (for +commands and events), member (for structs and unions), branch (for +alternates), or value (for enums), and finally optional tagged +sections. =20 FIXME: the parser accepts these things in almost any order. +FIXME: union branches should be described, too. =20 -Extensions added after the expression was first released carry a +Extensions added after the definition was first released carry a '(since x.y.z)' comment. =20 A tagged section starts with one of the following words: @@ -725,7 +879,7 @@ A tagged section starts with one of the following words: The section ends with the start of a new section. =20 A 'Since: x.y.z' tagged section lists the release that introduced the -expression. +definition. =20 For example: =20 @@ -771,12 +925,6 @@ For example: 'data': { '*query-nodes': 'bool' }, 'returns': ['BlockStats'] } =20 -=3D=3D=3D=3D Free-form documentation =3D=3D=3D=3D - -A documentation block that isn't an expression documentation block is -a free-form documentation block. These may be used to provide -additional text and structuring content. - =20 =3D=3D Client JSON Protocol introspection =3D=3D =20 @@ -862,7 +1010,7 @@ If the event carries no additional information, "arg-t= ype" names an object type without members. The event may not have a data member on the wire then. =20 -Each command or event defined with dictionary-valued 'data' in the +Each command or event defined with 'data' as MEMBERS object in the QAPI schema implicitly defines an object type. =20 Example: the SchemaInfo for EVENT_C from section Events @@ -1044,7 +1192,7 @@ receive direction compatibility. =20 Any change to types used in both contexts need to consider both. =20 -Members of enumeration types, complex types and alternate types may be +Enumeration type values and complex and alternate type members may be reordered freely. For enumerations and alternate types, this doesn't affect the wire encoding. For complex types, this might make the implementation emit JSON object members in a different order, which --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569329843; cv=none; d=zoho.com; s=zohoarc; b=XCZkPlYqUKN4OGLr6AKymMcBCBObmwZo9wVdzaxIRBuXsxTQa6AbbhC0rEfzw+8YfMZFlezXUXY1DVoiqYPBnORkkSJonHJh9hsiErMBOpgpvJcHsC3uVp7UMAt4lojyqybXq7ZvvLL7lYPNzFHUIpji9P/xUlmEc/V0EnIHFJU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569329843; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=eo6+ovHx2Io0ed6AKIhSjVXiWWm6/Z2NC2nz6czfFH8=; b=cqxjB1RFe177aXB/QSs/oRH3uvPUXQyRRmsjT0t91Aoy8xSTesDwl1yWzQjMEXgrK7ghptWF39IBVBX9nyWWUp9BXavb5i7GZUJu2tzuv850xdMsKFdb1+qKB6OnK1bSLIe1jExL0DnO27t+xKf0el51M4pdT7be85VU2PQ3y24= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569329843909444.96459716461845; Tue, 24 Sep 2019 05:57:23 -0700 (PDT) Received: from localhost ([::1]:45334 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCkNe-0004gj-1w for importer@patchew.org; Tue, 24 Sep 2019 08:57:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50571) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0o-0001Kg-O6 for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0j-0006xN-Hj for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55480) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0i-0006uJ-MB for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:41 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5D8C95859E for ; Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 080255D9E1; Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id B7AC21138406; Tue, 24 Sep 2019 14:33:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 18/37] qapi: Tweak code to match docs/devel/qapi-code-gen.txt Date: Tue, 24 Sep 2019 14:33:15 +0200 Message-Id: <20190924123334.30645-19-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The previous commit made qapi-code-gen.txt define "(top-level) expression" as either "directive" or "definition". The code still uses "expression" when it really means "definition". Tidy up. The previous commit made qapi-code-gen.txt use "object" rather than "dictionary". The code still uses "dictionary". Tidy up. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20190913201349.24332-17-armbru@redhat.com> --- scripts/qapi/common.py | 24 +++++++++---------- tests/qapi-schema/args-invalid.err | 2 +- tests/qapi-schema/doc-missing.err | 2 +- tests/qapi-schema/doc-no-symbol.err | 2 +- .../qapi-schema/enum-dict-member-unknown.err | 2 +- tests/qapi-schema/pragma-non-dict.err | 2 +- tests/qapi-schema/struct-data-invalid.err | 2 +- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index a538d2f37c..f27860540b 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -103,11 +103,11 @@ class QAPISemError(QAPIError): =20 class QAPIDoc(object): """ - A documentation comment block, either expression or free-form + A documentation comment block, either definition or free-form =20 - Expression documentation blocks consist of + Definition documentation blocks consist of =20 - * a body section: one line naming the expression, followed by an + * a body section: one line naming the definition, followed by an overview (any number of lines) =20 * argument sections: a description of each argument (for commands @@ -200,9 +200,9 @@ class QAPIDoc(object): Process a line of documentation text in the body section. =20 If this a symbol line and it is the section's first line, this - is an expression documentation block for that symbol. + is a definition documentation block for that symbol. =20 - If it's an expression documentation block, another symbol line + If it's a definition documentation block, another symbol line begins the argument section for the argument named by it, and a section tag begins an additional section. Start that section and append the line to it. @@ -220,7 +220,7 @@ class QAPIDoc(object): if not self.symbol: raise QAPIParseError(self._parser, "Invalid name") elif self.symbol: - # This is an expression documentation block + # This is a definition documentation block if name.startswith('@') and name.endswith(':'): self._append_line =3D self._append_args_line self._append_args_line(line) @@ -428,7 +428,7 @@ class QAPISchemaParser(object): pragma =3D expr['pragma'] if not isinstance(pragma, dict): raise QAPISemError( - info, "Value of 'pragma' must be a dictionary") + info, "Value of 'pragma' must be an object") for name, value in pragma.items(): self._pragma(name, value, info) else: @@ -437,7 +437,7 @@ class QAPISchemaParser(object): if cur_doc: if not cur_doc.symbol: raise QAPISemError( - cur_doc.info, "Expression documentation requir= ed") + cur_doc.info, "Definition documentation requir= ed") expr_elem['doc'] =3D cur_doc self.exprs.append(expr_elem) cur_doc =3D None @@ -789,7 +789,7 @@ def check_type(info, source, value, =20 if not isinstance(value, OrderedDict): raise QAPISemError(info, - "%s should be a dictionary or type name" % sour= ce) + "%s should be an object or type name" % source) =20 # value is a dictionary, check that each member is okay for (key, arg) in value.items(): @@ -971,8 +971,8 @@ def check_enum(expr, info): "Enum '%s' requires a string for 'prefix'" % na= me) =20 for member in members: - source =3D "dictionary member of enum '%s'" % name - check_known_keys(info, source, member, ['name'], ['if']) + check_known_keys(info, "member of enum '%s'" % name, member, + ['name'], ['if']) check_if(member, info) check_name(info, "Member of enum '%s'" % name, member['name'], enum_member=3DTrue) @@ -1081,7 +1081,7 @@ def check_exprs(exprs): =20 if not doc and doc_required: raise QAPISemError(info, - "Expression missing documentation comment") + "Definition missing documentation comment") =20 if 'enum' in expr: meta =3D 'enum' diff --git a/tests/qapi-schema/args-invalid.err b/tests/qapi-schema/args-in= valid.err index fe1e94975b..bfb2e4133e 100644 --- a/tests/qapi-schema/args-invalid.err +++ b/tests/qapi-schema/args-invalid.err @@ -1 +1 @@ -tests/qapi-schema/args-invalid.json:1: 'data' for command 'foo' should be = a dictionary or type name +tests/qapi-schema/args-invalid.json:1: 'data' for command 'foo' should be = an object or type name diff --git a/tests/qapi-schema/doc-missing.err b/tests/qapi-schema/doc-miss= ing.err index 7f2f326b30..3a377ddc57 100644 --- a/tests/qapi-schema/doc-missing.err +++ b/tests/qapi-schema/doc-missing.err @@ -1 +1 @@ -tests/qapi-schema/doc-missing.json:5: Expression missing documentation com= ment +tests/qapi-schema/doc-missing.json:5: Definition missing documentation com= ment diff --git a/tests/qapi-schema/doc-no-symbol.err b/tests/qapi-schema/doc-no= -symbol.err index 75f032a942..212984ff20 100644 --- a/tests/qapi-schema/doc-no-symbol.err +++ b/tests/qapi-schema/doc-no-symbol.err @@ -1 +1 @@ -tests/qapi-schema/doc-no-symbol.json:3: Expression documentation required +tests/qapi-schema/doc-no-symbol.json:3: Definition documentation required diff --git a/tests/qapi-schema/enum-dict-member-unknown.err b/tests/qapi-sc= hema/enum-dict-member-unknown.err index 2aae618be0..7fd9c032bf 100644 --- a/tests/qapi-schema/enum-dict-member-unknown.err +++ b/tests/qapi-schema/enum-dict-member-unknown.err @@ -1,2 +1,2 @@ -tests/qapi-schema/enum-dict-member-unknown.json:2: Unknown key 'bad-key' i= n dictionary member of enum 'MyEnum' +tests/qapi-schema/enum-dict-member-unknown.json:2: Unknown key 'bad-key' i= n member of enum 'MyEnum' Valid keys are 'if', 'name'. diff --git a/tests/qapi-schema/pragma-non-dict.err b/tests/qapi-schema/prag= ma-non-dict.err index 75bc335aea..b358261050 100644 --- a/tests/qapi-schema/pragma-non-dict.err +++ b/tests/qapi-schema/pragma-non-dict.err @@ -1 +1 @@ -tests/qapi-schema/pragma-non-dict.json:3: Value of 'pragma' must be a dict= ionary +tests/qapi-schema/pragma-non-dict.json:3: Value of 'pragma' must be an obj= ect diff --git a/tests/qapi-schema/struct-data-invalid.err b/tests/qapi-schema/= struct-data-invalid.err index 6644f4c2ad..4bf5bcc255 100644 --- a/tests/qapi-schema/struct-data-invalid.err +++ b/tests/qapi-schema/struct-data-invalid.err @@ -1 +1 @@ -tests/qapi-schema/struct-data-invalid.json:1: 'data' for struct 'foo' shou= ld be a dictionary or type name +tests/qapi-schema/struct-data-invalid.json:1: 'data' for struct 'foo' shou= ld be an object or type name --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569329490; cv=none; d=zoho.com; s=zohoarc; b=FfpFevO++IvwxHb4WLA/1CHdo4Q3T6tylfMSPQ4Bms3aayzFP3Dz6fnugnhzsahuUcA3Y+KAv/dxct6YOkTC93X64L4XYqTFAnfNEXifbnLUi+vabR5kiIlmgPzXl2Z1/uf7FjGuFAz8qCxkIjbcACtQgBrzTZjORRsxMJKMafk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569329490; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=297NWQ4G6FDYwiBUbOttGBT3K+ghw6j1YTGbjIA9MYI=; b=XkzX1byl8SWT7Xb17WSzPQCosxGsEZQyNlzUklU0MXy8Rc93mS1MdZ0SDrSGz/WquWthKJYXx7cjhsLFmKLzxbdzEr3Ugdfgvjv01fkavs40wAM6kt6F1nggOY6C9cmq/etkGe3a7vJR3eO+iTa2Z4p4XQPznOKOGksJ6/vVGm0= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569329490338212.23725868193674; Tue, 24 Sep 2019 05:51:30 -0700 (PDT) Received: from localhost ([::1]:45306 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCkHw-0007MO-Lj for importer@patchew.org; Tue, 24 Sep 2019 08:51:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50494) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0m-0001J5-Ak for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0j-0006wn-8I for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38418) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0i-0006uM-LO for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:41 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 705A9307C820 for ; Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 405A860C63; Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id BE4111138408; Tue, 24 Sep 2019 14:33:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 19/37] tests/qapi-schema: Cover unknown pragma Date: Tue, 24 Sep 2019 14:33:16 +0200 Message-Id: <20190924123334.30645-20-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Message-Id: <20190914153506.2151-2-armbru@redhat.com> Reviewed-by: Eric Blake --- tests/Makefile.include | 1 + tests/qapi-schema/pragma-unknown.err | 1 + tests/qapi-schema/pragma-unknown.exit | 1 + tests/qapi-schema/pragma-unknown.json | 1 + tests/qapi-schema/pragma-unknown.out | 0 5 files changed, 4 insertions(+) create mode 100644 tests/qapi-schema/pragma-unknown.err create mode 100644 tests/qapi-schema/pragma-unknown.exit create mode 100644 tests/qapi-schema/pragma-unknown.json create mode 100644 tests/qapi-schema/pragma-unknown.out diff --git a/tests/Makefile.include b/tests/Makefile.include index 2c3adb1530..089cc3ea95 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -427,6 +427,7 @@ qapi-schema +=3D pragma-doc-required-crap.json qapi-schema +=3D pragma-extra-junk.json qapi-schema +=3D pragma-name-case-whitelist-crap.json qapi-schema +=3D pragma-non-dict.json +qapi-schema +=3D pragma-unknown.json qapi-schema +=3D pragma-returns-whitelist-crap.json qapi-schema +=3D qapi-schema-test.json qapi-schema +=3D quoted-structural-chars.json diff --git a/tests/qapi-schema/pragma-unknown.err b/tests/qapi-schema/pragm= a-unknown.err new file mode 100644 index 0000000000..6ef2058316 --- /dev/null +++ b/tests/qapi-schema/pragma-unknown.err @@ -0,0 +1 @@ +tests/qapi-schema/pragma-unknown.json:1: Unknown pragma 'no-such-pragma' diff --git a/tests/qapi-schema/pragma-unknown.exit b/tests/qapi-schema/prag= ma-unknown.exit new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/qapi-schema/pragma-unknown.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/pragma-unknown.json b/tests/qapi-schema/prag= ma-unknown.json new file mode 100644 index 0000000000..c51bbbb53f --- /dev/null +++ b/tests/qapi-schema/pragma-unknown.json @@ -0,0 +1 @@ +{ 'pragma': { 'no-such-pragma': false } } diff --git a/tests/qapi-schema/pragma-unknown.out b/tests/qapi-schema/pragm= a-unknown.out new file mode 100644 index 0000000000..e69de29bb2 --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569329775; cv=none; d=zoho.com; s=zohoarc; b=iRoKbqxC1eEETgav8hhliuDh09VDWYKgcoLRsMnBP0w8vLpSq8kT3RW7yXlntZkjRd/qJqihlRVoh/TrB343yZ2PpP+BYhxyo5W6GmMadw1fDPhaoG2h5rQh61st9r34K7hTFnzULdKji0nJAwL2UvULrvjoccip2dT+YBuODlw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569329775; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=hP4PC/k1p+5VYIph7twAIr2kX4CrrnqCrkgyXqPy/AI=; b=K+1Ieq3NP+d/NtNobh2AdeJ56/McmLIPyY8VA0sS4+jICepsxMlvwu4Srom5hkkgjMC3zlMQyzizBrtK37Au97FCQcJYbNOqjeoQNl3gL86dzjw4GP2KhFGvRoF/h8wD35Cv9fvxmUWO+vis/3fKrs6z7th040Ui/7Phc7E4G6E= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569329775123379.33315928535933; Tue, 24 Sep 2019 05:56:15 -0700 (PDT) Received: from localhost ([::1]:45332 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCkMX-0003FW-EH for importer@patchew.org; Tue, 24 Sep 2019 08:56:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50491) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0m-0001J4-5e for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0i-0006vv-Os for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42778) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0i-0006ua-DD for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:40 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9ED31307D923 for ; Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 476575C21F; Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id C39E51136420; Tue, 24 Sep 2019 14:33:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 20/37] tests/qapi-schema: Delete two redundant tests Date: Tue, 24 Sep 2019 14:33:17 +0200 Message-Id: <20190924123334.30645-21-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Tests duplicate-key and double-data test the same thing. The former predates the latter, and it has a better name. Delete the latter, and tweak the former's comment. Tests include-format-err and include-extra-junk test the same thing. The former predates the latter, but the latter has a better name and a comment. Delete the former. Signed-off-by: Markus Armbruster Message-Id: <20190914153506.2151-3-armbru@redhat.com> Reviewed-by: Eric Blake --- tests/Makefile.include | 2 -- tests/qapi-schema/double-data.err | 1 - tests/qapi-schema/double-data.exit | 1 - tests/qapi-schema/double-data.json | 2 -- tests/qapi-schema/double-data.out | 0 tests/qapi-schema/duplicate-key.json | 2 +- tests/qapi-schema/include-format-err.err | 1 - tests/qapi-schema/include-format-err.exit | 1 - tests/qapi-schema/include-format-err.json | 2 -- tests/qapi-schema/include-format-err.out | 0 10 files changed, 1 insertion(+), 11 deletions(-) delete mode 100644 tests/qapi-schema/double-data.err delete mode 100644 tests/qapi-schema/double-data.exit delete mode 100644 tests/qapi-schema/double-data.json delete mode 100644 tests/qapi-schema/double-data.out delete mode 100644 tests/qapi-schema/include-format-err.err delete mode 100644 tests/qapi-schema/include-format-err.exit delete mode 100644 tests/qapi-schema/include-format-err.json delete mode 100644 tests/qapi-schema/include-format-err.out diff --git a/tests/Makefile.include b/tests/Makefile.include index 089cc3ea95..0c862dbc42 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -359,7 +359,6 @@ qapi-schema +=3D doc-missing-expr.json qapi-schema +=3D doc-missing-space.json qapi-schema +=3D doc-missing.json qapi-schema +=3D doc-no-symbol.json -qapi-schema +=3D double-data.json qapi-schema +=3D double-type.json qapi-schema +=3D duplicate-key.json qapi-schema +=3D empty.json @@ -404,7 +403,6 @@ qapi-schema +=3D ident-with-escape.json qapi-schema +=3D include-before-err.json qapi-schema +=3D include-cycle.json qapi-schema +=3D include-extra-junk.json -qapi-schema +=3D include-format-err.json qapi-schema +=3D include-nested-err.json qapi-schema +=3D include-no-file.json qapi-schema +=3D include-non-file.json diff --git a/tests/qapi-schema/double-data.err b/tests/qapi-schema/double-d= ata.err deleted file mode 100644 index cc765c4ff2..0000000000 --- a/tests/qapi-schema/double-data.err +++ /dev/null @@ -1 +0,0 @@ -tests/qapi-schema/double-data.json:2:41: Duplicate key "data" diff --git a/tests/qapi-schema/double-data.exit b/tests/qapi-schema/double-= data.exit deleted file mode 100644 index d00491fd7e..0000000000 --- a/tests/qapi-schema/double-data.exit +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/tests/qapi-schema/double-data.json b/tests/qapi-schema/double-= data.json deleted file mode 100644 index e76b519538..0000000000 --- a/tests/qapi-schema/double-data.json +++ /dev/null @@ -1,2 +0,0 @@ -# we reject an expression with duplicate top-level keys -{ 'struct': 'bar', 'data': { }, 'data': { 'string': 'str'} } diff --git a/tests/qapi-schema/double-data.out b/tests/qapi-schema/double-d= ata.out deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/qapi-schema/duplicate-key.json b/tests/qapi-schema/dupli= cate-key.json index 14ac0e8a40..06b55840c9 100644 --- a/tests/qapi-schema/duplicate-key.json +++ b/tests/qapi-schema/duplicate-key.json @@ -1,3 +1,3 @@ -# QAPI cannot include the same key more than once in any {} +# Cannot include the same key more than once in any {} { 'key': 'value', 'key': 'value' } diff --git a/tests/qapi-schema/include-format-err.err b/tests/qapi-schema/i= nclude-format-err.err deleted file mode 100644 index 721ff4eccc..0000000000 --- a/tests/qapi-schema/include-format-err.err +++ /dev/null @@ -1 +0,0 @@ -tests/qapi-schema/include-format-err.json:1: Invalid 'include' directive diff --git a/tests/qapi-schema/include-format-err.exit b/tests/qapi-schema/= include-format-err.exit deleted file mode 100644 index d00491fd7e..0000000000 --- a/tests/qapi-schema/include-format-err.exit +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/tests/qapi-schema/include-format-err.json b/tests/qapi-schema/= include-format-err.json deleted file mode 100644 index 44980f026f..0000000000 --- a/tests/qapi-schema/include-format-err.json +++ /dev/null @@ -1,2 +0,0 @@ -{ 'include': 'include-simple-sub.json', - 'foo': 'bar' } diff --git a/tests/qapi-schema/include-format-err.out b/tests/qapi-schema/i= nclude-format-err.out deleted file mode 100644 index e69de29bb2..0000000000 --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569330891; cv=none; d=zoho.com; s=zohoarc; b=NhGl7Hz8cJTRAs9PqrKDGD7/ZY17L2uGFdV2H0GADyAm0KhS2st34UOqCYtKmow3xzQ4dF13aiTRpddIqFzHdUztwBXHB98zSIlRpT/JhcPvtw4P9b3USeYYujcuPsRyTY636O4s1aGdvaXWb/bwXQaRZ0ZnXggxFfzeSnCFyj0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569330891; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=Ar0JQ1O85JRCgT24L3i9OeHyAbgYQVAGoj9EqiEZeQ8=; b=EdsQ3BhvrUPBfxHz46MGthi7n/E6e8gxtpb6otiDPAW71+Cdhese+JuiWhTh2+jlohXu5uR5lL9ieiZ8lNI/JxJHZcOnzrch45WoWASmgGXTN06WZ2lHup4OX4fvE2RlG26GtJt8Z5Y8dOb6LBEUirCScCACcyXKpmwGwu57+f0= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569330891648792.1910909999654; Tue, 24 Sep 2019 06:14:51 -0700 (PDT) Received: from localhost ([::1]:45506 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCkeX-0002RV-Vv for importer@patchew.org; Tue, 24 Sep 2019 09:14:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50549) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0o-0001K4-1r for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0j-0006wt-Al for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48548) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0i-0006uZ-JA for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:41 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9E7D7317528C for ; Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 483EA608C2; Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id CA97A1136421; Tue, 24 Sep 2019 14:33:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 21/37] tests/qapi-schema: Demonstrate misleading optional tag error Date: Tue, 24 Sep 2019 14:33:18 +0200 Message-Id: <20190924123334.30645-22-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Test flat-union-optional-discriminator declares its union tag as '*switch': 'Enum', and points to it with 'discriminator': '*switch'. This gets rejected as "discriminator of flat union 'MyUnion' uses invalid name '*switch'". Correct; member 'discriminator' doesn't accept a '*' prefix. However, this merely tests name validity checking, which we already cover elsewhere. More interesting is testing the valid name 'switch'. This reports "discriminator 'switch' is not a member of base struct 'Base'", which is misleading. Copy the existing 'discriminator': '*switch' test to flat-union-discriminator-bad-name, and rewrite its comment. Change flat-union-optional-discriminator to test 'discriminator': 'switch', and mark it FIXME. Signed-off-by: Markus Armbruster Message-Id: <20190914153506.2151-4-armbru@redhat.com> Reviewed-by: Eric Blake --- tests/Makefile.include | 1 + .../qapi-schema/flat-union-discriminator-bad-name.err | 1 + .../flat-union-discriminator-bad-name.exit | 1 + .../flat-union-discriminator-bad-name.json | 11 +++++++++++ .../qapi-schema/flat-union-discriminator-bad-name.out | 0 .../qapi-schema/flat-union-optional-discriminator.err | 2 +- .../flat-union-optional-discriminator.json | 3 ++- 7 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 tests/qapi-schema/flat-union-discriminator-bad-name.err create mode 100644 tests/qapi-schema/flat-union-discriminator-bad-name.exit create mode 100644 tests/qapi-schema/flat-union-discriminator-bad-name.json create mode 100644 tests/qapi-schema/flat-union-discriminator-bad-name.out diff --git a/tests/Makefile.include b/tests/Makefile.include index 0c862dbc42..7553616069 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -388,6 +388,7 @@ qapi-schema +=3D flat-union-bad-discriminator.json qapi-schema +=3D flat-union-base-any.json qapi-schema +=3D flat-union-base-union.json qapi-schema +=3D flat-union-clash-member.json +qapi-schema +=3D flat-union-discriminator-bad-name.json qapi-schema +=3D flat-union-empty.json qapi-schema +=3D flat-union-inline.json qapi-schema +=3D flat-union-inline-invalid-dict.json diff --git a/tests/qapi-schema/flat-union-discriminator-bad-name.err b/test= s/qapi-schema/flat-union-discriminator-bad-name.err new file mode 100644 index 0000000000..7238d126ca --- /dev/null +++ b/tests/qapi-schema/flat-union-discriminator-bad-name.err @@ -0,0 +1 @@ +tests/qapi-schema/flat-union-discriminator-bad-name.json:7: Discriminator = of flat union 'MyUnion' does not allow optional name '*switch' diff --git a/tests/qapi-schema/flat-union-discriminator-bad-name.exit b/tes= ts/qapi-schema/flat-union-discriminator-bad-name.exit new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/qapi-schema/flat-union-discriminator-bad-name.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/flat-union-discriminator-bad-name.json b/tes= ts/qapi-schema/flat-union-discriminator-bad-name.json new file mode 100644 index 0000000000..66376084fc --- /dev/null +++ b/tests/qapi-schema/flat-union-discriminator-bad-name.json @@ -0,0 +1,11 @@ +# discriminator '*switch' isn't a member of base, 'switch' is +# reports "does not allow optional name", which is good enough +{ 'enum': 'Enum', 'data': [ 'one', 'two' ] } +{ 'struct': 'Base', + 'data': { '*switch': 'Enum' } } +{ 'struct': 'Branch', 'data': { 'name': 'str' } } +{ 'union': 'MyUnion', + 'base': 'Base', + 'discriminator': '*switch', + 'data': { 'one': 'Branch', + 'two': 'Branch' } } diff --git a/tests/qapi-schema/flat-union-discriminator-bad-name.out b/test= s/qapi-schema/flat-union-discriminator-bad-name.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/flat-union-optional-discriminator.err b/test= s/qapi-schema/flat-union-optional-discriminator.err index aaabedb3bd..8b4a4ba847 100644 --- a/tests/qapi-schema/flat-union-optional-discriminator.err +++ b/tests/qapi-schema/flat-union-optional-discriminator.err @@ -1 +1 @@ -tests/qapi-schema/flat-union-optional-discriminator.json:6: Discriminator = of flat union 'MyUnion' does not allow optional name '*switch' +tests/qapi-schema/flat-union-optional-discriminator.json:7: Discriminator = 'switch' is not a member of base struct 'Base' diff --git a/tests/qapi-schema/flat-union-optional-discriminator.json b/tes= ts/qapi-schema/flat-union-optional-discriminator.json index 08a8f7ef8b..143ab23a0d 100644 --- a/tests/qapi-schema/flat-union-optional-discriminator.json +++ b/tests/qapi-schema/flat-union-optional-discriminator.json @@ -1,10 +1,11 @@ # we require the discriminator to be non-optional +# FIXME reports "discriminator 'switch' is not a member of base struct 'Ba= se'" { 'enum': 'Enum', 'data': [ 'one', 'two' ] } { 'struct': 'Base', 'data': { '*switch': 'Enum' } } { 'struct': 'Branch', 'data': { 'name': 'str' } } { 'union': 'MyUnion', 'base': 'Base', - 'discriminator': '*switch', + 'discriminator': 'switch', 'data': { 'one': 'Branch', 'two': 'Branch' } } --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569331206; cv=none; d=zoho.com; s=zohoarc; b=Zc0h79otG7q7zOcVCcKKfyuvcqBtNYMVuKcshgb6WrB0iR1KXUPutuWbGW58/NF/YxgphzupDmKsRsZkCY1oIFNTmNITWYtxp4s4VjbyJOuI1C5RktbWDEYSuk4KOGMcdoyplykpQfFQ6uHebhcYxUlEPc31hwLD0HxzobZsk/M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569331206; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=s1Fnb9v6aVoIYGR5IuzlkzecuMWk/+7AGGlNQyzS2iU=; b=kqKHgfqHadlrrZnfwbpfr+7K91u83q/OcjzAYoc2PWYjaAbrn3i0i5twI/MWx6UnsbDV3aDEnqQjfNDyV2W0WreBboPthrJNgcH6MowZC9QtLxJ8s1lWsTZOOPZWrGak0ipfiJ6K1CdWB7DYKCVuiaHscsBdraNdXqEbpXshQeY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569331206830474.8083229769567; Tue, 24 Sep 2019 06:20:06 -0700 (PDT) Received: from localhost ([::1]:45554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCkjY-00068e-Bv for importer@patchew.org; Tue, 24 Sep 2019 09:20:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50649) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0r-0001Nd-Ox for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0j-0006x2-Df for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55274) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0i-0006uc-Hl for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:41 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A016A18C8931 for ; Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4A53D60C80; Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id D06BF1136422; Tue, 24 Sep 2019 14:33:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 22/37] tests/qapi-schema: Demonstrate broken discriminator errors Date: Tue, 24 Sep 2019 14:33:19 +0200 Message-Id: <20190924123334.30645-23-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.70]); Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" When the union definition's base is an object, some error messages show it as an OrderedDict. Oops. Mark FIXME. Signed-off-by: Markus Armbruster Message-Id: <20190914153506.2151-5-armbru@redhat.com> Reviewed-by: Eric Blake --- tests/qapi-schema/flat-union-invalid-discriminator.err | 2 +- tests/qapi-schema/flat-union-invalid-discriminator.json | 6 ++---- tests/qapi-schema/flat-union-invalid-if-discriminator.err | 2 +- tests/qapi-schema/flat-union-invalid-if-discriminator.json | 6 ++---- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/tests/qapi-schema/flat-union-invalid-discriminator.err b/tests= /qapi-schema/flat-union-invalid-discriminator.err index 5f4055614e..947a6b73aa 100644 --- a/tests/qapi-schema/flat-union-invalid-discriminator.err +++ b/tests/qapi-schema/flat-union-invalid-discriminator.err @@ -1 +1 @@ -tests/qapi-schema/flat-union-invalid-discriminator.json:13: Discriminator = 'enum_wrong' is not a member of base struct 'TestBase' +tests/qapi-schema/flat-union-invalid-discriminator.json:11: Discriminator = 'enum_wrong' is not a member of base struct 'OrderedDict([('enum1', {'type'= : 'TestEnum'})])' diff --git a/tests/qapi-schema/flat-union-invalid-discriminator.json b/test= s/qapi-schema/flat-union-invalid-discriminator.json index 48b94c3a4d..de86cf0760 100644 --- a/tests/qapi-schema/flat-union-invalid-discriminator.json +++ b/tests/qapi-schema/flat-union-invalid-discriminator.json @@ -1,9 +1,7 @@ +# FIXME error message shows base as OrderedDict { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } =20 -{ 'struct': 'TestBase', - 'data': { 'enum1': 'TestEnum' } } - { 'struct': 'TestTypeA', 'data': { 'string': 'str' } } =20 @@ -11,7 +9,7 @@ 'data': { 'integer': 'int' } } =20 { 'union': 'TestUnion', - 'base': 'TestBase', + 'base': { 'enum1': 'TestEnum' }, 'discriminator': 'enum_wrong', 'data': { 'value1': 'TestTypeA', 'value2': 'TestTypeB' } } diff --git a/tests/qapi-schema/flat-union-invalid-if-discriminator.err b/te= sts/qapi-schema/flat-union-invalid-if-discriminator.err index 0c94c9860d..ec04c4840c 100644 --- a/tests/qapi-schema/flat-union-invalid-if-discriminator.err +++ b/tests/qapi-schema/flat-union-invalid-if-discriminator.err @@ -1 +1 @@ -tests/qapi-schema/flat-union-invalid-if-discriminator.json:13: The discrim= inator TestBase.enum1 for union TestUnion must not be conditional +tests/qapi-schema/flat-union-invalid-if-discriminator.json:11: The discrim= inator OrderedDict([('enum1', OrderedDict([('type', 'TestEnum'), ('if', 'FO= O')]))]).enum1 for union TestUnion must not be conditional diff --git a/tests/qapi-schema/flat-union-invalid-if-discriminator.json b/t= ests/qapi-schema/flat-union-invalid-if-discriminator.json index 618ec36396..bbaa9a3f82 100644 --- a/tests/qapi-schema/flat-union-invalid-if-discriminator.json +++ b/tests/qapi-schema/flat-union-invalid-if-discriminator.json @@ -1,9 +1,7 @@ +# FIXME error message shows base as OrderedDict { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } =20 -{ 'struct': 'TestBase', - 'data': { 'enum1': { 'type': 'TestEnum', 'if': 'FOO' } } } - { 'struct': 'TestTypeA', 'data': { 'string': 'str' } } =20 @@ -11,7 +9,7 @@ 'data': { 'integer': 'int' } } =20 { 'union': 'TestUnion', - 'base': 'TestBase', + 'base': { 'enum1': { 'type': 'TestEnum', 'if': 'FOO' } }, 'discriminator': 'enum1', 'data': { 'value1': 'TestTypeA', 'value2': 'TestTypeB' } } --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569331199; cv=none; d=zoho.com; s=zohoarc; b=ZPQJbhkuoLzB/68im5WCNlovexd+8qTUZ6woB7GgDvQgqx/KF5gJ6tZwBi2Hu0b+Nn/TwM3zqlLLNJgt9l4rNvQxpXcxov+Zz0HyLTrMyPbvC9kQDvTfztKaSZ2NjQMCAcGBI8HLLoxyCwceEjmCzU1bEtXqE4fk7Su6m0+Y1/8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569331199; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=VTa2NkHyJXTi2nDkR6v5LGoMY8R00xVVcfkNMl+x3nY=; b=ds2J3fEW6QtE6ncoO88oGQ5qjgsT844HbvabHu5Dt2ujoLuskRyrLd8WzLtqJ91EeLkh0iZUEg4JioXDR/DfK3BoN/1VrhZK5/v9AVv84LmQB2RYy8PWc0UYuJnGTaYVcjgX+kE+1v9+qva1ZPfTwzVyuSSsy6XkAMSSC0dnWgY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569331199339187.85309788614813; Tue, 24 Sep 2019 06:19:59 -0700 (PDT) Received: from localhost ([::1]:45552 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCkjS-000646-4P for importer@patchew.org; Tue, 24 Sep 2019 09:19:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50587) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0p-0001LK-Ac for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0j-0006xt-Mg for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53428) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0i-0006ug-QF for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:41 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A4D01877A64 for ; Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4E7EB5B6A5; Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id D5B111136423; Tue, 24 Sep 2019 14:33:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 23/37] tests/qapi-schema: Demonstrate insufficient 'if' checking Date: Tue, 24 Sep 2019 14:33:20 +0200 Message-Id: <20190924123334.30645-24-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]); Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Cover invalid 'if' in struct members, features, union and alternate branches. Four out of four are broken. Mark FIXME. Signed-off-by: Markus Armbruster Message-Id: <20190914153506.2151-6-armbru@redhat.com> Reviewed-by: Eric Blake [Comment typo fixed] --- tests/Makefile.include | 4 ++++ .../alternate-branch-if-invalid.err | 0 .../alternate-branch-if-invalid.exit | 1 + .../alternate-branch-if-invalid.json | 4 ++++ .../alternate-branch-if-invalid.out | 16 +++++++++++++ tests/qapi-schema/features-if-invalid.err | 0 tests/qapi-schema/features-if-invalid.exit | 1 + tests/qapi-schema/features-if-invalid.json | 5 ++++ tests/qapi-schema/features-if-invalid.out | 14 +++++++++++ .../qapi-schema/struct-member-if-invalid.err | 0 .../qapi-schema/struct-member-if-invalid.exit | 1 + .../qapi-schema/struct-member-if-invalid.json | 4 ++++ .../qapi-schema/struct-member-if-invalid.out | 15 ++++++++++++ tests/qapi-schema/union-branch-if-invalid.err | 0 .../qapi-schema/union-branch-if-invalid.exit | 1 + .../qapi-schema/union-branch-if-invalid.json | 7 ++++++ tests/qapi-schema/union-branch-if-invalid.out | 23 +++++++++++++++++++ 17 files changed, 96 insertions(+) create mode 100644 tests/qapi-schema/alternate-branch-if-invalid.err create mode 100644 tests/qapi-schema/alternate-branch-if-invalid.exit create mode 100644 tests/qapi-schema/alternate-branch-if-invalid.json create mode 100644 tests/qapi-schema/alternate-branch-if-invalid.out create mode 100644 tests/qapi-schema/features-if-invalid.err create mode 100644 tests/qapi-schema/features-if-invalid.exit create mode 100644 tests/qapi-schema/features-if-invalid.json create mode 100644 tests/qapi-schema/features-if-invalid.out create mode 100644 tests/qapi-schema/struct-member-if-invalid.err create mode 100644 tests/qapi-schema/struct-member-if-invalid.exit create mode 100644 tests/qapi-schema/struct-member-if-invalid.json create mode 100644 tests/qapi-schema/struct-member-if-invalid.out create mode 100644 tests/qapi-schema/union-branch-if-invalid.err create mode 100644 tests/qapi-schema/union-branch-if-invalid.exit create mode 100644 tests/qapi-schema/union-branch-if-invalid.json create mode 100644 tests/qapi-schema/union-branch-if-invalid.out diff --git a/tests/Makefile.include b/tests/Makefile.include index 7553616069..799fd4af02 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -294,6 +294,7 @@ check-qtest-generic-y +=3D tests/test-hmp$(EXESUF) qapi-schema +=3D alternate-any.json qapi-schema +=3D alternate-array.json qapi-schema +=3D alternate-base.json +qapi-schema +=3D alternate-branch-if-invalid.json qapi-schema +=3D alternate-clash.json qapi-schema +=3D alternate-conflict-dict.json qapi-schema +=3D alternate-conflict-enum-bool.json @@ -378,6 +379,7 @@ qapi-schema +=3D event-member-invalid-dict.json qapi-schema +=3D event-nest-struct.json qapi-schema +=3D features-bad-type.json qapi-schema +=3D features-duplicate-name.json +qapi-schema +=3D features-if-invalid.json qapi-schema +=3D features-missing-name.json qapi-schema +=3D features-name-bad-type.json qapi-schema +=3D features-no-list.json @@ -452,6 +454,7 @@ qapi-schema +=3D string-code-point-127.json qapi-schema +=3D struct-base-clash-deep.json qapi-schema +=3D struct-base-clash.json qapi-schema +=3D struct-data-invalid.json +qapi-schema +=3D struct-member-if-invalid.json qapi-schema +=3D struct-member-invalid-dict.json qapi-schema +=3D struct-member-invalid.json qapi-schema +=3D trailing-comma-list.json @@ -463,6 +466,7 @@ qapi-schema +=3D unclosed-string.json qapi-schema +=3D union-base-empty.json qapi-schema +=3D union-base-no-discriminator.json qapi-schema +=3D union-branch-case.json +qapi-schema +=3D union-branch-if-invalid.json qapi-schema +=3D union-branch-invalid-dict.json qapi-schema +=3D union-clash-branches.json qapi-schema +=3D union-empty.json diff --git a/tests/qapi-schema/alternate-branch-if-invalid.err b/tests/qapi= -schema/alternate-branch-if-invalid.err new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/alternate-branch-if-invalid.exit b/tests/qap= i-schema/alternate-branch-if-invalid.exit new file mode 100644 index 0000000000..573541ac97 --- /dev/null +++ b/tests/qapi-schema/alternate-branch-if-invalid.exit @@ -0,0 +1 @@ +0 diff --git a/tests/qapi-schema/alternate-branch-if-invalid.json b/tests/qap= i-schema/alternate-branch-if-invalid.json new file mode 100644 index 0000000000..6497f53475 --- /dev/null +++ b/tests/qapi-schema/alternate-branch-if-invalid.json @@ -0,0 +1,4 @@ +# Cover alternative with invalid 'if' +# FIXME not rejected, would generate '#if \n' +{ 'alternate': 'Alt', + 'data': { 'branch': { 'type': 'int', 'if': ' ' } } } diff --git a/tests/qapi-schema/alternate-branch-if-invalid.out b/tests/qapi= -schema/alternate-branch-if-invalid.out new file mode 100644 index 0000000000..89305d7f21 --- /dev/null +++ b/tests/qapi-schema/alternate-branch-if-invalid.out @@ -0,0 +1,16 @@ +module None +object q_empty +enum QType + prefix QTYPE + member none + member qnull + member qnum + member qstring + member qdict + member qlist + member qbool +module alternate-branch-if-invalid.json +alternate Alt + tag type + case branch: int + if [' '] diff --git a/tests/qapi-schema/features-if-invalid.err b/tests/qapi-schema/= features-if-invalid.err new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/features-if-invalid.exit b/tests/qapi-schema= /features-if-invalid.exit new file mode 100644 index 0000000000..573541ac97 --- /dev/null +++ b/tests/qapi-schema/features-if-invalid.exit @@ -0,0 +1 @@ +0 diff --git a/tests/qapi-schema/features-if-invalid.json b/tests/qapi-schema= /features-if-invalid.json new file mode 100644 index 0000000000..7e4c1ad720 --- /dev/null +++ b/tests/qapi-schema/features-if-invalid.json @@ -0,0 +1,5 @@ +# Cover feature with invalid 'if' +# FIXME not rejected, misinterpreted as unconditional +{ 'struct': 'Stru', + 'data': {}, + 'features': [{'name': 'f', 'if': null }] } diff --git a/tests/qapi-schema/features-if-invalid.out b/tests/qapi-schema/= features-if-invalid.out new file mode 100644 index 0000000000..9c2637baa3 --- /dev/null +++ b/tests/qapi-schema/features-if-invalid.out @@ -0,0 +1,14 @@ +module None +object q_empty +enum QType + prefix QTYPE + member none + member qnull + member qnum + member qstring + member qdict + member qlist + member qbool +module features-if-invalid.json +object Stru + feature f diff --git a/tests/qapi-schema/struct-member-if-invalid.err b/tests/qapi-sc= hema/struct-member-if-invalid.err new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/struct-member-if-invalid.exit b/tests/qapi-s= chema/struct-member-if-invalid.exit new file mode 100644 index 0000000000..573541ac97 --- /dev/null +++ b/tests/qapi-schema/struct-member-if-invalid.exit @@ -0,0 +1 @@ +0 diff --git a/tests/qapi-schema/struct-member-if-invalid.json b/tests/qapi-s= chema/struct-member-if-invalid.json new file mode 100644 index 0000000000..73987e04fc --- /dev/null +++ b/tests/qapi-schema/struct-member-if-invalid.json @@ -0,0 +1,4 @@ +# Cover member with invalid 'if' +# FIXME not rejected, would generate '#if True\n' +{ 'struct': 'Stru', + 'data': { 'member': { 'type': 'int', 'if': true } } } diff --git a/tests/qapi-schema/struct-member-if-invalid.out b/tests/qapi-sc= hema/struct-member-if-invalid.out new file mode 100644 index 0000000000..8fbb97985c --- /dev/null +++ b/tests/qapi-schema/struct-member-if-invalid.out @@ -0,0 +1,15 @@ +module None +object q_empty +enum QType + prefix QTYPE + member none + member qnull + member qnum + member qstring + member qdict + member qlist + member qbool +module struct-member-if-invalid.json +object Stru + member member: int optional=3DFalse + if [True] diff --git a/tests/qapi-schema/union-branch-if-invalid.err b/tests/qapi-sch= ema/union-branch-if-invalid.err new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/union-branch-if-invalid.exit b/tests/qapi-sc= hema/union-branch-if-invalid.exit new file mode 100644 index 0000000000..573541ac97 --- /dev/null +++ b/tests/qapi-schema/union-branch-if-invalid.exit @@ -0,0 +1 @@ +0 diff --git a/tests/qapi-schema/union-branch-if-invalid.json b/tests/qapi-sc= hema/union-branch-if-invalid.json new file mode 100644 index 0000000000..859b63b610 --- /dev/null +++ b/tests/qapi-schema/union-branch-if-invalid.json @@ -0,0 +1,7 @@ +# Cover branch with invalid 'if' +# FIXME not rejected, would generate '#if \n' +{ 'enum': 'Branches', 'data': ['branch1'] } +{ 'struct': 'Stru', 'data': { 'member': 'str' } } +{ 'union': 'Uni', + 'base': { 'tag': 'Branches' }, 'discriminator': 'tag', + 'data': { 'branch1': { 'type': 'Stru', 'if': [''] } } } diff --git a/tests/qapi-schema/union-branch-if-invalid.out b/tests/qapi-sch= ema/union-branch-if-invalid.out new file mode 100644 index 0000000000..2ed43218af --- /dev/null +++ b/tests/qapi-schema/union-branch-if-invalid.out @@ -0,0 +1,23 @@ +module None +object q_empty +enum QType + prefix QTYPE + member none + member qnull + member qnum + member qstring + member qdict + member qlist + member qbool +module union-branch-if-invalid.json +enum Branches + member branch1 +object Stru + member member: str optional=3DFalse +object q_obj_Uni-base + member tag: Branches optional=3DFalse +object Uni + base q_obj_Uni-base + tag tag + case branch1: Stru + if [''] --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569330051; cv=none; d=zoho.com; s=zohoarc; b=lDSBKYmLiKzgngwWaTNZGa89Kn/VjrG4m5L7uEGil6GXqITB1dT7BrR3UijsrHkAuMdZrOAjwWcyVIYZB7UE9xuX3g0lt6rOYMR/LUgQ52XCfABF+93O3OviqKNrcPWL3TCojggenxFNFKdgsfSt6TqS/81A7Wf9LyZIx7ItIJc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569330051; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=hFi2oP+cvCdndKxi8fZ9NrGwNn8/LIVzljq0dSdGLnc=; b=UJoUNKYYIUsOpjJaAER4m5lkoTeBSPY7SE61xnDyda6v/Tk/VvXwGq95uL21Ftea7cxpLfdPliOv8REKILoLZev/eww4euhPGgaGFT2jEHTJusrtOjIiMvJK1GkoYIIBkeHP2dBD2//HAtrhkg1yAbMTURiT0QGS3menypzMsMo= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569330051399128.47139927143542; Tue, 24 Sep 2019 06:00:51 -0700 (PDT) Received: from localhost ([::1]:45359 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCkQw-0007If-7E for importer@patchew.org; Tue, 24 Sep 2019 09:00:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50572) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0o-0001Kh-OH for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0j-0006yB-Rw for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46518) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0j-0006va-CY for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:41 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7675230A5A54 for ; Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4E98A5C220; Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id DC7351136424; Tue, 24 Sep 2019 14:33:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 24/37] tests/qapi-schema: Demonstrate suboptimal lexical errors Date: Tue, 24 Sep 2019 14:33:21 +0200 Message-Id: <20190924123334.30645-25-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The error message for forgotten quotes around a name shows just the name's first character, which isn't as nice as it could be. Same for attempting to use a number. Signed-off-by: Markus Armbruster Message-Id: <20190914153506.2151-7-armbru@redhat.com> Reviewed-by: Eric Blake --- tests/Makefile.include | 1 + tests/qapi-schema/bad-type-int.json | 2 +- tests/qapi-schema/funny-word.err | 1 + tests/qapi-schema/funny-word.exit | 1 + tests/qapi-schema/funny-word.json | 1 + tests/qapi-schema/funny-word.out | 0 6 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 tests/qapi-schema/funny-word.err create mode 100644 tests/qapi-schema/funny-word.exit create mode 100644 tests/qapi-schema/funny-word.json create mode 100644 tests/qapi-schema/funny-word.out diff --git a/tests/Makefile.include b/tests/Makefile.include index 799fd4af02..0595914526 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -402,6 +402,7 @@ qapi-schema +=3D flat-union-no-base.json qapi-schema +=3D flat-union-optional-discriminator.json qapi-schema +=3D flat-union-string-discriminator.json qapi-schema +=3D funny-char.json +qapi-schema +=3D funny-word.json qapi-schema +=3D ident-with-escape.json qapi-schema +=3D include-before-err.json qapi-schema +=3D include-cycle.json diff --git a/tests/qapi-schema/bad-type-int.json b/tests/qapi-schema/bad-ty= pe-int.json index 56fc6f8126..f3ad803cb6 100644 --- a/tests/qapi-schema/bad-type-int.json +++ b/tests/qapi-schema/bad-type-int.json @@ -1,3 +1,3 @@ # we reject an expression with a metatype that is not a string # FIXME: once the parser understands integer inputs, improve the error mes= sage -{ 'struct': 1, 'data': { } } +{ 'struct': 123, 'data': { } } diff --git a/tests/qapi-schema/funny-word.err b/tests/qapi-schema/funny-wor= d.err new file mode 100644 index 0000000000..0a440574bd --- /dev/null +++ b/tests/qapi-schema/funny-word.err @@ -0,0 +1 @@ +tests/qapi-schema/funny-word.json:1:3: Stray "c" diff --git a/tests/qapi-schema/funny-word.exit b/tests/qapi-schema/funny-wo= rd.exit new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/qapi-schema/funny-word.exit @@ -0,0 +1 @@ +1 diff --git a/tests/qapi-schema/funny-word.json b/tests/qapi-schema/funny-wo= rd.json new file mode 100644 index 0000000000..1153b9f12f --- /dev/null +++ b/tests/qapi-schema/funny-word.json @@ -0,0 +1 @@ +{ command: 'foo' } diff --git a/tests/qapi-schema/funny-word.out b/tests/qapi-schema/funny-wor= d.out new file mode 100644 index 0000000000..e69de29bb2 --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569330445; cv=none; d=zoho.com; s=zohoarc; b=A07oOBXfgyMb2heGXZeQ3UOjv8pWZbb6Cc4rRK2EZp281KATFUX12IncUyh1DnR2L1tB3tGogJx5U217jWH52U1T9tT0Hm0gyUpTQIoSDY/NRzeIeVFLPo/hGJ+yojX2wfM8ZGDYRAX/dUWMYtgNWPD5KX7rJDrgisve9HBtYOk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569330445; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=8qeW6AzkX8rzKHh8TRgx9DSTNcRGdI+3tdNFo20SrEA=; b=MTLujikH6YEITyLe4oC7rpkVoQEMp2BEMHbMWVVz70RLBkhdUnNOa6N77yRx07GsE8ql0LpFDY9i+TOng+249xjYa7toGeLpjvapsElLWReXV2bB4hZikTUZFbJ95f8qtPoLzZYkVPQs1Q4tVTDuq84hyOJK0s73WYjHWcwlPrU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569330445925617.799632903328; Tue, 24 Sep 2019 06:07:25 -0700 (PDT) Received: from localhost ([::1]:45394 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCkXJ-0002tC-Pv for importer@patchew.org; Tue, 24 Sep 2019 09:07:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50610) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0p-0001M2-VA for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0j-0006xk-K7 for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34870) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0i-0006uo-Nv for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:41 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D3834C0568FA for ; Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 52CF360E1C; Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id E8FED1136425; Tue, 24 Sep 2019 14:33:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 25/37] qapi: Use quotes more consistently in frontend error messages Date: Tue, 24 Sep 2019 14:33:22 +0200 Message-Id: <20190924123334.30645-26-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Consistently enclose error messages in double quotes. Use single quotes within, except for one case of "'". Signed-off-by: Markus Armbruster Message-Id: <20190914153506.2151-8-armbru@redhat.com> Reviewed-by: Eric Blake --- scripts/qapi/common.py | 37 ++++++++++--------- tests/qapi-schema/bad-type-int.err | 2 +- tests/qapi-schema/doc-missing-colon.err | 2 +- tests/qapi-schema/duplicate-key.err | 2 +- tests/qapi-schema/enum-int-member.err | 2 +- tests/qapi-schema/escape-outside-string.err | 1 + tests/qapi-schema/funny-char.err | 2 +- tests/qapi-schema/funny-word.err | 2 +- tests/qapi-schema/include-before-err.err | 2 +- tests/qapi-schema/include-nested-err.err | 2 +- tests/qapi-schema/leading-comma-list.err | 2 +- tests/qapi-schema/leading-comma-object.err | 2 +- tests/qapi-schema/missing-colon.err | 2 +- tests/qapi-schema/missing-comma-list.err | 2 +- tests/qapi-schema/missing-comma-object.err | 2 +- tests/qapi-schema/non-objects.err | 2 +- tests/qapi-schema/quoted-structural-chars.err | 2 +- tests/qapi-schema/trailing-comma-list.err | 2 +- tests/qapi-schema/unclosed-list.err | 2 +- tests/qapi-schema/unclosed-object.err | 2 +- 20 files changed, 38 insertions(+), 36 deletions(-) create mode 100644 tests/qapi-schema/escape-outside-string.err diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index f27860540b..142ab276ff 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -214,7 +214,7 @@ class QAPIDoc(object): # recognized, and get silently treated as ordinary text if not self.symbol and not self.body.text and line.startswith('@'): if not line.endswith(':'): - raise QAPIParseError(self._parser, "Line should end with := ") + raise QAPIParseError(self._parser, "Line should end with '= :'") self.symbol =3D line[1:-1] # FIXME invalid names other than the empty string aren't flagg= ed if not self.symbol: @@ -470,7 +470,7 @@ class QAPISchemaParser(object): else: fobj =3D open(incl_fname, 'r') except IOError as e: - raise QAPISemError(info, '%s: %s' % (e.strerror, incl_fname)) + raise QAPISemError(info, "%s: %s" % (e.strerror, incl_fname)) return QAPISchemaParser(fobj, previously_included, info) =20 def _pragma(self, name, value, info): @@ -522,7 +522,7 @@ class QAPISchemaParser(object): ch =3D self.src[self.cursor] self.cursor +=3D 1 if ch =3D=3D '\n': - raise QAPIParseError(self, 'Missing terminating "\= '"') + raise QAPIParseError(self, "Missing terminating \"= '\"") if esc: # Note: we recognize only \\ because we have # no use for funny characters in strings @@ -559,7 +559,7 @@ class QAPISchemaParser(object): self.line +=3D 1 self.line_pos =3D self.cursor elif not self.tok.isspace(): - raise QAPIParseError(self, 'Stray "%s"' % self.tok) + raise QAPIParseError(self, "Stray '%s'" % self.tok) =20 def get_members(self): expr =3D OrderedDict() @@ -567,24 +567,24 @@ class QAPISchemaParser(object): self.accept() return expr if self.tok !=3D "'": - raise QAPIParseError(self, 'Expected string or "}"') + raise QAPIParseError(self, "Expected string or '}'") while True: key =3D self.val self.accept() if self.tok !=3D ':': - raise QAPIParseError(self, 'Expected ":"') + raise QAPIParseError(self, "Expected ':'") self.accept() if key in expr: - raise QAPIParseError(self, 'Duplicate key "%s"' % key) + raise QAPIParseError(self, "Duplicate key '%s'" % key) expr[key] =3D self.get_expr(True) if self.tok =3D=3D '}': self.accept() return expr if self.tok !=3D ',': - raise QAPIParseError(self, 'Expected "," or "}"') + raise QAPIParseError(self, "Expected ',' or '}'") self.accept() if self.tok !=3D "'": - raise QAPIParseError(self, 'Expected string') + raise QAPIParseError(self, "Expected string") =20 def get_values(self): expr =3D [] @@ -592,20 +592,20 @@ class QAPISchemaParser(object): self.accept() return expr if self.tok not in "{['tfn": - raise QAPIParseError(self, 'Expected "{", "[", "]", string, ' - 'boolean or "null"') + raise QAPIParseError( + self, "Expected '{', '[', ']', string, boolean or 'null'") while True: expr.append(self.get_expr(True)) if self.tok =3D=3D ']': self.accept() return expr if self.tok !=3D ',': - raise QAPIParseError(self, 'Expected "," or "]"') + raise QAPIParseError(self, "Expected ',' or ']'") self.accept() =20 def get_expr(self, nested): if self.tok !=3D '{' and not nested: - raise QAPIParseError(self, 'Expected "{"') + raise QAPIParseError(self, "Expected '{'") if self.tok =3D=3D '{': self.accept() expr =3D self.get_members() @@ -616,8 +616,8 @@ class QAPISchemaParser(object): expr =3D self.val self.accept() else: - raise QAPIParseError(self, 'Expected "{", "[", string, ' - 'boolean or "null"') + raise QAPIParseError( + self, "Expected '{', '[', string, boolean or 'null'") return expr =20 def get_doc(self, info): @@ -881,9 +881,10 @@ def check_union(expr, info): "struct '%s'" % (discriminator, base)) if discriminator_value.get('if'): - raise QAPISemError(info, 'The discriminator %s.%s for union %s= ' - 'must not be conditional' % - (base, discriminator, name)) + raise QAPISemError( + info, + "The discriminator %s.%s for union %s must not be conditio= nal" + % (base, discriminator, name)) enum_define =3D enum_types.get(discriminator_value['type']) # Do not allow string discriminator if not enum_define: diff --git a/tests/qapi-schema/bad-type-int.err b/tests/qapi-schema/bad-typ= e-int.err index da89895404..2021fda5d1 100644 --- a/tests/qapi-schema/bad-type-int.err +++ b/tests/qapi-schema/bad-type-int.err @@ -1 +1 @@ -tests/qapi-schema/bad-type-int.json:3:13: Stray "1" +tests/qapi-schema/bad-type-int.json:3:13: Stray '1' diff --git a/tests/qapi-schema/doc-missing-colon.err b/tests/qapi-schema/do= c-missing-colon.err index 817398b8e4..b41d5078b0 100644 --- a/tests/qapi-schema/doc-missing-colon.err +++ b/tests/qapi-schema/doc-missing-colon.err @@ -1 +1 @@ -tests/qapi-schema/doc-missing-colon.json:4:1: Line should end with : +tests/qapi-schema/doc-missing-colon.json:4:1: Line should end with ':' diff --git a/tests/qapi-schema/duplicate-key.err b/tests/qapi-schema/duplic= ate-key.err index 6d02f83538..3af2f55174 100644 --- a/tests/qapi-schema/duplicate-key.err +++ b/tests/qapi-schema/duplicate-key.err @@ -1 +1 @@ -tests/qapi-schema/duplicate-key.json:3:10: Duplicate key "key" +tests/qapi-schema/duplicate-key.json:3:10: Duplicate key 'key' diff --git a/tests/qapi-schema/enum-int-member.err b/tests/qapi-schema/enum= -int-member.err index 071c5213d8..3f8d7b5b71 100644 --- a/tests/qapi-schema/enum-int-member.err +++ b/tests/qapi-schema/enum-int-member.err @@ -1 +1 @@ -tests/qapi-schema/enum-int-member.json:3:31: Stray "1" +tests/qapi-schema/enum-int-member.json:3:31: Stray '1' diff --git a/tests/qapi-schema/escape-outside-string.err b/tests/qapi-schem= a/escape-outside-string.err new file mode 100644 index 0000000000..efee335ba0 --- /dev/null +++ b/tests/qapi-schema/escape-outside-string.err @@ -0,0 +1 @@ +tests/qapi-schema/escape-outside-string.json:3:27: Stray '\' diff --git a/tests/qapi-schema/funny-char.err b/tests/qapi-schema/funny-cha= r.err index bfc890cd9f..139ecf4eb8 100644 --- a/tests/qapi-schema/funny-char.err +++ b/tests/qapi-schema/funny-char.err @@ -1 +1 @@ -tests/qapi-schema/funny-char.json:2:36: Stray ";" +tests/qapi-schema/funny-char.json:2:36: Stray ';' diff --git a/tests/qapi-schema/funny-word.err b/tests/qapi-schema/funny-wor= d.err index 0a440574bd..18aedb4a99 100644 --- a/tests/qapi-schema/funny-word.err +++ b/tests/qapi-schema/funny-word.err @@ -1 +1 @@ -tests/qapi-schema/funny-word.json:1:3: Stray "c" +tests/qapi-schema/funny-word.json:1:3: Stray 'c' diff --git a/tests/qapi-schema/include-before-err.err b/tests/qapi-schema/i= nclude-before-err.err index 55652751e1..2b26322170 100644 --- a/tests/qapi-schema/include-before-err.err +++ b/tests/qapi-schema/include-before-err.err @@ -1 +1 @@ -tests/qapi-schema/include-before-err.json:2:13: Expected ":" +tests/qapi-schema/include-before-err.json:2:13: Expected ':' diff --git a/tests/qapi-schema/include-nested-err.err b/tests/qapi-schema/i= nclude-nested-err.err index 1b7b22706b..aec6207eb0 100644 --- a/tests/qapi-schema/include-nested-err.err +++ b/tests/qapi-schema/include-nested-err.err @@ -1,2 +1,2 @@ In file included from tests/qapi-schema/include-nested-err.json:1: -tests/qapi-schema/missing-colon.json:1:10: Expected ":" +tests/qapi-schema/missing-colon.json:1:10: Expected ':' diff --git a/tests/qapi-schema/leading-comma-list.err b/tests/qapi-schema/l= eading-comma-list.err index f5c870bb9c..e021e42ad9 100644 --- a/tests/qapi-schema/leading-comma-list.err +++ b/tests/qapi-schema/leading-comma-list.err @@ -1 +1 @@ -tests/qapi-schema/leading-comma-list.json:2:13: Expected "{", "[", "]", st= ring, boolean or "null" +tests/qapi-schema/leading-comma-list.json:2:13: Expected '{', '[', ']', st= ring, boolean or 'null' diff --git a/tests/qapi-schema/leading-comma-object.err b/tests/qapi-schema= /leading-comma-object.err index f767b95544..3852f123d2 100644 --- a/tests/qapi-schema/leading-comma-object.err +++ b/tests/qapi-schema/leading-comma-object.err @@ -1 +1 @@ -tests/qapi-schema/leading-comma-object.json:1:3: Expected string or "}" +tests/qapi-schema/leading-comma-object.json:1:3: Expected string or '}' diff --git a/tests/qapi-schema/missing-colon.err b/tests/qapi-schema/missin= g-colon.err index d9d66b377a..a255e51918 100644 --- a/tests/qapi-schema/missing-colon.err +++ b/tests/qapi-schema/missing-colon.err @@ -1 +1 @@ -tests/qapi-schema/missing-colon.json:1:10: Expected ":" +tests/qapi-schema/missing-colon.json:1:10: Expected ':' diff --git a/tests/qapi-schema/missing-comma-list.err b/tests/qapi-schema/m= issing-comma-list.err index e73d2770d6..df3f553f39 100644 --- a/tests/qapi-schema/missing-comma-list.err +++ b/tests/qapi-schema/missing-comma-list.err @@ -1 +1 @@ -tests/qapi-schema/missing-comma-list.json:2:20: Expected "," or "]" +tests/qapi-schema/missing-comma-list.json:2:20: Expected ',' or ']' diff --git a/tests/qapi-schema/missing-comma-object.err b/tests/qapi-schema= /missing-comma-object.err index 52b3a8a1ec..0f691b8ddd 100644 --- a/tests/qapi-schema/missing-comma-object.err +++ b/tests/qapi-schema/missing-comma-object.err @@ -1 +1 @@ -tests/qapi-schema/missing-comma-object.json:2:3: Expected "," or "}" +tests/qapi-schema/missing-comma-object.json:2:3: Expected ',' or '}' diff --git a/tests/qapi-schema/non-objects.err b/tests/qapi-schema/non-obje= cts.err index 334f0c91ae..a972abd937 100644 --- a/tests/qapi-schema/non-objects.err +++ b/tests/qapi-schema/non-objects.err @@ -1 +1 @@ -tests/qapi-schema/non-objects.json:1:1: Expected "{" +tests/qapi-schema/non-objects.json:1:1: Expected '{' diff --git a/tests/qapi-schema/quoted-structural-chars.err b/tests/qapi-sch= ema/quoted-structural-chars.err index 9b183841dd..6e036c8044 100644 --- a/tests/qapi-schema/quoted-structural-chars.err +++ b/tests/qapi-schema/quoted-structural-chars.err @@ -1 +1 @@ -tests/qapi-schema/quoted-structural-chars.json:1:1: Expected "{" +tests/qapi-schema/quoted-structural-chars.json:1:1: Expected '{' diff --git a/tests/qapi-schema/trailing-comma-list.err b/tests/qapi-schema/= trailing-comma-list.err index 212e14ae28..601c4537c3 100644 --- a/tests/qapi-schema/trailing-comma-list.err +++ b/tests/qapi-schema/trailing-comma-list.err @@ -1 +1 @@ -tests/qapi-schema/trailing-comma-list.json:2:36: Expected "{", "[", string= , boolean or "null" +tests/qapi-schema/trailing-comma-list.json:2:36: Expected '{', '[', string= , boolean or 'null' diff --git a/tests/qapi-schema/unclosed-list.err b/tests/qapi-schema/unclos= ed-list.err index fb41a86abd..1cc3a094fe 100644 --- a/tests/qapi-schema/unclosed-list.err +++ b/tests/qapi-schema/unclosed-list.err @@ -1 +1 @@ -tests/qapi-schema/unclosed-list.json:1:20: Expected "," or "]" +tests/qapi-schema/unclosed-list.json:1:20: Expected ',' or ']' diff --git a/tests/qapi-schema/unclosed-object.err b/tests/qapi-schema/uncl= osed-object.err index db3deedd63..fd1a86b704 100644 --- a/tests/qapi-schema/unclosed-object.err +++ b/tests/qapi-schema/unclosed-object.err @@ -1 +1 @@ -tests/qapi-schema/unclosed-object.json:1:21: Expected "," or "}" +tests/qapi-schema/unclosed-object.json:1:21: Expected ',' or '}' --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569328939; cv=none; d=zoho.com; s=zohoarc; b=O5GLJsqzpygba1ew6yhBK0du74bS+SRZ1I2MErFyWHBq9QWyXU4a4THbExvagDCTMsAFPRiUkfA+bt1ejM3leGeu4qmraXJDJKW4M6mn804OAIVjcXCXgNcZJYB9tC6BCrbP2LyiMSzFKFJCOw9anPyJVzhLbK/QoVyMIiwR8TY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569328939; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=M116O30S1Y+JDdJl7ki86ArYw45+3r29oW/4GhhrHCY=; b=ctwzsrCwlFxdS26hMcSfdj/o/jX4qDVZAhQjGrE7VaQaHPI3N1+9dvAxEuawvNamvBNjBX8tRVC/osuoPorVIzZ8ZcSxc0mNdNaMMW5vofRufCoEiJkZahK9KWvASdJCW5xmfzVtBwBl0+pmuzY56IcUWvEvjnOwgCpdvkvrp54= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569328939450649.8755322073794; Tue, 24 Sep 2019 05:42:19 -0700 (PDT) Received: from localhost ([::1]:45228 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk93-0007VW-NG for importer@patchew.org; Tue, 24 Sep 2019 08:42:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50510) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0n-0001JA-5w for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0j-0006wQ-4B for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38420) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0i-0006uY-JT for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:40 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8610E306085E for ; Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 563D910013D9; Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id F12871136426; Tue, 24 Sep 2019 14:33:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 26/37] qapi: Improve reporting of lexical errors Date: Tue, 24 Sep 2019 14:33:23 +0200 Message-Id: <20190924123334.30645-27-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 24 Sep 2019 12:33:39 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Show text up to next structural character, whitespace, or quote character instead of just the first character. Forgotten quotes now get reported like "Stray 'command'" instead of "Stray 'c'". Signed-off-by: Markus Armbruster Message-Id: <20190914153506.2151-9-armbru@redhat.com> Reviewed-by: Eric Blake --- scripts/qapi/common.py | 6 +++++- tests/qapi-schema/bad-type-int.err | 2 +- tests/qapi-schema/funny-word.err | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 142ab276ff..b3383b17ef 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -559,7 +559,11 @@ class QAPISchemaParser(object): self.line +=3D 1 self.line_pos =3D self.cursor elif not self.tok.isspace(): - raise QAPIParseError(self, "Stray '%s'" % self.tok) + # Show up to next structural, whitespace or quote + # character + match =3D re.match('[^[\\]{}:,\\s\'"]+', + self.src[self.cursor-1:]) + raise QAPIParseError(self, "Stray '%s'" % match.group(0)) =20 def get_members(self): expr =3D OrderedDict() diff --git a/tests/qapi-schema/bad-type-int.err b/tests/qapi-schema/bad-typ= e-int.err index 2021fda5d1..9b2c12c1eb 100644 --- a/tests/qapi-schema/bad-type-int.err +++ b/tests/qapi-schema/bad-type-int.err @@ -1 +1 @@ -tests/qapi-schema/bad-type-int.json:3:13: Stray '1' +tests/qapi-schema/bad-type-int.json:3:13: Stray '123' diff --git a/tests/qapi-schema/funny-word.err b/tests/qapi-schema/funny-wor= d.err index 18aedb4a99..af92fe2551 100644 --- a/tests/qapi-schema/funny-word.err +++ b/tests/qapi-schema/funny-word.err @@ -1 +1 @@ -tests/qapi-schema/funny-word.json:1:3: Stray 'c' +tests/qapi-schema/funny-word.json:1:3: Stray 'command' --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569331662; cv=none; d=zoho.com; s=zohoarc; b=h388GJcjRReE8R4h1Pe9j04BmUxI5nowHEgJsVZMVLhZDHUE5gKGviXM0/f3ZWq+wXd3G9QgKaq5OXuyclnq6A6AqBxWGkFbUwVhU2xhJEdyV9melp84O+WgPIFECJkgYoxXdKH1sj/1sAH/10cCP4S0MDhbvCKlDuJK2hdQ5Rc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569331662; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=kyEtUy8G2S/m09U/1yqbA9hSj2BBblgVDGA/2HoVbD0=; b=drCRaNyEGK6xFCrjbq7cOj8C+LOaF1h/zDh/Sqc/s0wBCzlL4wN9RIcUXOuBm3CslNzjufgZKv3G8047OizHv1owF5+EkMt38nOMwudHDH36KvUjIDCuptCupbPfm/2L0O6PL8hBKjpIpYEY/xfmZLv7FGlpxjG1gx9uZXetXek= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569331662540215.42807413968933; Tue, 24 Sep 2019 06:27:42 -0700 (PDT) Received: from localhost ([::1]:45614 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCkqw-0006iq-Pu for importer@patchew.org; Tue, 24 Sep 2019 09:27:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50652) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0r-0001No-QS for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0k-0006zb-KL for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42798) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0k-0006wU-3D for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:42 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E28A2307D91F for ; Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8CE5660852; Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 0601D1136427; Tue, 24 Sep 2019 14:33:35 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 27/37] qapi: Remove null from schema language Date: Tue, 24 Sep 2019 14:33:24 +0200 Message-Id: <20190924123334.30645-28-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" We represent the parse tree as OrderedDict. We fetch optional dict members with .get(). So far, so good. We represent null literals as None. .get() returns None both for "absent" and for "present, value is the null literal". Uh-oh. Test features-if-invalid exposes this bug: "'if': null" is misinterpreted as absent "if". We added null to the schema language to "allow [...] an explicit default value" (commit e53188ada5 "qapi: Allow true, false and null in schema json", v2.4.0). Hasn't happened; null is still unused except as generic invalid value in tests/. To fix, we'd have to replace .get() by something more careful, or represent null differently. Feasible, but we got more and bigger fish to fry right now. Remove the null literal from the schema language. Replace null in tests by another invalid value. Test features-if-invalid now behaves as it should. Signed-off-by: Markus Armbruster Message-Id: <20190914153506.2151-10-armbru@redhat.com> Reviewed-by: Eric Blake --- docs/devel/qapi-code-gen.txt | 4 ++-- scripts/qapi/common.py | 4 ---- tests/qapi-schema/features-if-invalid.err | 1 + tests/qapi-schema/features-if-invalid.exit | 2 +- tests/qapi-schema/features-if-invalid.json | 3 +-- tests/qapi-schema/features-if-invalid.out | 14 -------------- .../pragma-name-case-whitelist-crap.json | 2 +- 7 files changed, 6 insertions(+), 24 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index b12a5b4de8..64d9e4c6a9 100644 --- a/docs/devel/qapi-code-gen.txt +++ b/docs/devel/qapi-code-gen.txt @@ -52,7 +52,7 @@ Differences: * Strings are restricted to printable ASCII, and escape sequences to just '\\'. =20 -* Numbers are not supported. +* Numbers and null are not supported. =20 A second layer of syntax defines the sequences of JSON texts that are a correctly structured QAPI schema. We provide a grammar for this @@ -67,7 +67,7 @@ syntax in an EBNF-like notation: expression A separated by , * Grouping: expression ( A ) matches expression A * JSON's structural characters are terminals: { } [ ] : , -* JSON's literal names are terminals: false true null +* JSON's literal names are terminals: false true * String literals enclosed in 'single quotes' are terminal, and match this JSON string, with a leading '*' stripped off * When JSON object member's name starts with '*', the member is diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index b3383b17ef..ef7c7be4fd 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -548,10 +548,6 @@ class QAPISchemaParser(object): self.val =3D False self.cursor +=3D 4 return - elif self.src.startswith('null', self.pos): - self.val =3D None - self.cursor +=3D 3 - return elif self.tok =3D=3D '\n': if self.cursor =3D=3D len(self.src): self.tok =3D None diff --git a/tests/qapi-schema/features-if-invalid.err b/tests/qapi-schema/= features-if-invalid.err index e69de29bb2..295800b4fc 100644 --- a/tests/qapi-schema/features-if-invalid.err +++ b/tests/qapi-schema/features-if-invalid.err @@ -0,0 +1 @@ +tests/qapi-schema/features-if-invalid.json:2: 'if' condition must be a str= ing or a list of strings diff --git a/tests/qapi-schema/features-if-invalid.exit b/tests/qapi-schema= /features-if-invalid.exit index 573541ac97..d00491fd7e 100644 --- a/tests/qapi-schema/features-if-invalid.exit +++ b/tests/qapi-schema/features-if-invalid.exit @@ -1 +1 @@ -0 +1 diff --git a/tests/qapi-schema/features-if-invalid.json b/tests/qapi-schema= /features-if-invalid.json index 7e4c1ad720..89c2a6c234 100644 --- a/tests/qapi-schema/features-if-invalid.json +++ b/tests/qapi-schema/features-if-invalid.json @@ -1,5 +1,4 @@ # Cover feature with invalid 'if' -# FIXME not rejected, misinterpreted as unconditional { 'struct': 'Stru', 'data': {}, - 'features': [{'name': 'f', 'if': null }] } + 'features': [{'name': 'f', 'if': false }] } diff --git a/tests/qapi-schema/features-if-invalid.out b/tests/qapi-schema/= features-if-invalid.out index 9c2637baa3..e69de29bb2 100644 --- a/tests/qapi-schema/features-if-invalid.out +++ b/tests/qapi-schema/features-if-invalid.out @@ -1,14 +0,0 @@ -module None -object q_empty -enum QType - prefix QTYPE - member none - member qnull - member qnum - member qstring - member qdict - member qlist - member qbool -module features-if-invalid.json -object Stru - feature f diff --git a/tests/qapi-schema/pragma-name-case-whitelist-crap.json b/tests= /qapi-schema/pragma-name-case-whitelist-crap.json index 58382bf4e4..734e1c617b 100644 --- a/tests/qapi-schema/pragma-name-case-whitelist-crap.json +++ b/tests/qapi-schema/pragma-name-case-whitelist-crap.json @@ -1,3 +1,3 @@ # 'name-case-whitelist' must be list of strings =20 -{ 'pragma': { 'name-case-whitelist': null } } +{ 'pragma': { 'name-case-whitelist': false } } --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569330886; cv=none; d=zoho.com; s=zohoarc; b=EiIO/a7+jYE/Y4jLQ6zdu+ArvhbomYZRiI8GNNvpaJzcW/YNtvgpePTdwk7gUJXVzLBWu/r/vqngFGPGca84EacwaLqQYnUIXjUoyRWfwamUdOhiMG12ZGSF0gA2ypFa+xPnN3heO/roxN7mraorn7A1rMWIz5LJG4puTEmlZEg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569330886; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=pG1TNmHIL7xnsBWGyagzlpsOGwRnybqVRGNSjMqqq7k=; b=DIHC5peXbZIpYzu+MjdB4LvmvFl9LbNwMjXzzGWUGKRcp+MfpR1dI9ot7Wxa6WPjOjH8lLnCJUXk0zZ10L4xiR0vEWLjIt4iT1c13gGe4Ay0c4AZq5zBg4uKdr+hgdeT/U+r55cyT0/7UoHPsJenFmT3KMakBInG+wDAeW4RSKE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569330886134215.41069901527896; Tue, 24 Sep 2019 06:14:46 -0700 (PDT) Received: from localhost ([::1]:45504 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCkeR-0002LO-NK for importer@patchew.org; Tue, 24 Sep 2019 09:14:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50642) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0r-0001NF-5X for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0k-0006zI-HL for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46520) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0j-0006wX-Vg for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:42 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EAF8830A7B99 for ; Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 941FE608C2; Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 0EB241136428; Tue, 24 Sep 2019 14:33:35 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 28/37] qapi: Fix broken discriminator error messages Date: Tue, 24 Sep 2019 14:33:25 +0200 Message-Id: <20190924123334.30645-29-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" check_union() checks the discriminator exists in base and makes sense. Two error messages mention the base. These are broken for anonymous bases, as demonstrated by tests flat-union-invalid-discriminator and flat-union-invalid-if-discriminator.err. The third one doesn't bother. First broken when commit ac4338f8eb "qapi: Allow anonymous base for flat union" (v2.6.0) neglected to adjust the "not a member of base" error message. Commit ccadd6bcba "qapi: Add 'if' to implicit struct members" (v4.0.0) then cloned the flawed error message. Dumb them down not to mention the base. Signed-off-by: Markus Armbruster Message-Id: <20190914153506.2151-11-armbru@redhat.com> Reviewed-by: Eric Blake --- scripts/qapi/common.py | 9 ++++----- tests/qapi-schema/flat-union-invalid-discriminator.err | 2 +- tests/qapi-schema/flat-union-invalid-discriminator.json | 1 - .../qapi-schema/flat-union-invalid-if-discriminator.err | 2 +- .../qapi-schema/flat-union-invalid-if-discriminator.json | 1 - tests/qapi-schema/flat-union-optional-discriminator.err | 2 +- tests/qapi-schema/union-base-empty.err | 2 +- 7 files changed, 8 insertions(+), 11 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index ef7c7be4fd..a58e904978 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -877,14 +877,13 @@ def check_union(expr, info): discriminator_value =3D base_members.get(discriminator) if not discriminator_value: raise QAPISemError(info, - "Discriminator '%s' is not a member of base= " - "struct '%s'" - % (discriminator, base)) + "Discriminator '%s' is not a member of 'bas= e'" + % discriminator) if discriminator_value.get('if'): raise QAPISemError( info, - "The discriminator %s.%s for union %s must not be conditio= nal" - % (base, discriminator, name)) + "The discriminator '%s' for union %s must not be condition= al" + % (discriminator, name)) enum_define =3D enum_types.get(discriminator_value['type']) # Do not allow string discriminator if not enum_define: diff --git a/tests/qapi-schema/flat-union-invalid-discriminator.err b/tests= /qapi-schema/flat-union-invalid-discriminator.err index 947a6b73aa..495d5a520e 100644 --- a/tests/qapi-schema/flat-union-invalid-discriminator.err +++ b/tests/qapi-schema/flat-union-invalid-discriminator.err @@ -1 +1 @@ -tests/qapi-schema/flat-union-invalid-discriminator.json:11: Discriminator = 'enum_wrong' is not a member of base struct 'OrderedDict([('enum1', {'type'= : 'TestEnum'})])' +tests/qapi-schema/flat-union-invalid-discriminator.json:10: Discriminator = 'enum_wrong' is not a member of 'base' diff --git a/tests/qapi-schema/flat-union-invalid-discriminator.json b/test= s/qapi-schema/flat-union-invalid-discriminator.json index de86cf0760..c4fce97362 100644 --- a/tests/qapi-schema/flat-union-invalid-discriminator.json +++ b/tests/qapi-schema/flat-union-invalid-discriminator.json @@ -1,4 +1,3 @@ -# FIXME error message shows base as OrderedDict { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } =20 diff --git a/tests/qapi-schema/flat-union-invalid-if-discriminator.err b/te= sts/qapi-schema/flat-union-invalid-if-discriminator.err index ec04c4840c..cc5c3fb80b 100644 --- a/tests/qapi-schema/flat-union-invalid-if-discriminator.err +++ b/tests/qapi-schema/flat-union-invalid-if-discriminator.err @@ -1 +1 @@ -tests/qapi-schema/flat-union-invalid-if-discriminator.json:11: The discrim= inator OrderedDict([('enum1', OrderedDict([('type', 'TestEnum'), ('if', 'FO= O')]))]).enum1 for union TestUnion must not be conditional +tests/qapi-schema/flat-union-invalid-if-discriminator.json:10: The discrim= inator 'enum1' for union TestUnion must not be conditional diff --git a/tests/qapi-schema/flat-union-invalid-if-discriminator.json b/t= ests/qapi-schema/flat-union-invalid-if-discriminator.json index bbaa9a3f82..e49992b798 100644 --- a/tests/qapi-schema/flat-union-invalid-if-discriminator.json +++ b/tests/qapi-schema/flat-union-invalid-if-discriminator.json @@ -1,4 +1,3 @@ -# FIXME error message shows base as OrderedDict { 'enum': 'TestEnum', 'data': [ 'value1', 'value2' ] } =20 diff --git a/tests/qapi-schema/flat-union-optional-discriminator.err b/test= s/qapi-schema/flat-union-optional-discriminator.err index 8b4a4ba847..45f5407c34 100644 --- a/tests/qapi-schema/flat-union-optional-discriminator.err +++ b/tests/qapi-schema/flat-union-optional-discriminator.err @@ -1 +1 @@ -tests/qapi-schema/flat-union-optional-discriminator.json:7: Discriminator = 'switch' is not a member of base struct 'Base' +tests/qapi-schema/flat-union-optional-discriminator.json:7: Discriminator = 'switch' is not a member of 'base' diff --git a/tests/qapi-schema/union-base-empty.err b/tests/qapi-schema/uni= on-base-empty.err index 7695806d81..9453720ede 100644 --- a/tests/qapi-schema/union-base-empty.err +++ b/tests/qapi-schema/union-base-empty.err @@ -1 +1 @@ -tests/qapi-schema/union-base-empty.json:5: Discriminator 'type' is not a m= ember of base struct 'Empty' +tests/qapi-schema/union-base-empty.json:5: Discriminator 'type' is not a m= ember of 'base' --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569328932; cv=none; d=zoho.com; s=zohoarc; b=f0le2vqdybkWks6oJCDl/Tm5/iXaektDLoIG5VjJxM8u62dUgeYuTBplUkadQnGRhMxgiSOldgFSZp+N/oOvC5vfdBi8l1XLKoeH2iVETpoUTAds26L885OiTSPKxydb36k8roD4eANTgkpCnPDYF9lPAxglbOJe6uGCId3IrO4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569328932; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=iTnr/ycB3fDm13mKm/Sd4UeEX2EIAwv8TDSZESInKPE=; b=hDO80ud5JtWfLccUVkZDKnTXOGQJYSelKg5WXX7QAEgmV95anEU53g4rSihMsTvJzhRBPk7Ntael8UteXZD2sE90HdPSKfeeVYF433hR1+iyCcFomhsyOdUp9JFN55Huy8nBixLTuMTLvdwJJPbZw7j9pur88eQYo71H1G88b6s= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569328932221156.6156865420952; Tue, 24 Sep 2019 05:42:12 -0700 (PDT) Received: from localhost ([::1]:45226 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk8w-0007N0-Ef for importer@patchew.org; Tue, 24 Sep 2019 08:42:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50556) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0o-0001KI-A1 for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0k-0006yY-9K for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37046) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0j-0006wD-Ru for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:42 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CAB5610CC1EE for ; Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 98265600CC; Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 185A41136429; Tue, 24 Sep 2019 14:33:35 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 29/37] qapi: Reject blank 'if' conditions in addition to empty ones Date: Tue, 24 Sep 2019 14:33:26 +0200 Message-Id: <20190924123334.30645-30-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.65]); Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" "'if': 'COND'" generates "#if COND". We reject empty COND because it won't compile. Blank COND won't compile any better, so reject that, too. Signed-off-by: Markus Armbruster Message-Id: <20190914153506.2151-12-armbru@redhat.com> Reviewed-by: Eric Blake --- scripts/qapi/common.py | 5 +++-- tests/qapi-schema/bad-if-list.err | 2 +- tests/qapi-schema/bad-if-list.json | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index a58e904978..2b46164854 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -742,8 +742,9 @@ def check_if(expr, info): if not isinstance(ifcond, str): raise QAPISemError( info, "'if' condition must be a string or a list of string= s") - if ifcond =3D=3D '': - raise QAPISemError(info, "'if' condition '' makes no sense") + if ifcond.strip() =3D=3D '': + raise QAPISemError(info, "'if' condition '%s' makes no sense" + % ifcond) =20 ifcond =3D expr.get('if') if ifcond is None: diff --git a/tests/qapi-schema/bad-if-list.err b/tests/qapi-schema/bad-if-l= ist.err index 0af6316f78..53af099083 100644 --- a/tests/qapi-schema/bad-if-list.err +++ b/tests/qapi-schema/bad-if-list.err @@ -1 +1 @@ -tests/qapi-schema/bad-if-list.json:2: 'if' condition '' makes no sense +tests/qapi-schema/bad-if-list.json:2: 'if' condition ' ' makes no sense diff --git a/tests/qapi-schema/bad-if-list.json b/tests/qapi-schema/bad-if-= list.json index 49ced9b9ca..ea3d95bb6b 100644 --- a/tests/qapi-schema/bad-if-list.json +++ b/tests/qapi-schema/bad-if-list.json @@ -1,3 +1,3 @@ # check invalid 'if' content { 'struct': 'TestIfStruct', 'data': { 'foo': 'int' }, - 'if': ['foo', ''] } + 'if': ['foo', ' '] } --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569331428; cv=none; d=zoho.com; s=zohoarc; b=lnfDlpsXql/0+KHhxFPPzlHfNsmxpjmlVnWx/4tEWV2QC7I4JXgyDmYsW+mO2f/rVn+DR6co7Ytqsg7i2RWIn6fNPRGB8xHAzCJixkUS1x3kmrsddhfQCwFEXWR+UugSl2k4laAzSqMEeo2uEub32I1FAmquuAAKpJHKS5Fsdr0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569331428; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=Jy/k4WA4uLdTfbCNYBO98N2cSXEIB/XRvPT51cBJSFk=; b=eL2MbUBzssBSA1pLuYnIetB9PmfM5AAZPHk/RqXhgKdkOQdQLE2odRPd52AdIVHsaSe8MXZH31xB4kmPDnYUqAVQyGlV9Roes2ls0KCbqL1ShoY2/rFRjcITUAapPwJDSVQ5eZYXz69tldyl3es8nHJ6fHhdNTT+0FJCiOMjCfc= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569331428692151.7402921577659; Tue, 24 Sep 2019 06:23:48 -0700 (PDT) Received: from localhost ([::1]:45591 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCknD-0001iv-5w for importer@patchew.org; Tue, 24 Sep 2019 09:23:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50698) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0t-0001PM-Q4 for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0k-0006zk-L5 for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:28409) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0k-0006wc-8S for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:42 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ED10F18CB8EC for ; Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 970AC5D9E1; Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 2218E113642A; Tue, 24 Sep 2019 14:33:35 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 30/37] qapi: Fix missing 'if' checks in struct, union, alternate 'data' Date: Tue, 24 Sep 2019 14:33:27 +0200 Message-Id: <20190924123334.30645-31-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.63]); Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Commit 87adbbffd4..3e270dcacc "qapi: Add 'if' to (implicit struct|union|alternate) members" (v4.0.0) neglected test coverage, and promptly failed to check the conditions. Review fail. Recent commit "tests/qapi-schema: Demonstrate insufficient 'if' checking" added test coverage, demonstrating the bug. Fix it by add the missing check_if(). Signed-off-by: Markus Armbruster Message-Id: <20190914153506.2151-13-armbru@redhat.com> Reviewed-by: Eric Blake --- scripts/qapi/common.py | 3 +++ .../alternate-branch-if-invalid.err | 1 + .../alternate-branch-if-invalid.exit | 2 +- .../alternate-branch-if-invalid.json | 1 - .../alternate-branch-if-invalid.out | 16 ------------- .../qapi-schema/struct-member-if-invalid.err | 1 + .../qapi-schema/struct-member-if-invalid.exit | 2 +- .../qapi-schema/struct-member-if-invalid.json | 1 - .../qapi-schema/struct-member-if-invalid.out | 15 ------------ tests/qapi-schema/union-branch-if-invalid.err | 1 + .../qapi-schema/union-branch-if-invalid.exit | 2 +- .../qapi-schema/union-branch-if-invalid.json | 1 - tests/qapi-schema/union-branch-if-invalid.out | 23 ------------------- 13 files changed, 9 insertions(+), 60 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 2b46164854..cacee9b8bb 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -803,6 +803,7 @@ def check_type(info, source, value, # an optional argument. check_known_keys(info, "member '%s' of %s" % (key, source), arg, ['type'], ['if']) + check_if(arg, info) check_type(info, "Member '%s' of %s" % (key, source), arg['type'], allow_array=3DTrue, allow_metas=3D['built-in', 'union', 'alternate', 'struc= t', @@ -902,6 +903,7 @@ def check_union(expr, info): =20 check_known_keys(info, "member '%s' of union '%s'" % (key, name), value, ['type'], ['if']) + check_if(value, info) # Each value must name a known type check_type(info, "Member '%s' of union '%s'" % (key, name), value['type'], @@ -930,6 +932,7 @@ def check_alternate(expr, info): check_known_keys(info, "member '%s' of alternate '%s'" % (key, name), value, ['type'], ['if']) + check_if(value, info) typ =3D value['type'] =20 # Ensure alternates have no type conflicts. diff --git a/tests/qapi-schema/alternate-branch-if-invalid.err b/tests/qapi= -schema/alternate-branch-if-invalid.err index e69de29bb2..f1d6c10e00 100644 --- a/tests/qapi-schema/alternate-branch-if-invalid.err +++ b/tests/qapi-schema/alternate-branch-if-invalid.err @@ -0,0 +1 @@ +tests/qapi-schema/alternate-branch-if-invalid.json:2: 'if' condition ' ' m= akes no sense diff --git a/tests/qapi-schema/alternate-branch-if-invalid.exit b/tests/qap= i-schema/alternate-branch-if-invalid.exit index 573541ac97..d00491fd7e 100644 --- a/tests/qapi-schema/alternate-branch-if-invalid.exit +++ b/tests/qapi-schema/alternate-branch-if-invalid.exit @@ -1 +1 @@ -0 +1 diff --git a/tests/qapi-schema/alternate-branch-if-invalid.json b/tests/qap= i-schema/alternate-branch-if-invalid.json index 6497f53475..fea6d9080c 100644 --- a/tests/qapi-schema/alternate-branch-if-invalid.json +++ b/tests/qapi-schema/alternate-branch-if-invalid.json @@ -1,4 +1,3 @@ # Cover alternative with invalid 'if' -# FIXME not rejected, would generate '#if \n' { 'alternate': 'Alt', 'data': { 'branch': { 'type': 'int', 'if': ' ' } } } diff --git a/tests/qapi-schema/alternate-branch-if-invalid.out b/tests/qapi= -schema/alternate-branch-if-invalid.out index 89305d7f21..e69de29bb2 100644 --- a/tests/qapi-schema/alternate-branch-if-invalid.out +++ b/tests/qapi-schema/alternate-branch-if-invalid.out @@ -1,16 +0,0 @@ -module None -object q_empty -enum QType - prefix QTYPE - member none - member qnull - member qnum - member qstring - member qdict - member qlist - member qbool -module alternate-branch-if-invalid.json -alternate Alt - tag type - case branch: int - if [' '] diff --git a/tests/qapi-schema/struct-member-if-invalid.err b/tests/qapi-sc= hema/struct-member-if-invalid.err index e69de29bb2..bfd65db97b 100644 --- a/tests/qapi-schema/struct-member-if-invalid.err +++ b/tests/qapi-schema/struct-member-if-invalid.err @@ -0,0 +1 @@ +tests/qapi-schema/struct-member-if-invalid.json:2: 'if' condition must be = a string or a list of strings diff --git a/tests/qapi-schema/struct-member-if-invalid.exit b/tests/qapi-s= chema/struct-member-if-invalid.exit index 573541ac97..d00491fd7e 100644 --- a/tests/qapi-schema/struct-member-if-invalid.exit +++ b/tests/qapi-schema/struct-member-if-invalid.exit @@ -1 +1 @@ -0 +1 diff --git a/tests/qapi-schema/struct-member-if-invalid.json b/tests/qapi-s= chema/struct-member-if-invalid.json index 73987e04fc..35078bd660 100644 --- a/tests/qapi-schema/struct-member-if-invalid.json +++ b/tests/qapi-schema/struct-member-if-invalid.json @@ -1,4 +1,3 @@ # Cover member with invalid 'if' -# FIXME not rejected, would generate '#if True\n' { 'struct': 'Stru', 'data': { 'member': { 'type': 'int', 'if': true } } } diff --git a/tests/qapi-schema/struct-member-if-invalid.out b/tests/qapi-sc= hema/struct-member-if-invalid.out index 8fbb97985c..e69de29bb2 100644 --- a/tests/qapi-schema/struct-member-if-invalid.out +++ b/tests/qapi-schema/struct-member-if-invalid.out @@ -1,15 +0,0 @@ -module None -object q_empty -enum QType - prefix QTYPE - member none - member qnull - member qnum - member qstring - member qdict - member qlist - member qbool -module struct-member-if-invalid.json -object Stru - member member: int optional=3DFalse - if [True] diff --git a/tests/qapi-schema/union-branch-if-invalid.err b/tests/qapi-sch= ema/union-branch-if-invalid.err index e69de29bb2..607edee382 100644 --- a/tests/qapi-schema/union-branch-if-invalid.err +++ b/tests/qapi-schema/union-branch-if-invalid.err @@ -0,0 +1 @@ +tests/qapi-schema/union-branch-if-invalid.json:4: 'if' condition '' makes = no sense diff --git a/tests/qapi-schema/union-branch-if-invalid.exit b/tests/qapi-sc= hema/union-branch-if-invalid.exit index 573541ac97..d00491fd7e 100644 --- a/tests/qapi-schema/union-branch-if-invalid.exit +++ b/tests/qapi-schema/union-branch-if-invalid.exit @@ -1 +1 @@ -0 +1 diff --git a/tests/qapi-schema/union-branch-if-invalid.json b/tests/qapi-sc= hema/union-branch-if-invalid.json index 859b63b610..46d4239af6 100644 --- a/tests/qapi-schema/union-branch-if-invalid.json +++ b/tests/qapi-schema/union-branch-if-invalid.json @@ -1,5 +1,4 @@ # Cover branch with invalid 'if' -# FIXME not rejected, would generate '#if \n' { 'enum': 'Branches', 'data': ['branch1'] } { 'struct': 'Stru', 'data': { 'member': 'str' } } { 'union': 'Uni', diff --git a/tests/qapi-schema/union-branch-if-invalid.out b/tests/qapi-sch= ema/union-branch-if-invalid.out index 2ed43218af..e69de29bb2 100644 --- a/tests/qapi-schema/union-branch-if-invalid.out +++ b/tests/qapi-schema/union-branch-if-invalid.out @@ -1,23 +0,0 @@ -module None -object q_empty -enum QType - prefix QTYPE - member none - member qnull - member qnum - member qstring - member qdict - member qlist - member qbool -module union-branch-if-invalid.json -enum Branches - member branch1 -object Stru - member member: str optional=3DFalse -object q_obj_Uni-base - member tag: Branches optional=3DFalse -object Uni - base q_obj_Uni-base - tag tag - case branch1: Stru - if [''] --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569330013; cv=none; d=zoho.com; s=zohoarc; b=Oi891DzpKt2iOQrAwnVnQm40BSta1TrWJkXHTVI/sQu2hXTxm1XdzB7jiCa9bZqRWHi0k336ospK9IngaI/jKWKrkEHXNMMsd+NXrEydjcW8Hkn9n9VJ10ILZ6HuVPeNamvzULlrJCmnC9PYPbKXxiyRDJizISNXbgiW6HF2hlo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569330013; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=zTGMdPy/v64PEvtcT7EYMM8HO31vc4z4bqmFe1NjhTE=; b=dGaJ4f5Fkqms26QPhaPj26xnlozcVPFuCfYpsEAeBko+Hg6EyMyHiR5DUifJ35rpW+8k5qr2Q9wvm+roePXmzXzRS3etJE1OfwqjXozSNIemd+gXWe1/WsYUkD/NjwJoaBoBxoNJ2vBKbBsGtLgyc4kknT88zvZ59M8V74ibKQ0= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569330013682992.617927343268; Tue, 24 Sep 2019 06:00:13 -0700 (PDT) Received: from localhost ([::1]:45354 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCkQL-00074e-SC for importer@patchew.org; Tue, 24 Sep 2019 09:00:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50619) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0q-0001MS-Cz for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0k-0006zF-If for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42800) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0k-0006wg-1U for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:42 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F370B307D923 for ; Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9CF5610013D9; Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 2AE36113642B; Tue, 24 Sep 2019 14:33:35 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 31/37] qapi: Normalize 'if' in check_exprs(), like other sugar Date: Tue, 24 Sep 2019 14:33:28 +0200 Message-Id: <20190924123334.30645-32-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 24 Sep 2019 12:33:41 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" We normalize shorthand to longhand forms in check_expr(): enumeration values with normalize_enum(), feature values with normalize_features(), struct members, union branches and alternate branches with normalize_members(). If conditions are an exception: we normalize them in QAPISchemaEntity.check() and QAPISchemaMember.__init(), with listify_cond(). The idea goes back to commit 2cbc94376e "qapi: pass 'if' condition into QAPISchemaEntity objects", v3.0.0. Normalize in check_expr() instead, with new helper normalize_if(). Signed-off-by: Markus Armbruster Message-Id: <20190914153506.2151-14-armbru@redhat.com> Reviewed-by: Eric Blake --- scripts/qapi/common.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index cacee9b8bb..4d1f62e808 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -804,6 +804,7 @@ def check_type(info, source, value, check_known_keys(info, "member '%s' of %s" % (key, source), arg, ['type'], ['if']) check_if(arg, info) + normalize_if(arg) check_type(info, "Member '%s' of %s" % (key, source), arg['type'], allow_array=3DTrue, allow_metas=3D['built-in', 'union', 'alternate', 'struc= t', @@ -904,6 +905,7 @@ def check_union(expr, info): check_known_keys(info, "member '%s' of union '%s'" % (key, name), value, ['type'], ['if']) check_if(value, info) + normalize_if(value) # Each value must name a known type check_type(info, "Member '%s' of union '%s'" % (key, name), value['type'], @@ -933,6 +935,7 @@ def check_alternate(expr, info): "member '%s' of alternate '%s'" % (key, name), value, ['type'], ['if']) check_if(value, info) + normalize_if(value) typ =3D value['type'] =20 # Ensure alternates have no type conflicts. @@ -978,6 +981,7 @@ def check_enum(expr, info): check_known_keys(info, "member of enum '%s'" % name, member, ['name'], ['if']) check_if(member, info) + normalize_if(member) check_name(info, "Member of enum '%s'" % name, member['name'], enum_member=3DTrue) =20 @@ -1003,6 +1007,7 @@ def check_struct(expr, info): ['name'], ['if']) =20 check_if(f, info) + normalize_if(f) check_name(info, "Feature of struct %s" % name, f['name']) =20 =20 @@ -1067,6 +1072,12 @@ def normalize_features(features): for f in features] =20 =20 +def normalize_if(expr): + ifcond =3D expr.get('if') + if isinstance(ifcond, str): + expr['if'] =3D [ifcond] + + def check_exprs(exprs): global all_names =20 @@ -1123,6 +1134,7 @@ def check_exprs(exprs): else: raise QAPISemError(expr_elem['info'], "Expression is missing metatype") + normalize_if(expr) name =3D expr[meta] add_name(name, info, meta) if doc and doc.symbol !=3D name: @@ -1177,14 +1189,6 @@ def check_exprs(exprs): # Schema compiler frontend # =20 -def listify_cond(ifcond): - if not ifcond: - return [] - if not isinstance(ifcond, list): - return [ifcond] - return ifcond - - class QAPISchemaEntity(object): def __init__(self, name, info, doc, ifcond=3DNone): assert name is None or isinstance(name, str) @@ -1197,7 +1201,7 @@ class QAPISchemaEntity(object): # such place). self.info =3D info self.doc =3D doc - self._ifcond =3D ifcond # self.ifcond is set only after .check() + self._ifcond =3D ifcond or [] =20 def c_name(self): return c_name(self.name) @@ -1209,7 +1213,7 @@ class QAPISchemaEntity(object): typ.check(schema) self.ifcond =3D typ.ifcond else: - self.ifcond =3D listify_cond(self._ifcond) + self.ifcond =3D self._ifcond if self.info: self.module =3D os.path.relpath(self.info['file'], os.path.dirname(schema.fname)) @@ -1515,7 +1519,7 @@ class QAPISchemaMember(object): def __init__(self, name, ifcond=3DNone): assert isinstance(name, str) self.name =3D name - self.ifcond =3D listify_cond(ifcond) + self.ifcond =3D ifcond or [] self.owner =3D None =20 def set_owner(self, name): --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569330458; cv=none; d=zoho.com; s=zohoarc; b=Xt8RX15eQt2UxOyUd8QHimDTtk6Wva4hZeC7CRetOsBePonSsR8GJ3D7Ssqy/ofhLkDE44GwzL9kwXPEcYsUzbw9KTXi5DttKY8KaGbefrWFBHYh82CvlOnalFqcqDFEQffxnlXP4T2ljXttGhyycJYQITRaf4XX9ozVxrZDgC8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569330458; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=M3qwx4U0Qn8Hzguy4gj2SfD5Ebl8a6BbT768OxRyGfQ=; b=l9/ShlJoIYzUfQtJcIujjTPo1KJC7jDXlNsTYPvwjyHwAGeLF+W88SC+NGfDm+FAzKsHVQ6h1n234o6HYT9OzEHOP79Sy5yafpfALnctc/Q6u4R/l72/YtwVREg2sYiYAcsVERxI6kl4cIJiJBnZ4RaIzXPqyqyEXJAwWQ1q2Lw= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569330458176213.66572755631387; Tue, 24 Sep 2019 06:07:38 -0700 (PDT) Received: from localhost ([::1]:45398 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCkXU-0003AS-5v for importer@patchew.org; Tue, 24 Sep 2019 09:07:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50570) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0o-0001Ke-Mb for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0k-0006yi-BB for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55284) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0j-0006wB-PZ for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:42 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CF68218C8935 for ; Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9FDFD6012C; Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 33D9B113642C; Tue, 24 Sep 2019 14:33:35 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 32/37] qapi: Simplify check_keys() Date: Tue, 24 Sep 2019 14:33:29 +0200 Message-Id: <20190924123334.30645-33-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.70]); Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" check_keys() parameter expr_elem expects a dictionary with keys 'expr' and 'info'. Passing the two values separately is simpler, so do that. Signed-off-by: Markus Armbruster Message-Id: <20190914153506.2151-15-armbru@redhat.com> Reviewed-by: Eric Blake --- scripts/qapi/common.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 4d1f62e808..4d4e0be770 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -1029,9 +1029,7 @@ def check_known_keys(info, source, keys, required, op= tional): source, pprint(allowed))) =20 =20 -def check_keys(expr_elem, meta, required, optional=3D[]): - expr =3D expr_elem['expr'] - info =3D expr_elem['info'] +def check_keys(expr, info, meta, required, optional=3D[]): name =3D expr[meta] if not isinstance(name, str): raise QAPISemError(info, "'%s' key must have a string value" % met= a) @@ -1100,40 +1098,39 @@ def check_exprs(exprs): =20 if 'enum' in expr: meta =3D 'enum' - check_keys(expr_elem, 'enum', ['data'], ['if', 'prefix']) + check_keys(expr, info, 'enum', ['data'], ['if', 'prefix']) normalize_enum(expr) enum_types[expr[meta]] =3D expr elif 'union' in expr: meta =3D 'union' - check_keys(expr_elem, 'union', ['data'], + check_keys(expr, info, 'union', ['data'], ['base', 'discriminator', 'if']) normalize_members(expr.get('base')) normalize_members(expr['data']) union_types[expr[meta]] =3D expr elif 'alternate' in expr: meta =3D 'alternate' - check_keys(expr_elem, 'alternate', ['data'], ['if']) + check_keys(expr, info, 'alternate', ['data'], ['if']) normalize_members(expr['data']) elif 'struct' in expr: meta =3D 'struct' - check_keys(expr_elem, 'struct', ['data'], + check_keys(expr, info, 'struct', ['data'], ['base', 'if', 'features']) normalize_members(expr['data']) normalize_features(expr.get('features')) struct_types[expr[meta]] =3D expr elif 'command' in expr: meta =3D 'command' - check_keys(expr_elem, 'command', [], + check_keys(expr, info, 'command', [], ['data', 'returns', 'gen', 'success-response', 'boxed', 'allow-oob', 'allow-preconfig', 'if']) normalize_members(expr.get('data')) elif 'event' in expr: meta =3D 'event' - check_keys(expr_elem, 'event', [], ['data', 'boxed', 'if']) + check_keys(expr, info, 'event', [], ['data', 'boxed', 'if']) normalize_members(expr.get('data')) else: - raise QAPISemError(expr_elem['info'], - "Expression is missing metatype") + raise QAPISemError(info, "Expression is missing metatype") normalize_if(expr) name =3D expr[meta] add_name(name, info, meta) --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569329509; cv=none; d=zoho.com; s=zohoarc; b=UJjOoh49oK1JDF04xpPy+8YgzDWAvHBJB2CPuR3Pbm1s2jgrDjxX9SjHE3UTVuWsqISyxOqWN6iGUg6QryHqJ/36WZBXzBjBgLUgEvfufCpl+sdRCHAwl3pre8gts6D/NbEuibW7f5QFOoh5ZYUylJKOS9S7t3WndsXPcNkozx4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569329509; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=znh07qt0XK77x8iuKK8wJ78kA9qUmGisY0C5nuIi6/A=; b=gBeRRPsjSB6c5xl0AslYJXbNMFQb39e0tuJMppVl5CJPESQoMbDcC/a6VBv+EteguhN6IGNxYIdYVEoW3DtmgGySi8eFBkSzcfRvAsHtakzuznWpj2lXlYcqNQ7S0y0s6r1t12tzisC+MoYER5SkXWnBdiGhr/rgr+P9X5lg5qU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569329509932627.7503545820555; Tue, 24 Sep 2019 05:51:49 -0700 (PDT) Received: from localhost ([::1]:45308 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCkIA-0007XK-Ko for importer@patchew.org; Tue, 24 Sep 2019 08:51:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50566) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0o-0001KV-GT for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0k-0006yP-9U for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55708) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0j-0006wE-QN for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:41 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D1B6518CB8E9 for ; Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A07426012D; Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 3C2E7113642D; Tue, 24 Sep 2019 14:33:35 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 33/37] qapi: Clean up around check_known_keys() Date: Tue, 24 Sep 2019 14:33:30 +0200 Message-Id: <20190924123334.30645-34-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.63]); Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" All callers pass a dict argument to @keys, except check_keys() passes a dict's .keys(). Drop .keys() there, and rename parameter @keys to @value. Signed-off-by: Markus Armbruster Message-Id: <20190914153506.2151-16-armbru@redhat.com> Reviewed-by: Eric Blake --- scripts/qapi/common.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 4d4e0be770..3c3154a039 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -1011,18 +1011,18 @@ def check_struct(expr, info): check_name(info, "Feature of struct %s" % name, f['name']) =20 =20 -def check_known_keys(info, source, keys, required, optional): +def check_known_keys(info, source, value, required, optional): =20 def pprint(elems): return ', '.join("'" + e + "'" for e in sorted(elems)) =20 - missing =3D set(required) - set(keys) + missing =3D set(required) - set(value) if missing: raise QAPISemError(info, "Key%s %s %s missing from %s" % ('s' if len(missing) > 1 else '', pprint(miss= ing), 'are' if len(missing) > 1 else 'is', source)) allowed =3D set(required + optional) - unknown =3D set(keys) - allowed + unknown =3D set(value) - allowed if unknown: raise QAPISemError(info, "Unknown key%s %s in %s\nValid keys are %= s." % ('s' if len(unknown) > 1 else '', pprint(unkn= own), @@ -1035,7 +1035,7 @@ def check_keys(expr, info, meta, required, optional= =3D[]): raise QAPISemError(info, "'%s' key must have a string value" % met= a) required =3D required + [meta] source =3D "%s '%s'" % (meta, name) - check_known_keys(info, source, expr.keys(), required, optional) + check_known_keys(info, source, expr, required, optional) for (key, value) in expr.items(): if key in ['gen', 'success-response'] and value is not False: raise QAPISemError(info, --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569329768; cv=none; d=zoho.com; s=zohoarc; b=k3TglFOF/BVMVHxmHfqWJK8Oho5cEXfIhkld5K1uuKzbcS3nV8AbeBsPCMvufyzi+yJu48D6/mkvZw2j2431DY6BeYl2DGw2TNrO4mfucWJ4tKaA3YL1DDcfCp1mghloM+liHIOhwriYmBgv+bf50O3yDzL6CwyZ7qndCbA8PWg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569329768; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=8ZjTYmhwe14Cbvnws4JuJmYU1+tHfFDFD/VD4ryTL6s=; b=Vrm42IA4NDpN1C6Z5uhbRNi2s7fZOA+ggwhC9tYjzyCAfeDFqOhEEoOlMXpP7Pu8eNcYSs+/cW7tqcacG2uTCGYjKjrNxVP//EPnS3vqUJprFUeYLhKpONX8FH+TffyMGovj0U/2Mw9xsS8JJOUVqOF4arDqx3/jZ6YdyQgl6K4= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569329768506707.6252448529008; Tue, 24 Sep 2019 05:56:08 -0700 (PDT) Received: from localhost ([::1]:45328 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCkMQ-00033Z-JZ for importer@patchew.org; Tue, 24 Sep 2019 08:56:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50618) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0q-0001MO-9L for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0k-0006z7-F6 for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36436) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0j-0006wH-TM for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:42 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D1A6C300CB2B for ; Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A10BC60933; Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 44E08113642E; Tue, 24 Sep 2019 14:33:35 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 34/37] qapi: Delete useless check_exprs() code for simple union kind Date: Tue, 24 Sep 2019 14:33:31 +0200 Message-Id: <20190924123334.30645-35-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Commit bceae7697f "qapi script: support enum type as discriminator in union" made check_exprs() add the implicit enum types of simple unions to global @enum_types. I'm not sure it was needed even then. It's certainly not needed now. Delete it. discriminator_find_enum_define() and add_name() parameter @implicit are now dead. Bury them. Signed-off-by: Markus Armbruster Message-Id: <20190914153506.2151-17-armbru@redhat.com> Reviewed-by: Eric Blake --- scripts/qapi/common.py | 39 ++------------------------------------- 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 3c3154a039..7e79c42b6a 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -672,26 +672,6 @@ def find_alternate_member_qtype(qapi_type): return None =20 =20 -# Return the discriminator enum define if discriminator is specified as an -# enum type, otherwise return None. -def discriminator_find_enum_define(expr): - base =3D expr.get('base') - discriminator =3D expr.get('discriminator') - - if not (discriminator and base): - return None - - base_members =3D find_base_members(base) - if not base_members: - return None - - discriminator_value =3D base_members.get(discriminator) - if not discriminator_value: - return None - - return enum_types.get(discriminator_value['type']) - - # Names must be letters, numbers, -, and _. They must start with letter, # except for downstream extensions which must start with __RFQDN_. # Dots are only valid in the downstream extension prefix. @@ -722,7 +702,7 @@ def check_name(info, source, name, allow_optional=3DFal= se, raise QAPISemError(info, "%s uses invalid name '%s'" % (source, na= me)) =20 =20 -def add_name(name, info, meta, implicit=3DFalse): +def add_name(name, info, meta): global all_names check_name(info, "'%s'" % meta, name) # FIXME should reject names that differ only in '_' vs. '.' @@ -730,7 +710,7 @@ def add_name(name, info, meta, implicit=3DFalse): if name in all_names: raise QAPISemError(info, "%s '%s' is already defined" % (all_names[name], name)) - if not implicit and (name.endswith('Kind') or name.endswith('List')): + if name.endswith('Kind') or name.endswith('List'): raise QAPISemError(info, "%s '%s' should not end in '%s'" % (meta, name, name[-4:])) all_names[name] =3D meta @@ -1138,21 +1118,6 @@ def check_exprs(exprs): raise QAPISemError(info, "Definition of '%s' follows documenta= tion" " for '%s'" % (name, doc.symbol)) =20 - # Try again for hidden UnionKind enum - for expr_elem in exprs: - expr =3D expr_elem['expr'] - - if 'include' in expr: - continue - if 'union' in expr and not discriminator_find_enum_define(expr): - name =3D '%sKind' % expr['union'] - elif 'alternate' in expr: - name =3D '%sKind' % expr['alternate'] - else: - continue - enum_types[name] =3D {'enum': name} - add_name(name, info, 'enum', implicit=3DTrue) - # Validate that exprs make sense for expr_elem in exprs: expr =3D expr_elem['expr'] --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569329775; cv=none; d=zoho.com; s=zohoarc; b=E/hGROyqaNzDXx48ejKcNkRA06lKWi0/05ieblDxuAKo4HqJjTSc7gILdYFxe95bh+YdEAAgOeaZGoSWvC+ONxJbDn2oxKhBTLOCq4Ty2Wvdz0kcyOC9TcTNswzz4LEVvNa3DbkZj5JY8obGCGK/eiA6cHKN2tLoeA0oN+ci1AI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569329775; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=biYy+GBStUPYqLk+n/lZVwSYdg+u08Q3ZZSySJxcS/Y=; b=Vlt2M1ehDm450ll3t4j1Udbe/xVtWppfZT1GCTl2XdMLCEIyjlrI+mLglgn8l9s0hiTpPhuZ+WdUqii6U3L5gNvnSZSHUemqJ/VcWZNh+RhNqXPsQFDs+3aEMtPiTmK4uoU7nLEoT7goJ8cRYXmfKeMvsjQvcDCFCajnNM7WxF8= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569329775204382.2730389212585; Tue, 24 Sep 2019 05:56:15 -0700 (PDT) Received: from localhost ([::1]:45330 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCkMU-000397-Hz for importer@patchew.org; Tue, 24 Sep 2019 08:56:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50560) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0o-0001KL-DY for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0k-0006yu-Cr for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38442) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0j-0006wW-UQ for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:42 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DFA68300D1C8 for ; Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AFD2E60A35; Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 4CC6F113642F; Tue, 24 Sep 2019 14:33:35 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 35/37] qapi: Fix to .check() empty structs just once Date: Tue, 24 Sep 2019 14:33:32 +0200 Message-Id: <20190924123334.30645-36-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" QAPISchemaObjectType.check() does nothing for types that have been checked already. Except the "has been checked" predicate is broken for empty types: self.members is [] then, which isn't true. The bug is harmless, but fix it anyway: use self.member is not None instead. Signed-off-by: Markus Armbruster Message-Id: <20190914153506.2151-18-armbru@redhat.com> Reviewed-by: Eric Blake --- scripts/qapi/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 7e79c42b6a..e2c87d1349 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -1406,7 +1406,7 @@ class QAPISchemaObjectType(QAPISchemaType): if self.members is False: # check for cycles raise QAPISemError(self.info, "Object %s contains itself" % self.name) - if self.members: + if self.members is not None: # already checked return self.members =3D False # mark as being checked seen =3D OrderedDict() --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569331933; cv=none; d=zoho.com; s=zohoarc; b=W60H/U8K6SHGwJ+kiGAe/c0KeCfJgQd0HkpAVFatk38MWazpi7FuZbV06wRUK/nwJLumndCv+D18IlA6vQRD/rV/Y4rmMWE7WGvdzzVZZAkr76w55flqmfYYTwiY6PdzEWzzNaT2yA2DAOYNe7ybQx9LszH1fXlixAdCg+12l0I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569331933; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=H3LoomUqD2oGpA1MrtykEfpb3gxTo5eQvNygzfJij0g=; b=I593/A0MLU7FU3qXRn0mj6FhLBTJvIoITEC9wlo+by9Ng8cvGmRAYSg7GPgPNOpmkikUAR6fbCDogj0OmX9GynTFRBBmwh1UJJIMGbAFGxtcLDXQU/a+JzhqZFa2enuYRv/4XpOrfqseZSbPSOWU3NBoAqG/ew093p6udEHrRp8= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569331933419601.6931677304257; Tue, 24 Sep 2019 06:32:13 -0700 (PDT) Received: from localhost ([::1]:45708 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCkvL-0002BV-KU for importer@patchew.org; Tue, 24 Sep 2019 09:32:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50716) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0u-0001QF-FH for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0k-0006zg-LV for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48576) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0k-0006x1-51 for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:42 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 202C818C4288 for ; Tue, 24 Sep 2019 12:33:41 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BBBE75C1B2; Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 544BF1136430; Tue, 24 Sep 2019 14:33:35 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 36/37] qapi: Fix excessive QAPISchemaEntity.check() recursion Date: Tue, 24 Sep 2019 14:33:33 +0200 Message-Id: <20190924123334.30645-37-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.62]); Tue, 24 Sep 2019 12:33:41 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Entity checking goes back to commit ac88219a6c "qapi: New QAPISchema intermediate representation", v2.5.0. It's designed to work as follows: QAPISchema.check() calls .check() for all the schema's entities. An entity's .check() recurses into another entity's .check() only if the C struct generated for the former contains the C struct generated for the latter (pointers don't count). This is used to detect "object contains itself". There are two instances of this: * An object's C struct contains its base's C struct QAPISchemaObjectType.check() calls self.base.check() * An object's C struct contains its variants' C structs QAPISchemaObjectTypeVariants().check calls v.type.check(). Since commit b807a1e1e3 "qapi: Check for QAPI collisions involving variant members", v2.6.0. Thus, only object types can participate in recursion. QAPISchemaObjectType.check() is made for that: it checks @self when called the first time, recursing into base and variants, it reports an "contains itself" error when this recursion reaches an object being checked, and does nothing it reaches an object that has been checked already. The other .check() may safely assume they get called exactly once. Sadly, this design has since eroded: * QAPISchemaCommand.check() and QAPISchemaEvent.check() call .args_type.check(). Since commit c818408e44 "qapi: Implement boxed types for commands/events", v2.7.0. Harmless, since args_type can only be an object type. * QAPISchemaEntity.check() calls ._ifcond.check() when inheriting the condition from another type. Since commit 4fca21c1b0 qapi: leave the ifcond attribute undefined until check(), v3.0.0. This makes simple union wrapper types recurse into the wrapped type (nothing else uses this condition inheritance). The .check() of types used as simple union branch type get called multiple times. * QAPISchemaObjectType.check() calls its super type's .check() *before* the conditional handling multiple calls. Also since commit 4fca21c1b0. QAPISchemaObjectType.check()'s guard against multiple checking doesn't protect QAPISchemaEntity.check(). * QAPISchemaArrayType.check() calls .element_type.check(). Also since commit 4fca21c1b0. The .check() of types used as array element types get called multiple times. Commit 56a4689582 "qapi: Fix array first used in a different module" (v4.0.0) added more code relying on this .element_type.check(). The absence of explosions suggests the .check() involved happen to be effectively idempotent. Fix the unwanted recursion anyway: * QAPISchemaCommand.check() and QAPISchemaEvent.check() calling .args_type.check() is unnecessary. Delete the calls. * Fix QAPISchemaObjectType.check() to call its super type's .check() after the conditional handling multiple calls. * A QAPISchemaEntity's .ifcond becomes valid at .check(). This is due to arrays and simple unions. Most types get ifcond and info passed to their constructor. Array types don't: they get it from their element type, which becomes known only in .element_type.check(). The implicit wrapper object types for simple union branches don't: they get it from the wrapped type, which might be an array. Ditch the idea to set .ifcond in .check(). Instead, turn it into a property and compute it on demand. Safe because it's only used after the schema has been checked. Most types simply return the ifcond passed to their constructor. Array types forward to their .element_type instead, and the wrapper types forward to the wrapped type. * A QAPISchemaEntity's .module becomes valid at .check(). This is because computing it needs info and schema.fname, and because array types get it from their element type instead. Make it a property just like .ifcond. Additionally, have QAPISchemaEntity.check() assert it gets called at most once, so the design invariant will stick this time. Neglecting that was entirely my fault. Signed-off-by: Markus Armbruster Message-Id: <20190914153506.2151-19-armbru@redhat.com> Reviewed-by: Eric Blake [Commit message tidied up] --- scripts/qapi/common.py | 74 +++++++++++++++++++++++++++++------------- 1 file changed, 52 insertions(+), 22 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index e2c87d1349..c199a2b58c 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -1155,7 +1155,7 @@ class QAPISchemaEntity(object): def __init__(self, name, info, doc, ifcond=3DNone): assert name is None or isinstance(name, str) self.name =3D name - self.module =3D None + self._module =3D None # For explicitly defined entities, info points to the (explicit) # definition. For builtins (and their arrays), info is None. # For implicitly defined entities, info points to a place that @@ -1164,21 +1164,27 @@ class QAPISchemaEntity(object): self.info =3D info self.doc =3D doc self._ifcond =3D ifcond or [] + self._checked =3D False =20 def c_name(self): return c_name(self.name) =20 def check(self, schema): - if isinstance(self._ifcond, QAPISchemaType): - # inherit the condition from a type - typ =3D self._ifcond - typ.check(schema) - self.ifcond =3D typ.ifcond - else: - self.ifcond =3D self._ifcond + assert not self._checked if self.info: - self.module =3D os.path.relpath(self.info['file'], - os.path.dirname(schema.fname)) + self._module =3D os.path.relpath(self.info['file'], + os.path.dirname(schema.fname)) + self._checked =3D True + + @property + def ifcond(self): + assert self._checked + return self._ifcond + + @property + def module(self): + assert self._checked + return self._module =20 def is_implicit(self): return not self.info @@ -1353,9 +1359,16 @@ class QAPISchemaArrayType(QAPISchemaType): QAPISchemaType.check(self, schema) self.element_type =3D schema.lookup_type(self._element_type_name) assert self.element_type - self.element_type.check(schema) - self.module =3D self.element_type.module - self.ifcond =3D self.element_type.ifcond + + @property + def ifcond(self): + assert self._checked + return self.element_type.ifcond + + @property + def module(self): + assert self._checked + return self.element_type.module =20 def is_implicit(self): return True @@ -1402,13 +1415,20 @@ class QAPISchemaObjectType(QAPISchemaType): self.features =3D features =20 def check(self, schema): - QAPISchemaType.check(self, schema) - if self.members is False: # check for cycles + # This calls another type T's .check() exactly when the C + # struct emitted by gen_object() contains that T's C struct + # (pointers don't count). + if self.members is not None: + # A previous .check() completed: nothing to do + return + if self._checked: + # Recursed: C struct contains itself raise QAPISemError(self.info, "Object %s contains itself" % self.name) - if self.members is not None: # already checked - return - self.members =3D False # mark as being checked + + QAPISchemaType.check(self, schema) + assert self._checked and self.members is None + seen =3D OrderedDict() if self._base_name: self.base =3D schema.lookup_type(self._base_name) @@ -1420,10 +1440,11 @@ class QAPISchemaObjectType(QAPISchemaType): m.check_clash(self.info, seen) if self.doc: self.doc.connect_member(m) - self.members =3D seen.values() + members =3D seen.values() + if self.variants: self.variants.check(schema, seen) - assert self.variants.tag_member in self.members + assert self.variants.tag_member in members self.variants.check_clash(self.info, seen) =20 # Features are in a name space separate from members @@ -1434,6 +1455,8 @@ class QAPISchemaObjectType(QAPISchemaType): if self.doc: self.doc.check() =20 + self.members =3D members # mark completed + # Check that the members of this type do not cause duplicate JSON memb= ers, # and update seen to track the members seen so far. Report any errors # on behalf of info, which is not necessarily self.info @@ -1442,6 +1465,15 @@ class QAPISchemaObjectType(QAPISchemaType): for m in self.members: m.check_clash(info, seen) =20 + @property + def ifcond(self): + assert self._checked + if isinstance(self._ifcond, QAPISchemaType): + # Simple union wrapper type inherits from wrapped type; + # see _make_implicit_object_type() + return self._ifcond.ifcond + return self._ifcond + def is_implicit(self): # See QAPISchema._make_implicit_object_type(), as well as # _def_predefineds() @@ -1658,7 +1690,6 @@ class QAPISchemaCommand(QAPISchemaEntity): if self._arg_type_name: self.arg_type =3D schema.lookup_type(self._arg_type_name) assert isinstance(self.arg_type, QAPISchemaObjectType) - self.arg_type.check(schema) assert not self.arg_type.variants or self.boxed elif self.boxed: raise QAPISemError(self.info, "Use of 'boxed' requires 'data'") @@ -1687,7 +1718,6 @@ class QAPISchemaEvent(QAPISchemaEntity): if self._arg_type_name: self.arg_type =3D schema.lookup_type(self._arg_type_name) assert isinstance(self.arg_type, QAPISchemaObjectType) - self.arg_type.check(schema) assert not self.arg_type.variants or self.boxed elif self.boxed: raise QAPISemError(self.info, "Use of 'boxed' requires 'data'") --=20 2.21.0 From nobody Mon May 6 14:50:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1569330676; cv=none; d=zoho.com; s=zohoarc; b=AJmj1ZGqttiQknkdOpvfmlTqdLKUymIrV9T/AkizF+p4/frBfcha0b+SHDyTX79qtwGBXXzJNszcMlsVeM1rlRwbUiphU5bcig9sWK7j3980NRJJyZ+aGH+8twoXvDwdaof/R8S1IsaTFA0Txce7cxI6hAHxOL9PmvYY5wwoKrA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569330676; h=Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=eeOlz2FjPvZ1w8UjdOkPVrlMQdE77FXoHFm64qDwzUU=; b=ckFWqGN3p9aM7dh9TSLlnB9tQajRIO+NWCHkqnb0K/8AjeqwyVwHFrPUgrgZhbtd0aCExZI0UQqvMAc3OuxLypPcdaYa1iVXqqMouMNwfJc5fUYv84BTxNmTg1zuQX4Ac6KHMRAI4/WulYY6o2JicBSaCl3cyrXVkkMiaffNp0Y= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569330676496712.5175113480602; Tue, 24 Sep 2019 06:11:16 -0700 (PDT) Received: from localhost ([::1]:45448 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCkb4-00076u-Fw for importer@patchew.org; Tue, 24 Sep 2019 09:11:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50651) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCk0r-0001Nm-NF for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCk0k-0006zs-Ne for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53444) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCk0k-0006x7-AG for qemu-devel@nongnu.org; Tue, 24 Sep 2019 08:33:42 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2A57D8A1C82 for ; Tue, 24 Sep 2019 12:33:41 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-142.ams2.redhat.com [10.36.117.142]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C7B656017E; Tue, 24 Sep 2019 12:33:40 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5A93B1136431; Tue, 24 Sep 2019 14:33:35 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 37/37] qapi: Assert .visit() and .check_clash() run only after .check() Date: Tue, 24 Sep 2019 14:33:34 +0200 Message-Id: <20190924123334.30645-38-armbru@redhat.com> In-Reply-To: <20190924123334.30645-1-armbru@redhat.com> References: <20190924123334.30645-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]); Tue, 24 Sep 2019 12:33:41 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Easy since the previous commit provides .checked. Signed-off-by: Markus Armbruster Message-Id: <20190914153506.2151-20-armbru@redhat.com> Reviewed-by: Eric Blake --- scripts/qapi/common.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index c199a2b58c..b00caacca3 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -1190,7 +1190,7 @@ class QAPISchemaEntity(object): return not self.info =20 def visit(self, visitor): - pass + assert self._checked =20 =20 class QAPISchemaVisitor(object): @@ -1245,6 +1245,7 @@ class QAPISchemaInclude(QAPISchemaEntity): self.fname =3D fname =20 def visit(self, visitor): + QAPISchemaEntity.visit(self, visitor) visitor.visit_include(self.fname, self.info) =20 =20 @@ -1309,6 +1310,7 @@ class QAPISchemaBuiltinType(QAPISchemaType): return self.json_type() =20 def visit(self, visitor): + QAPISchemaType.visit(self, visitor) visitor.visit_builtin_type(self.name, self.info, self.json_type()) =20 =20 @@ -1344,6 +1346,7 @@ class QAPISchemaEnumType(QAPISchemaType): return 'string' =20 def visit(self, visitor): + QAPISchemaType.visit(self, visitor) visitor.visit_enum_type(self.name, self.info, self.ifcond, self.members, self.prefix) =20 @@ -1386,6 +1389,7 @@ class QAPISchemaArrayType(QAPISchemaType): return 'array of ' + elt_doc_type =20 def visit(self, visitor): + QAPISchemaType.visit(self, visitor) visitor.visit_array_type(self.name, self.info, self.ifcond, self.element_type) =20 @@ -1461,6 +1465,7 @@ class QAPISchemaObjectType(QAPISchemaType): # and update seen to track the members seen so far. Report any errors # 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) @@ -1498,6 +1503,7 @@ class QAPISchemaObjectType(QAPISchemaType): return 'object' =20 def visit(self, visitor): + QAPISchemaType.visit(self, visitor) visitor.visit_object_type(self.name, self.info, self.ifcond, self.base, self.local_members, self.vari= ants, self.features) @@ -1665,6 +1671,7 @@ class QAPISchemaAlternateType(QAPISchemaType): return 'value' =20 def visit(self, visitor): + QAPISchemaType.visit(self, visitor) visitor.visit_alternate_type(self.name, self.info, self.ifcond, self.variants) =20 @@ -1698,6 +1705,7 @@ class QAPISchemaCommand(QAPISchemaEntity): assert isinstance(self.ret_type, QAPISchemaType) =20 def visit(self, visitor): + QAPISchemaEntity.visit(self, visitor) visitor.visit_command(self.name, self.info, self.ifcond, self.arg_type, self.ret_type, self.gen, self.success_response, @@ -1723,6 +1731,7 @@ class QAPISchemaEvent(QAPISchemaEntity): raise QAPISemError(self.info, "Use of 'boxed' requires 'data'") =20 def visit(self, visitor): + QAPISchemaEntity.visit(self, visitor) visitor.visit_event(self.name, self.info, self.ifcond, self.arg_type, self.boxed) =20 --=20 2.21.0