From cb36da9bd84076470f36da56542e85a2436e3d95 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 29 Oct 2024 15:00:26 +0100 Subject: rust: qom: add possibility of overriding unparent Add a blanket definition of ClassInitImpl that thunks ObjectImpl::UNPARENT and overrides it in ObjectClass if it is not None. ClassInitImpl can now call its superclass's ClassInitImpl, so that the C and Rust hierarchies match more closely. This is mostly done as an example of implementing the metaclass hierarchy under ClassInitImpl. Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/qemu-api/src/device_class.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'rust/qemu-api/src/device_class.rs') diff --git a/rust/qemu-api/src/device_class.rs b/rust/qemu-api/src/device_class.rs index dcec548829..a9965d1f12 100644 --- a/rust/qemu-api/src/device_class.rs +++ b/rust/qemu-api/src/device_class.rs @@ -5,7 +5,7 @@ use std::ffi::CStr; use crate::{ - bindings::{self, DeviceClass, DeviceState, Error, Property, VMStateDescription}, + bindings::{self, DeviceClass, DeviceState, Error, ObjectClass, Property, VMStateDescription}, definitions::ClassInitImpl, prelude::*, }; @@ -68,7 +68,7 @@ unsafe extern "C" fn rust_reset_fn(dev: *mut DeviceState) { impl ClassInitImpl for T where - T: DeviceImpl, + T: ClassInitImpl + DeviceImpl, { fn class_init(dc: &mut DeviceClass) { if ::REALIZE.is_some() { @@ -88,6 +88,8 @@ where bindings::device_class_set_props_n(dc, prop.as_ptr(), prop.len()); } } + + >::class_init(&mut dc.parent_class); } } -- cgit 1.4.1