summary refs log tree commit diff stats
path: root/rust/qemu-api/tests
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2024-10-25 08:23:53 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2024-11-05 14:18:16 +0100
commit718e255f0a97cf43939ae2e90ba4673ae9a8bd2f (patch)
treeab5d09e3b4cb9cae3e44fed6a8f77458f354c6c5 /rust/qemu-api/tests
parent9f7d4520d679364f7ca95b7ddb899ff084e7d7c6 (diff)
downloadfocaccia-qemu-718e255f0a97cf43939ae2e90ba4673ae9a8bd2f.tar.gz
focaccia-qemu-718e255f0a97cf43939ae2e90ba4673ae9a8bd2f.zip
rust: introduce a c_str macro
This allows CStr constants to be defined easily on Rust 1.63.0, while
checking that there are no embedded NULs.  c"" literals were only
stabilized in Rust 1.77.0.

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'rust/qemu-api/tests')
-rw-r--r--rust/qemu-api/tests/tests.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs
index c7089f0cf2..381ac84657 100644
--- a/rust/qemu-api/tests/tests.rs
+++ b/rust/qemu-api/tests/tests.rs
@@ -6,7 +6,7 @@ use std::{ffi::CStr, os::raw::c_void};
 
 use qemu_api::{
     bindings::*,
-    declare_properties, define_property,
+    c_str, declare_properties, define_property,
     definitions::{Class, ObjectImpl},
     device_class_init,
     zeroable::Zeroable,
@@ -16,7 +16,7 @@ use qemu_api::{
 fn test_device_decl_macros() {
     // Test that macros can compile.
     pub static VMSTATE: VMStateDescription = VMStateDescription {
-        name: c"name".as_ptr(),
+        name: c_str!("name").as_ptr(),
         unmigratable: true,
         ..Zeroable::ZERO
     };
@@ -36,7 +36,7 @@ fn test_device_decl_macros() {
     declare_properties! {
         DUMMY_PROPERTIES,
             define_property!(
-                c"migrate-clk",
+                c_str!("migrate-clk"),
                 DummyState,
                 migrate_clock,
                 unsafe { &qdev_prop_bool },
@@ -55,7 +55,7 @@ fn test_device_decl_macros() {
     impl ObjectImpl for DummyState {
         type Class = DummyClass;
         const TYPE_INFO: qemu_api::bindings::TypeInfo = qemu_api::type_info! { Self };
-        const TYPE_NAME: &'static CStr = c"dummy";
+        const TYPE_NAME: &'static CStr = c_str!("dummy");
         const PARENT_TYPE_NAME: Option<&'static CStr> = Some(TYPE_DEVICE);
         const ABSTRACT: bool = false;
         const INSTANCE_INIT: Option<unsafe extern "C" fn(obj: *mut Object)> = None;