From patchwork Thu Feb 18 06:48:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 8346611 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 8CF24C0553 for ; Thu, 18 Feb 2016 06:50:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E421C20395 for ; Thu, 18 Feb 2016 06:50:45 +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 2C9B720386 for ; Thu, 18 Feb 2016 06:50:45 +0000 (UTC) Received: from localhost ([::1]:37659 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWIQG-0000cj-IF for patchwork-qemu-devel@patchwork.kernel.org; Thu, 18 Feb 2016 01:50:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40211) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWIOF-0005Mt-8w for qemu-devel@nongnu.org; Thu, 18 Feb 2016 01:48:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aWIOD-00020H-NZ for qemu-devel@nongnu.org; Thu, 18 Feb 2016 01:48:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45707) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWIOD-00020C-Fh for qemu-devel@nongnu.org; Thu, 18 Feb 2016 01:48:37 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 1B867C0006EC; Thu, 18 Feb 2016 06:48:37 +0000 (UTC) Received: from red.redhat.com (ovpn-113-75.phx2.redhat.com [10.3.113.75]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1I6mXAc023855; Thu, 18 Feb 2016 01:48:36 -0500 From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 17 Feb 2016 23:48:21 -0700 Message-Id: <1455778109-6278-8-git-send-email-eblake@redhat.com> In-Reply-To: <1455778109-6278-1-git-send-email-eblake@redhat.com> References: <1455778109-6278-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 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 v11 07/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 From: Markus Armbruster 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 --- v11: rebase on top of moved variant code v10: new patch, replacing 31/37 --- 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 6cea7d6..4650c5b 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) - - # 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)