Skip to content

Commit

Permalink
Explicitly use os::raw::c_char rather than u8/i8
Browse files Browse the repository at this point in the history
- Some platforms define it as i8 (x86_64) others u8 (aarch64)

Rust fmt
  • Loading branch information
jake-ruyi committed Jan 22, 2019
1 parent 1acf214 commit 71b0487
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion runng-sys/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod tests {
fn it_works() {
unsafe {
let url = CString::new("inproc://test").unwrap();
let url = url.as_bytes_with_nul().as_ptr() as *const i8;
let url = url.as_bytes_with_nul().as_ptr() as *const std::os::raw::c_char;

// Reply socket
let mut rep_socket = nng_socket { id: 0 };
Expand Down
6 changes: 4 additions & 2 deletions runng/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ trait InternalSocket {
}

// Return string and pointer so string isn't dropped
fn to_cstr(string: &str) -> Result<(std::ffi::CString, *const i8), std::ffi::NulError> {
fn to_cstr(
string: &str,
) -> Result<(std::ffi::CString, *const std::os::raw::c_char), std::ffi::NulError> {
let string = std::ffi::CString::new(string)?;
let ptr = string.as_bytes_with_nul().as_ptr() as *const i8;
let ptr = string.as_bytes_with_nul().as_ptr() as *const std::os::raw::c_char;
Ok((string, ptr))
}

0 comments on commit 71b0487

Please sign in to comment.