[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 28/48] rust: vmstate: implement Zeroable for VMStateField
From: |
Paolo Bonzini |
Subject: |
[PULL 28/48] rust: vmstate: implement Zeroable for VMStateField |
Date: |
Fri, 24 Jan 2025 10:44:22 +0100 |
This shortens a bit the constants. Do not bother using it
in the vmstate macros since most of them will go away soon.
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
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 2b14d4839df..7652930affc 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
@@ -503,20 +503,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.48.1
- [PULL 36/48] rust: pl011: remove unnecessary "extern crate", (continued)
- [PULL 36/48] rust: pl011: remove unnecessary "extern crate", Paolo Bonzini, 2025/01/24
- [PULL 37/48] rust: pl011: hide unnecessarily "pub" items from outside pl011::device, Paolo Bonzini, 2025/01/24
- [PULL 48/48] rust: qemu-api: add sub-subclass to the integration tests, Paolo Bonzini, 2025/01/24
- [PULL 21/48] rust/qdev: Make REALIZE safe, Paolo Bonzini, 2025/01/24
- [PULL 45/48] rust: pl011: drop use of ControlFlow, Paolo Bonzini, 2025/01/24
- [PULL 40/48] rust: pl011: pull interrupt updates out of read/write ops, Paolo Bonzini, 2025/01/24
- [PULL 32/48] rust: pl011: switch vmstate to new-style macros, Paolo Bonzini, 2025/01/24
- [PULL 38/48] rust: pl011: extract conversion to RegisterOffset, Paolo Bonzini, 2025/01/24
- [PULL 47/48] rust/zeroable: Implement Zeroable with const_zero macro, Paolo Bonzini, 2025/01/24
- [PULL 27/48] rust: vmstate: add varray support to vmstate_of!, Paolo Bonzini, 2025/01/24
- [PULL 28/48] rust: vmstate: implement Zeroable for VMStateField,
Paolo Bonzini <=
- [PULL 31/48] rust: qemu_api: add vmstate_struct, Paolo Bonzini, 2025/01/24
- [PULL 39/48] rust: pl011: extract CharBackend receive logic into a separate function, Paolo Bonzini, 2025/01/24
- [PULL 44/48] rust: pl011: pull device-specific code out of MemoryRegionOps callbacks, Paolo Bonzini, 2025/01/24
- [PULL 33/48] rust: vmstate: remove translation of C vmstate macros, Paolo Bonzini, 2025/01/24
- [PULL 41/48] rust: pl011: extract PL011Registers, Paolo Bonzini, 2025/01/24
- [PULL 46/48] rust: qdev: make reset take a shared reference, Paolo Bonzini, 2025/01/24
- Re: [PULL 00/48] i386, rust changes for 2024-01-24, Stefan Hajnoczi, 2025/01/24
- [PULL 00/48] i386, rust changes for 2024-01-24, Paolo Bonzini, 2025/01/28