qemu-rust.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-rust@nongnu.org, zhao1.liu@intel.com, junjie.mao@hotmail.com
Subject: Re: [RFC PATCH 7/9] rust: qemu_api: add vmstate_struct and vmstate_cell
Date: Tue, 7 Jan 2025 17:49:01 +0100	[thread overview]
Message-ID: <CABgObfZ0O3r02v26+KiqAMNk2CSsYp8q2siN_f1xwUDXvT=VDg@mail.gmail.com> (raw)
In-Reply-To: <20241231002336.25931-8-pbonzini@redhat.com>

On Tue, Dec 31, 2024 at 1:23 AM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> These are not type safe, but they're the best that can be done without
> const_refs_static.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

FWIW, I'll change these patch to support varrays in v2.

Paolo

> ---
>  rust/qemu-api/src/vmstate.rs | 34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
>
> diff --git a/rust/qemu-api/src/vmstate.rs b/rust/qemu-api/src/vmstate.rs
> index b59a4b66339..e45c93587b2 100644
> --- a/rust/qemu-api/src/vmstate.rs
> +++ b/rust/qemu-api/src/vmstate.rs
> @@ -610,6 +610,40 @@ macro_rules! vmstate_array_of_pointer_to_struct {
>      }};
>  }
>
> +// FIXME: including the `vmsd` field in a `const` is not possible without
> +// the const_refs_static feature (stabilized in Rust 1.83.0).  Without it,
> +// it is not possible to use VMS_STRUCT in a transparent manner using
> +// `vmstate_of!`.  While VMSTATE_CLOCK can at least try to be type-safe,
> +// VMSTATE_STRUCT includes $type only for documentation purposes; it
> +// is checked against $field_name and $struct_name, but not against $vmsd
> +// which is what really would matter.
> +#[doc(alias = "VMSTATE_STRUCT")]
> +#[macro_export]
> +macro_rules! vmstate_struct {
> +    ($field_name:ident, $struct_name:ty, $vmsd:expr, $type:ty) => {{
> +        $crate::bindings::VMStateField {
> +            name: ::core::concat!(::core::stringify!($field_name), "\0")
> +                .as_bytes()
> +                .as_ptr() as *const ::std::os::raw::c_char,
> +            offset: {
> +                $crate::assert_field_type!($struct_name, $field_name, $type);
> +                $crate::offset_of!($struct_name, $field_name)
> +            }
> +            size: ::core::mem::size_of::<$type>(),
> +            flags: $crate::bindings::VMStateFlags::VMS_STRUCT,
> +            vmsd: unsafe { $vmsd },
> +            ..$crate::zeroable::Zeroable::ZERO
> +        }
> +    }};
> +}
> +
> +#[macro_export]
> +macro_rules! vmstate_cell {
> +    ($field_name:ident, $struct_name:ty, $vmsd:expr, $type:ty) => {
> +        $crate::vmstate_struct!($field_name, $struct_name, $vmsd, $type)
> +    };
> +}
> +
>  #[doc(alias = "VMSTATE_CLOCK_V")]
>  #[macro_export]
>  macro_rules! vmstate_clock_v {
> --
> 2.47.1
>



  reply	other threads:[~2025-01-07 16:49 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-31  0:23 [RFC PATCH 0/9] rust: (mostly) type safe VMState Paolo Bonzini
2024-12-31  0:23 ` [RFC PATCH 1/9] rust: vmstate: add new type safe implementation Paolo Bonzini
2025-01-07  8:58   ` Zhao Liu
2025-01-07 12:23     ` Paolo Bonzini
2025-01-07 14:01       ` Zhao Liu
2024-12-31  0:23 ` [RFC PATCH 2/9] rust: vmstate: implement VMState for non-leaf types Paolo Bonzini
2025-01-07 15:43   ` Zhao Liu
2024-12-31  0:23 ` [RFC PATCH 3/9] rust: vmstate: add varray support to vmstate_of! Paolo Bonzini
2025-01-08  3:28   ` Zhao Liu
2025-01-15 10:14     ` Paolo Bonzini
2024-12-31  0:23 ` [RFC PATCH 4/9] rust: vmstate: implement Zeroable for VMStateField Paolo Bonzini
2025-01-06 14:31   ` Zhao Liu
2024-12-31  0:23 ` [RFC PATCH 5/9] rust: vmstate: implement VMState for scalar types Paolo Bonzini
2025-01-08  6:45   ` Zhao Liu
2025-01-15 13:08     ` Paolo Bonzini
2025-01-16  6:59       ` Zhao Liu
2024-12-31  0:23 ` [RFC PATCH 6/9] rust: vmstate: add public utility macros to implement VMState Paolo Bonzini
2025-01-08  8:15   ` Zhao Liu
2024-12-31  0:23 ` [RFC PATCH 7/9] rust: qemu_api: add vmstate_struct and vmstate_cell Paolo Bonzini
2025-01-07 16:49   ` Paolo Bonzini [this message]
2024-12-31  0:23 ` [RFC PATCH 8/9] rust: pl011: switch vmstate to new-style macros Paolo Bonzini
2025-01-08  8:27   ` Zhao Liu
2024-12-31  0:23 ` [RFC PATCH 9/9] rust: vmstate: remove translation of C vmstate macros Paolo Bonzini
2025-01-08  8:40   ` Zhao Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CABgObfZ0O3r02v26+KiqAMNk2CSsYp8q2siN_f1xwUDXvT=VDg@mail.gmail.com' \
    --to=pbonzini@redhat.com \
    --cc=junjie.mao@hotmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-rust@nongnu.org \
    --cc=zhao1.liu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).