qemu-devel
[Top][All Lists]
Advanced

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

Re: [PATCH 03/14] rust: define traits and pointer wrappers to convert fr


From: Marc-André Lureau
Subject: Re: [PATCH 03/14] rust: define traits and pointer wrappers to convert from/to C representations
Date: Wed, 3 Jul 2024 16:58:11 +0400

Hi

On Wed, Jul 3, 2024 at 4:48 PM Marc-André Lureau <marcandre.lureau@gmail.com> wrote:
Hi

(adding Sebastian, one of the glib-rs developers in CC)

On Mon, Jul 1, 2024 at 7:02 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
The qemu::util::foreign module provides:

- A trait for structs that can be converted to a C ("foreign") representation
  (CloneToForeign)

- A trait for structs that can be built from a C ("foreign") representation
  (FromForeign), and the utility IntoNative that can be used with less typing
  (similar to the standard library's From and Into pair)

- Automatic implementations of the above traits for Option<>, supporting NULL
  pointers

- A wrapper for a pointer that automatically frees the contained data.  If
  a struct XYZ implements CloneToForeign, you can build an OwnedPointer<XYZ>
  and it will free the contents automatically unless you retrieve it with
  owned_ptr.into_inner()

[...] Also, you don't offer the equivalent of "to_glib_none" which uses a temporary stash and is quite useful, as a majority of functions don't take ownership.

I realize this may be somewhat offered by OwnedPointer (although not mentioned explicitly in the doc). Its usage seems unsafe, as you have to handle the foreign pointer lifetime manually...


--
Marc-André Lureau

reply via email to

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