diff options
| author | Paolo Bonzini <pbonzini@redhat.com> | 2025-01-17 12:00:01 +0100 |
|---|---|---|
| committer | Paolo Bonzini <pbonzini@redhat.com> | 2025-02-13 12:19:33 +0100 |
| commit | 0fcccf3ff04a54d597bffcb7a42668c52a7dcec0 (patch) | |
| tree | a6905ff81eb79bc8f24f2d46637196f7d49022b4 /rust/qemu-api/tests/tests.rs | |
| parent | df45e26a81022f4f8f976b603cb0466b1cd64baf (diff) | |
| download | focaccia-qemu-0fcccf3ff04a54d597bffcb7a42668c52a7dcec0.tar.gz focaccia-qemu-0fcccf3ff04a54d597bffcb7a42668c52a7dcec0.zip | |
rust: qom: add reference counting functionality
Add a smart pointer that allows to add and remove references from QOM objects. It's important to note that while all QOM objects have a reference count, in practice not all of them have their lifetime guarded by it. Embedded objects, specifically, are confined to the lifetime of the owner. When writing Rust bindings this is important, because embedded objects are *never* used through the "Owned<>" smart pointer that is introduced here. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'rust/qemu-api/tests/tests.rs')
| -rw-r--r-- | rust/qemu-api/tests/tests.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs index 5c3e75ed3d..5f6096a572 100644 --- a/rust/qemu-api/tests/tests.rs +++ b/rust/qemu-api/tests/tests.rs @@ -15,7 +15,7 @@ use qemu_api::{ declare_properties, define_property, prelude::*, qdev::{DeviceClass, DeviceImpl, DeviceState, Property}, - qom::{ClassInitImpl, ObjectImpl, ParentField}, + qom::{ClassInitImpl, ObjectImpl, Owned, ParentField}, vmstate::VMStateDescription, zeroable::Zeroable, }; @@ -139,6 +139,17 @@ fn test_object_new() { } #[test] +#[allow(clippy::redundant_clone)] +/// Create, clone and then drop an instance. +fn test_clone() { + init_qom(); + let p: *mut DummyState = unsafe { object_new(DummyState::TYPE_NAME.as_ptr()).cast() }; + let p = unsafe { Owned::from_raw(p) }; + assert_eq!(p.clone().typename(), "dummy"); + drop(p); +} + +#[test] /// Try invoking a method on an object. fn test_typename() { init_qom(); |