diff mbox series

[11/14] rust: replace std::ffi::c_char with libc::c_char

Message ID 20240701145853.1394967-12-pbonzini@redhat.com (mailing list archive)
State New, archived
Headers show
Series rust: example of bindings code for Rust in QEMU | expand

Commit Message

Paolo Bonzini July 1, 2024, 2:58 p.m. UTC
Allow working with Rust versions prior to 1.64.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 qemu/src/bindings/mod.rs | 3 ++-
 qemu/src/util/foreign.rs | 7 +++++--
 2 files changed, 7 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/qemu/src/bindings/mod.rs b/qemu/src/bindings/mod.rs
index a49447b..0ad3828 100644
--- a/qemu/src/bindings/mod.rs
+++ b/qemu/src/bindings/mod.rs
@@ -1,4 +1,5 @@ 
-use std::ffi::{c_char, c_void};
+use libc::c_char;
+use std::ffi::c_void;
 
 #[repr(C)]
 pub struct Object {
diff --git a/qemu/src/util/foreign.rs b/qemu/src/util/foreign.rs
index 0b8b708..464400a 100644
--- a/qemu/src/util/foreign.rs
+++ b/qemu/src/util/foreign.rs
@@ -4,8 +4,11 @@ 
 /// Traits to map between C structs and native Rust types.
 /// Similar to glib-rs but a bit simpler and possibly more
 /// idiomatic.
+
+use libc::c_char;
+
 use std::borrow::Cow;
-use std::ffi::{c_char, c_void, CStr, CString};
+use std::ffi::{c_void, CStr, CString};
 use std::fmt;
 use std::fmt::Debug;
 use std::mem;
@@ -166,7 +169,7 @@  pub trait FromForeign: CloneToForeign + Sized {
     /// # use qemu::FromForeign;
     /// let p = c"Hello, world!".as_ptr();
     /// let s = unsafe {
-    ///     String::cloned_from_foreign(p as *const std::ffi::c_char)
+    ///     String::cloned_from_foreign(p as *const libc::c_char)
     /// };
     /// assert_eq!(s, "Hello, world!");
     /// ```