[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 28/41] rust: re-export C types from qemu-api submodules
From: |
Paolo Bonzini |
Subject: |
[PULL 28/41] rust: re-export C types from qemu-api submodules |
Date: |
Thu, 19 Dec 2024 09:32:15 +0100 |
Long term we do not want device code to use "bindings" at all, so make it
possible to get the relevant types from the other modules of qemu-api.
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
rust/qemu-api/src/qdev.rs | 7 +++++--
rust/qemu-api/src/qom.rs | 12 +++++++-----
rust/qemu-api/src/sysbus.rs | 5 +----
rust/qemu-api/src/vmstate.rs | 9 +++++----
rust/qemu-api/tests/tests.rs | 9 +++++++--
5 files changed, 25 insertions(+), 17 deletions(-)
diff --git a/rust/qemu-api/src/qdev.rs b/rust/qemu-api/src/qdev.rs
index ad4c12d097e..07a502a8371 100644
--- a/rust/qemu-api/src/qdev.rs
+++ b/rust/qemu-api/src/qdev.rs
@@ -6,10 +6,13 @@
use std::ffi::CStr;
+pub use bindings::{DeviceClass, DeviceState, Property};
+
use crate::{
- bindings::{self, DeviceClass, DeviceState, Error, ObjectClass, Property,
VMStateDescription},
+ bindings::{self, Error},
prelude::*,
- qom::ClassInitImpl,
+ qom::{ClassInitImpl, ObjectClass},
+ vmstate::VMStateDescription,
};
/// Trait providing the contents of [`DeviceClass`].
diff --git a/rust/qemu-api/src/qom.rs b/rust/qemu-api/src/qom.rs
index 2222d1a5ab9..a663647ffe5 100644
--- a/rust/qemu-api/src/qom.rs
+++ b/rust/qemu-api/src/qom.rs
@@ -33,7 +33,9 @@
use std::{ffi::CStr, os::raw::c_void};
-use crate::bindings::{self, Object, ObjectClass, TypeInfo};
+pub use bindings::{Object, ObjectClass};
+
+use crate::bindings::{self, TypeInfo};
unsafe extern "C" fn rust_instance_init<T: ObjectImpl>(obj: *mut Object) {
// SAFETY: obj is an instance of T, since rust_instance_init<T>
@@ -164,9 +166,9 @@ pub trait ObjectImpl: ObjectType +
ClassInitImpl<Self::Class> {
///
/// Each struct will implement this trait with `T` equal to each
/// superclass. For example, a device should implement at least
-/// `ClassInitImpl<`[`DeviceClass`](crate::bindings::DeviceClass)`>` and
-/// `ClassInitImpl<`[`ObjectClass`](crate::bindings::ObjectClass)`>`.
-/// Such implementations are made in one of two ways.
+/// `ClassInitImpl<`[`DeviceClass`](crate::qdev::DeviceClass)`>` and
+/// `ClassInitImpl<`[`ObjectClass`]`>`. Such implementations are made
+/// in one of two ways.
///
/// For most superclasses, `ClassInitImpl` is provided by the `qemu-api`
/// crate itself. The Rust implementation of methods will come from a
@@ -221,7 +223,7 @@ pub trait ClassInitImpl<T> {
///
/// The virtual method implementations usually come from another
/// trait, for example [`DeviceImpl`](crate::qdev::DeviceImpl)
- /// when `T` is [`DeviceClass`](crate::bindings::DeviceClass).
+ /// when `T` is [`DeviceClass`](crate::qdev::DeviceClass).
///
/// On entry, `klass`'s parent class is initialized, while the other fields
/// are all zero; it is therefore assumed that all fields in `T` can be
diff --git a/rust/qemu-api/src/sysbus.rs b/rust/qemu-api/src/sysbus.rs
index fa69cadd7c1..9abc687a261 100644
--- a/rust/qemu-api/src/sysbus.rs
+++ b/rust/qemu-api/src/sysbus.rs
@@ -7,10 +7,7 @@
pub use bindings::{SysBusDevice, SysBusDeviceClass};
use crate::{
- bindings::{self, DeviceClass},
- cell::bql_locked,
- irq::InterruptSource,
- prelude::*,
+ bindings, cell::bql_locked, irq::InterruptSource, prelude::*,
qdev::DeviceClass,
qom::ClassInitImpl,
};
diff --git a/rust/qemu-api/src/vmstate.rs b/rust/qemu-api/src/vmstate.rs
index bedcf1e8f39..25c68b703ea 100644
--- a/rust/qemu-api/src/vmstate.rs
+++ b/rust/qemu-api/src/vmstate.rs
@@ -10,6 +10,8 @@
//! [`vmstate_fields`](crate::vmstate_fields) are meant to be used when
//! declaring a device model state struct.
+pub use crate::bindings::VMStateDescription;
+
#[doc(alias = "VMSTATE_UNUSED_BUFFER")]
#[macro_export]
macro_rules! vmstate_unused_buffer {
@@ -328,7 +330,7 @@ macro_rules! vmstate_fields {
}
/// A transparent wrapper type for the `subsections` field of
-/// [`VMStateDescription`](crate::bindings::VMStateDescription).
+/// [`VMStateDescription`].
///
/// This is necessary to be able to declare subsection descriptions as statics,
/// because the only way to implement `Sync` for a foreign type (and `*const`
@@ -342,9 +344,8 @@ macro_rules! vmstate_fields {
unsafe impl Sync for VMStateSubsectionsWrapper {}
-/// Helper macro to declare a list of subsections
-/// ([`VMStateDescription`](`crate::bindings::VMStateDescription`)) into a
-/// static and return a pointer to the array of pointers it created.
+/// Helper macro to declare a list of subsections ([`VMStateDescription`])
+/// into a static and return a pointer to the array of pointers it created.
#[macro_export]
macro_rules! vmstate_subsections {
($($subsection:expr),*$(,)*) => {{
diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs
index 78f7da474b2..68557fb85c7 100644
--- a/rust/qemu-api/tests/tests.rs
+++ b/rust/qemu-api/tests/tests.rs
@@ -5,8 +5,13 @@
use std::ffi::CStr;
use qemu_api::{
- bindings::*, c_str, declare_properties, define_property, prelude::*,
qdev::DeviceImpl,
- qom::ObjectImpl, zeroable::Zeroable,
+ bindings::*,
+ c_str, declare_properties, define_property,
+ prelude::*,
+ qdev::{DeviceImpl, DeviceState, Property},
+ qom::ObjectImpl,
+ vmstate::VMStateDescription,
+ zeroable::Zeroable,
};
#[test]
--
2.47.1
- [PULL 18/41] hw/core: Replace device_class_set_props with a macro, (continued)
- [PULL 18/41] hw/core: Replace device_class_set_props with a macro, Paolo Bonzini, 2024/12/19
- [PULL 19/41] target/riscv: Do not abuse DEFINE_PROP_END_OF_LIST, Paolo Bonzini, 2024/12/19
- [PULL 22/41] hw/core/qdev-properties: Constify Property argument to object_field_prop_ptr, Paolo Bonzini, 2024/12/19
- [PULL 21/41] include/hw/qdev-properties: Shrink struct Property, Paolo Bonzini, 2024/12/19
- [PULL 23/41] hw/core/qdev-properties: Constify Property argument to PropertyInfo.print, Paolo Bonzini, 2024/12/19
- [PULL 24/41] Constify all opaque Property pointers, Paolo Bonzini, 2024/12/19
- [PULL 20/41] include/hw/qdev-properties: Remove DEFINE_PROP_END_OF_LIST, Paolo Bonzini, 2024/12/19
- [PULL 26/41] rust: qom: add possibility of overriding unparent, Paolo Bonzini, 2024/12/19
- [PULL 25/41] rust: qom: put class_init together from multiple ClassInitImpl<>, Paolo Bonzini, 2024/12/19
- [PULL 27/41] rust: rename qemu-api modules to follow C code a bit more, Paolo Bonzini, 2024/12/19
- [PULL 28/41] rust: re-export C types from qemu-api submodules,
Paolo Bonzini <=
- [PULL 29/41] rust: tests: allow writing more than one test, Paolo Bonzini, 2024/12/19
- [PULL 30/41] rust: qom: add casting functionality, Paolo Bonzini, 2024/12/19
- [PULL 32/41] rust: qemu-api: add a module to wrap functions and zero-sized closures, Paolo Bonzini, 2024/12/19
- [PULL 33/41] kvm: consistently return 0/-errno from kvm_convert_memory, Paolo Bonzini, 2024/12/19
- [PULL 31/41] rust: qom: add initial subset of methods on Object, Paolo Bonzini, 2024/12/19
- [PULL 34/41] target/i386: Reset TSCs of parked vCPUs too on VM reset, Paolo Bonzini, 2024/12/19
- [PULL 35/41] rust: pl011: fix declaration of LineControl bits, Paolo Bonzini, 2024/12/19
- [PULL 36/41] rust: pl011: match break logic of C version, Paolo Bonzini, 2024/12/19
- [PULL 37/41] rust: pl011: always use reset() method on registers, Paolo Bonzini, 2024/12/19
- [PULL 38/41] rust: pl011: fix break errors and definition of Data struct, Paolo Bonzini, 2024/12/19