From patchwork Tue May 9 08:06:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 759941 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 3wMX9B2pDLz9s65 for ; Tue, 9 May 2017 18:10:06 +1000 (AEST) Received: from localhost ([::1]:35641 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d80Db-0002Kt-N0 for incoming@patchwork.ozlabs.org; Tue, 09 May 2017 04:10:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44110) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d80Ab-00085O-1y for qemu-devel@nongnu.org; Tue, 09 May 2017 04:06:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d80AV-0007Yt-Et for qemu-devel@nongnu.org; Tue, 09 May 2017 04:06:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35176) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d80AV-0007Xq-6a for qemu-devel@nongnu.org; Tue, 09 May 2017 04:06:51 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3BA3C804ED for ; Tue, 9 May 2017 08:06:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3BA3C804ED Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3BA3C804ED Received: from blackfin.pond.sub.org (ovpn-116-149.ams2.redhat.com [10.36.116.149]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 09B80881FA for ; Tue, 9 May 2017 08:06:50 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 6BD6C1142143; Tue, 9 May 2017 10:06:45 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 9 May 2017 10:06:32 +0200 Message-Id: <1494317205-2211-16-git-send-email-armbru@redhat.com> In-Reply-To: <1494317205-2211-1-git-send-email-armbru@redhat.com> References: <1494317205-2211-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 09 May 2017 08:06:50 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v3 15/28] qapi: New QAPI_CLONE_MEMBERS() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 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" QAPI_CLONE() returns a newly allocated QAPI object. Inconvenient when we want to clone into an existing object. QAPI_CLONE_MEMBERS() does exactly that. Signed-off-by: Markus Armbruster Message-Id: <1493192202-3184-4-git-send-email-armbru@redhat.com> Reviewed-by: Eric Blake --- include/qapi/clone-visitor.h | 14 ++++++++++++++ qapi/qapi-clone-visitor.c | 13 +++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/qapi/clone-visitor.h b/include/qapi/clone-visitor.h index b16177e..a4915c7 100644 --- a/include/qapi/clone-visitor.h +++ b/include/qapi/clone-visitor.h @@ -24,6 +24,9 @@ typedef struct QapiCloneVisitor QapiCloneVisitor; void *qapi_clone(const void *src, void (*visit_type)(Visitor *, const char *, void **, Error **)); +void qapi_clone_members(void *dst, const void *src, size_t sz, + void (*visit_type_members)(Visitor *, void *, + Error **)); /* * Deep-clone QAPI object @src of the given @type, and return the result. @@ -36,4 +39,15 @@ void *qapi_clone(const void *src, void (*visit_type)(Visitor *, const char *, (void (*)(Visitor *, const char *, void**, \ Error **))visit_type_ ## type)) +/* + * Copy deep clones of @type members from @src to @dst. + * + * Not usable on QAPI scalars (integers, strings, enums), nor on a + * QAPI object that references the 'any' type. + */ +#define QAPI_CLONE_MEMBERS(type, dst, src) \ + qapi_clone_members(dst, src, sizeof(type), \ + (void (*)(Visitor *, void *, \ + Error **))visit_type_ ## type ## _members) + #endif diff --git a/qapi/qapi-clone-visitor.c b/qapi/qapi-clone-visitor.c index 34086cb..de756bf 100644 --- a/qapi/qapi-clone-visitor.c +++ b/qapi/qapi-clone-visitor.c @@ -180,3 +180,16 @@ void *qapi_clone(const void *src, void (*visit_type)(Visitor *, const char *, visit_free(v); return dst; } + +void qapi_clone_members(void *dst, const void *src, size_t sz, + void (*visit_type_members)(Visitor *, void *, + Error **)) +{ + Visitor *v; + + v = qapi_clone_visitor_new(); + memcpy(dst, src, sz); + to_qcv(v)->depth++; + visit_type_members(v, dst, &error_abort); + visit_free(v); +}