From nobody Mon Feb 9 22:04:28 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1768397025; cv=none; d=zohomail.com; s=zohoarc; b=hM3XsL5AOFW7n9GOOvmO8/DmCG9ujOXfLkuktjDWbpk/teLZ7ZvTdFEtWPWjrx2CZ2SAzIhryC9GhsDlD63tSR33DTckga864PFigrG6psKB3GPniEeh8AOJhc4zocOJqksnM2UVgHw3S2rFrJ+FVW3LB9Yc9RHzyf69u6oE1tY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1768397025; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=/NDK5VnnkFXqjnSY/+1rjEdw0JQMtPwLYXBs1hRb32U=; b=mTx5PYckMY8BChMbuEeJgbhgzoj8KzCcyr85wVmv2jjQb5/AOICBYPAVolTQwrs38ZAFsBdAGFYmktgUD3WwLpK60ws1yxZ2rOclEH2UmtUvw5NKEDpBcR8BAs1z6IurxpLvAr21oguFrZ0XkaiyZFjcss9Wk2nk7EdfPc1Mxqg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1768397025243298.96132239945723; Wed, 14 Jan 2026 05:23:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vg0qU-0006YJ-4R; Wed, 14 Jan 2026 08:23:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vg0qL-0006Xk-V3 for qemu-devel@nongnu.org; Wed, 14 Jan 2026 08:23:25 -0500 Received: from smtp-out1.suse.de ([2a07:de40:b251:101:10:150:64:1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vg0qK-0006i9-75 for qemu-devel@nongnu.org; Wed, 14 Jan 2026 08:23:25 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 3E9863411C; Wed, 14 Jan 2026 13:23:21 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id A24673EA63; Wed, 14 Jan 2026 13:23:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 4A2uGMeYZ2nxBwAAD6G6ig (envelope-from ); Wed, 14 Jan 2026 13:23:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1768397001; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/NDK5VnnkFXqjnSY/+1rjEdw0JQMtPwLYXBs1hRb32U=; b=mqi/+1M+ut4kWCYVsqPJuKH28X/nzdiXLDPbDxCOL+XUysa2kCC2mIZAioW7daIMSjB0E+ Celo07s0WgXiXp51O4Uutna+SwkG/SAwg4DpK+uY6fScyM26GVmwIdpv9KKhEfRjKOOkzX d8eWQAjy1T0EgqdybXF2T0+WGtz+Ytg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1768397001; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/NDK5VnnkFXqjnSY/+1rjEdw0JQMtPwLYXBs1hRb32U=; b=Y7qwDrvTDspUAheKM0Rvt8/xkTTzmND/5Z4VKmvJhVOUz9SpOPRdFDeiwnQ+lvumdrFrFZ pKOwyf258e/loBBA== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="mqi/+1M+"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=Y7qwDrvT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1768397001; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/NDK5VnnkFXqjnSY/+1rjEdw0JQMtPwLYXBs1hRb32U=; b=mqi/+1M+ut4kWCYVsqPJuKH28X/nzdiXLDPbDxCOL+XUysa2kCC2mIZAioW7daIMSjB0E+ Celo07s0WgXiXp51O4Uutna+SwkG/SAwg4DpK+uY6fScyM26GVmwIdpv9KKhEfRjKOOkzX d8eWQAjy1T0EgqdybXF2T0+WGtz+Ytg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1768397001; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/NDK5VnnkFXqjnSY/+1rjEdw0JQMtPwLYXBs1hRb32U=; b=Y7qwDrvTDspUAheKM0Rvt8/xkTTzmND/5Z4VKmvJhVOUz9SpOPRdFDeiwnQ+lvumdrFrFZ pKOwyf258e/loBBA== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: peterx@redhat.com, armbru@redhat.com, Michael Roth Subject: [PATCH 4/5] qapi: Add QAPI_MERGE Date: Wed, 14 Jan 2026 10:23:08 -0300 Message-ID: <20260114132309.5832-5-farosas@suse.de> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260114132309.5832-1-farosas@suse.de> References: <20260114132309.5832-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -3.01 X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[99.99%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:mid,suse.de:email,imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Action: no action X-Rspamd-Queue-Id: 3E9863411C X-Rspamd-Server: rspamd1.dmz-prg2.suse.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a07:de40:b251:101:10:150:64:1; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1768397027409158500 Content-Type: text/plain; charset="utf-8" The migration subsystem currently has code to merge two objects of the same type. It does so by checking which fields are present in a source object and overwriting the corresponding fields on the destination object. This leads to a lot of open-coded lines such as: if (src->has_foobar) { dst->foobar =3D src->foobar; } This pattern could be replaced by a copy using visitors. Implement a macro that extracts elements from a source object using an output visitor and merges it with a destination object using an input visitor. Acked-by: Peter Xu Signed-off-by: Fabiano Rosas --- include/qapi/type-helpers.h | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/include/qapi/type-helpers.h b/include/qapi/type-helpers.h index fc8352cdec..f22d7b7139 100644 --- a/include/qapi/type-helpers.h +++ b/include/qapi/type-helpers.h @@ -10,6 +10,9 @@ */ =20 #include "qapi/qapi-types-common.h" +#include "qapi/qobject-input-visitor.h" +#include "qapi/qobject-output-visitor.h" +#include "qapi/dealloc-visitor.h" =20 HumanReadableText *human_readable_text_from_str(GString *str); =20 @@ -20,3 +23,40 @@ HumanReadableText *human_readable_text_from_str(GString = *str); * cleanup. */ char **strv_from_str_list(const strList *list); + +/* + * Merge @src over @dst by copying deep clones of the present members + * from @src to @dst. Non-present on @src are left untouched on + * @dst. Pointer members that are overwritten are also freed. + */ +#define QAPI_MERGE(type, dst_, src_) \ + ({ \ + QObject *out_ =3D NULL; \ + Visitor *v_; \ + /* read in from src */ \ + v_ =3D qobject_output_visitor_new(&out_); \ + visit_type_ ## type(v_, NULL, &src_, &error_abort); \ + visit_complete(v_, &out_); \ + visit_free(v_); \ + /* \ + * Free the memory for which the pointers will be overwritten \ + * in the next step. \ + */ \ + v_ =3D qapi_dealloc_present_visitor_new(out_); \ + visit_start_struct(v_, NULL, NULL, 0, &error_abort); \ + visit_type_ ## type ## _members(v_, dst_, &error_abort); \ + visit_end_struct(v_, NULL); \ + visit_free(v_); \ + /* \ + * Write to dst but leave existing fields intact (except for \ + * has_* which will be updated according to their presence in \ + * src). \ + */ \ + v_ =3D qobject_input_visitor_new(out_); \ + visit_start_struct(v_, NULL, NULL, 0, &error_abort); \ + visit_type_ ## type ## _members(v_, dst_, &error_abort); \ + visit_check_struct(v_, &error_abort); \ + visit_end_struct(v_, NULL); \ + visit_free(v_); \ + qobject_unref(out_); \ + }) --=20 2.51.0