From patchwork Wed Mar 15 11:13:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 663355 Delivered-To: patch@linaro.org Received: by 2002:a5d:5602:0:0:0:0:0 with SMTP id l2csp1521700wrv; Wed, 15 Mar 2023 04:14:17 -0700 (PDT) X-Google-Smtp-Source: AK7set+BEQkNjXqfZ39ixEmjaQNByXziQXA0ZEGbcq8rqVNBB2qkufHdCzfO6Zx50B9frkHXDmJL X-Received: by 2002:ac8:7e8b:0:b0:3bf:cfe0:1f2c with SMTP id w11-20020ac87e8b000000b003bfcfe01f2cmr39542820qtj.35.1678878857486; Wed, 15 Mar 2023 04:14:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678878857; cv=none; d=google.com; s=arc-20160816; b=CMzE//WPhbF21eaUvAOVfwjxz3aLk6WjUO0ixmlMRI1NoNNu7k44eT6YRERr9EBOmz 6arPkztmrE43hoJ9QMutLKMF/SkRBOt/Fh02EZntwVax4PDG1fYdGln831jcP8BeX8k5 Bfi8tM+JvDh/dxF1U1cWQAf+LAAV2bMK5Y8IGcjCyaXntFtZOliC4GR9tlP7UtRiDWhO n/ypOJOuDsUPjMXUNAtLvJ+R+prSRtyol1/lF16sN0SlTzHiGjsLdO7x+RrEpp+NjT/E aO+HxJqOcEXYKlp9F/mjpIb/NzioLDG9x8a12NgXybxNkNw8o33ir5etwY3bl7LHZitN 0a6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8XaO46O+XQUbG+N4rkWdsjN5zkz70OOKz1YQ5MqrEQ0=; b=QTmzuiiY8T2AHVRtQhWJOfbWYGGFlPHUZUXKR4cuOD6rdSG5vDivjJOF24F4tNEIRh Gvyal5T3tjJxL5QH8L/+3A0cFQIW+3KP2NXjvL03CJiAAfjO26j9XMD2ZuVX8fwa7A1a cMjFU+t3V8HFWIOtHcHD/pJyQWvqBQW6ENn5hi5PtxrdQMyTuGXY4DeNUA42oORaPUcV wxiIaE5RO6xhfEt35QrPN4k8c9CGQSCzDg2sAk3U81YU/jJxErhUtqdc0zuDwaObKhC+ wKhaC+9isZ+SbvNiZhYeeF6j82AiZ2Jm2/+NxfEOY7bOPJ22tN/D2EnihRi44I6/VcEv Pjqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ANFRiKz5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id e3-20020a05622a110300b003b27a36b134si4177606qty.782.2023.03.15.04.14.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 Mar 2023 04:14:17 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ANFRiKz5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pcP4H-0006uA-HE; Wed, 15 Mar 2023 07:13:17 -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 1pcP4F-0006tW-Lm for qemu-devel@nongnu.org; Wed, 15 Mar 2023 07:13:15 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pcP4E-0005qi-0I for qemu-devel@nongnu.org; Wed, 15 Mar 2023 07:13:15 -0400 Received: by mail-wm1-x32b.google.com with SMTP id bh21-20020a05600c3d1500b003ed1ff06fb0so918326wmb.3 for ; Wed, 15 Mar 2023 04:13:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678878792; 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=8XaO46O+XQUbG+N4rkWdsjN5zkz70OOKz1YQ5MqrEQ0=; b=ANFRiKz512cXDQgiRz5x48OCVngl/gh1lq7OncOkB63wdNGe7iomblFcRlcnvVkZkZ k7KUA2/O04iZKORVG4rdwlfkjsq1mb8jzVmqu096mML+CnZ1aALNt+qEIW8FKTK3ZrAo XMUAveW5G2D609/3SpBe5qa95VKfWPYPF4GrkHk/itS+9q9b7eIYtCXXA9/RtN5kQc0T huIt8KHoMiMr85RG973XOZxoR93Xs5JbYPZadeVZhLqRghosQFRV/SCHIibKxxBzcm0n g60VjjfrybVtVxSYpl7JUfEpzg+6XKR2UMrpxDg95Q+CuTvKoFOzo6TZLbxvnju5qmQx UpjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678878792; 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=8XaO46O+XQUbG+N4rkWdsjN5zkz70OOKz1YQ5MqrEQ0=; b=d4P2eXj5/UmaWHu1tkLjo6FdQbP1damjgwynBcTLrhINzGXftHpoUqrpmp/uUGRunR 9mmDlKoyyVGP0TtN26TtGADFjvW4paAntVCVjl6+WTuaJzptnCGeBxFGuqV93ZNahXZd uZag7NxOi6GUBzzgvfLtYifYkTeg3QDXt4+hi1QyCBSV8RgB3b/9wNMWWTn6dKRq6JGv H34kJrvPEYyf/Bvid8YrIpx9/OcvQZ92hJH9q9Gcxb0eZFtEzfkARBByodp7qkuJcXcH vXaGwejXoM2G4b+ICI8eOU3EK+Xt0zRgWNC0cJZkc27MoPKLZqxsIeQaMXljbjsXbqVF yIyQ== X-Gm-Message-State: AO0yUKUtf/FEitxUy0/NkXd3RBc4qPKPABM3JuiLKY8eIDYVWW58STQp 9UdqTC4mdWiK3aFfFY1Wr6eqJHpGR83ubxDDO2065w== X-Received: by 2002:a05:600c:4511:b0:3ed:307e:3f69 with SMTP id t17-20020a05600c451100b003ed307e3f69mr2806067wmo.7.1678878791888; Wed, 15 Mar 2023 04:13:11 -0700 (PDT) Received: from localhost.localdomain ([81.0.6.76]) by smtp.gmail.com with ESMTPSA id t8-20020a05600c450800b003daf6e3bc2fsm5428248wmo.1.2023.03.15.04.13.10 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 15 Mar 2023 04:13:11 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-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_Lureau?= , Michael Roth , Markus Armbruster , Stefan Berger , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 1/3] scripts/git.orderfile: Display QAPI script changes before schema ones Date: Wed, 15 Mar 2023 12:13:02 +0100 Message-Id: <20230315111304.21692-2-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 Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=philmd@linaro.org; helo=mail-wm1-x32b.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org When modifying QAPI scripts and modifying C files along, it makes sense to display QAPI changes first. Signed-off-by: Philippe Mathieu-Daudé --- scripts/git.orderfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/git.orderfile b/scripts/git.orderfile index 8edac0380b..70adc1a74a 100644 --- a/scripts/git.orderfile +++ b/scripts/git.orderfile @@ -22,6 +22,8 @@ Makefile* *.mak meson.build +# qapi scripts +scripts/qapi* # qapi schema qapi/*.json qga/*.json From patchwork Wed Mar 15 11:13:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 663358 Delivered-To: patch@linaro.org Received: by 2002:a5d:5602:0:0:0:0:0 with SMTP id l2csp1521889wrv; Wed, 15 Mar 2023 04:14:46 -0700 (PDT) X-Google-Smtp-Source: AK7set9bNJhWGvSxkGXgQUalmEb9afmpAF+HT50YKYLr9yNC1TA/Nys7p00ERIN/P6esBCCYERtW X-Received: by 2002:ad4:5c65:0:b0:56b:f28a:ee2d with SMTP id i5-20020ad45c65000000b0056bf28aee2dmr10933401qvh.5.1678878886572; Wed, 15 Mar 2023 04:14:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678878886; cv=none; d=google.com; s=arc-20160816; b=sTbKb5rm7b4f7/8Zk9Jbz/loCpLUd7Gfj9PFrpWtDV4Z/CvUgjAbNLd0OuPF8BFQs+ gp1qO1myQ9FBOEKbHyjx7kkPHArjni8SMVLOMjflpyEsr1tXy1tp9fesgpQSpQOmmpva tTykzs9tNjCIAlLZVn+kyVVXng+uGJ07ItXz23g300vkhDYGpbxK0EmWYhcfGyYbOSmC eD5CF9co8+j+Sjw2IxgsYKTJBNSKWSjMz9bKk0ZbaWgyTXuW0QIJwlb3N5j6SWqwYgKO pToUjpPKp9Cae5EieBqHlBEMmPwIAnBCk9N9EaAsXwQVBNADSo9S3Eh07RBeZwffFpDw 6tzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=hTQgFcYrB1xCmGiqUBDxS+gQ3e4QTFB6UCIQEY/7TGM=; b=TYwV8YpwVT5eUbJSUyV2Q+zOj2kkLOeUxGyNM1nG983PT2ZHDIw9/dCR2vJcHprHnY bgTTCBCksyUk+CC0NuiblM3/oIH9C2zVKtLX2FGrQV3GaCRyW2z3uT4YG+C+wR06Zb5y LduRUqVWiouKD+eIZ2Bn/qAPnyKQcyuGqEzebonFF/EQyfXgCyHMqpnc2+GV0cqnDmyh +EY2GuH/cI/xv6IzcbBs+ms/BX6YIHH9kYQMiulCHty4ZM3YTdbL+fuDZtrs3iv50ga/ n6yEwG/DR+1i0KZ3U0zOdUmJFfRDEd2K80hkjpzbB+n0wv6CvwsXH4lOcEZRIZxuTeSW swXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="B/IdBUaJ"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w18-20020a0cb552000000b005aa91f55b5esi4337605qvd.71.2023.03.15.04.14.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 Mar 2023 04:14:46 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="B/IdBUaJ"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) 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-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) 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) From: =?utf-8?q?Philippe_Mathieu-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_Lureau?= , Michael Roth , Markus Armbruster , Stefan Berger , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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é 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:: Member 'enum' names the enum type. +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:: { 'enum': 'MyEnum', 'data': [ 'value1', 'value2', 'value3' ] } -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): 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, ifcond, role, members): return name def _def_enum_type(self, expr: QAPIExpression): - name = expr['enum'] data = expr['data'] + if not data: + return + name = expr['enum'] prefix = expr.get('prefix') ifcond = QAPISchemaIfCond(expr.get('if')) info = expr.info From patchwork Wed Mar 15 11:13:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 663357 Delivered-To: patch@linaro.org Received: by 2002:a5d:5602:0:0:0:0:0 with SMTP id l2csp1521838wrv; Wed, 15 Mar 2023 04:14:40 -0700 (PDT) X-Google-Smtp-Source: AK7set+iyjEyqL3saxYHFlb7farbTLCQ3XvwTPT8YbEk/5zXLpQJGY8d1AhJW39+deoHNnzsnS64 X-Received: by 2002:a05:6214:e41:b0:56f:d8:dbb4 with SMTP id o1-20020a0562140e4100b0056f00d8dbb4mr28019680qvc.2.1678878879975; Wed, 15 Mar 2023 04:14:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678878879; cv=none; d=google.com; s=arc-20160816; b=KV3EG0wqZXh0cpj8eZHVgOfWQ6obDsaG6JytAQ/+hlwcx6kO5tX7J4b+PjGHatFygN wtp50+eG5b6TjpunBOKtvp1E6v/xnEHlOqg5rAPGJXQ1ZNSV8fhB3PERCZXfqQt4ts0r WkPegTvLFz6kaqQ2MS+x6y+PKFOmsneU5EGUoducu7bcGky2q5LOBs2678bHi8VXWbRs ugdhrgtdyj+KEpkSPW8SEWgItUCpUSLBKzo582DYUUHbhJTn7UThuMXtpJmAIvVfGaqH CXZcmeoWUMy2/BW+zcVBCFV3HvRKVkV0GWQAPTtgyAvrl7QGwWtGtrdLhOjudtPhu90u gplA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=//5seo2TSzF/3VLgMfgiFJLBcnXxkX/wX9Zucyusedg=; b=enQo0eQqq0TU2K+FACd58acWwsT3sCm4GzOd6IBtiPUlEEizecAygVNCp+ObZY/2yb jxa3yq95oFfS+Hh6fyCZNvRcdCBDRXuyQBsDmLFs1S4ymjx24HrPOx7eS8YIK6rANDuF nKbaXRdzr6mxoe/jpGuIXhQyH5PdH2Tcu+prD4R9SRoy7XLzQ5mEtAqt2NT0JW0oGrG7 mTfWgntKsyDs4dXLWB2l1XGvY4nlTy3JytWNTdUc8TzRbGzoiQ+RtvffUyewOMorcBKr emf1HOhVazc3iY/5/TB72OcvIEmQwOgisWl6tmTR+rt+NMYFwGwNmMUwxt0s93wkUmhj ZP1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kiLbaHox; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z135-20020a37658d000000b0073baa07a36dsi4085474qkb.201.2023.03.15.04.14.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 Mar 2023 04:14:39 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kiLbaHox; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pcP4Y-0006wZ-69; Wed, 15 Mar 2023 07:13:34 -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 1pcP4V-0006w4-Mw for qemu-devel@nongnu.org; Wed, 15 Mar 2023 07:13:31 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pcP4T-0005sT-8O for qemu-devel@nongnu.org; Wed, 15 Mar 2023 07:13:31 -0400 Received: by mail-wr1-x429.google.com with SMTP id v16so16990692wrn.0 for ; Wed, 15 Mar 2023 04:13:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678878803; 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=//5seo2TSzF/3VLgMfgiFJLBcnXxkX/wX9Zucyusedg=; b=kiLbaHoxR7xXH1UD+jjOx1WuHeSNe8kI31RUqeatmQ1tTy3PZdtPcC8U+vPLTq4Hcf E5iVBqDn0HkPkcMok/WOb+2LQwXM7RlN1wniFerIJbdHNyPz1l+rPB2WOBgKBwKTtSmY AmIhop/nNLpsELNG9tZi5vVfVhU1OmX7eU5Xk+IeL8Qy4dLDtIRgJB6z3Nyko8NPmfgW anxQz49zGsUA9nllgbUQmKXWRbfgRiaeNTLZk8XEmr/6ugxk/Ikx3gmcwSyhhp+W5bFI ZA/nko1/8rnEWuJ8pRSvA5O8GMPOecKbYyxRnDH4NlMlDaybAVhx7Partw+Ybl524PMt uxYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678878803; 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=//5seo2TSzF/3VLgMfgiFJLBcnXxkX/wX9Zucyusedg=; b=MN3SzKfN0huF31i6ZWCPkHfiOcKSz+aDYMJNdLzwOGte5Eg5zTrS07mbQJd3ZyhAr1 VcQnN56Otr3xa9iyStrr+p3oGZD2IG6MYkCNidH54sj24/sI6gIDDmRHfGMCjUwN+Twy JonEXRz0wtTgHYjbxmSgMGuMSCXY78q03g4vNlt4Fq/9WOBxyjpVPUgXO4DmU1RNgoIk OrMbmKRWz7wRrQs2v/jKYOBFmNMGhXJ8QqhK2G1lT9KF2w9H8bCxmAoHu5D3RR+vZsme 5DsYqylTAIcQXj1IzlVHI+vCS+jmk6kCv1AYQhDG+6ic3YubnhHZqXb6+10mcp2mHJa3 BMRQ== X-Gm-Message-State: AO0yUKVwzzJ6NRgGj/XjAFx//pEUwkHUh7T2mrejGt2Kqn1tnuy4K98i 7Bm1wBg3M8GONYFr5a8HX4WNv0JVfUoydP25hrYajw== X-Received: by 2002:a5d:5259:0:b0:2cf:eed0:f6fb with SMTP id k25-20020a5d5259000000b002cfeed0f6fbmr1767101wrc.32.1678878802976; Wed, 15 Mar 2023 04:13:22 -0700 (PDT) Received: from localhost.localdomain ([81.0.6.76]) by smtp.gmail.com with ESMTPSA id f3-20020a0560001b0300b002c559626a50sm4417937wrz.13.2023.03.15.04.13.21 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 15 Mar 2023 04:13:22 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-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_Lureau?= , Michael Roth , Markus Armbruster , Stefan Berger , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Richard Henderson Subject: [PATCH v2 3/3] qapi: Generate enum count as definition Date: Wed, 15 Mar 2023 12:13:04 +0100 Message-Id: <20230315111304.21692-4-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 Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=philmd@linaro.org; helo=mail-wr1-x429.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org QAPI's gen_enum() generates QAPI enum values and the number of this values (as foo__MAX). The number of entries in an enum type is not part of the enumerated values, but we generate it as such. See for example: typedef enum OnOffAuto { ON_OFF_AUTO_AUTO, ON_OFF_AUTO_ON, ON_OFF_AUTO_OFF, ON_OFF_AUTO__MAX, <--------- } OnOffAuto; Instead of declaring the enum count as the last enumerated value, #define it, so it is not part of the enum. The previous example becomes: typedef enum OnOffAuto { ON_OFF_AUTO_AUTO, ON_OFF_AUTO_ON, ON_OFF_AUTO_OFF, #define ON_OFF_AUTO__MAX 3 <--------- } OnOffAuto; When iterating over a QAPISchemaEnumType, all possible values are covered. The 'default' switch case generated in gen_visit_object_members() is now unreachable, remove it. Since Clang enables the -Wswitch warning by default [*], remove all pointless foo__MAX cases in switch statement, in order to avoid: audio/audio.c:2231:10: error: case value not in enumerated type 'AudioFormat' (aka 'enum AudioFormat') [-Wswitch] case AUDIO_FORMAT__MAX: ^ ui/input.c:233:14: error: case value not in enumerated type 'KeyValueKind' (aka 'enum KeyValueKind') [-Wswitch] case KEY_VALUE_KIND__MAX: ^ ... [*] https://clang.llvm.org/docs/DiagnosticsReference.html#wswitch Reviewed-by: Richard Henderson Reviewed-by: Juan Quintela Signed-off-by: Philippe Mathieu-Daudé --- docs/devel/qapi-code-gen.rst | 4 ++-- scripts/qapi/types.py | 11 +++++++---- scripts/qapi/visit.py | 2 -- audio/audio_template.h | 3 --- audio/audio.c | 6 ------ migration/migration.c | 2 -- replay/replay-input.c | 12 ------------ softmmu/tpm-hmp-cmds.c | 2 -- ui/input-linux.c | 4 ---- ui/input.c | 6 ------ 10 files changed, 9 insertions(+), 43 deletions(-) diff --git a/docs/devel/qapi-code-gen.rst b/docs/devel/qapi-code-gen.rst index d684c7c24d..45b0da448d 100644 --- a/docs/devel/qapi-code-gen.rst +++ b/docs/devel/qapi-code-gen.rst @@ -227,7 +227,7 @@ 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. +additional definition constant PREFIX__MAX with value N. Do not use string or an integer type when an enumeration type can do the job satisfactorily. @@ -1825,7 +1825,7 @@ Example:: typedef enum example_QAPIEvent { EXAMPLE_QAPI_EVENT_MY_EVENT, - EXAMPLE_QAPI_EVENT__MAX, + #define EXAMPLE_QAPI_EVENT__MAX 1 } example_QAPIEvent; #define example_QAPIEvent_str(val) \ diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index c39d054d2c..b24bcb40ad 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -86,16 +86,13 @@ def gen_enum_lookup(name: str, def gen_enum(name: str, members: List[QAPISchemaEnumMember], prefix: Optional[str] = None) -> str: - # append automatically generated _MAX value - enum_members = members + [QAPISchemaEnumMember('_MAX', None)] - ret = mcgen(''' typedef enum %(c_name)s { ''', c_name=c_name(name)) - for memb in enum_members: + for memb in members: ret += memb.ifcond.gen_if() ret += mcgen(''' %(c_enum)s, @@ -103,6 +100,12 @@ def gen_enum(name: str, c_enum=c_enum_const(name, memb.name, prefix)) ret += memb.ifcond.gen_endif() + ret += mcgen(''' +#define %(c_name)s %(c_length)s +''', + c_name=c_enum_const(name, '_MAX', prefix), + c_length=len(members)) + ret += mcgen(''' } %(c_name)s; ''', diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 26a584ee4c..f66a31a963 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -159,8 +159,6 @@ def gen_visit_object_members(name: str, ret += var.ifcond.gen_endif() ret += mcgen(''' - default: - abort(); } ''') diff --git a/audio/audio_template.h b/audio/audio_template.h index e42326c20d..d545c03afb 100644 --- a/audio/audio_template.h +++ b/audio/audio_template.h @@ -376,9 +376,6 @@ AudiodevPerDirectionOptions *glue(audio_get_pdo_, TYPE)(Audiodev *dev) #endif case AUDIODEV_DRIVER_WAV: return dev->u.wav.TYPE; - - case AUDIODEV_DRIVER__MAX: - break; } abort(); } diff --git a/audio/audio.c b/audio/audio.c index 70b096713c..ea372288eb 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -2071,9 +2071,6 @@ void audio_create_pdos(Audiodev *dev) CASE(SPICE, spice, ); #endif CASE(WAV, wav, ); - - case AUDIODEV_DRIVER__MAX: - abort(); }; } @@ -2219,9 +2216,6 @@ int audioformat_bytes_per_sample(AudioFormat fmt) case AUDIO_FORMAT_S32: case AUDIO_FORMAT_F32: return 4; - - case AUDIO_FORMAT__MAX: - ; } abort(); } diff --git a/migration/migration.c b/migration/migration.c index ae2025d9d8..bdadab3b5e 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2220,8 +2220,6 @@ bool migration_is_idle(void) case MIGRATION_STATUS_DEVICE: case MIGRATION_STATUS_WAIT_UNPLUG: return false; - case MIGRATION_STATUS__MAX: - g_assert_not_reached(); } return false; diff --git a/replay/replay-input.c b/replay/replay-input.c index 1147e3d34e..c6de8e33ac 100644 --- a/replay/replay-input.c +++ b/replay/replay-input.c @@ -38,9 +38,6 @@ void replay_save_input_event(InputEvent *evt) replay_put_dword(key->key->u.qcode.data); replay_put_byte(key->down); break; - case KEY_VALUE_KIND__MAX: - /* keep gcc happy */ - break; } break; case INPUT_EVENT_KIND_BTN: @@ -58,9 +55,6 @@ void replay_save_input_event(InputEvent *evt) replay_put_dword(move->axis); replay_put_qword(move->value); break; - case INPUT_EVENT_KIND__MAX: - /* keep gcc happy */ - break; } } @@ -89,9 +83,6 @@ InputEvent *replay_read_input_event(void) evt.u.key.data->key->u.qcode.data = (QKeyCode)replay_get_dword(); evt.u.key.data->down = replay_get_byte(); break; - case KEY_VALUE_KIND__MAX: - /* keep gcc happy */ - break; } break; case INPUT_EVENT_KIND_BTN: @@ -109,9 +100,6 @@ InputEvent *replay_read_input_event(void) evt.u.abs.data->axis = (InputAxis)replay_get_dword(); evt.u.abs.data->value = replay_get_qword(); break; - case INPUT_EVENT_KIND__MAX: - /* keep gcc happy */ - break; } return QAPI_CLONE(InputEvent, &evt); diff --git a/softmmu/tpm-hmp-cmds.c b/softmmu/tpm-hmp-cmds.c index 9ed6ad6c4d..5a354cf6ac 100644 --- a/softmmu/tpm-hmp-cmds.c +++ b/softmmu/tpm-hmp-cmds.c @@ -52,8 +52,6 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict) teo = ti->options->u.emulator.data; monitor_printf(mon, ",chardev=%s", teo->chardev); break; - case TPM_TYPE__MAX: - break; } monitor_printf(mon, "\n"); c++; diff --git a/ui/input-linux.c b/ui/input-linux.c index e572a2e905..a6e7574422 100644 --- a/ui/input-linux.c +++ b/ui/input-linux.c @@ -120,10 +120,6 @@ static bool input_linux_check_toggle(InputLinux *il) return (il->keydown[KEY_LEFTCTRL] || il->keydown[KEY_RIGHTCTRL]) && il->keydown[KEY_SCROLLLOCK]; - - case GRAB_TOGGLE_KEYS__MAX: - /* avoid gcc error */ - break; } return false; } diff --git a/ui/input.c b/ui/input.c index f2d1e7a3a7..ca8f49a403 100644 --- a/ui/input.c +++ b/ui/input.c @@ -230,9 +230,6 @@ static void qemu_input_event_trace(QemuConsole *src, InputEvent *evt) name = QKeyCode_str(key->key->u.qcode.data); trace_input_event_key_qcode(idx, name, key->down); break; - case KEY_VALUE_KIND__MAX: - /* keep gcc happy */ - break; } break; case INPUT_EVENT_KIND_BTN: @@ -250,9 +247,6 @@ static void qemu_input_event_trace(QemuConsole *src, InputEvent *evt) name = InputAxis_str(move->axis); trace_input_event_abs(idx, name, move->value); break; - case INPUT_EVENT_KIND__MAX: - /* keep gcc happy */ - break; } }