All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhao Liu <zhao1.liu@intel.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org, junjie.mao@hotmail.com
Subject: Re: [RFC PATCH 6/9] rust: vmstate: add public utility macros to implement VMState
Date: Wed, 8 Jan 2025 16:15:45 +0800	[thread overview]
Message-ID: <Z340Mb21QlQGl4kJ@intel.com> (raw)
In-Reply-To: <20241231002336.25931-7-pbonzini@redhat.com>

> +/// This macro can be used (by just passing it a type) to forward the `VMState`
> +/// trait to the first field of a tuple.  This is a workaround for lack of
> +/// support of nested [`offset_of`](core::mem::offset_of) until Rust 1.82.0.
> +///
> +/// # Examples
> +///
> +/// ```
> +/// # use qemu_api::vmstate::impl_vmstate_forward;
> +/// pub struct Fifo([u8; 16]);
> +/// impl_vmstate_forward!(Fifo);
> +/// ```
> +#[macro_export]
> +macro_rules! impl_vmstate_forward {
> +    // This is similar to impl_vmstate_transparent below, but it
> +    // uses the same trick as vmstate_of! to obtain the type of
> +    // the first field of the tuple
> +    ($tuple:ty) => {
> +        unsafe impl $crate::vmstate::VMState for $tuple {
> +            const SCALAR_TYPE: $crate::vmstate::VMStateFieldType =
> +                $crate::call_func_with_field!($crate::vmstate::vmstate_scalar_type, $tuple, 0);
> +            const BASE: $crate::bindings::VMStateField =
> +                $crate::call_func_with_field!($crate::vmstate::vmstate_base, $tuple, 0);
> +        }
> +    };
> +}
> +

Powerful!

>  // Transparent wrappers: just use the internal type
>  
>  macro_rules! impl_vmstate_transparent {
> @@ -283,6 +318,26 @@ unsafe impl<$base> VMState for $type where $base: VMState $($where)* {
>  impl_vmstate_transparent!(crate::cell::BqlCell<T> where T: VMState);
>  impl_vmstate_transparent!(crate::cell::BqlRefCell<T> where T: VMState);
>  
> +#[macro_export]
> +macro_rules! impl_vmstate_bitsized {
> +    ($type:ty) => {
> +        unsafe impl $crate::vmstate::VMState for $type {
> +            const SCALAR_TYPE: $crate::vmstate::VMStateFieldType =
> +                                        <<<$type as ::bilge::prelude::Bitsized>::ArbitraryInt
> +                                          as ::bilge::prelude::Number>::UnderlyingType
> +                                         as $crate::vmstate::VMState>::SCALAR_TYPE;
> +            const BASE: $crate::bindings::VMStateField =
> +                                        <<<$type as ::bilge::prelude::Bitsized>::ArbitraryInt
> +                                          as ::bilge::prelude::Number>::UnderlyingType
> +                                         as $crate::vmstate::VMState>::BASE;
> +            const VARRAY_FLAG: $crate::bindings::VMStateFlags =
> +                                        <<<$type as ::bilge::prelude::Bitsized>::ArbitraryInt
> +                                          as ::bilge::prelude::Number>::UnderlyingType
> +                                         as $crate::vmstate::VMState>::VARRAY_FLAG;
> +        }
> +    };
> +}
> +
>  // Scalar types using predefined VMStateInfos
>  
>  macro_rules! impl_vmstate_scalar {

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




  reply	other threads:[~2025-01-08  7:57 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 [this message]
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
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=Z340Mb21QlQGl4kJ@intel.com \
    --to=zhao1.liu@intel.com \
    --cc=junjie.mao@hotmail.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-rust@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.