From patchwork Thu Mar 17 22:48:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 8614771 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 45391C0553 for ; Thu, 17 Mar 2016 22:49:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 994EB20160 for ; Thu, 17 Mar 2016 22:49:04 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CFA3720155 for ; Thu, 17 Mar 2016 22:49:03 +0000 (UTC) Received: from localhost ([::1]:40370 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aggj0-00010s-Tp for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Mar 2016 18:49:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47014) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aggiq-000108-Jm for qemu-devel@nongnu.org; Thu, 17 Mar 2016 18:48:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aggik-0007ma-L2 for qemu-devel@nongnu.org; Thu, 17 Mar 2016 18:48:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38610) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aggik-0007ku-GM for qemu-devel@nongnu.org; Thu, 17 Mar 2016 18:48:46 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id EC599C943E; Thu, 17 Mar 2016 22:48:43 +0000 (UTC) Received: from red.redhat.com (ovpn-113-69.phx2.redhat.com [10.3.113.69]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2HMmgGi004178; Thu, 17 Mar 2016 18:48:43 -0400 From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 17 Mar 2016 16:48:26 -0600 Message-Id: <1458254921-17042-2-git-send-email-eblake@redhat.com> In-Reply-To: <1458254921-17042-1-git-send-email-eblake@redhat.com> References: <1458254921-17042-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: armbru@redhat.com, Michael Roth Subject: [Qemu-devel] [PATCH v6 01/16] qapi: Assert in places where variants are not handled X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We are getting closer to the point where we could use one union as the base or variant type within another union type (as long as there are no collisions between any possible combination of member names allowed across all discriminator choices). But until we get to that point, it is worth asserting that variants are not present in places where we are not prepared to handle them: when exploding a type into a parameter list, we do not expect variants. The qapi.py code is already checking this, via the older check_type() method; but someday we hope to get rid of that and move checking into QAPISchema*.check(). The two asserts added here make sure any refactoring still catches problems, and makes it locally obvious why we can iterate over only type.members without worrying about type.variants. Signed-off-by: Eric Blake --- v6: no change v5: drop redundant hunk, improve commit message v4: new patch, split out from .is_empty() patch --- scripts/qapi-commands.py | 3 ++- scripts/qapi-event.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py index f44e01f..edcbd10 100644 --- a/scripts/qapi-commands.py +++ b/scripts/qapi-commands.py @@ -2,7 +2,7 @@ # QAPI command marshaller generator # # Copyright IBM, Corp. 2011 -# Copyright (C) 2014-2015 Red Hat, Inc. +# Copyright (C) 2014-2016 Red Hat, Inc. # # Authors: # Anthony Liguori @@ -30,6 +30,7 @@ def gen_call(name, arg_type, ret_type): argstr = '' if arg_type: + assert not arg_type.variants for memb in arg_type.members: if memb.optional: argstr += 'has_%s, ' % c_name(memb.name) diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py index fb579dd..c03cb78 100644 --- a/scripts/qapi-event.py +++ b/scripts/qapi-event.py @@ -59,6 +59,7 @@ def gen_event_send(name, arg_type): name=name) if arg_type and arg_type.members: + assert not arg_type.variants ret += mcgen(''' qov = qmp_output_visitor_new(); v = qmp_output_get_visitor(qov);