From nobody Tue Feb 10 10:59:20 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1678878887; cv=none; d=zohomail.com; s=zohoarc; b=NODkHXNRJs4JrjN6xAUfD6qCf3Xmp5DinU5XJm9CoM2cjtzuvLX0PMgnSpa6UNgUbaFvVZI/JBATLWu1X6gyGQZ7HsoLlir05qoxdkNwPbww33KtB0gLX6rBTzacxgGGGmVX/4JMbaDHZ1kByLypd/j8JFqIiJv+Oez0cxm+NIg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678878887; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hTQgFcYrB1xCmGiqUBDxS+gQ3e4QTFB6UCIQEY/7TGM=; b=bBpCJaeo9Hs5Dc+9yyJ5bHDR180EUTOxbZMN1/a5O9Uoe5swCe0q9rDMIhdErRuw9r+UUbQTkg3iZg79T9Jl1STrA2n9scUreX8kP3Fa7SmK5NnoBVKLkLHGgHkXB4QkUHkTyJApwrGMPlQJJLg1BALNdJ6Eh4ZsUDBfLcXqsbI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 167887888700478.67060020879649; Wed, 15 Mar 2023 04:14:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pcP4T-0006vb-2Q; Wed, 15 Mar 2023 07:13:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pcP4O-0006un-4x for qemu-devel@nongnu.org; Wed, 15 Mar 2023 07:13:28 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pcP4K-0005s1-OU for qemu-devel@nongnu.org; Wed, 15 Mar 2023 07:13:23 -0400 Received: by mail-wr1-x42b.google.com with SMTP id v16so16990468wrn.0 for ; Wed, 15 Mar 2023 04:13:19 -0700 (PDT) Received: from localhost.localdomain ([81.0.6.76]) by smtp.gmail.com with ESMTPSA id y7-20020adfd087000000b002c57475c375sm4392066wrh.110.2023.03.15.04.13.15 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 15 Mar 2023 04:13:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678878798; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hTQgFcYrB1xCmGiqUBDxS+gQ3e4QTFB6UCIQEY/7TGM=; b=B/IdBUaJFH2GrzCYKuva8pLi6YQp173FpK3QzJ56V+A+3N3NTLOrU/68w5K0w1M7kq N/6ai59pjs8M4aevGkGwcGIx0pNTPCQ1sONa68hVEYaPWfMIFI8jRzyECTCGN3qukwtg yIaB32/Vf2aXkWc2aaqdts8WbMkKA9UE80RStCtFWsnjU2QZhOHSngXRE43O1iYUCMHL rSOnk8X8q5+ckYxNH8K1+Rd7xHRmcEWKzJZ4P7tWm8ZSp5IjG4TDHTG1wFOhT9wHW7dE GIKEQ16zYf+0gz8sXdRG1mkp5m+nshaXjJ6SlP1y29githcrk2xBpAiXQJ5GilUPqBEF up6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678878798; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hTQgFcYrB1xCmGiqUBDxS+gQ3e4QTFB6UCIQEY/7TGM=; b=AdCizg7iKtzJFewfTqyx8ouCUbTiHODoQL3q/TK+mwe2xUwp8Xv+hRdsQCefpYcsHE +kuF742cyX9Qkrl7qoJTWQOwtkG7GzvLUb4M8SfrPGUgidVFUAZZptNixN/ph7yEH6X8 XadAqidVk6F61j4ecGWXPhGJt2Jm90Gy0fR5Bfg2Nkx37908zhEAxuUEAqta8ntTcbNf xRu0M0NODROpyZ8LZL+PO6e18aLnmmFUwobrrSEzWVCvotnkA9gEzj2cEKVNLqPHdjjL SSyCo7r0BUMfeC5HpvYW7IDM7+hHm7AulK75iddvjSEQb8OA06kXt2VSnZvu9hW3v8Uy euEg== X-Gm-Message-State: AO0yUKXR4uwKE9olfJ2ASxJmmISY8k16hyCmvLSQB9fAlKc/3QI+kS5I sxQv6w38BAtsF3JDA9mmrlOIlgV57ZzmEOzf4sLfig== X-Google-Smtp-Source: AK7set9jUqvSPcxdMEfse1S2hQ7WXvWodIrR2QFKiMCXYE4sxdC79oGR0tX7e7SccrbWv2LSGP/w9Q== X-Received: by 2002:adf:d845:0:b0:2cf:e132:bfbb with SMTP id k5-20020adfd845000000b002cfe132bfbbmr1634015wrl.38.1678878797756; Wed, 15 Mar 2023 04:13:17 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Pavel Dovgalyuk , "Dr. David Alan Gilbert" , Juan Quintela , Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Michael Roth , Markus Armbruster , Stefan Berger , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 2/3] qapi: Do not generate empty enum Date: Wed, 15 Mar 2023 12:13:03 +0100 Message-Id: <20230315111304.21692-3-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230315111304.21692-1-philmd@linaro.org> References: <20230315111304.21692-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=philmd@linaro.org; helo=mail-wr1-x42b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1678878887234100001 Per the C++ standard, empty enum are ill-formed. Do not generate them in order to avoid: In file included from qga/qga-qapi-emit-events.c:14: qga/qga-qapi-emit-events.h:20:1: error: empty enum is invalid 20 | } qga_QAPIEvent; | ^ Reported-by: Markus Armbruster Signed-off-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Stefan Berger --- docs/devel/qapi-code-gen.rst | 6 +++--- scripts/qapi/schema.py | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/devel/qapi-code-gen.rst b/docs/devel/qapi-code-gen.rst index 23e7f2fb1c..d684c7c24d 100644 --- a/docs/devel/qapi-code-gen.rst +++ b/docs/devel/qapi-code-gen.rst @@ -206,6 +206,9 @@ Syntax:: =20 Member 'enum' names the enum type. =20 +Empty enumeration (no member) does not generate anything (not even +constant PREFIX__MAX). + Each member of the 'data' array defines a value of the enumeration type. The form STRING is shorthand for :code:`{ 'name': STRING }`. The 'name' values must be be distinct. @@ -214,9 +217,6 @@ Example:: =20 { 'enum': 'MyEnum', 'data': [ 'value1', 'value2', 'value3' ] } =20 -Nothing prevents an empty enumeration, although it is probably not -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 diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 207e4d71f3..28045dbe93 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -309,6 +309,7 @@ class QAPISchemaEnumType(QAPISchemaType): =20 def __init__(self, name, info, doc, ifcond, features, members, prefix): super().__init__(name, info, doc, ifcond, features) + assert members for m in members: assert isinstance(m, QAPISchemaEnumMember) m.set_defined_in(name) @@ -1047,8 +1048,10 @@ def _make_implicit_object_type(self, name, info, ifc= ond, role, members): return name =20 def _def_enum_type(self, expr: QAPIExpression): - name =3D expr['enum'] data =3D expr['data'] + if not data: + return + name =3D expr['enum'] prefix =3D expr.get('prefix') ifcond =3D QAPISchemaIfCond(expr.get('if')) info =3D expr.info --=20 2.38.1