Skip to content

Commit

Permalink
fix: proper to_ptr type cast to c_char
Browse files Browse the repository at this point in the history
On some platforms casting to `i8` is invalid as the
compiler expects a `u8`. This applies to `CString`
and `String` `.to_ptr()` calls.

Signed-off-by: Max Newcomer <[email protected]>
  • Loading branch information
maxwnewcomer committed Dec 31, 2024
1 parent 687da6c commit 79c0bbe
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
7 changes: 4 additions & 3 deletions io-engine/src/bdev/ftl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use std::{
collections::HashMap,
convert::TryFrom,
fmt::{Debug, Formatter},
os::raw::c_char,
};

use core::ffi::c_void;
Expand Down Expand Up @@ -210,9 +211,9 @@ impl CreateDestroy for Ftl {
..unsafe { mem::zeroed() }
};
unsafe { spdk_ftl_get_default_conf(&mut ftl_conf, spdk_ftl_conf_size) };
ftl_conf.name = ftl_dev_name.as_ptr() as *mut i8;
ftl_conf.base_bdev = base_dev_name.as_ptr() as *mut i8;
ftl_conf.cache_bdev = cache_dev_name.as_ptr() as *mut i8;
ftl_conf.name = ftl_dev_name.as_ptr() as *mut c_char;
ftl_conf.base_bdev = base_dev_name.as_ptr() as *mut c_char;
ftl_conf.cache_bdev = cache_dev_name.as_ptr() as *mut c_char;
ftl_conf.fast_shutdown = true;
ftl_conf.verbose_mode = true;
ftl_conf.mode = spdk_ftl_mode::SPDK_FTL_MODE_CREATE as u32;
Expand Down
4 changes: 2 additions & 2 deletions io-engine/tests/memory_pool.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, ffi::CString, ptr::null_mut};
use std::{collections::HashMap, ffi::CString, os::raw::c_char, ptr::null_mut};

use once_cell::sync::OnceCell;

Expand All @@ -16,7 +16,7 @@ fn get_ms() -> &'static MayastorTest<'static> {
struct TestCtx {
id: u64,
pos: u32,
ctx: *const i8,
ctx: *const c_char,
}

const POOL_SIZE: u64 = 128 * 1024 - 1;
Expand Down
8 changes: 4 additions & 4 deletions libnvme-rs/src/nvme_uri.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{convert::TryFrom, io, time::Duration};
use std::{convert::TryFrom, io, os::raw::c_char, time::Duration};

use url::{ParseError, Url};

Expand All @@ -15,14 +15,14 @@ use crate::{

/// Wrapper for caller-owned C-strings from libnvme
pub struct NvmeStringWrapper {
s: *mut i8,
s: *mut c_char,
}

impl NvmeStringWrapper {
pub fn new(s: *mut i8) -> Self {
pub fn new(s: *mut c_char) -> Self {
NvmeStringWrapper { s }
}
pub fn as_ptr(&self) -> *const i8 {
pub fn as_ptr(&self) -> *const c_char {
self.s
}
}
Expand Down

0 comments on commit 79c0bbe

Please sign in to comment.