From patchwork Fri Feb 19 12:17:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 8360381 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 70D19C0553 for ; Fri, 19 Feb 2016 12:20:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C1EC120443 for ; Fri, 19 Feb 2016 12:20:41 +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 097312043C for ; Fri, 19 Feb 2016 12:20:41 +0000 (UTC) Received: from localhost ([::1]:51521 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWk36-0006kf-9B for patchwork-qemu-devel@patchwork.kernel.org; Fri, 19 Feb 2016 07:20:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36341) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWk0l-0002h9-II for qemu-devel@nongnu.org; Fri, 19 Feb 2016 07:18:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aWk0j-0007do-Pz for qemu-devel@nongnu.org; Fri, 19 Feb 2016 07:18:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35835) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWk0j-0007dH-IS for qemu-devel@nongnu.org; Fri, 19 Feb 2016 07:18:13 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 4A9401F56A for ; Fri, 19 Feb 2016 12:18:13 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-67.ams2.redhat.com [10.36.116.67]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1JCIAEB023642 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 19 Feb 2016 07:18:12 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 2168B3043FE9; Fri, 19 Feb 2016 13:18:07 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 19 Feb 2016 13:17:59 +0100 Message-Id: <1455884286-26272-9-git-send-email-armbru@redhat.com> In-Reply-To: <1455884286-26272-1-git-send-email-armbru@redhat.com> References: <1455884286-26272-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 08/15] qapi-visit: Unify struct and union visit 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 gen_visit_union() is now just like gen_visit_struct(). Rename it to gen_visit_object(), use it for structs, and drop gen_visit_struct(). Output is unchanged. Signed-off-by: Markus Armbruster Message-Id: <1453902888-20457-4-git-send-email-armbru@redhat.com> [split out variant handling, rebase to earlier changes] Signed-off-by: Eric Blake Message-Id: <1455778109-6278-8-git-send-email-eblake@redhat.com> --- scripts/qapi-visit.py | 45 ++++++--------------------------------------- 1 file changed, 6 insertions(+), 39 deletions(-) diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index 5e91342..4a04354 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -155,40 +155,6 @@ out: return ret -def gen_visit_struct(name, base, members): - ret = gen_visit_struct_fields(name, base, members, None) - - # FIXME: if *obj is NULL on entry, and visit_start_struct() assigns to - # *obj, but then visit_type_FOO_fields() fails, we should clean up *obj - # rather than leaving it non-NULL. As currently written, the caller must - # call qapi_free_FOO() to avoid a memory leak of the partial FOO. - ret += mcgen(''' - -void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj, Error **errp) -{ - Error *err = NULL; - - visit_start_struct(v, name, (void **)obj, sizeof(%(c_name)s), &err); - if (err) { - goto out; - } - if (!*obj) { - goto out_obj; - } - visit_type_%(c_name)s_fields(v, obj, &err); - error_propagate(errp, err); - err = NULL; -out_obj: - visit_end_struct(v, &err); -out: - error_propagate(errp, err); -} -''', - c_name=c_name(name)) - - return ret - - def gen_visit_list(name, element_type): # FIXME: if *obj is NULL on entry, and the first visit_next_list() # assigns to *obj, while a later one fails, we should clean up *obj @@ -284,9 +250,13 @@ out: return ret -def gen_visit_union(name, base, members, variants): +def gen_visit_object(name, base, members, variants): ret = gen_visit_struct_fields(name, base, members, variants) + # FIXME: if *obj is NULL on entry, and visit_start_struct() assigns to + # *obj, but then visit_type_FOO_fields() fails, we should clean up *obj + # rather than leaving it non-NULL. As currently written, the caller must + # call qapi_free_FOO() to avoid a memory leak of the partial FOO. ret += mcgen(''' void visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj, Error **errp) @@ -363,10 +333,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor): def visit_object_type(self, name, info, base, members, variants): self.decl += gen_visit_decl(name) - if variants: - self.defn += gen_visit_union(name, base, members, variants) - else: - self.defn += gen_visit_struct(name, base, members) + self.defn += gen_visit_object(name, base, members, variants) def visit_alternate_type(self, name, info, variants): self.decl += gen_visit_decl(name)