From nobody Sat Jan 31 20:41:04 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1767878008; cv=none; d=zohomail.com; s=zohoarc; b=aIJwgz0leGYzwCtKhTzwXZ++ZXyG5A35cFC4D2ifMizj7oAQkjQHF2lZY8mb+mxQ9loBSewpTjn0iixUtw8TOPAApZvUbJSs2YlZPt2QItnlX5xxcdaE0moVMsqRVre7AOTBXEAqfjX+njc61L7e2tHKW5X6Vm0rGGSkzEwIrsc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1767878008; h=Content-Type: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=24uu20SH0A5RmWohW/685UZSc7h5TVZr0Shnp1cHoEY=; b=O0kg7FzmxoP2dbpHCMy99J2A7MGAzPAx0VlG66XBSHrPhRH4wwa54Y2qo7hm+ZbNCazWTylps2VWS6xCZsHo80K7HOisSJLfQVo9IgMcdtjUQ+MOw4EkIZ6VoVP0wYDNO2eHMo8G+ZTRYRYWy29zkwZGooZvfvKJzjx5b9YDklQ= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1767878008919631.6354826879565; Thu, 8 Jan 2026 05:13:28 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vdpnI-0007cv-An; Thu, 08 Jan 2026 08:11:16 -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 1vdpnG-0007bt-67 for qemu-devel@nongnu.org; Thu, 08 Jan 2026 08:11:14 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vdpnD-00080h-8D for qemu-devel@nongnu.org; Thu, 08 Jan 2026 08:11:13 -0500 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-613-bARp6NvaOYmmnuwfE-roWQ-1; Thu, 08 Jan 2026 08:11:07 -0500 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-4325aa61c6bso2068210f8f.0 for ; Thu, 08 Jan 2026 05:11:07 -0800 (PST) Received: from [192.168.10.48] ([151.61.26.160]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-432d286cdecsm2534047f8f.7.2026.01.08.05.11.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jan 2026 05:11:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767877870; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=24uu20SH0A5RmWohW/685UZSc7h5TVZr0Shnp1cHoEY=; b=LSkOWSoUfrVj4Xc59Tg9x5jp//4rxr/XNRzILhLJbF5HbHtxgNi9dO/QwaN7BbUJlHa6Ny OAKkxNZ10fkmq2nRwrzi7iw4pLdHFOggd6PMp/nWR5OpgmVgqmWVluK0R6SU/YFn+AxTmr 8bFdVAcfozcc7jjWVufohXaHDlNyBb4= X-MC-Unique: bARp6NvaOYmmnuwfE-roWQ-1 X-Mimecast-MFC-AGG-ID: bARp6NvaOYmmnuwfE-roWQ_1767877867 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1767877865; x=1768482665; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=24uu20SH0A5RmWohW/685UZSc7h5TVZr0Shnp1cHoEY=; b=ao1Pnfb501s1ruzHhNzZLdZfU3J9ggAgvsVSGNFE4BuZkjpb4BOegpjmjvRgn16PaI 5tViTECPDQBWKg5iCi9QFg5TAIBnIiGrS9XLxQC6WHoUp59b7fveqf8/U/RLCQEIKtTW c6O3aqk/sLn8OqmOXxSZUGkY8t/wT8Z1nQrJgdespIRO35a8av6BxAwBAnGstVV0W3bN EO0/QxjNbyZLAwnQ74p3TgnEoxSs7YIcfcug87GQvckBbJ8YGy4ut8uKvtCp1xDejjO4 3COMhsXYEtSRI64Xjs+ENtIL41Ngs6Dx25S2Cx2Dy6iDh/YG9k1zNst+YtI5nw/JFDJG 0png== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767877865; x=1768482665; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=24uu20SH0A5RmWohW/685UZSc7h5TVZr0Shnp1cHoEY=; b=YsSauTAQ0IiIaU90Qf5VBRRl+sEKdlQA65ODTMJDe2KDy/kWn3vrnvSho1wTVSSMCG Uc0zZSYydlkCfnNt/XKkZCeuBeWhUbZf6HYYpiCtwdfpUz4GhTvGApvIGmRle6tzJq3F cGvQENit94bIW+tBbi48a7ZJ7nkJDOto+qyG98BAoS5HrCM5uaHCrK+q5G3b1JtnmiXA P49hXZh7Rw+IjRZ/eNtECf1byk7rLMryppAHY+ckSEx8WWGhWCHAEncVVDacYyiq0PdT SAs6Zn+ll7cI/X8k3Wvddro1poN23JHmeEQrNeQLdIhC7bX+604RcW7IucodPBoYYI3T 2xFg== X-Gm-Message-State: AOJu0YxZ0fhiY65b6w8h/QMa0c1HV1ArnTb6LZyrsOsc0EnmINSvGXB2 g9Xtdm2mQ5ao7fyuIMMbuI7JvXWBwRAaQbIsZiEfnbI4+qHNE6NLe91ZZ5v6BD+K5Jo8oDuUa9o PYZPYgp2uQzdJovwRvhH4VcZT7mbhwDEMXCKSZPeVtUYcIvSgkIn/37ANuVpj/HKFJ/YyBq1W14 EqkgnDjmU8Dx+X9OKnT0OP3NOBhCUugvf8r8/Q24Qy X-Gm-Gg: AY/fxX6NBjdmcSCYLi2q8XvV69weRqEYE7R0j0lbNXnsSg8+j2NS2AKsIP8ekv+6fXh ShHFMX/PxX/Lc2g2OfDWqXfKn9D/VZQ9LkaQ9L2YkQ/v6wejRxiMdbWHdusskHe2Vohw7QAMKj/ I8mSbcyL4d3149J7DmmhyDbsvgPNtayjaywL1DgC62qMKWZ0+YnNVbMOuIB2KTwvX1Za2h2RHEA 1GyCXl99FtjCTcORn9W6LUNKowqTvv4Vo4I5O21hIRqsJDORnnC7U7zV5I3TymwEbz0e44wyDwT yZ4cKy31MvGJMs6XRl/J5L8pacCnTQjMkOOzGTwF+kfoV/Cv/o4WQV6ivo+XDUnI6F2TDiwKHNY 6O8lY45uQ86jbUvkVQajJ8IUHRo+0osetqr/QfTUp5O53jpbOBj8hNVTlZ2yxNCTuXiRPoWtog6 URlwdqisu/0qG2Ew== X-Received: by 2002:a05:6000:4024:b0:431:808:2d50 with SMTP id ffacd0b85a97d-432c3628270mr7910121f8f.13.1767877865223; Thu, 08 Jan 2026 05:11:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IGvittNCdbmpfD2E/UnLYDT9eFkNlLTgyzUxBRwqQaAyJ/ztD9DUB9Z6TDup7+DvYUKcUJ6Uw== X-Received: by 2002:a05:6000:4024:b0:431:808:2d50 with SMTP id ffacd0b85a97d-432c3628270mr7910093f8f.13.1767877864765; Thu, 08 Jan 2026 05:11:04 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: armbru@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , qemu-rust@nongnu.org Subject: [PATCH v2 07/16] rust/qobject: add from/to JSON bindings for QObject Date: Thu, 8 Jan 2026 14:10:34 +0100 Message-ID: <20260108131043.490084-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260108131043.490084-1-pbonzini@redhat.com> References: <20260108131043.490084-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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 @redhat.com) X-ZM-MESSAGEID: 1767878010557158500 These are used by tests. However it could even be an idea to use serde_json + transcoding and get rid of the C version... Co-authored-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Paolo Bonzini Reviewed-by: Zhao Liu --- rust/util/wrapper.h | 1 + rust/util/src/qobject/mod.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/rust/util/wrapper.h b/rust/util/wrapper.h index 0907dd59142..c88820a5e5b 100644 --- a/rust/util/wrapper.h +++ b/rust/util/wrapper.h @@ -37,3 +37,4 @@ typedef enum memory_order { #include "qobject/qobject.h" #include "qobject/qlist.h" #include "qobject/qdict.h" +#include "qobject/qjson.h" diff --git a/rust/util/src/qobject/mod.rs b/rust/util/src/qobject/mod.rs index b95dddddedc..95d41cec4f1 100644 --- a/rust/util/src/qobject/mod.rs +++ b/rust/util/src/qobject/mod.rs @@ -23,6 +23,7 @@ use common::assert_field_type; pub use deserializer::from_qobject; pub use error::{Error, Result}; +use foreign::prelude::*; pub use serializer::to_qobject; =20 use crate::bindings; @@ -112,6 +113,22 @@ fn refcnt(&self) -> &AtomicUsize { let qobj =3D self.0.get(); unsafe { AtomicUsize::from_ptr(addr_of_mut!((*qobj).base.refcnt)) } } + + pub fn to_json(&self) -> String { + let qobj =3D self.0.get(); + unsafe { + let json =3D bindings::qobject_to_json(qobj); + glib_sys::g_string_free(json, glib_sys::GFALSE).into_native() + } + } + + pub fn from_json(json: &str) -> std::result::Result { + let c_json =3D std::ffi::CString::new(json)?; + unsafe { + crate::Error::with_errp(|errp| bindings::qobject_from_json(c_j= son.as_ptr(), errp)) + .map(|qobj| QObject::from_raw(qobj)) + } + } } =20 /// Rust equivalent of the C `QOBJECT` macro; for internal use only, becau= se --=20 2.52.0