From nobody Sat Nov 23 20:57:52 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=1730126086; cv=none; d=zohomail.com; s=zohoarc; b=aiTppK71T53+c5ydw0OLi4IinN4IVZWD87KoWxOXfxGEw9I4eTrH7S13WPVWWsBa1WXW5JlBVyKUeqGbV35mjOHgytQNyoYwGcB48s6QUlUFOcfv16GrT00Bdz2ZF7p/T+NGkUGZV9F/T17Oo9UwQ+rKje1tSfST11TI/TUddYY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730126086; 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=QiU3F2kXawiGc9Re1cuFwMlOJOPD2msOkF+jupV2l3BrniQks4+F7tIjZ+oU5vF0CIIzE4ewMQW5pGMJKV0aYbbI3X7hHA8B9qh93A37IACSa4csFhHEvylKciwk0/S/lgOplQ+r4x6wzhdDkWnDuCbpCrSwn7abHbx/m/h4suQ= 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 1730126086222735.2414380315893; Mon, 28 Oct 2024 07:34:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t5QmG-00021V-SN; Mon, 28 Oct 2024 10:31:30 -0400 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 1t5QlH-0000X7-Bs for qemu-devel@nongnu.org; Mon, 28 Oct 2024 10:30:35 -0400 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 1t5QlF-0003zY-P9 for qemu-devel@nongnu.org; Mon, 28 Oct 2024 10:30:26 -0400 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-631-kJYvjULUMyiwCEFbJ2Cnug-1; Mon, 28 Oct 2024 10:30:23 -0400 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-43151e4ef43so29228445e9.3 for ; Mon, 28 Oct 2024 07:30:22 -0700 (PDT) Received: from [192.168.10.3] ([151.49.226.83]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4318b567838sm143777595e9.23.2024.10.28.07.30.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 07:30:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730125824; 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=gU/w9mEjUSRslODDV+LRCv+zb+cDGGszbQ+mAGWacdcpqhm1kZ4fZ5zbEgPr5Xqx2pe3yB Uvv4v3I5ZcMSGGcqwnMQCwhqGpzDMXyqy94LtgSJCn61dkI9u/JUBGIHrViFDN4KfJDbd/ rCzpRitQ7pJTlM6aHpg0NjoLwbARXq4= X-MC-Unique: kJYvjULUMyiwCEFbJ2Cnug-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730125821; x=1730730621; 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=oefe8RoS6+0+LiCg0QObPSeDKplSB6Zi1LzKICXIn/PRr9Lc69weOfmbaxvOPK1Ukp g4gRO/5jsKfk90jQcVRuhOgumi+LVzN4npW4JGqP9/1oOd5xsB6dNhEa8KjI8qaVGwNU +/ScsXAE97Dh5wpD/URmhY47YGvz2bjZn+VZkWnTuH19TkpKZ1JmJ52g1akf5+7zM/L7 JMP7ude+5i+IpsdjvPMQi7jJcTlCSu+w1upJyQl//5Da4R5+5K1kKy/KdXKe6RZ1ptD7 eftprG7oGbkLTK+BzTcSDpjvPtzDAObIeYalnGxAUxWa60R+H2SgCbkGCap7MHmzeKgI bCdQ== X-Gm-Message-State: AOJu0YwSvmjPZrjWi5Au9/rSBkdYaOmSLyTFfqKq0a/AXghNIvBRpkxp 8Sr3/d0s/2K4SmQuzzhurg0Jb9kXHXJ6GCKNMaCjG61wG2qflJByfKL+h500lOXX8QhkKcpuxLZ zug+6reVScPGIwhuMLHt87z92J45qY2FNmT4tJI/xZvok9Tg7cvJEunFBhylgXQiInREJkiUGTC pLbyjhXjL0ipzy6YF5ZzvDhYH4fX7CNbSQTrmcFbg= X-Received: by 2002:a05:600c:35cd:b0:431:5863:4240 with SMTP id 5b1f17b1804b1-4319ad0f10cmr71826835e9.24.1730125820935; Mon, 28 Oct 2024 07:30:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGwkn0iLfnA9Cyx3xl6Bz568wmEr3A8/4dZfsNLCpF9Ns4X1pK1fBQVC7b/jmexd0ZvgmERxQ== X-Received: by 2002:a05:600c:35cd:b0:431:5863:4240 with SMTP id 5b1f17b1804b1-4319ad0f10cmr71826605e9.24.1730125820538; Mon, 28 Oct 2024 07:30:20 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Junjie Mao , Kevin Wolf Subject: [PULL 18/24] rust: clean up define_property macro Date: Mon, 28 Oct 2024 15:29:25 +0100 Message-ID: <20241028142932.363687-19-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241028142932.363687-1-pbonzini@redhat.com> References: <20241028142932.363687-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.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.373, 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_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: 1730126088416116600 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