Searched hist:"0 d43ddae35a29d1822ec3f35a31bfe7c91618ef4" (Results 1 – 2 of 2) sorted by relevance
/qemu/rust/qemu-api/src/ |
H A D | prelude.rs | 0d43ddae35a29d1822ec3f35a31bfe7c91618ef4 Sun Dec 08 11:16:56 UTC 2024 Paolo Bonzini <pbonzini@redhat.com> rust: vmstate: add new type safe implementation
The existing translation of the C macros for vmstate does not make any attempt to type-check vmstate declarations against the struct, so introduce a new system that computes VMStateField based on the actual struct declaration.
Macros do not have full access to the type system, therefore a full implementation of this scheme requires a helper trait to analyze the type and produce a VMStateField from it; a macro "vmstate_of!" accepts arguments similar to "offset_of!" and tricks the compiler into looking up the trait for the right type.
The patch introduces not just vmstate_of!, but also the slightly too clever enabling macro call_func_with_field!. The particular trick used here was proposed on the users.rust-lang.org forum, so I take no merit and all the blame.
Introduce the trait and some functions to access it; the actual implementation comes later.
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
H A D | vmstate.rs | 0d43ddae35a29d1822ec3f35a31bfe7c91618ef4 Sun Dec 08 11:16:56 UTC 2024 Paolo Bonzini <pbonzini@redhat.com> rust: vmstate: add new type safe implementation
The existing translation of the C macros for vmstate does not make any attempt to type-check vmstate declarations against the struct, so introduce a new system that computes VMStateField based on the actual struct declaration.
Macros do not have full access to the type system, therefore a full implementation of this scheme requires a helper trait to analyze the type and produce a VMStateField from it; a macro "vmstate_of!" accepts arguments similar to "offset_of!" and tricks the compiler into looking up the trait for the right type.
The patch introduces not just vmstate_of!, but also the slightly too clever enabling macro call_func_with_field!. The particular trick used here was proposed on the users.rust-lang.org forum, so I take no merit and all the blame.
Introduce the trait and some functions to access it; the actual implementation comes later.
Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|