From patchwork Thu Jan 8 17:33:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 426727 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 90DF0140119 for ; Fri, 9 Jan 2015 04:39:51 +1100 (AEDT) Received: from localhost ([::1]:47084 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y9H3l-0002jl-Mn for incoming@patchwork.ozlabs.org; Thu, 08 Jan 2015 12:39:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59771) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y9GzL-0003N4-VO for qemu-devel@nongnu.org; Thu, 08 Jan 2015 12:35:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y9GzD-0006Jt-I9 for qemu-devel@nongnu.org; Thu, 08 Jan 2015 12:35:15 -0500 Received: from e31.co.us.ibm.com ([32.97.110.149]:56171) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y9GzD-0006Iy-CD for qemu-devel@nongnu.org; Thu, 08 Jan 2015 12:35:07 -0500 Received: from /spool/local by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 8 Jan 2015 10:35:06 -0700 Received: from d03dlp03.boulder.ibm.com (9.17.202.179) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 8 Jan 2015 10:35:05 -0700 Received: from b03cxnp08026.gho.boulder.ibm.com (b03cxnp08026.gho.boulder.ibm.com [9.17.130.18]) by d03dlp03.boulder.ibm.com (Postfix) with ESMTP id CAE4A19D8040; Thu, 8 Jan 2015 10:23:41 -0700 (MST) Received: from d03av05.boulder.ibm.com (d03av05.boulder.ibm.com [9.17.195.85]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t08HZZZ448300184; Thu, 8 Jan 2015 10:35:35 -0700 Received: from d03av05.boulder.ibm.com (localhost [127.0.0.1]) by d03av05.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t08HZ4Dt019337; Thu, 8 Jan 2015 10:35:04 -0700 Received: from localhost (morrigu.austin.ibm.com [9.41.105.45]) by d03av05.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t08HZ3MT019246; Thu, 8 Jan 2015 10:35:03 -0700 From: Michael Roth To: qemu-devel@nongnu.org Date: Thu, 8 Jan 2015 11:33:19 -0600 Message-Id: <1420738472-23267-16-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1420738472-23267-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1420738472-23267-1-git-send-email-mdroth@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15010817-8236-0000-0000-000008730CB5 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 32.97.110.149 Cc: qemu-stable@nongnu.org Subject: [Qemu-devel] [PATCH 15/88] qapi: dealloc visitor, implement visit_start_union 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org If the .data field of a QAPI Union is NULL, we don't need to free any of the union fields. Make use of the new visit_start_union interface to access this information and instruct the generated code to not visit these fields when this occurs. Cc: qemu-stable@nongnu.org Reported-by: Fam Zheng Suggested-by: Paolo Bonzini Reviewed-by: Paolo Bonzini Reviewed-by: Eric Blake Signed-off-by: Michael Roth Signed-off-by: Luiz Capitulino (cherry picked from commit 146db9f91979db89a123ea10d2b825d3670d2b36) Signed-off-by: Michael Roth --- qapi/qapi-dealloc-visitor.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/qapi/qapi-dealloc-visitor.c b/qapi/qapi-dealloc-visitor.c index dc53545..a14a1c7 100644 --- a/qapi/qapi-dealloc-visitor.c +++ b/qapi/qapi-dealloc-visitor.c @@ -162,6 +162,31 @@ static void qapi_dealloc_type_enum(Visitor *v, int *obj, const char *strings[], { } +/* If there's no data present, the dealloc visitor has nothing to free. + * Thus, indicate to visitor code that the subsequent union fields can + * be skipped. This is not an error condition, since the cleanup of the + * rest of an object can continue unhindered, so leave errp unset in + * these cases. + * + * NOTE: In cases where we're attempting to deallocate an object that + * may have missing fields, the field indicating the union type may + * be missing. In such a case, it's possible we don't have enough + * information to differentiate data_present == false from a case where + * data *is* present but happens to be a scalar with a value of 0. + * This is okay, since in the case of the dealloc visitor there's no + * work that needs to done in either situation. + * + * The current inability in QAPI code to more thoroughly verify a union + * type in such cases will likely need to be addressed if we wish to + * implement this interface for other types of visitors in the future, + * however. + */ +static bool qapi_dealloc_start_union(Visitor *v, bool data_present, + Error **errp) +{ + return data_present; +} + Visitor *qapi_dealloc_get_visitor(QapiDeallocVisitor *v) { return &v->visitor; @@ -191,6 +216,7 @@ QapiDeallocVisitor *qapi_dealloc_visitor_new(void) v->visitor.type_str = qapi_dealloc_type_str; v->visitor.type_number = qapi_dealloc_type_number; v->visitor.type_size = qapi_dealloc_type_size; + v->visitor.start_union = qapi_dealloc_start_union; QTAILQ_INIT(&v->stack);