From nobody Sun May 5 15:59:40 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=1568406100; cv=none; d=zoho.com; s=zohoarc; b=oRSLgx7nK6ESP4Nit+Jw0sPMluA8qG6C8mx30yI13ZeApDURcGFgM2jaFNEt8X37/4AHJVifHtvfLVldiZhQOygy2CDy2uTzyWXYUw5ssd95ydkGhz8J5UkvnXjXq9jKjbYgVr+5SG7a3yCzdzVoS7MLugDB26rqfONCw07Mfaw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568406100; 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=k0efsiJc8g6vvNl19V+pz1xC7UolEHb+lku5jcY61cc=; b=I+Ai+s3KHh54wCuS+FcDUPT7D8IYn/Zx7QXMMVRHegvV4S3zEfRDkOYiy+go6KXs9yivFUgNuGxmIV8KNGCTjgRImpOa57kLMoHJQQE1WZ26wiJ31KtlGh2Hs+bScweP5VAzmdF0UqD7nIgpKHwuQtqVRcIQrsmcKIlFfrrO7MQ= 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 1568406100222390.26042323334; Fri, 13 Sep 2019 13:21:40 -0700 (PDT) Received: from localhost ([::1]:47438 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8s4X-0003TX-6m for importer@patchew.org; Fri, 13 Sep 2019 16:21:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39253) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8rx8-0005yS-9m for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:13:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8rx6-0000br-U9 for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:13:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59704) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8rx6-0000b0-MP for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:13:56 -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 EFCE450F45; Fri, 13 Sep 2019 20:13:55 +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 E76B0194BB; Fri, 13 Sep 2019 20:13:50 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 76CF011386A6; Fri, 13 Sep 2019 22:13:49 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 13 Sep 2019 22:13:34 +0200 Message-Id: <20190913201349.24332-2-armbru@redhat.com> In-Reply-To: <20190913201349.24332-1-armbru@redhat.com> References: <20190913201349.24332-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.30]); Fri, 13 Sep 2019 20:13:56 +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 Subject: [Qemu-devel] [PATCH v3 01/16] scripts/git.orderfile: Match QAPI schema more precisely 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: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com, =?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 --- 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 Sun May 5 15:59:40 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=1568405821; cv=none; d=zoho.com; s=zohoarc; b=EV6RE21IjxCLjpkIe0xUaWS2THZGcUB8WICnCAZHjnyEAYFf6jHujZMuZLYAPttYoBuNDPWKF+mDVHnIKfbj54W2+t172fA/yAQ3Ouw6p22mAu1I1hPlNUyUQj7xv4wDV0cYvG5hniWXJ8NoykgPLFI6fhhdvFEuxYdbHISaxWI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568405821; 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=H4z8QZMCbz0a7g5ZMY/X1EZDXv1Od3DCar3X6RlilYA=; b=UBO6eU8rEyb6FjHeeUMtfxPyslBJ7EKy+jdC9eJduTpX/QMvjfeKnTZphHLRf6S9wk9SJQlf8iYTYowXSGzhkM5J1JRP4mI0VVX+4ccTVY0b8q+IOkQwhJmb1dAedm1FTmPjz+vt7f0MEC67Dt6mEd8rgkCdXt6FGPq+bVcLu6g= 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 1568405821910234.62643135811425; Fri, 13 Sep 2019 13:17:01 -0700 (PDT) Received: from localhost ([::1]:47414 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8s01-0007ss-Pj for importer@patchew.org; Fri, 13 Sep 2019 16:16:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39177) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8rx5-0005xf-LB for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:13:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8rx4-0000ZP-Is for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:13:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57344) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8rx4-0000Yj-BN for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:13:54 -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 A9311315C006; Fri, 13 Sep 2019 20:13:53 +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 E99D7600C6; Fri, 13 Sep 2019 20:13:50 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 79BF711386A7; Fri, 13 Sep 2019 22:13:49 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 13 Sep 2019 22:13:35 +0200 Message-Id: <20190913201349.24332-3-armbru@redhat.com> In-Reply-To: <20190913201349.24332-1-armbru@redhat.com> References: <20190913201349.24332-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.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 13 Sep 2019 20:13:53 +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 Subject: [Qemu-devel] [PATCH v3 02/16] qapi: Drop check_type()'s redundant parameter @allow_optional 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: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com 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 --- 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 Sun May 5 15:59:40 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=1568406285; cv=none; d=zoho.com; s=zohoarc; b=WJZkH66z5txLyQ0neUHD+fMANY4UBWvpZjE4ya4nlexATJDbsLS8vgbJQ/+hHUQiJY9TmN6dejOLF55ypROpN9ogvCjbkA9t7ebZOlbydqr2ECD9jZNHXfY+OyC7J9zKBgtztnB2oDi2m1oIGxVgxozVAi8nUXtUUs7JivZPLME= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568406285; 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=5ALtjgi7qLoL9WmORJolDRzqz2N23u1JVVcOhQePMig=; b=SXCPlOIEfkOkWWgrCZE7dQwCWgrZzmTA8so1/BE4+TcU8luCx7NQmN5bkJSUDQ0d3qN06i2cL8tWyC1hpS8nxtRLPIVlcg0fxMB+nT5CBLEM0jLXaN5EjvijcpZtAqDTGiLO+J+91ZoMY0bKFoECFoNZC5pVzES4AGbUnj3lHrs= 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 156840628546474.0966686302911; Fri, 13 Sep 2019 13:24:45 -0700 (PDT) Received: from localhost ([::1]:47468 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8s7S-0007Fx-6Z for importer@patchew.org; Fri, 13 Sep 2019 16:24:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39191) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8rx6-0005xh-3v for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:13:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8rx4-0000ZZ-JO for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:13:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44976) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8rx4-0000Yh-Bk for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:13:54 -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 A899B30860C2; Fri, 13 Sep 2019 20:13:53 +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 ECD2960C57; Fri, 13 Sep 2019 20:13:50 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 7D06911385FD; Fri, 13 Sep 2019 22:13:49 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 13 Sep 2019 22:13:36 +0200 Message-Id: <20190913201349.24332-4-armbru@redhat.com> In-Reply-To: <20190913201349.24332-1-armbru@redhat.com> References: <20190913201349.24332-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.44]); Fri, 13 Sep 2019 20:13:53 +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 Subject: [Qemu-devel] [PATCH v3 03/16] qapi: Drop support for boxed alternate arguments 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: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com 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 --- 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 Sun May 5 15:59:40 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=1568405823; cv=none; d=zoho.com; s=zohoarc; b=H11FI1nBlCeYf0kUFvVi96syTp5uttI+/Ijs12uPbJ/phVTOCJZH42tGK9Xu5sPb6HgdNt7BZEJ4XQv6NtygCfxiRmpE/1CUH95PFW8BOD9B+i5cz5dy0dIFnwSNLaiUsu2aNlqx0tS+N3ytp8FblxgXwPcVFVdyJK7mFEQSInE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568405823; 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=x8J6NORIej2vaZFuwWyeZTeVKneiGsQjzAG0EljdZdA=; b=SK0T5dfiV+9diP+hg0OWPUqiTNPfnjXpViCbbTICr/UEl1pfl4CwohhXiU1l3HNZJIIxIl32bAd+JmSRjdKi28Wzjty39vmVq/rnjSUnQsakfipCie2awaTLkSR6jCu5ZTOiM1WpCHKbZ/Ht1bBkNTZ5eorKQvpGonZ5/WbGw+0= 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 1568405823319303.06890804457237; Fri, 13 Sep 2019 13:17:03 -0700 (PDT) Received: from localhost ([::1]:47412 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8s00-0007sG-SB for importer@patchew.org; Fri, 13 Sep 2019 16:16:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39195) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8rx6-0005xj-7r for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:13:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8rx4-0000Zm-QX for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:13:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36864) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8rx4-0000Yp-Ig for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:13:54 -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 DE443308FBA9; Fri, 13 Sep 2019 20:13:53 +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 F13AD5C1B5; Fri, 13 Sep 2019 20:13:50 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 8047F11385A7; Fri, 13 Sep 2019 22:13:49 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 13 Sep 2019 22:13:37 +0200 Message-Id: <20190913201349.24332-5-armbru@redhat.com> In-Reply-To: <20190913201349.24332-1-armbru@redhat.com> References: <20190913201349.24332-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.43]); Fri, 13 Sep 2019 20:13:53 +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 Subject: [Qemu-devel] [PATCH v3 04/16] docs/devel/qapi-code-gen: Minor specification fixes 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: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com 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 --- 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 Sun May 5 15:59:40 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=1568405818; cv=none; d=zoho.com; s=zohoarc; b=n59EGOhwgIulhJQL6D9SxaI3lH3rjcNdNsoHRchNIXYJD42IEmWBQ0avciEk7TcRBliHnMLIFqq6PLbwzxN6gQoOX4uz6gRSd6qXdYrv3hrpPOQO34jRpeYaDMpHyKAWU3wLF2OuJup/VNTd5JLKH0WlqWdg8GSdKpUfQZPyoNI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568405818; 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=to7WDK3bkvt+tm4d9RJZtn3irbbrt26Dw0/8cTCLBt0=; b=ZgA8F7UCLb6vRNrEzBs9owEMrirnPSmCzbcEXXgGclKhTP1oJUqpAD40+8yjtnBkbV9vVjcxkH0rlJAtj9SLsfsYelAnIYwl4gXjS4HoDy0ih2EfQ52SUX3S8Pb4lr0J+804hIzLMLdMRmK9713BQqcWk37Hp8uGOAas8jECIXA= 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 1568405818710253.73937146320372; Fri, 13 Sep 2019 13:16:58 -0700 (PDT) Received: from localhost ([::1]:47416 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8s00-0007u8-GM for importer@patchew.org; Fri, 13 Sep 2019 16:16:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39212) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8rx6-0005xl-UF for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:13:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8rx5-0000aX-Qd for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:13:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:24196) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8rx5-0000Zu-Jq for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:13:55 -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 D8A5D1DA2; Fri, 13 Sep 2019 20:13:54 +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 A841560920; Fri, 13 Sep 2019 20:13:54 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 8360811385C9; Fri, 13 Sep 2019 22:13:49 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 13 Sep 2019 22:13:38 +0200 Message-Id: <20190913201349.24332-6-armbru@redhat.com> In-Reply-To: <20190913201349.24332-1-armbru@redhat.com> References: <20190913201349.24332-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.6.2 (mx1.redhat.com [10.5.110.71]); Fri, 13 Sep 2019 20:13:54 +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 Subject: [Qemu-devel] [PATCH v3 05/16] tests/qapi-schema: Demonstrate bad reporting of funny characters 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: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com 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 --- 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 Sun May 5 15:59:40 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=1568405828; cv=none; d=zoho.com; s=zohoarc; b=bKMCJGaeKKi6CQ8NpkWr0dJSGK/Pb2ZnrDS7Y+CBqu386SuS1m0I/W8PzpzJbTXgpclRWZmHh3QmeKpUuFnypSk0yPDGAvh9EAWx6fqMP7Fza3eskla1n5F2GWNUxeeHQ1urtUqKhGhw+MpeALjH0avNYUn0funBDhwvCZz32J8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568405828; 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=idSkM9I5ewfYBeNV+35wPFaA9JlZeBqMY39AeIQgVEk=; b=Wk+mtVdbRvkNIH5no4n+pev6x87y0guNCmqLd2kFie8uS2gr0a+DCScT8IuNU0RfSKuvlTzown0ak5eLlbp7xvB8vqlWDgNUbVBBVpjuV1drROpIrhShrfTc8vi9u72IcxMZkGdWe8cN0e2I/smzKUZO+j9oOQrjwDsAsmKNvK4= 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 1568405828785376.26186985989614; Fri, 13 Sep 2019 13:17:08 -0700 (PDT) Received: from localhost ([::1]:47418 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8s0A-0007zi-GE for importer@patchew.org; Fri, 13 Sep 2019 16:17:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39239) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8rx7-0005y0-PO for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:14:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8rx5-0000aq-WF for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:13:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55560) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8rx5-0000Zy-Nl for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:13:55 -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 0E47281129; Fri, 13 Sep 2019 20:13:55 +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 AAA55600C6; Fri, 13 Sep 2019 20:13:54 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 869D711385CB; Fri, 13 Sep 2019 22:13:49 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 13 Sep 2019 22:13:39 +0200 Message-Id: <20190913201349.24332-7-armbru@redhat.com> In-Reply-To: <20190913201349.24332-1-armbru@redhat.com> References: <20190913201349.24332-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.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 13 Sep 2019 20:13:55 +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 Subject: [Qemu-devel] [PATCH v3 06/16] qapi: Restrict strings to printable ASCII 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: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com 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 --- 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 b39860a8d0..17c53bed52 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -452,6 +452,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 @@ -463,7 +465,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 Sun May 5 15:59:40 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=1568406100; cv=none; d=zoho.com; s=zohoarc; b=BA/tJbYb6zGEoTzfwKFAShoH0mcPlU3fNYcwCsK9FzYc1KXFNdXVXuy1+qOHi8H5dQYh0yiqTK/rLwQbLYn3jN6buVQqyQ1k1uhVosghlThIqhKEssFBONNauKMQQRtzvYGjK7f38K80zieaSgYGRK3hWLlirSHwYgD5l+byVHs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568406100; 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=FijRIHfi3I1LAswoIxbSbT1iFkDYmkTjEPbsV5xBi1c=; b=UohQOue/WBorpVKuhN38D/OhVT/Ik+t6YlLF9Q64hNe9PmEh1QfJFLpPxc8aya5o3f6YV5p43hPwc0Mfh6oyHSF14KXzoOwafkHCKv55S5kRxbRFm1C5Be+T3KrVCENn0gflE+qHyO3W2Dy8rzaYqbpuvS85b+FhKpF37iqVvos= 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 1568406100577730.5014303603585; Fri, 13 Sep 2019 13:21:40 -0700 (PDT) Received: from localhost ([::1]:47440 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8s4X-0003Ut-SX for importer@patchew.org; Fri, 13 Sep 2019 16:21:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39264) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8rx8-0005yU-NN for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:14:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8rx6-0000bI-Ca for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:13:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40286) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8rx6-0000a9-2Q for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:13:56 -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 4B567806A46; Fri, 13 Sep 2019 20:13:55 +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 E5AF15C1B5; Fri, 13 Sep 2019 20:13:54 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 89E561138528; Fri, 13 Sep 2019 22:13:49 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 13 Sep 2019 22:13:40 +0200 Message-Id: <20190913201349.24332-8-armbru@redhat.com> In-Reply-To: <20190913201349.24332-1-armbru@redhat.com> References: <20190913201349.24332-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]); Fri, 13 Sep 2019 20:13:55 +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 Subject: [Qemu-devel] [PATCH v3 07/16] qapi: Drop support for escape sequences other than \\ 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: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com 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 --- 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 17c53bed52..023a4e4789 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -375,9 +375,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 Sun May 5 15:59:40 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=1568406553; cv=none; d=zoho.com; s=zohoarc; b=fcqF+qZrtviG3xaa2Y90j/yfWhEwJd4TivzuIiAZbk1kvE31aHseYMYYYCT6MYVsBJY+32Y3+3rVSuAcmUS11EuvVKR2IFrBlpialo204t+SCmPTVcP1Kwe4FPOuKQRdxzlOLEIA36D2pVLqnnsWnx8UPMwvtny/LK3c3798rbw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568406553; 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=Et35Umgmwsg5vRRKcu5lEWvPjXSRgol+T3oI0p1IdzA=; b=X+yQjfBr0lZzw2WFHQetYAjq/qvvbRJ+QswOoghUGuzX8L44dNqw3ETR61IXNVRKcz+R6+Q58I4xCcV5YVVu1Mj39LTux+qMmU0oUpcrSSi33lXkERfojFvN9d5bR3E9KVEfufH57HW8LTMTqjp+Lyy5sHNmWvX2SJqMqPFvcTY= 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 1568406553614191.93186700319598; Fri, 13 Sep 2019 13:29:13 -0700 (PDT) Received: from localhost ([::1]:47500 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8sBs-0002tV-5h for importer@patchew.org; Fri, 13 Sep 2019 16:29:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39263) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8rx8-0005yT-Mg for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:14:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8rx6-0000bC-C2 for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:13:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41808) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8rx6-0000aA-20 for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:13:56 -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 4D346C05683F; Fri, 13 Sep 2019 20:13:55 +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 E6B42600CE; Fri, 13 Sep 2019 20:13:54 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 8D4AA11384A9; Fri, 13 Sep 2019 22:13:49 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 13 Sep 2019 22:13:41 +0200 Message-Id: <20190913201349.24332-9-armbru@redhat.com> In-Reply-To: <20190913201349.24332-1-armbru@redhat.com> References: <20190913201349.24332-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.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 13 Sep 2019 20:13:55 +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 Subject: [Qemu-devel] [PATCH v3 08/16] qapi: Permit 'boxed' with empty type 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: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com 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 --- 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 023a4e4789..52caeb705e 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -312,7 +312,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 Sun May 5 15:59:40 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=1568406550; cv=none; d=zoho.com; s=zohoarc; b=LBtNqh/D0b5rsOlW2bHBt9MKlY6XZ+jG7MI7k32/Ds2LAHuaiO71ZxeC8040d3KltcxF9pYiIYySu2wuSgwhEkLqRpQShx1uDY/pX3OGDO4lxxqCx3d/ln6fYyGn9t3k4uP2qOAeoJN7gHDhaamunNmD7YJr+Btr9cz/kx8WqOw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568406550; 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=p41iFx7sh006WDKwS1WhlhW7qFIr8VdnA1tq5Rd1oV4=; b=C0Xq3bs8datiUFa8Km3cVq4zKJQk1CsDChQcIU6c3lxa9pphhHVUWF6iw9O5LTiGaF16CYjzyTf0keNiY7f4qSnox3K6cUeTkm628B0QoQEQaGurSf1RT3FQ7UNw1SZElokm/81w0eaZYN1G9UjDKj22X1UbJ6y9vK3SLEHlRWk= 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 1568406550506208.9490391667547; Fri, 13 Sep 2019 13:29:10 -0700 (PDT) Received: from localhost ([::1]:47498 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8sBo-0002oa-Pz for importer@patchew.org; Fri, 13 Sep 2019 16:29:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39307) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8rxA-00061N-WB for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:14:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8rx8-0000ev-P9 for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:14:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44874) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8rx8-0000cY-ET for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:13:58 -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 802B118C8929; Fri, 13 Sep 2019 20:13:57 +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 E8F395D717; Fri, 13 Sep 2019 20:13:54 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 9095C11384D8; Fri, 13 Sep 2019 22:13:49 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 13 Sep 2019 22:13:42 +0200 Message-Id: <20190913201349.24332-10-armbru@redhat.com> In-Reply-To: <20190913201349.24332-1-armbru@redhat.com> References: <20190913201349.24332-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.70]); Fri, 13 Sep 2019 20:13:57 +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 Subject: [Qemu-devel] [PATCH v3 09/16] qapi: Permit alternates with just one branch 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: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com 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 --- 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 Sun May 5 15:59:40 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=1568406549; cv=none; d=zoho.com; s=zohoarc; b=YmzQGhL680PATgWwCy3LXjbV1eRe/LNTQuSIV9D34igcrPb+lTCgwzi+LkViWLmlSyUiCQMmWrKI4VRE+J7WipI4BIgr0jouCA8SiPm8gGYY85nfcjrIGG8qXbnQ44kMJUVJ/P+a5GZtY1YRIzJWxED/V5QTtKD2vlM8F5k2hgk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568406549; 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=XK/oO6Xan1B68AI8EWfUfWtSGAnyC2O4Pn8hhw9Sohk=; b=crIABCVZU5k4Yuqbq5c2cPn71xBF+pmVGF/qPVo5sfHIahMWw+OXiqbz/kVR0enAJoHYRhWiA7tv60DqAKpHXCzVpqy+1XCiCsrp2EbRWTYuuOH2YCdDhysXKJ4YbCFoBPDZoS8sWsjYAYjKPx8CsB9EQ0PR6TLLx4BbhZGH5f4= 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 1568406549939482.1073018159648; Fri, 13 Sep 2019 13:29:09 -0700 (PDT) Received: from localhost ([::1]:47496 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8sBo-0002lW-2g for importer@patchew.org; Fri, 13 Sep 2019 16:29:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39324) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8rxB-00061t-9t for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:14:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8rx8-0000f1-Qj for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:14:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41496) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8rx8-0000cW-EE for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:13:58 -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 8139130A5A54; Fri, 13 Sep 2019 20:13:57 +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 ED12A5D71C; Fri, 13 Sep 2019 20:13:54 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 93DD71138406; Fri, 13 Sep 2019 22:13:49 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 13 Sep 2019 22:13:43 +0200 Message-Id: <20190913201349.24332-11-armbru@redhat.com> In-Reply-To: <20190913201349.24332-1-armbru@redhat.com> References: <20190913201349.24332-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.47]); Fri, 13 Sep 2019 20:13:57 +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 Subject: [Qemu-devel] [PATCH v3 10/16] qapi: Permit omitting all flat union branches 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: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com 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 am 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 --- 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 Sun May 5 15:59:40 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=1568406105; cv=none; d=zoho.com; s=zohoarc; b=RszWhkUyRKuTR+LVHoENtrdVjIqx8vnB1t51pJHCfyS9jDoAPeKGCzP0MwBNrf9TLmmUL9Ok0Ci9dHPbzjoiw60hXXLsQs0xIVS5eOVs96txafRoM021f+7rNOIolF9qpsXhVjAvT4N/tFJbh6SaoSVw7ZQfueypR19wssawlYM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568406105; 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=gNMmEda7IN3yraYqZVPeTcqn0YbLQAVXCOOlWGq4qaA=; b=GIsqphdsksFAHCIlDo5tSKO+GwKSSiNtmCMUTlMronztxuL2Y7bOsa/dU0+tUZ+ZNN7k3aoySrznZvg/DJ3keDsLzDGrsP4IlBpvXlnSzHgUEFWotD7JO77vmrnv7heGgdZGtMV9b6dxyIPaWNYspuTuTNeSc4cJ/yYljoHgNI8= 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 1568406105521724.29757785282; Fri, 13 Sep 2019 13:21:45 -0700 (PDT) Received: from localhost ([::1]:47442 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8s4d-0003fM-SE for importer@patchew.org; Fri, 13 Sep 2019 16:21:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39312) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8rxA-00061S-VQ for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:14:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8rx8-0000fC-Sk for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:14:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42140) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8rx8-0000d2-IS for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:13:58 -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 CD41B10F2E82; Fri, 13 Sep 2019 20:13:57 +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 2764910018F9; Fri, 13 Sep 2019 20:13:55 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 97AF11138408; Fri, 13 Sep 2019 22:13:49 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 13 Sep 2019 22:13:44 +0200 Message-Id: <20190913201349.24332-12-armbru@redhat.com> In-Reply-To: <20190913201349.24332-1-armbru@redhat.com> References: <20190913201349.24332-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.6.2 (mx1.redhat.com [10.5.110.66]); Fri, 13 Sep 2019 20:13:57 +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 Subject: [Qemu-devel] [PATCH v3 11/16] qapi: Adjust frontend errors to say enum value, not member 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: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com 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 --- 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 Sun May 5 15:59:40 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=1568406923; cv=none; d=zoho.com; s=zohoarc; b=O/SBjvGzZYSjsVX9HtZplbSgcO4ZSJ4wBD6EWYr6FgP6Dc5HXz6NFHyhzXibXOuXScsFTgIJDkNdtY5yhy3eYPY3LB+Y1b3H8hwnI4jcJCIdohwSF00VhfFohfdE748u37+6LNG8NgJh5h7ZO4F+SHFHmB30q7akkIqcpCCbYqQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568406923; 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=MvbC+TPhbgVRn9nxQ4R6i7IucDgHSURd8SoMBOE4Ke0=; b=leDZCyB1O0jIBTh4ClCzQ2SZ54F6bDTiU561LNAyMGqnNW7XZzxLMPqNEqt6e0RbsKnVtXviJ45URiWBpSv9Y0sHa64xLnWh6Vk8++aqS6uQkD5uSWZiiUsIDg/NdLlQEXdQnuHlVEjNrGnZ/QMko39VlfYBgP3iJ6puVlO7Vuk= 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 1568406923796393.25943355490904; Fri, 13 Sep 2019 13:35:23 -0700 (PDT) Received: from localhost ([::1]:47568 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8sHn-000087-D6 for importer@patchew.org; Fri, 13 Sep 2019 16:35:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39306) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8rxB-00061M-0c for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:14:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8rx6-0000bb-NL for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:14:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60826) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8rx6-0000aj-Di for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:13:56 -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 B179D793ED; Fri, 13 Sep 2019 20:13:55 +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 30B6E600C6; Fri, 13 Sep 2019 20:13:55 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 9B1EB1136445; Fri, 13 Sep 2019 22:13:49 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 13 Sep 2019 22:13:45 +0200 Message-Id: <20190913201349.24332-13-armbru@redhat.com> In-Reply-To: <20190913201349.24332-1-armbru@redhat.com> References: <20190913201349.24332-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.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 13 Sep 2019 20:13:55 +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 Subject: [Qemu-devel] [PATCH v3 12/16] docs/devel/qapi-code-gen: Reorder sections for readability 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: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com 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 --- 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 Sun May 5 15:59:40 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=1568406286; cv=none; d=zoho.com; s=zohoarc; b=MUUlhWAoN+aPiSWcUKnhna1thWQn7LnT96KZWF55fLd/G0nV+smwpGOXYgem+Y3emxIf2d8EOfD5lCY//h8/bst9+WLfi6OcdwF46K1BT8eaUkE/S27H8Kt0m61PI46zKDVhPAOFy0HbsOt/mbKZmJ3lW1E6Cmbfkojy2r8k1GI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568406286; 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=wtNzumvr52mNFUkEwgkpuMwkO9JG1iuxmjAUhGNtDdI=; b=Bo95mDXt04Lxrj94OxKfb+A/QEjF0DJPXcTsrVvGPWiCTxjMkq7T5Za8fFYRlM03y+Weadpv1rQFeNf8KoqK+N05q41vUw5W6msglrFxq78mA2R4Gar8rTL80XC6SBB4DY3TIwqG/3XcUcqLqwdzPvEAOJp8m7OO0LUcouSSgMU= 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 1568406286167354.87120949484745; Fri, 13 Sep 2019 13:24:46 -0700 (PDT) Received: from localhost ([::1]:47472 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8s7Y-0007QN-Dy for importer@patchew.org; Fri, 13 Sep 2019 16:24:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39276) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8rx9-0005zB-KC for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:14:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8rx7-0000cI-GX for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:13:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36872) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8rx7-0000bQ-6K for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:13:57 -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 79B01308FBFC; Fri, 13 Sep 2019 20:13:56 +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 201374510; Fri, 13 Sep 2019 20:13:56 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 9E4281136447; Fri, 13 Sep 2019 22:13:49 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 13 Sep 2019 22:13:46 +0200 Message-Id: <20190913201349.24332-14-armbru@redhat.com> In-Reply-To: <20190913201349.24332-1-armbru@redhat.com> References: <20190913201349.24332-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.43]); Fri, 13 Sep 2019 20:13:56 +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 Subject: [Qemu-devel] [PATCH v3 13/16] docs/devel/qapi-code-gen: Rewrite compatibility considerations 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: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com 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 --- docs/devel/qapi-code-gen.txt | 95 +++++++++++++++++++++++------------- 1 file changed, 60 insertions(+), 35 deletions(-) diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt index 663ef10a56..2406e1bdbc 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,62 @@ 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. + + =3D=3D Code generation =3D=3D =20 The QAPI code generator qapi-gen.py generates code and documentation --=20 2.21.0 From nobody Sun May 5 15:59:40 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=1568406285; cv=none; d=zoho.com; s=zohoarc; b=cKuyKMDECAZRczc14EqGo5oS/E7In0MYg1ObRgeiAixqAhDitXjoW0YNpCL+6/ajCru8EOa48tkzEU8R3sQ1sWCYs/Zh0znLuLOQCqTIgZaHmMJnqLrxSVgrYuBaozHcbGhauNgECNsv2P+nIvz/SBuH4CHnKy7GiJgJpJE1xRw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568406285; 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=C+srGiBbscAX62dC16gLITBrezdaaBkDQJvnfJ0NsEo=; b=ISTVI17ddWmlCjrz5Ha+YNMYt9UsBBwrs5k2uzQmGN7ZzAzeU4o3jVO41kpJoZCe+kMQMI01bjEdLnzuu4/8vhEhqcLMuYVFZ6srs7EwA3XYLNTkXw8uPjIC/vnacJLBXC0UV5nDih9IhxhmxDtfVz94mUXpR4D/Eu0+5fm1NGA= 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 1568406285542737.1146604132414; Fri, 13 Sep 2019 13:24:45 -0700 (PDT) Received: from localhost ([::1]:47470 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8s7S-0007HK-P0 for importer@patchew.org; Fri, 13 Sep 2019 16:24:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39301) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8rxA-000619-P2 for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:14:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8rx7-0000cQ-IL for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:14:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42136) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8rx7-0000bX-8n for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:13:57 -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 7DAF210F2E81; Fri, 13 Sep 2019 20:13:56 +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 2539A194BB; Fri, 13 Sep 2019 20:13:56 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id A16D11136448; Fri, 13 Sep 2019 22:13:49 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 13 Sep 2019 22:13:47 +0200 Message-Id: <20190913201349.24332-15-armbru@redhat.com> In-Reply-To: <20190913201349.24332-1-armbru@redhat.com> References: <20190913201349.24332-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.66]); Fri, 13 Sep 2019 20:13:56 +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 Subject: [Qemu-devel] [PATCH v3 14/16] docs/devel/qapi-code-gen: Rewrite introduction to schema 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: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com 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 --- 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 2406e1bdbc..e75d680f6e 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 Sun May 5 15:59:40 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=1568406300; cv=none; d=zoho.com; s=zohoarc; b=ZbA/YfcCO0qq8i1YW+DVD1F6DQmN5GjdiSc5HMHWYxLNAR0KHO/weNb8wlskPyqgfjjyNEAyWHX1oMOtwRZ7PtMQJuWq3yPsgPCdtXZAPqhOLwr2kL77Ags4gGNC0GBTha3Eig2I60oKrjoaymAW/cj0C+B3p7Mrc7enL/dHXOc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568406300; 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=rKhWnbJE324w9cUYR3ALaU3oJOI5mv2XmJnSrco9v7E=; b=FG/FtuTI5U/K/sL3Fft7aQZEoVC5QuUuveko1VqhNeErmBWaek6kLEvsLrcf602GYA60bTXGyMEo2wbEKSvGJjYtf17902V/bvlC3J87xERzbKah2h+nnmey3isOLjXqZLhZj3s8a2sGuCwMYQKmQ3tLIHBCQZVFDNetswqLW68= 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 1568406300063658.8751445935713; Fri, 13 Sep 2019 13:25:00 -0700 (PDT) Received: from localhost ([::1]:47474 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8s7h-0007bk-UX for importer@patchew.org; Fri, 13 Sep 2019 16:24:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39363) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8rxE-00068i-Tb for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:14:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8rx8-0000dR-F8 for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:14:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60922) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8rx7-0000c9-Tt for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:13:58 -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 235EDC057867; Fri, 13 Sep 2019 20:13:57 +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 4ADC7600C6; Fri, 13 Sep 2019 20:13:56 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id A5335113306C; Fri, 13 Sep 2019 22:13:49 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 13 Sep 2019 22:13:48 +0200 Message-Id: <20190913201349.24332-16-armbru@redhat.com> In-Reply-To: <20190913201349.24332-1-armbru@redhat.com> References: <20190913201349.24332-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.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 13 Sep 2019 20:13:57 +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 Subject: [Qemu-devel] [PATCH v3 15/16] docs/devel/qapi-code-gen: Improve QAPI schema language doc 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: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com 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 --- 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 e75d680f6e..94f3054898 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 Sun May 5 15:59:40 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=1568406799; cv=none; d=zoho.com; s=zohoarc; b=mV6K8pP4xWnYGOv+QNEEdXFxxt4LHZZj7VB4y+BdXc9Ox6vLVUxVNVsM138kuJjgipAUf5iAuPUoZore5IEgjUZCbwhDT2kRXSFwjnqfMfzmUgr8akM/30qzYUY08Xqo4H3kMad1KcUrZ84qfoKKhqUqL+HhxKDyDAKb9GE1x2Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568406799; 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=ZEgzVy6VCEP6BEB/hKZtvW1O3nmcjRFeSCShMUfihkA=; b=jVBDBwy2c6PI7ch23qhvyRXL8NaQB9w7tRYF0FYYdxcsxh/TBbLVSYGu131i4a6+j0QlFZ9Mc3HK6FE9YEYfhI91q3bVGD2R2BFM+65Q3ewjZZYI1QsQxOzYZSBUxXEMzdj4VU3pcS4gERu7xZuml4xevGybQU5St/J9AKpxpUg= 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 1568406799477184.19834012118986; Fri, 13 Sep 2019 13:33:19 -0700 (PDT) Received: from localhost ([::1]:47534 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8sFp-0006KL-Ce for importer@patchew.org; Fri, 13 Sep 2019 16:33:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39328) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8rxB-000627-Ik for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:14:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8rx7-0000cm-Ob for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:14:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:11464) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8rx7-0000bi-E4 for qemu-devel@nongnu.org; Fri, 13 Sep 2019 16:13:57 -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 A987330860C2; Fri, 13 Sep 2019 20:13:56 +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 530DA60C57; Fri, 13 Sep 2019 20:13:56 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id A92381133070; Fri, 13 Sep 2019 22:13:49 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 13 Sep 2019 22:13:49 +0200 Message-Id: <20190913201349.24332-17-armbru@redhat.com> In-Reply-To: <20190913201349.24332-1-armbru@redhat.com> References: <20190913201349.24332-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.44]); Fri, 13 Sep 2019 20:13:56 +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 Subject: [Qemu-devel] [PATCH v3 16/16] qapi: Tweak code to match docs/devel/qapi-code-gen.txt 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: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com 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 --- 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