From nobody Tue Dec 3 19:20:55 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730741671; cv=none; d=zohomail.com; s=zohoarc; b=gRIFq7U7ILVXnGTKa47Vh+8Fts3/nuzCH7Oq3vCVfGeP6i1KqIU62uNrR3A/0vSrW4Va+jJLdAIreY4UGiVoiqis3Hj7AdXSxZ8oxhdJqz1Z0AarWQ0beuEB30/dP/2NpoBrpRARX0+r9njucF1fRbsHVf2D+m/ElnPXvLuYMp4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730741671; 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=Pk/ExTQ6ucVRc/G0SIy96rszaYTtvZQeQUouajsdp/c=; b=PvAshuLN+fN84K9laPHW6Qu+yaUlmIBPsZ/ZfVLU55bY4Psh+SXhAjby0O7l+K9+p+C9mFJFm3+t63hNTAT9zu2N0Il/aTORaoxcQAdkRcqQtReOO0gRV/OzBREvZxuvw5idqfYD5Hs5Qir8o1wRI1vkpmvtRRlQz07VCq5H7mU= 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 173074167168788.61993880781574; Mon, 4 Nov 2024 09:34:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t80s8-0005IN-Th; Mon, 04 Nov 2024 12:28:12 -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 1t80s7-0005Hw-Lb for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:11 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t80rt-0000GW-Vu for qemu-devel@nongnu.org; Mon, 04 Nov 2024 12:28:11 -0500 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-358--fCdCgH8Ow-mL7AQPVzcvA-1; Mon, 04 Nov 2024 12:27:56 -0500 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-37d462b64e3so2205463f8f.3 for ; Mon, 04 Nov 2024 09:27:56 -0800 (PST) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c10e7387sm13668758f8f.51.2024.11.04.09.27.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 09:27:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730741277; h=from:from:reply-to:subject:subject: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=Pk/ExTQ6ucVRc/G0SIy96rszaYTtvZQeQUouajsdp/c=; b=WbOJjC5O594iEUlYuS+BqGG8xJjNdg/HX/vkDDY1SHnCX0PiSwxvBxgF4VnrYTIoil030t bH/ya23m+f2AL/lplNz10No/w+UWd6nCahEeZT3WSNEq1UrkNzLmpdW2uhnZAJvkKbcvtz LRriz5aD4MV85KrOMUKcRoWUWZqabpY= X-MC-Unique: -fCdCgH8Ow-mL7AQPVzcvA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730741274; x=1731346074; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Pk/ExTQ6ucVRc/G0SIy96rszaYTtvZQeQUouajsdp/c=; b=GUfzGOhBkfUFpmy62zsh47iX9drkjB8Fc1qdVMUObafFbwzQTMpGErP7DQ5Tm+ohvZ ExxvLW2t1cBPH41tadyAX/kTdq86r/FsSVfbgAyLKaTsTSJXw1NwEEv9vyGyYKifm8ZF ciYERUnYUhgZ+ecg7WjF5/AZLFHpkzMjKWNV8EO1B2Yzkg3ZP7ary984xJ6+3kfgNkvZ sVu1nHNKodjLVjNdVDUn63W7TiUyfZaDU3DMku3eMgQjufQA+V0FmvwAjTogt4Flxly9 EPWOmrOWMfaB5S2kS1Hyu9iK8HK3hmpzc2dPGTi0k0bw4PrtxapnHIPsooP16XipbfkR 84yw== X-Gm-Message-State: AOJu0Yw3Vy1dockVmCiMNLRgeuRvdMlH5jiNqOrrC8yHl1VRb4kCxvyG JVgjaPY0Rv5PeWCMwBLmV3qhNeYb0ys8xZOfSd3rDFwut/YWmgWGOQLYsM33kSHu6DEmde/iJL7 prWBAP+XQYKOjGcLzs2O5yTs2OvUD8or2xLpD8lTgOQ2AOrVwk9s+wEVIZVB/p9/Y5sfZtdeMtK w3+FALVTHfmsrU73abj6GWk6j5ol46+c6tg70ubjA= X-Received: by 2002:a5d:59ae:0:b0:37d:4436:4505 with SMTP id ffacd0b85a97d-381c7a6da29mr11183512f8f.32.1730741274161; Mon, 04 Nov 2024 09:27:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IE5OD0chnnFJNh9oI3nKMGx+drihViu2NxC6XbMhte5HIU3oQ1YFjnJIpz9F384EgrbBzmZmA== X-Received: by 2002:a5d:59ae:0:b0:37d:4436:4505 with SMTP id ffacd0b85a97d-381c7a6da29mr11183471f8f.32.1730741273702; Mon, 04 Nov 2024 09:27:53 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Junjie Mao , Kevin Wolf , Manos Pitsidianakis , Pierrick Bouvier , Zhao Liu Subject: [PULL 14/40] rust: clean up define_property macro Date: Mon, 4 Nov 2024 18:26:53 +0100 Message-ID: <20241104172721.180255-15-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104172721.180255-1-pbonzini@redhat.com> References: <20241104172721.180255-1-pbonzini@redhat.com> MIME-Version: 1.0 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 client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, 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_VALIDITY_CERTIFIED_BLOCKED=0.001, 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: 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: 1730741672994116600 Content-Type: text/plain; charset="utf-8" Use the "struct update" syntax to initialize most of the fields to zero, and simplify the handmade type-checking of $name. Reviewed-by: Junjie Mao Reviewed-by: Kevin Wolf Signed-off-by: Paolo Bonzini --- rust/qemu-api/src/device_class.rs | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/rust/qemu-api/src/device_class.rs b/rust/qemu-api/src/device_c= lass.rs index 2219b9f73d0..aab60484096 100644 --- a/rust/qemu-api/src/device_class.rs +++ b/rust/qemu-api/src/device_class.rs @@ -29,44 +29,27 @@ macro_rules! device_class_init { macro_rules! define_property { ($name:expr, $state:ty, $field:expr, $prop:expr, $type:expr, default = =3D $defval:expr$(,)*) =3D> { $crate::bindings::Property { - name: { - #[used] - static _TEMP: &::core::ffi::CStr =3D $name; - _TEMP.as_ptr() - }, + // use associated function syntax for type checking + name: ::core::ffi::CStr::as_ptr($name), info: $prop, offset: ::core::mem::offset_of!($state, $field) .try_into() .expect("Could not fit offset value to type"), - bitnr: 0, - bitmask: 0, set_default: true, - defval: $crate::bindings::Property__bindgen_ty_1 { u: $defval.= into() }, - arrayoffset: 0, - arrayinfo: ::core::ptr::null(), - arrayfieldsize: 0, - link_type: ::core::ptr::null(), + defval: $crate::bindings::Property__bindgen_ty_1 { u: $defval = as u64 }, + ..unsafe { ::core::mem::MaybeUninit::<$crate::bindings::Proper= ty>::zeroed().assume_init() } } }; ($name:expr, $state:ty, $field:expr, $prop:expr, $type:expr$(,)*) =3D>= { $crate::bindings::Property { - name: { - #[used] - static _TEMP: &::core::ffi::CStr =3D $name; - _TEMP.as_ptr() - }, + // use associated function syntax for type checking + name: ::core::ffi::CStr::as_ptr($name), info: $prop, offset: ::core::mem::offset_of!($state, $field) .try_into() .expect("Could not fit offset value to type"), - bitnr: 0, - bitmask: 0, set_default: false, - defval: $crate::bindings::Property__bindgen_ty_1 { i: 0 }, - arrayoffset: 0, - arrayinfo: ::core::ptr::null(), - arrayfieldsize: 0, - link_type: ::core::ptr::null(), + ..unsafe { ::core::mem::MaybeUninit::<$crate::bindings::Proper= ty>::zeroed().assume_init() } } }; } --=20 2.47.0