mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 16:23:55 -06:00
rust: qom: put class_init together from multiple ClassInitImpl<>
Parameterize the implementation of ClassInitImpl so that it is possible to call up the chain of implementations, one superclass at a time starting at ClassInitImpl<Self::Class>. In order to avoid having to implement (for example) ClassInitImpl<PL011Class>, also remove the dummy PL011Class and PL011LuminaryClass structs and specify the same ObjectType::Class as the superclass. In the future this default behavior can be handled by a procedural macro, by looking at the first field in the struct. Note that the new trait is safe: the calls are started by rust_class_init<>(), which is not public and can convert the class pointer to a Rust reference. Since CLASS_BASE_INIT applies to the type that is being defined, and only to it, move it to ObjectImpl. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
b1987a2547
commit
6dd818fbbb
5 changed files with 127 additions and 80 deletions
|
@ -13,7 +13,6 @@ use qemu_api::{
|
|||
c_str,
|
||||
definitions::ObjectImpl,
|
||||
device_class::DeviceImpl,
|
||||
impl_device_class,
|
||||
irq::InterruptSource,
|
||||
prelude::*,
|
||||
};
|
||||
|
@ -108,7 +107,7 @@ pub struct PL011State {
|
|||
}
|
||||
|
||||
unsafe impl ObjectType for PL011State {
|
||||
type Class = PL011Class;
|
||||
type Class = <SysBusDevice as ObjectType>::Class;
|
||||
const TYPE_NAME: &'static CStr = crate::TYPE_PL011;
|
||||
}
|
||||
|
||||
|
@ -118,11 +117,6 @@ impl ObjectImpl for PL011State {
|
|||
const INSTANCE_INIT: Option<unsafe fn(&mut Self)> = Some(Self::init);
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct PL011Class {
|
||||
_inner: [u8; 0],
|
||||
}
|
||||
|
||||
impl DeviceImpl for PL011State {
|
||||
fn properties() -> &'static [Property] {
|
||||
&device_class::PL011_PROPERTIES
|
||||
|
@ -134,8 +128,6 @@ impl DeviceImpl for PL011State {
|
|||
const RESET: Option<fn(&mut Self)> = Some(Self::reset);
|
||||
}
|
||||
|
||||
impl_device_class!(PL011State);
|
||||
|
||||
impl PL011State {
|
||||
/// Initializes a pre-allocated, unitialized instance of `PL011State`.
|
||||
///
|
||||
|
@ -627,11 +619,6 @@ pub struct PL011Luminary {
|
|||
parent_obj: PL011State,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct PL011LuminaryClass {
|
||||
_inner: [u8; 0],
|
||||
}
|
||||
|
||||
impl PL011Luminary {
|
||||
/// Initializes a pre-allocated, unitialized instance of `PL011Luminary`.
|
||||
///
|
||||
|
@ -646,7 +633,7 @@ impl PL011Luminary {
|
|||
}
|
||||
|
||||
unsafe impl ObjectType for PL011Luminary {
|
||||
type Class = PL011LuminaryClass;
|
||||
type Class = <PL011State as ObjectType>::Class;
|
||||
const TYPE_NAME: &'static CStr = crate::TYPE_PL011_LUMINARY;
|
||||
}
|
||||
|
||||
|
@ -657,5 +644,3 @@ impl ObjectImpl for PL011Luminary {
|
|||
}
|
||||
|
||||
impl DeviceImpl for PL011Luminary {}
|
||||
|
||||
impl_device_class!(PL011Luminary);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue