From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-rust@nongnu.org, zhao1.liu@intel.com, junjie.mao@hotmail.com
Subject: [RFC PATCH 4/9] rust: vmstate: implement Zeroable for VMStateField
Date: Tue, 31 Dec 2024 01:23:31 +0100 [thread overview]
Message-ID: <20241231002336.25931-5-pbonzini@redhat.com> (raw)
In-Reply-To: <20241231002336.25931-1-pbonzini@redhat.com>
This shortens a bit the constants. Do not bother using it
in the vmstate macros since most of them will go away soon.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
rust/qemu-api/src/vmstate.rs | 18 +++---------------
rust/qemu-api/src/zeroable.rs | 31 +++++++++++++++++++++++++++++++
2 files changed, 34 insertions(+), 15 deletions(-)
diff --git a/rust/qemu-api/src/vmstate.rs b/rust/qemu-api/src/vmstate.rs
index 079c19c687b..49d0a3c31d4 100644
--- a/rust/qemu-api/src/vmstate.rs
+++ b/rust/qemu-api/src/vmstate.rs
@@ -21,8 +21,8 @@
use core::{marker::PhantomData, mem, ptr::NonNull};
-use crate::bindings::VMStateFlags;
pub use crate::bindings::{VMStateDescription, VMStateField};
+use crate::bindings::VMStateFlags;
/// This macro is used to call a function with a generic argument bound
/// to the type of a field. The function must take a
@@ -488,20 +488,8 @@ macro_rules! vmstate_fields {
static _FIELDS: &[$crate::bindings::VMStateField] = &[
$($field),*,
$crate::bindings::VMStateField {
- name: ::core::ptr::null(),
- err_hint: ::core::ptr::null(),
- offset: 0,
- size: 0,
- start: 0,
- num: 0,
- num_offset: 0,
- size_offset: 0,
- info: ::core::ptr::null(),
- flags: VMStateFlags::VMS_END,
- vmsd: ::core::ptr::null(),
- version_id: 0,
- struct_version_id: 0,
- field_exists: None,
+ flags: $crate::bindings::VMStateFlags::VMS_END,
+ ..$crate::zeroable::Zeroable::ZERO
}
];
_FIELDS.as_ptr()
diff --git a/rust/qemu-api/src/zeroable.rs b/rust/qemu-api/src/zeroable.rs
index 6125aeed8b4..57cac96de06 100644
--- a/rust/qemu-api/src/zeroable.rs
+++ b/rust/qemu-api/src/zeroable.rs
@@ -49,6 +49,37 @@ unsafe impl Zeroable for crate::bindings::Property {
};
}
+// bindgen does not derive Default here
+#[allow(clippy::derivable_impls)]
+impl Default for crate::bindings::VMStateFlags {
+ fn default() -> Self {
+ Self(0)
+ }
+}
+
+unsafe impl Zeroable for crate::bindings::VMStateFlags {
+ const ZERO: Self = Self(0);
+}
+
+unsafe impl Zeroable for crate::bindings::VMStateField {
+ const ZERO: Self = Self {
+ name: ptr::null(),
+ err_hint: ptr::null(),
+ offset: 0,
+ size: 0,
+ start: 0,
+ num: 0,
+ num_offset: 0,
+ size_offset: 0,
+ info: ptr::null(),
+ flags: Zeroable::ZERO,
+ vmsd: ptr::null(),
+ version_id: 0,
+ struct_version_id: 0,
+ field_exists: None,
+ };
+}
+
unsafe impl Zeroable for crate::bindings::VMStateDescription {
const ZERO: Self = Self {
name: ptr::null(),
--
2.47.1
next prev parent reply other threads:[~2024-12-31 0:25 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-31 0:23 [RFC PATCH 0/9] rust: (mostly) type safe VMState Paolo Bonzini
2024-12-31 0:23 ` [RFC PATCH 1/9] rust: vmstate: add new type safe implementation Paolo Bonzini
2025-01-07 8:58 ` Zhao Liu
2025-01-07 12:23 ` Paolo Bonzini
2025-01-07 14:01 ` Zhao Liu
2024-12-31 0:23 ` [RFC PATCH 2/9] rust: vmstate: implement VMState for non-leaf types Paolo Bonzini
2025-01-07 15:43 ` Zhao Liu
2024-12-31 0:23 ` [RFC PATCH 3/9] rust: vmstate: add varray support to vmstate_of! Paolo Bonzini
2025-01-08 3:28 ` Zhao Liu
2025-01-15 10:14 ` Paolo Bonzini
2024-12-31 0:23 ` Paolo Bonzini [this message]
2025-01-06 14:31 ` [RFC PATCH 4/9] rust: vmstate: implement Zeroable for VMStateField Zhao Liu
2024-12-31 0:23 ` [RFC PATCH 5/9] rust: vmstate: implement VMState for scalar types Paolo Bonzini
2025-01-08 6:45 ` Zhao Liu
2025-01-15 13:08 ` Paolo Bonzini
2025-01-16 6:59 ` Zhao Liu
2024-12-31 0:23 ` [RFC PATCH 6/9] rust: vmstate: add public utility macros to implement VMState Paolo Bonzini
2025-01-08 8:15 ` Zhao Liu
2024-12-31 0:23 ` [RFC PATCH 7/9] rust: qemu_api: add vmstate_struct and vmstate_cell Paolo Bonzini
2025-01-07 16:49 ` Paolo Bonzini
2024-12-31 0:23 ` [RFC PATCH 8/9] rust: pl011: switch vmstate to new-style macros Paolo Bonzini
2025-01-08 8:27 ` Zhao Liu
2024-12-31 0:23 ` [RFC PATCH 9/9] rust: vmstate: remove translation of C vmstate macros Paolo Bonzini
2025-01-08 8:40 ` Zhao Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241231002336.25931-5-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=junjie.mao@hotmail.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-rust@nongnu.org \
--cc=zhao1.liu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).