[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 08/12] rust: qom: make INSTANCE_POST_INIT take a shared reference
From: |
Paolo Bonzini |
Subject: |
[PATCH 08/12] rust: qom: make INSTANCE_POST_INIT take a shared reference |
Date: |
Fri, 20 Dec 2024 15:29:50 +0100 |
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
rust/hw/char/pl011/src/device.rs | 4 ++--
rust/qemu-api/src/qom.rs | 8 ++------
2 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs
index 72a4cea042c..6792d13fb77 100644
--- a/rust/hw/char/pl011/src/device.rs
+++ b/rust/hw/char/pl011/src/device.rs
@@ -145,7 +145,7 @@ impl ObjectImpl for PL011State {
type ParentType = SysBusDevice;
const INSTANCE_INIT: Option<unsafe fn(&mut Self)> = Some(Self::init);
- const INSTANCE_POST_INIT: Option<fn(&mut Self)> = Some(Self::post_init);
+ const INSTANCE_POST_INIT: Option<fn(&Self)> = Some(Self::post_init);
}
impl DeviceImpl for PL011State {
@@ -206,7 +206,7 @@ unsafe fn init(&mut self) {
}
}
- fn post_init(&mut self) {
+ fn post_init(&self) {
let sbd: &SysBusDevice = self.upcast();
sbd.init_mmio(&self.iomem);
diff --git a/rust/qemu-api/src/qom.rs b/rust/qemu-api/src/qom.rs
index 861f1e50ac4..5934eb0cc50 100644
--- a/rust/qemu-api/src/qom.rs
+++ b/rust/qemu-api/src/qom.rs
@@ -163,11 +163,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(),
fmt::Error> {
// SAFETY: obj is an instance of T, since rust_instance_post_init<T>
// is called from QOM core as the instance_post_init function
// for class T
- //
- // FIXME: it's not really guaranteed that there are no backpointers to
- // obj; it's quite possible that they have been created by instance_init().
- // The receiver should be &self, not &mut self.
- T::INSTANCE_POST_INIT.unwrap()(unsafe { &mut *obj.cast::<T>() })
+ T::INSTANCE_POST_INIT.unwrap()(unsafe { &*obj.cast::<T>() })
}
unsafe extern "C" fn rust_class_init<T: ObjectType + ClassInitImpl<T::Class>>(
@@ -459,7 +455,7 @@ pub trait ObjectImpl: ObjectType +
ClassInitImpl<Self::Class> {
/// Function that is called to finish initialization of an object, once
/// `INSTANCE_INIT` functions have been called.
- const INSTANCE_POST_INIT: Option<fn(&mut Self)> = None;
+ const INSTANCE_POST_INIT: Option<fn(&Self)> = None;
/// Called on descendent classes after all parent class initialization
/// has occurred, but before the class itself is initialized. This
--
2.47.1
- Re: [PATCH 11/12] rust: qemu-api-macros: add automatic TryFrom/TryInto derivation, (continued)
- [PATCH 07/12] rust: pl011: only leave embedded object initialization in instance_init, Paolo Bonzini, 2024/12/20
- [PATCH 09/12] rust: qdev: expose inherited methods to subclasses of SysBusDevice, Paolo Bonzini, 2024/12/20
- [PATCH 05/12] rust: qom: automatically use Drop trait to implement instance_finalize, Paolo Bonzini, 2024/12/20
- [PATCH 10/12] rust: qemu-api-macros: extend error reporting facility to parse errors, Paolo Bonzini, 2024/12/20
- [PATCH 06/12] rust: qom: move device_id to PL011 class side, Paolo Bonzini, 2024/12/20
- [PATCH 08/12] rust: qom: make INSTANCE_POST_INIT take a shared reference,
Paolo Bonzini <=
- [PATCH 12/12] rust: hide warnings for subprojects, Paolo Bonzini, 2024/12/20
- Re: [PATCH 00/12] Next round of qemu_api patches, Zhao Liu, 2024/12/23