mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-28 04:43:54 -06:00
rust: qom: add possibility of overriding unparent
Add a blanket definition of ClassInitImpl<ObjectClass> that thunks ObjectImpl::UNPARENT and overrides it in ObjectClass if it is not None. ClassInitImpl<DeviceClass> 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 <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
6dd818fbbb
commit
cb36da9bd8
2 changed files with 45 additions and 5 deletions
|
@ -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<T: DeviceImpl>(dev: *mut DeviceState) {
|
|||
|
||||
impl<T> ClassInitImpl<DeviceClass> for T
|
||||
where
|
||||
T: DeviceImpl,
|
||||
T: ClassInitImpl<ObjectClass> + DeviceImpl,
|
||||
{
|
||||
fn class_init(dc: &mut DeviceClass) {
|
||||
if <T as DeviceImpl>::REALIZE.is_some() {
|
||||
|
@ -88,6 +88,8 @@ where
|
|||
bindings::device_class_set_props_n(dc, prop.as_ptr(), prop.len());
|
||||
}
|
||||
}
|
||||
|
||||
<T as ClassInitImpl<ObjectClass>>::class_init(&mut dc.parent_class);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue