On Thu, Feb 27, 2025 at 03:22:17PM +0100, Paolo Bonzini wrote:
> Date: Thu, 27 Feb 2025 15:22:17 +0100
> From: Paolo Bonzini <[email protected]>
> Subject: [PATCH 10/12] rust: memory: wrap MemoryRegion with Opaque<>
> X-Mailer: git-send-email 2.48.1
>
> Signed-off-by: Paolo Bonzini <[email protected]>
> ---
> rust/qemu-api/src/bindings.rs | 3 ---
> rust/qemu-api/src/memory.rs | 35 +++++++++++++++++++++--------------
> 2 files changed, 21 insertions(+), 17 deletions(-)
...
> impl MemoryRegion {
> // inline to ensure that it is not included in tests, which only
> @@ -174,13 +174,20 @@ pub fn init_io<T: IsA<Object>>(
> size: u64,
> ) {
> unsafe {
> - Self::do_init_io(&mut self.inner, owner.cast::<Object>(),
> &ops.0, name, size);
> + Self::do_init_io(
> + // self.0.as_mut_ptr() needed because Rust tries to call
> + // ObjectDeref::as_mut_ptr() on "&mut Self", instead of
> coercing
> + // to "&Self" and then calling MemoryRegion::as_mut_ptr().
> + // Revisit if/when ObjectCastMut is not needed anymore; it is
> + // only used in a couple places for initialization.
> + self.0.as_mut_ptr(),
> + owner.cast::<Object>(),
> + &ops.0,
> + name,
> + size,
> + );
> }
> }
The extra comment is nice, too. :-)
Reviewed-by: Zhao Liu <[email protected]>