[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 03/13] rust: assertions: Support index field wrapped in BqlCell
From: |
Paolo Bonzini |
Subject: |
[PULL 03/13] rust: assertions: Support index field wrapped in BqlCell |
Date: |
Sat, 3 May 2025 09:58:48 +0200 |
Currently, if the `num` field of a varray is not a numeric type, such as
being placed in a wrapper, the array variant of assert_field_type will
fail the check.
HPET currently wraps num_timers in BqlCell<>. Although BqlCell<> is not
necessary from strictly speaking, it makes sense for vmstate to respect
BqlCell.
The failure of assert_field_type is because it cannot convert BqlCell<T>
into usize for use as the index. Use a constant 0 instead for the index,
by avoiding $(...)? and extracting the common parts of
assert_field_type! into an internal case.
Commit message based on a patch by Zhao Liu <zhao1.liu@intel.com>.
Link: https://lore.kernel.org/r/20250414144943.1112885-3-zhao1.liu@intel.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
rust/qemu-api/src/assertions.rs | 25 +++++++++----------------
1 file changed, 9 insertions(+), 16 deletions(-)
diff --git a/rust/qemu-api/src/assertions.rs b/rust/qemu-api/src/assertions.rs
index eb12e9499a7..a2d38c877df 100644
--- a/rust/qemu-api/src/assertions.rs
+++ b/rust/qemu-api/src/assertions.rs
@@ -78,33 +78,26 @@ fn types_must_be_equal<T, U>(_: T)
/// ```
#[macro_export]
macro_rules! assert_field_type {
- ($t:ty, $i:tt, $ti:ty) => {
+ (@internal $param_name:ident, $ti:ty, $t:ty, $($field:tt)*) => {
const _: () = {
#[allow(unused)]
- fn assert_field_type(v: $t) {
- fn types_must_be_equal<T, U>(_: T)
+ fn assert_field_type($param_name: &$t) {
+ fn types_must_be_equal<T, U>(_: &T)
where
T: $crate::assertions::EqType<Itself = U>,
{
}
- types_must_be_equal::<_, $ti>(v.$i);
+ types_must_be_equal::<_, $ti>(&$($field)*);
}
};
};
+ ($t:ty, $i:tt, $ti:ty) => {
+ $crate::assert_field_type!(@internal v, $ti, $t, v.$i);
+ };
+
($t:ty, $i:tt, $ti:ty, num = $num:ident) => {
- const _: () = {
- #[allow(unused)]
- fn assert_field_type(v: $t) {
- fn types_must_be_equal<T, U>(_: T)
- where
- T: $crate::assertions::EqType<Itself = U>,
- {
- }
- let index: usize = v.$num.try_into().unwrap();
- types_must_be_equal::<_, &$ti>(&v.$i[index]);
- }
- };
+ $crate::assert_field_type!(@internal v, $ti, $t, v.$i[0]);
};
}
--
2.49.0
- [PULL 00/13] Rust, i386 changes for 2025-05-03, Paolo Bonzini, 2025/05/03
- [PULL 01/13] rust/vmstate: Add support for field_exists checks, Paolo Bonzini, 2025/05/03
- [PULL 02/13] vmstate: support varray for vmstate_clock!, Paolo Bonzini, 2025/05/03
- [PULL 03/13] rust: assertions: Support index field wrapped in BqlCell,
Paolo Bonzini <=
- [PULL 04/13] rust/vmstate_test: Test varray with num field wrapped in BqlCell, Paolo Bonzini, 2025/05/03
- [PULL 05/13] rust/timer: Define NANOSECONDS_PER_SECOND binding as u64, Paolo Bonzini, 2025/05/03
- [PULL 07/13] target/i386/emulate: remove rflags leftovers, Paolo Bonzini, 2025/05/03
- [PULL 06/13] rust/hpet: Support migration, Paolo Bonzini, 2025/05/03
- [PULL 08/13] target/i386/hvf: fix a compilation error, Paolo Bonzini, 2025/05/03
- [PULL 09/13] target/i386: do not trigger IRQ shadow for LSS, Paolo Bonzini, 2025/05/03
- [PULL 11/13] hw/char/serial: Remove unused prog_if compat property, Paolo Bonzini, 2025/05/03
- [PULL 13/13] monitor: don't wake up qmp_dispatcher_co coroutine upon cleanup, Paolo Bonzini, 2025/05/03
- [PULL 10/13] target/i386: do not block singlestep for STI, Paolo Bonzini, 2025/05/03