[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 18/26] rust: qom: add possibility of overriding unparent
From: |
Zhao Liu |
Subject: |
Re: [PATCH 18/26] rust: qom: add possibility of overriding unparent |
Date: |
Thu, 12 Dec 2024 17:40:05 +0800 |
On Mon, Dec 09, 2024 at 01:37:09PM +0100, Paolo Bonzini wrote:
> Date: Mon, 9 Dec 2024 13:37:09 +0100
> From: Paolo Bonzini <pbonzini@redhat.com>
> Subject: [PATCH 18/26] rust: qom: add possibility of overriding unparent
> X-Mailer: git-send-email 2.47.1
>
> 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.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> rust/qemu-api/src/definitions.rs | 44 ++++++++++++++++++++++++++++---
> rust/qemu-api/src/device_class.rs | 6 +++--
> 2 files changed, 45 insertions(+), 5 deletions(-)
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
(with an additional comment below...)
> diff --git a/rust/qemu-api/src/definitions.rs
> b/rust/qemu-api/src/definitions.rs
> index 2429b9f53f0..958ea34decc 100644
> --- a/rust/qemu-api/src/definitions.rs
> +++ b/rust/qemu-api/src/definitions.rs
> @@ -6,7 +6,7 @@
>
> use std::{ffi::CStr, os::raw::c_void};
>
> -use crate::bindings::{Object, ObjectClass, TypeInfo};
> +use crate::bindings::{self, Object, ObjectClass, TypeInfo};
>
> unsafe extern "C" fn rust_instance_init<T: ObjectImpl>(obj: *mut Object) {
> // SAFETY: obj is an instance of T, since rust_instance_init<T>
> @@ -115,6 +115,9 @@ pub trait ObjectImpl: ObjectType +
> ClassInitImpl<Self::Class> {
> class_data: core::ptr::null_mut(),
> interfaces: core::ptr::null_mut(),
> };
> +
> + // methods on ObjectClass
> + const UNPARENT: Option<fn(&mut Self)> = None;
> }
Will we change `&mut Self` to an immutable reference in the future?
IIUC, the parent on the C side also has a pointer to current object.
- [PATCH 21/26] rust: tests: allow writing more than one test, (continued)
[PATCH 18/26] rust: qom: add possibility of overriding unparent, Paolo Bonzini, 2024/12/09
- Re: [PATCH 18/26] rust: qom: add possibility of overriding unparent,
Zhao Liu <=
[PATCH 25/26] rust: qemu-api: add a module to wrap functions and zero-sized closures, Paolo Bonzini, 2024/12/09
[PATCH 22/26] rust: qom: add casting functionality, Paolo Bonzini, 2024/12/09
[PATCH 17/26] rust: qom: put class_init together from multiple ClassInitImpl<>, Paolo Bonzini, 2024/12/09
[PATCH 20/26] rust: re-export C types from qemu-api submodules, Paolo Bonzini, 2024/12/09