From nobody Sun Jul 26 10:08:35 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1784898096; cv=none; d=zohomail.com; s=zohoarc; b=DDSHCbYmpr+nGzEybYQfEeGtWP8r2Vd3t//cOOgf/LfU+T2L5jRe3KIJ/C4Nkk8LOzgjvyJtIf/PJQ5wZ4FVQ0pLuUygN4k7ub116ZkBgir0yK/GKDRk2+4Hh27ha5wb/QQBeDDjEIT162MuEWDHLBYnlSg1aUkzbo08l5ihRtI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784898096; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=xX7A7nyNxFP073ud26/uwemwUIjt9lbN+6fG2uf9t7U=; b=RD3SMkPZnlRczbNOG3cRudmEcYzW+UqePmd6eOBSLz/ZCpzRQ12T8vY2SzrApZz+0LD8OSOTvQnY2QChb3jkXjvOx4D8WnHrOtsvDEtFqW7v9Wtz8nWfP1cy9PxwFOV3tWg1lCu0FYol9BvZ63oen3g9eQh0WDR1TCx5WA4a8DY= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784898096664531.7999188299183; Fri, 24 Jul 2026 06:01:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wnFWN-0002YJ-8v; Fri, 24 Jul 2026 09:00:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wnFWL-0002RU-CL for qemu-devel@nongnu.org; Fri, 24 Jul 2026 09:00:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wnFWH-0002cd-NA for qemu-devel@nongnu.org; Fri, 24 Jul 2026 09:00:56 -0400 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-355-F-yzVrzxMeSPyBSFiR2vrw-1; Fri, 24 Jul 2026 09:00:50 -0400 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-474170b59dfso351031f8f.3 for ; Fri, 24 Jul 2026 06:00:49 -0700 (PDT) Received: from [192.168.10.48] ([151.49.94.110]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47f85c67339sm25550692f8f.31.2026.07.24.06.00.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jul 2026 06:00:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784898051; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xX7A7nyNxFP073ud26/uwemwUIjt9lbN+6fG2uf9t7U=; b=dK1u0qTlg/b0GUxczaRmZvgmaVyMX7T3xsJ5wc+aCwS49h1tWIkcnyrm2x3u7hJKtb29/q CA6EKxayh3cBPhYJEIBv78ru5KcNbPrMGTzYe3e7vz+Rts2HgCX3r/XJX2Be37uqoK9oex EkNVcpHYhuoink0fdFYoAe912bmyvos= X-MC-Unique: F-yzVrzxMeSPyBSFiR2vrw-1 X-Mimecast-MFC-AGG-ID: F-yzVrzxMeSPyBSFiR2vrw_1784898049 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1784898049; x=1785502849; darn=nongnu.org; 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:content-type; bh=xX7A7nyNxFP073ud26/uwemwUIjt9lbN+6fG2uf9t7U=; b=E9/7tRHuO1n9cD11U794SOnkhnccRFzMwTpkeYVTleEFpN+eDn0g2TkeNrmWtFBfLS /nHCm6VGZsrLmIKd8utVK60LMyLWwXz2PF3DfaDFfJ6iicBtsEtKEn34+LmXEMBcPGJK Wy9vYGDcwoijeaQR8mHxF11PWfcO5+iLAV7KPFYz4AchLAOoBIS3EQuyWMFkJ8LWIezS OCbf2HJNv8gqToZUNAgnbKvRz66fN4Yqw44ksrpott2qintHTtHQjdi3Wv8xl7vIojvs nui+L36ryeeaPoreg5SIVlybVjQYtnnJFBcTzXFfVEj/P4dFHlrtMcVteHxj/8S6UJjm pmcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784898049; x=1785502849; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=xX7A7nyNxFP073ud26/uwemwUIjt9lbN+6fG2uf9t7U=; b=LBnhu1w2x9FV0bo3mYeJ0V05n/x1dbojFu9vlGoqyp7BI14mOp1drbqtQ1MmCcettb jvZ6PW6Dlx/MAxPzmsCsCzjsv8Trca6YrmnWxEOnGDpeznv8KVoBC5+P0DAWtrMlCmDU mDr6STvgzKW52UwI37dVILzP/J3YvsOGcseXCEut+09YjOr0fny8KVKq1AUygIwINnZJ at/LCoOSl2prByjvus5cDk57P4VK6gogAx/SA/0llj3KRDNuteVaPfgkvrwCPdNvWjqW PHM22hYtyViIGZNyv3LsZ3tHWtNakMWvJrMsHeaCrBDqmd0LD91aQ28QDtboRJo+yP1B gwrg== X-Gm-Message-State: AOJu0Yz6mia8geDMp/RhxPrVhZ3E7ISUe2UHzBg0WdUg0cjT1w6SDQ/h +qzcgzyKc9B/6WYHEyBTQoCb4i23W1A5li9u6KFWdaEUj5WNVjHe+DqAuav/VXRTEXydJXf+nw1 5NKlntuxaoEFQpyh1nkWVlTbxNmCgjHAcaoCR7U0X09EQDJl+CEL3zM6oqFMlZrNDKnz9mRcGhg dRb5Z5e/Ev62yKrZmDhA/u1EkqxfL9iccJwN+hVtIJ X-Gm-Gg: AR+sD13vPz095jRPd/IlwwUCoKcLZiU7cobxKhPRzUklWilZYbijnnyKfKJwm1XDaEp BKELPodggt6KkllCJLLVjpqgv9hLwPycknZb7C2Q0SUVsJYkdhS7pG3REE33O/Rvpl5/xzGZraX nYtz8BUjQXJlx6SY/qDcm4ZWANE7jFR33YSlHtQeZsS24lD0tpaJKeNiyKWC/8pMfglMqYup6Ie dNCSqf3hgwCAL1JO71st6irJ6HYfAn+QLS+hLQGGIb+x9xO/xgzlqAlWCj/wUzvyXVmJS2MI4Wv 5N73QdgmiQea8GOrYgQ7R6rrlnyTq/1gU4n9Ta6u5owWdsiCJ1wVvx2rmvKOAWsyjNEKVrGSetJ 45IbbJFWZ/vWaK0ar/IZRn7rAnZExxxjq5VEDODie/XNW2l9C0+rfnuSqJ3kNpSgCZgYpTQSLxg s0NlKA X-Received: by 2002:a05:6000:983:b0:47f:89cd:b48 with SMTP id ffacd0b85a97d-47f8d76de31mr9288738f8f.5.1784898048698; Fri, 24 Jul 2026 06:00:48 -0700 (PDT) X-Received: by 2002:a05:6000:983:b0:47f:89cd:b48 with SMTP id ffacd0b85a97d-47f8d76de31mr9288664f8f.5.1784898048136; Fri, 24 Jul 2026 06:00:48 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: armbru@redhat.com Subject: [PATCH 1/3] scripts/qapi: enum with conditional first item must be optional Date: Fri, 24 Jul 2026 15:00:41 +0200 Message-ID: <20260724130044.1369843-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260724130044.1369843-1-pbonzini@redhat.com> References: <20260724130044.1369843-1-pbonzini@redhat.com> MIME-Version: 1.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.419, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1784898099989158501 Content-Type: text/plain; charset="utf-8" Prevent an all-zero struct from having different meanings with different configurations or builds of QEMU. This needs some changes to doc-good.json, which used unwittingly such an enum. Signed-off-by: Paolo Bonzini --- scripts/qapi/schema.py | 8 ++++++++ tests/qapi-schema/doc-good.json | 16 ++++++++-------- tests/qapi-schema/doc-good.out | 12 ++++++------ tests/qapi-schema/doc-good.txt | 8 ++++---- tests/qapi-schema/enum-if-first-required.err | 2 ++ tests/qapi-schema/enum-if-first-required.json | 6 ++++++ tests/qapi-schema/enum-if-first-required.out | 0 tests/qapi-schema/meson.build | 1 + 8 files changed, 35 insertions(+), 18 deletions(-) create mode 100644 tests/qapi-schema/enum-if-first-required.err create mode 100644 tests/qapi-schema/enum-if-first-required.json create mode 100644 tests/qapi-schema/enum-if-first-required.out diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 8d88b40de2e..71296b15de2 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -963,6 +963,14 @@ def check(self, schema: QAPISchema) -> None: assert self.defined_in self.type =3D schema.resolve_type(self._type_name, self.info, self.describe) + if (not self.optional + and isinstance(self.type, QAPISchemaEnumType) + and self.type.members[0].ifcond.is_present()): + raise QAPISemError( + self.info, + "enum type '%s' of %s has a conditional first value" + " and must be optional" + % (self.type.name, self.describe(self.info))) seen: Dict[str, QAPISchemaMember] =3D {} for f in self.features: f.check_clash(self.info, seen) diff --git a/tests/qapi-schema/doc-good.json b/tests/qapi-schema/doc-good.j= son index fac13425b72..76521ffe9e6 100644 --- a/tests/qapi-schema/doc-good.json +++ b/tests/qapi-schema/doc-good.json @@ -73,12 +73,12 @@ # @enum-feat: Also _one_ {and only} # @enum-member-feat: a member feature # -# @two is undocumented +# @zero is undocumented ## { 'enum': 'Enum', - 'data': [ { 'name': 'one', 'if': 'IFONE', - 'features': [ 'enum-member-feat' ] }, - 'two' ], + 'data': [ 'zero', + { 'name': 'one', 'if': 'IFONE', + 'features': [ 'enum-member-feat' ] } ], 'features': [ 'enum-feat' ], 'if': 'IFCOND' } =20 @@ -112,10 +112,10 @@ 'if': 'IFSTR' } } } =20 ## -# @Variant2: +# @Variant0: # ## -{ 'struct': 'Variant2', 'data': {} } +{ 'struct': 'Variant0', 'data': {} } =20 ## # @Object: @@ -128,8 +128,8 @@ 'base': 'Base', 'discriminator': 'base1', 'data': { 'one': 'Variant1', - 'two': { 'type': 'Variant2', - 'if': { 'any': ['IFONE', 'IFTWO'] } } } } + 'zero': { 'type': 'Variant0', + 'if': { 'any': ['IFONE', 'IFTWO'] } } } } =20 ## # @Alternate: diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out index 371dd25ffc7..2782f6b57d9 100644 --- a/tests/qapi-schema/doc-good.out +++ b/tests/qapi-schema/doc-good.out @@ -10,10 +10,10 @@ enum QType member qbool module doc-good.json enum Enum + member zero member one if IFONE feature enum-member-feat - member two if IFCOND feature enum-feat object Base @@ -24,12 +24,12 @@ object Variant1 if IFSTR feature member-feat feature variant1-feat -object Variant2 +object Variant0 object Object base Base tag base1 case one: Variant1 - case two: Variant2 + case zero: Variant0 if {'any': ['IFONE', 'IFTWO']} feature union-feat1 alternate Alternate @@ -110,14 +110,14 @@ doc symbol=3DEnum =20 Member=3Done The _one_ {and only}, description on the same line - Member=3Dtwo + Member=3Dzero =20 Feature=3Denum-feat Also _one_ {and only} Feature=3Denum-member-feat a member feature Plain -@two is undocumented +@zero is undocumented doc symbol=3DBase Intro =20 @@ -139,7 +139,7 @@ Another paragraph a feature Feature=3Dmember-feat a member feature -doc symbol=3DVariant2 +doc symbol=3DVariant0 Intro =20 doc symbol=3DObject diff --git a/tests/qapi-schema/doc-good.txt b/tests/qapi-schema/doc-good.txt index 74b73681d32..922a61dcf23 100644 --- a/tests/qapi-schema/doc-good.txt +++ b/tests/qapi-schema/doc-good.txt @@ -43,14 +43,14 @@ Enum Enum Values: * **one** -- The _one_ {and only}, description on the same line =20 - * **two** -- Not documented + * **zero** -- Not documented =20 Features: * **enum-feat** -- Also _one_ {and only} =20 * **enum-member-feat** -- a member feature =20 - "two" is undocumented + "zero" is undocumented =20 Object Base *Availability*: "IFALL1 and IFALL2" @@ -75,7 +75,7 @@ Object Variant1 =20 * **member-feat** -- a member feature =20 -Object Variant2 +Object Variant0 =20 Object Object =20 @@ -84,7 +84,7 @@ Object Object =20 * When "base1" is "one": The members of "Variant1". =20 - * When "base1" is "two": The members of "Variant2". + * When "base1" is "zero": The members of "Variant0". =20 Features: * **union-feat1** -- a feature diff --git a/tests/qapi-schema/enum-if-first-required.err b/tests/qapi-sche= ma/enum-if-first-required.err new file mode 100644 index 00000000000..6d8bdcf2507 --- /dev/null +++ b/tests/qapi-schema/enum-if-first-required.err @@ -0,0 +1,2 @@ +enum-if-first-required.json: In struct 'TestStruct': +enum-if-first-required.json:5: enum type 'TestEnum' of member 'field' has = a conditional first value and must be optional diff --git a/tests/qapi-schema/enum-if-first-required.json b/tests/qapi-sch= ema/enum-if-first-required.json new file mode 100644 index 00000000000..1769b5fdef9 --- /dev/null +++ b/tests/qapi-schema/enum-if-first-required.json @@ -0,0 +1,6 @@ +# Enum with conditional first value cannot be used in required fields +{ 'enum': 'TestEnum', + 'data': [ { 'name': 'member1', 'if': 'CONFIG_FOO' }, + 'member2' ] } +{ 'struct': 'TestStruct', + 'data': { 'field': 'TestEnum' } } diff --git a/tests/qapi-schema/enum-if-first-required.out b/tests/qapi-sche= ma/enum-if-first-required.out new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/qapi-schema/meson.build b/tests/qapi-schema/meson.build index debff633ac1..3b0c16a8b67 100644 --- a/tests/qapi-schema/meson.build +++ b/tests/qapi-schema/meson.build @@ -97,6 +97,7 @@ schemas =3D [ 'enum-bad-prefix.json', 'enum-clash-member.json', 'enum-dict-member-unknown.json', + 'enum-if-first-required.json', 'enum-if-invalid.json', 'enum-int-member.json', 'enum-member-case.json', --=20 2.55.0 From nobody Sun Jul 26 10:08:35 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1784898119; cv=none; d=zohomail.com; s=zohoarc; b=F5L+NKj6d1Byr6OeX+I+9keqfNlVf9XtxbuL11HIwUcibY0pD4ipKmVDKLZvI2XJdFOHhNElpUwc/0+cKpipD5m1t9OZnFy5IKke1YPd0RXRNCuSSeH2XzWY8lXxVRfTVjQSVdVDOYgSHzxYTeY/zuEcb2/UNMkt45Y5x0tBWnA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784898119; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Am04rAViHBWH56STMMt95NmhR4rS6t7b5I/fYOQuq1I=; b=c2HCOxPFkp0g9t3npJgXAO4PtfJjx2+jTTYeURige1rzGbMyoFmpMD+yPedlzyfC0rMq6dSAz9lePs4uUoTStJbPwigIzV1gBbtSIHyFD7dNZSPnOnSxsNJzWkPWlq5II99yzOl+i8VFIwR/VLJQvGXUq+3TptKqQFL3iZuogqQ= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784898119126426.59024631392947; Fri, 24 Jul 2026 06:01:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wnFWO-0002a0-18; Fri, 24 Jul 2026 09:01:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wnFWL-0002SP-HJ for qemu-devel@nongnu.org; Fri, 24 Jul 2026 09:00:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wnFWJ-0002gG-Ck for qemu-devel@nongnu.org; Fri, 24 Jul 2026 09:00:57 -0400 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-437-4m6AP_2NOG25_DfFxg0Mvw-1; Fri, 24 Jul 2026 09:00:53 -0400 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-49571407d1dso3445095e9.0 for ; Fri, 24 Jul 2026 06:00:52 -0700 (PDT) Received: from [192.168.10.48] ([151.49.94.110]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4957b5f35a1sm47388715e9.0.2026.07.24.06.00.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jul 2026 06:00:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784898054; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Am04rAViHBWH56STMMt95NmhR4rS6t7b5I/fYOQuq1I=; b=NKghtqI8PyM1Yo8TRZ9YZ0XKjGfbc8lctLyczTlbfD/uaZ9qijW4PICMvWEmyE64HkdCip whpI7zy5sU5f9gVs9J5s1mIjnGaD624nEpujn28S7NgkupMkTrmwQvQPqFsL0pe/xIq+sx yPjeH97KBMPtbiQLU7n0gYhSNrzFFrY= X-MC-Unique: 4m6AP_2NOG25_DfFxg0Mvw-1 X-Mimecast-MFC-AGG-ID: 4m6AP_2NOG25_DfFxg0Mvw_1784898052 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1784898052; x=1785502852; darn=nongnu.org; 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:content-type; bh=Am04rAViHBWH56STMMt95NmhR4rS6t7b5I/fYOQuq1I=; b=gzb3yP9DoIG+rpUxRbQvDRHyIFXgS9VmPlpAWXOLgW6VMMcgRO0OFS8VaoZKF19Ixb cho0ZAI1xjFZNo5261vE3xAlD3gptHGtmnUJTmgj69alMUH4oogz5cyoGYNGDF1p34dF dWplO1fzUbEnx0X0rGYg3BCVwcnioCJh0fin+aUCMDVctQN28foy9KZZypuGWmm0o1Zi o7B3e7QIPF8mVGColvSzaX8xq1fmjK27kKELf9FmqzN/e4UEAc/ZOA8fHfzAcBNV2ouj x9z5VvX7OaZq2gPTTbcm6GHh56wH5KuB65FviVkCuJS8DQ2PKbVljth34YaLkfWzn6NZ 9bxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784898052; x=1785502852; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Am04rAViHBWH56STMMt95NmhR4rS6t7b5I/fYOQuq1I=; b=hvmIoffo5o5Cun6YF5dR6KVC2ZCytFB7ammBpc6BqvpGgtPQ3E2grgoA7OpKQgYozF /rgLIRl0iA28hDeCaDWGDlvP2/uHDrfCH+vIGn4GwUAnKNoFMO9EuoZfw1dWRhEL5o4F jJaJEyTf9tkLhxbixjxIlFcSgv2toH2Q7KWAzbNJZcgI+Fy9dqqZlCFJqmWt/1IntN+A x0HCmuhVtytG4ugUvM1wB0gNUDj0RbRZtdfgwVtTA01eLr0ZOxWmZ3UhKMdoUalkCn10 +70U9Se8jeZtmh3JBKBAFTLQkS0jhGCWyfPX/3FNYvr6giAsdfVAhWf7PsrrERXeP0FY YEEA== X-Gm-Message-State: AOJu0YzOOAiXidqk8d2231Cn++08NMzuGKos5j4mDJktQlxPPqdlTpTr 1lOjPAopTysO5WvrCFY6Z3rSsTbI01c7MiApMj4bd+mfQUnK02TgWpYGOaDkAI48hnKWbPd59yl XT+n6pViXuXsQBPQ6jnFgBG7p8MZ5gwni9ykyU0zwyBCD+94SaHUMzonwEABBdne131P7JO5BZT yobzj2s78J9RXE0AbrOqKdRDMkdCQK2ImMNCfILttE X-Gm-Gg: AR+sD13phGCwtaaDDkHvAPPZFy/iyeqnxM5j4Ac7zmDFb16GXnOZSTzSOCNaShNxZkD subhVw5UIbn2S2LUWO7Zt1XPVQFykgWVC0kqnt6LVgRIeb9UqUmQGWN15TSLn77hamMcwDKB7Ip 3YrhyNXmXWvTiknd5t+5zAns5++9Wi75SpTZs1svHIjNqgEg55dvkutfrt4uwrvtfuCA87L2Aw6 xMw7J+rMotqJ+x+BENulNvXxtY2j8H93CvCDE+zlsfck6K3K0OBtjWVbV0IBUb1TU0Z9lYsJkSw l+1jRP2ZtOTugPhdP+Cuc9QWOFhHLZwTZsZDmekyXEJeb7fqpPrZoyl3WW/hyvjeEjYhvdEyTZy /Op3s4jeNNs42nvtL3VwVMZCurobWVKoz+eywBni2e549gG/D9Q3FZbp6JISoxF7vALVuk2iHd0 vsJrI/ X-Received: by 2002:a05:600c:35cb:b0:495:4fd4:619b with SMTP id 5b1f17b1804b1-49573cc1305mr103003755e9.1.1784898051366; Fri, 24 Jul 2026 06:00:51 -0700 (PDT) X-Received: by 2002:a05:600c:35cb:b0:495:4fd4:619b with SMTP id 5b1f17b1804b1-49573cc1305mr103002805e9.1.1784898050650; Fri, 24 Jul 2026 06:00:50 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: armbru@redhat.com Subject: [PATCH 2/3] scripts/qapi: reject empty enums Date: Fri, 24 Jul 2026 15:00:42 +0200 Message-ID: <20260724130044.1369843-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260724130044.1369843-1-pbonzini@redhat.com> References: <20260724130044.1369843-1-pbonzini@redhat.com> MIME-Version: 1.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.419, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1784898120035158500 Content-Type: text/plain; charset="utf-8" Raise an error if an enum has no members. Such enums cannot be populated with a valid value, and therefore they can only be used as optional members. But QAPI leaves out optional members from the serialization protocol, and therefore the existence of the enum is completely pointless. The same limitation is not extended to an enum whose members are all compiled out; these can still be useful as optional members. However they cannot implicitly block usage of parent structures because, by virtue of having only conditional members, they are "enums with conditional first item" and must therefore be optional. Signed-off-by: Paolo Bonzini --- scripts/qapi/schema.py | 4 ++++ tests/qapi-schema/enum-empty.err | 2 ++ tests/qapi-schema/enum-empty.json | 2 ++ tests/qapi-schema/enum-empty.out | 0 tests/qapi-schema/meson.build | 1 + tests/qapi-schema/qapi-schema-test.json | 3 --- tests/qapi-schema/qapi-schema-test.out | 1 - tests/qapi-schema/union-empty-if.err | 2 ++ tests/qapi-schema/union-empty-if.json | 6 ++++++ tests/qapi-schema/union-empty-if.out | 0 tests/qapi-schema/union-empty.err | 4 ++-- 11 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 tests/qapi-schema/enum-empty.err create mode 100644 tests/qapi-schema/enum-empty.json create mode 100644 tests/qapi-schema/enum-empty.out create mode 100644 tests/qapi-schema/union-empty-if.err create mode 100644 tests/qapi-schema/union-empty-if.json create mode 100644 tests/qapi-schema/union-empty-if.out diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 71296b15de2..a5a11298817 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -428,6 +428,10 @@ def __init__( =20 def check(self, schema: QAPISchema) -> None: super().check(schema) + if not self.members: + raise QAPISemError( + self.info, + "enum '%s' must have at least one value" % self.name) seen: Dict[str, QAPISchemaMember] =3D {} for m in self.members: m.check_clash(self.info, seen) diff --git a/tests/qapi-schema/enum-empty.err b/tests/qapi-schema/enum-empt= y.err new file mode 100644 index 00000000000..6070bf62cbd --- /dev/null +++ b/tests/qapi-schema/enum-empty.err @@ -0,0 +1,2 @@ +enum-empty.json: In enum 'TestEmpty': +enum-empty.json:2: enum 'TestEmpty' must have at least one value diff --git a/tests/qapi-schema/enum-empty.json b/tests/qapi-schema/enum-emp= ty.json new file mode 100644 index 00000000000..3b3dfb2e3d8 --- /dev/null +++ b/tests/qapi-schema/enum-empty.json @@ -0,0 +1,2 @@ +# An enum must have at least one value +{ 'enum': 'TestEmpty', 'data': [] } diff --git a/tests/qapi-schema/enum-empty.out b/tests/qapi-schema/enum-empt= y.out new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/qapi-schema/meson.build b/tests/qapi-schema/meson.build index 3b0c16a8b67..1058b7ecfae 100644 --- a/tests/qapi-schema/meson.build +++ b/tests/qapi-schema/meson.build @@ -196,6 +196,7 @@ schemas =3D [ 'union-clash-member.json', 'union-discriminator-bad-name.json', 'union-empty.json', + 'union-empty-if.json', 'union-inline-invalid-dict.json', 'union-int-branch.json', 'union-invalid-base.json', diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qa= pi-schema-test.json index 8ca977c49d2..195f1c4847b 100644 --- a/tests/qapi-schema/qapi-schema-test.json +++ b/tests/qapi-schema/qapi-schema-test.json @@ -23,9 +23,6 @@ 'data': { 'enum1': 'EnumOne', # Intentional forward reference '*enum2': 'EnumOne', 'enum3': 'EnumOne', '*enum4': 'EnumOne' }= } =20 -# An empty enum, although unusual, is currently acceptable -{ 'enum': 'MyEnum', 'data': [ ] } - # Likewise for an empty struct, including an empty base { 'struct': 'Empty1', 'data': { } } { 'struct': 'Empty2', 'base': 'Empty1', 'data': { } } diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qap= i-schema-test.out index 4617eb4e98a..ddd8bf80d66 100644 --- a/tests/qapi-schema/qapi-schema-test.out +++ b/tests/qapi-schema/qapi-schema-test.out @@ -18,7 +18,6 @@ object NestedEnumsOne member enum2: EnumOne optional=3DTrue member enum3: EnumOne optional=3DFalse member enum4: EnumOne optional=3DTrue -enum MyEnum object Empty1 object Empty2 base Empty1 diff --git a/tests/qapi-schema/union-empty-if.err b/tests/qapi-schema/union= -empty-if.err new file mode 100644 index 00000000000..2b8691ab2f5 --- /dev/null +++ b/tests/qapi-schema/union-empty-if.err @@ -0,0 +1,2 @@ +union-empty-if.json: In struct 'Base': +union-empty-if.json:5: enum type 'Empty' of member 'type' has a conditiona= l first value and must be optional diff --git a/tests/qapi-schema/union-empty-if.json b/tests/qapi-schema/unio= n-empty-if.json new file mode 100644 index 00000000000..36625dc4a89 --- /dev/null +++ b/tests/qapi-schema/union-empty-if.json @@ -0,0 +1,6 @@ +# union discriminator enum cannot have only conditional items +{ 'enum': 'Empty', + 'data': [ { 'name' : 'bar', 'if': { 'all': ['FOO'] } } ] } + +{ 'struct': 'Base', 'data': { 'type': 'Empty' } } +{ 'union': 'Union', 'base': 'Base', 'discriminator': 'type', 'data': { } } diff --git a/tests/qapi-schema/union-empty-if.out b/tests/qapi-schema/union= -empty-if.out new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/qapi-schema/union-empty.err b/tests/qapi-schema/union-em= pty.err index d4284399621..c07dcf32a5a 100644 --- a/tests/qapi-schema/union-empty.err +++ b/tests/qapi-schema/union-empty.err @@ -1,2 +1,2 @@ -union-empty.json: In union 'Union': -union-empty.json:4: union has no branches +union-empty.json: In enum 'Empty': +union-empty.json:2: enum 'Empty' must have at least one value --=20 2.55.0 From nobody Sun Jul 26 10:08:35 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1784898108; cv=none; d=zohomail.com; s=zohoarc; b=NgrrH2iY2lpjgU6+3co8gNyBp5tXPqISr6w9QVgS3JXIGJ4OA7zBifz2eihckmKH08/eNCff53ei0qi9MfBuoWsDY0pJYzuftY+u+z/vntJe+/s+dNEhbZeM0UNpdPKBvOLhkT9M3aEwttCLJQC8OLDupPrHSbtiHJB4fHbIp1E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784898108; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=50gT1BbEkOffJdXKR8tsxDkoo+2x5EtDK0ypy8SAMVQ=; b=ZoS6ZOrDbYzk+3o2hc83NLhTnxdDJIZaSIUcdA3fTxBIKy+9OmuaeicHoCwss989Mffdg+zaWMx/mCEvxf7o7EkAvGQjdm+1/pxFSoOVJiiW7xZ9CtoedIrqCkTGXmfgM3+YH1SwrhB2xtKOvUi0hLuM8Iudb/9AGx3zxx+PtXg= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784898108282599.9940975973897; Fri, 24 Jul 2026 06:01:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wnFWP-0002dA-Qn; Fri, 24 Jul 2026 09:01:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wnFWN-0002YR-6q for qemu-devel@nongnu.org; Fri, 24 Jul 2026 09:00:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wnFWL-0002ig-Ha for qemu-devel@nongnu.org; Fri, 24 Jul 2026 09:00:58 -0400 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-204-Ql5UdiykOFqKEhbslUX9Gw-1; Fri, 24 Jul 2026 09:00:55 -0400 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-496b370b089so185965e9.1 for ; Fri, 24 Jul 2026 06:00:55 -0700 (PDT) Received: from [192.168.10.48] ([151.49.94.110]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4957afac1cbsm64499025e9.10.2026.07.24.06.00.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jul 2026 06:00:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784898056; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=50gT1BbEkOffJdXKR8tsxDkoo+2x5EtDK0ypy8SAMVQ=; b=fXsu/dCaZ3TudKOQOI/Bq4ilWZkmuEZoQRrKGnKOPS57psCKR5HDNtrhPfqKJ2ASkUJL+I HAFWP/f+rWlILBfvmIfwY98cFrOliCzzB1r/dBDghgWC4Wyd+LygH2KVl4DzI+48WO6zkt Y5ikZVtjbrLD/C/gUmz7HAO53BwYhrM= X-MC-Unique: Ql5UdiykOFqKEhbslUX9Gw-1 X-Mimecast-MFC-AGG-ID: Ql5UdiykOFqKEhbslUX9Gw_1784898054 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1784898054; x=1785502854; darn=nongnu.org; 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:content-type; bh=50gT1BbEkOffJdXKR8tsxDkoo+2x5EtDK0ypy8SAMVQ=; b=k6lFyoct0UCnHYO0cjENgMxTQaNV6hyiu5jC30679r7/iN/WopaNsHCR6pQeYzYExv fVS+LEFqk8eGij5cP6HN+p7LY2sANbn79O7JkmS2x5vMjHnmmMGApPLe9868P9yBKZ9L LllWmiXPaZpinslRZavtYZ3X6WKXrpIQF295FEpMn1AgWvKYHFWZSDdwjn4q0ZzgAMKL 5g6UztezYo8kn5kmr6Na+Tpqrd6RVHeGG9vm5M6C+4wnqdr5JhGrB4cnZrW0Mao0xWBZ J4tcwrzCZ47gMGnc0sVCuxKG3h7l2Ro0zphe+3Mt50D+2m+0CWMQlcrvmpc05k3d/Rrv nhwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784898054; x=1785502854; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=50gT1BbEkOffJdXKR8tsxDkoo+2x5EtDK0ypy8SAMVQ=; b=JyzuDk/IYPHVZ2/DfdVEGL8FKLTpJWgkdpknhGQmrB+h7vgCgZph9xwQzJDyenS6no dZUtKWA6mnQGz2A1wA4MgF/lqXRTqJM0b9BUi43NjtHn8vfHWT8wqiUj4fLV3MHVQ2fT A25kyadZ0nB5C8DvNwC4gUnFaN6tLHCeicVjJx1E5Rvzxt7be55r5MQbvwrVnL7XsQh1 g5YCQ87zcVImPHIgy40M8l8V5twCiaZqHyOlm4zs+Itk5oiUQAdePbsx8odfS6EWKOsr cuDEhdcIf/aEPB4tzRiCCNe1IVJvGpAKiN0yeqrbQdZIWN/+TDOSD4Gdhn0/MceQZkuB s/2Q== X-Gm-Message-State: AOJu0Yzjj8Slp+eSSuEKc6cX7cRDKqGahJWqJxnTni4MBOHrhy4czG1T HHu5PyMWkaE9tJu/IysLpyiBr7zkxkhBUHHIfFgmz0nv+YxzV58SwWRzVBGPYD05sC1s8hmn3oC d8dqQ36CXIvChjr77RD5ooNbt2z0Het8vxDGN1kY2k3z2SjlaHHGxMZSrK4hHBiT5XDgik82RmK 6WuJZGVzoF6I6d4W8+Ot2/yNJOnAFpTgItvuQjQjFR X-Gm-Gg: AR+sD11ufWyYi6+3kqrjA00JjREkP5AwATzOr2ZQmYiH/sqvHx34yAypGiQ1rHsZuH3 hrLO/vIUV3wyWVJ4p7uIg7NgtR1wnJ2HZqVNrVDuRQHbg+mNMJBT7GLKvzUaO5U5Twil7gZLQ+7 MqjHrLy/2hUHTYBBL6wx1Z3DcnDF0RDhbsouInYCRIfD54Mj7aGPHlKRluXsv+F6TDXEcUJkDGr Ewdi9PU0qhNsmtDhlZHU7bZdji6oNs1KEIn1jT8/QuNXCFFN5mBSk35wFny+mFAg7Oohuw6j7f0 FS5B50f68W8NkT4Lo98++9tift8K0jym7q/5Xk5uVf8I574zEx1ydt+NrhDql93YRAB2+OsuLnn ONVcW5TukvNgMpspZaY+pnRYYEhvOCiYM1YUocWQG1n2tOwNxwI+r3Ux3ne3smmghI+qb8ryAWg hGqaEr X-Received: by 2002:a05:600c:8714:b0:493:f478:4c71 with SMTP id 5b1f17b1804b1-496997235cemr6082645e9.7.1784898053950; Fri, 24 Jul 2026 06:00:53 -0700 (PDT) X-Received: by 2002:a05:600c:8714:b0:493:f478:4c71 with SMTP id 5b1f17b1804b1-496997235cemr6082065e9.7.1784898053448; Fri, 24 Jul 2026 06:00:53 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: armbru@redhat.com Subject: [PATCH 3/3] scripts/qapi: pull c_name and lstrip from camel_to_upper to caller Date: Fri, 24 Jul 2026 15:00:43 +0200 Message-ID: <20260724130044.1369843-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260724130044.1369843-1-pbonzini@redhat.com> References: <20260724130044.1369843-1-pbonzini@redhat.com> MIME-Version: 1.0 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.419, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1784898109890158500 Content-Type: text/plain; charset="utf-8" Allow using camel_to_upper for other languages too. In particular, the lstrip() is needed to avoid reserved C identifiers, for example: typedef enum __org_qemu_x_Enum { __ORG_QEMU_X_ENUM___ORG_QEMU_X_VALUE, __ORG_QEMU_X_ENUM__MAX, } __org_qemu_x_Enum; Insulate Rust from this, since underscores have a different meaning in Rust (though only for the sake of warnings). Signed-off-by: Paolo Bonzini --- scripts/qapi/common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index d7c8aa3365c..43a0be5f97f 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -61,7 +61,7 @@ def camel_to_upper(value: str) -> str: ret +=3D ch upc =3D ch.isupper() =20 - return c_name(ret.upper()).lstrip('_') + return ret.upper() =20 =20 def c_enum_const(type_name: str, @@ -75,7 +75,7 @@ def c_enum_const(type_name: str, :param prefix: Optional, prefix that overrides the type_name. """ if prefix is None: - prefix =3D camel_to_upper(type_name) + prefix =3D c_name(camel_to_upper(type_name)).lstrip('_') return prefix + '_' + c_name(const_name, False).upper() =20 =20 --=20 2.55.0