mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 23:33:54 -06:00
rust: qom: remove operations on &mut
The dubious casts of mutable references to objects are not used anymore: the wrappers for qdev_init_clock_in and for IRQ and MMIO initialization can be called directly on the subclasses, without casts, plus they take a shared reference so they can just use "upcast()" instead of "upcast_mut()". Remove them. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
5778ce9997
commit
094cd35913
4 changed files with 2 additions and 121 deletions
|
@ -2,13 +2,10 @@
|
|||
// Author(s): Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
use std::{
|
||||
ffi::{c_void, CStr},
|
||||
ptr::{addr_of, addr_of_mut},
|
||||
};
|
||||
use std::{ffi::CStr, ptr::addr_of};
|
||||
|
||||
use qemu_api::{
|
||||
bindings::{module_call_init, module_init_type, object_new, object_unref, qdev_prop_bool},
|
||||
bindings::{module_call_init, module_init_type, qdev_prop_bool},
|
||||
c_str,
|
||||
cell::{self, BqlCell},
|
||||
declare_properties, define_property,
|
||||
|
@ -182,30 +179,3 @@ fn test_cast() {
|
|||
assert_eq!(addr_of!(*sbd_ref), p_ptr.cast());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(clippy::shadow_unrelated)]
|
||||
/// Test casts on mutable references.
|
||||
fn test_cast_mut() {
|
||||
init_qom();
|
||||
let p: *mut DummyState = unsafe { object_new(DummyState::TYPE_NAME.as_ptr()).cast() };
|
||||
|
||||
let p_ref: &mut DummyState = unsafe { &mut *p };
|
||||
let obj_ref: &mut Object = p_ref.upcast_mut();
|
||||
assert_eq!(addr_of_mut!(*obj_ref), p.cast());
|
||||
|
||||
let sbd_ref: Result<&mut SysBusDevice, &mut Object> = obj_ref.dynamic_cast_mut();
|
||||
let obj_ref = sbd_ref.unwrap_err();
|
||||
|
||||
let dev_ref: Result<&mut DeviceState, &mut Object> = obj_ref.downcast_mut();
|
||||
let dev_ref = dev_ref.unwrap();
|
||||
assert_eq!(addr_of_mut!(*dev_ref), p.cast());
|
||||
|
||||
// SAFETY: the cast is wrong, but the value is only used for comparison
|
||||
unsafe {
|
||||
let sbd_ref: &mut SysBusDevice = obj_ref.unsafe_cast_mut();
|
||||
assert_eq!(addr_of_mut!(*sbd_ref), p.cast());
|
||||
|
||||
object_unref(p_ref.as_object_mut_ptr().cast::<c_void>());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue