qemu-rust
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 10/15] rust: qom: wrap Object with Opaque<>


From: Zhao Liu
Subject: Re: [PATCH 10/15] rust: qom: wrap Object with Opaque<>
Date: Tue, 25 Feb 2025 16:47:35 +0800

> @@ -621,7 +629,7 @@ pub trait ObjectImpl: ObjectType + IsA<Object> {
>  /// We expect the FFI user of this function to pass a valid pointer that
>  /// can be downcasted to type `T`. We also expect the device is
>  /// readable/writeable from one thread at any time.
> -unsafe extern "C" fn rust_unparent_fn<T: ObjectImpl>(dev: *mut Object) {
> +unsafe extern "C" fn rust_unparent_fn<T: ObjectImpl>(dev: *mut 
> bindings::Object) {
>      let state = NonNull::new(dev).unwrap().cast::<T>();
>      T::UNPARENT.unwrap()(unsafe { state.as_ref() });
>  }
> @@ -796,8 +804,9 @@ fn new() -> Owned<Self> {
>          // SAFETY: the object created by object_new is allocated on
>          // the heap and has a reference count of 1
>          unsafe {
> -            let obj = &*object_new(Self::TYPE_NAME.as_ptr());
> -            Owned::from_raw(obj.unsafe_cast::<Self>())
> +            let obj = object_new(Self::TYPE_NAME.as_ptr());

Having the same name is always not ideal, so let's name the first one raw_obj.

> +            let obj = Object::from_raw(obj).unsafe_cast::<Self>();
> +            Owned::from_raw(obj)
>          }
>      }
>  }

Others look good to me,

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>

> 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]