mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-08 02:03:56 -06:00
rust: provide safe wrapper for MaybeUninit::zeroed()
MaybeUninit::zeroed() is handy, but it introduces unsafe (and has a pretty heavy syntax in general). Introduce a trait that provides the same functionality while staying within safe Rust. In addition, MaybeUninit::zeroed() is not available as a "const" function until Rust 1.75.0, so this also prepares for having handwritten implementations of the trait until we can assume that version. Reviewed-by: Junjie Mao <junjie.mao@hotmail.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
c92c447ff0
commit
6e50bde1e1
6 changed files with 35 additions and 10 deletions
|
@ -4,7 +4,7 @@
|
|||
|
||||
use core::ptr::NonNull;
|
||||
|
||||
use qemu_api::{bindings::*, definitions::ObjectImpl};
|
||||
use qemu_api::{bindings::*, definitions::ObjectImpl, zeroable::Zeroable};
|
||||
|
||||
use crate::device::PL011State;
|
||||
|
||||
|
@ -12,7 +12,7 @@ use crate::device::PL011State;
|
|||
pub static VMSTATE_PL011: VMStateDescription = VMStateDescription {
|
||||
name: PL011State::TYPE_INFO.name,
|
||||
unmigratable: true,
|
||||
..unsafe { ::core::mem::MaybeUninit::<VMStateDescription>::zeroed().assume_init() }
|
||||
..Zeroable::ZERO
|
||||
};
|
||||
|
||||
qemu_api::declare_properties! {
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
// Author(s): Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
use core::{mem::MaybeUninit, ptr::NonNull};
|
||||
use core::ptr::NonNull;
|
||||
|
||||
use qemu_api::bindings::*;
|
||||
use qemu_api::{bindings::*, zeroable::Zeroable};
|
||||
|
||||
use crate::device::PL011State;
|
||||
|
||||
|
@ -14,11 +14,11 @@ pub static PL011_OPS: MemoryRegionOps = MemoryRegionOps {
|
|||
read_with_attrs: None,
|
||||
write_with_attrs: None,
|
||||
endianness: device_endian::DEVICE_NATIVE_ENDIAN,
|
||||
valid: unsafe { MaybeUninit::<MemoryRegionOps__bindgen_ty_1>::zeroed().assume_init() },
|
||||
valid: Zeroable::ZERO,
|
||||
impl_: MemoryRegionOps__bindgen_ty_2 {
|
||||
min_access_size: 4,
|
||||
max_access_size: 4,
|
||||
..unsafe { MaybeUninit::<MemoryRegionOps__bindgen_ty_2>::zeroed().assume_init() }
|
||||
..Zeroable::ZERO
|
||||
},
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue