Skip to content

Commit

Permalink
bugfix: Fix use of i8 instead of c_char causing build failures on Lin…
Browse files Browse the repository at this point in the history
…ux (#45)

The code mistakenly assumed that c_char was i8 on all Rust platforms, but
that is not true on Linux, so this is causing type mismatch errors at build
time on Linux.

(This mistake of mine was presumably reinforced by Rust issue #15823, which is
an issue with rustdoc rendering some type aliases in function signatures as
the pointed-to type and not by the alias name, which--among other effects--causes
CStr::from_raw() and CString::into_raw() to show `i8` in their type signatures
instead of `c_char`.)

See also: rust-lang/rust#15823
  • Loading branch information
ConnorGray authored Jan 6, 2023
1 parent 9f11f9b commit d6ace94
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ mod test_readme {


use std::convert::TryFrom;
use std::ffi::{CStr, CString};
use std::ffi::{c_char, CStr, CString};
use std::fmt::{self, Display};
use std::net;

Expand Down Expand Up @@ -516,7 +516,7 @@ impl Link {
pub fn open_with_args(args: &[&str]) -> Result<Self, Error> {
// NOTE: Before returning, we must convert these back into CString's to
// deallocate them.
let mut c_strings: Vec<*mut i8> = args
let mut c_strings: Vec<*mut c_char> = args
.into_iter()
.map(|&str| {
CString::new(str)
Expand Down Expand Up @@ -623,7 +623,7 @@ impl Link {
let Link { raw_link } = *self;

unsafe {
let name: *const i8 = self::sys::WSName(raw_link as *mut _);
let name: *const c_char = self::sys::WSName(raw_link as *mut _);
CStr::from_ptr(name).to_str().unwrap().to_owned()
}
}
Expand Down Expand Up @@ -652,7 +652,7 @@ impl Link {
pub fn error(&self) -> Option<Error> {
let Link { raw_link } = *self;

let (code, message): (i32, *const i8) =
let (code, message): (i32, *const c_char) =
unsafe { (sys::WSError(raw_link), WSErrorMessage(raw_link)) };

if code == sys::MLEOK || message.is_null() {
Expand Down

0 comments on commit d6ace94

Please sign in to comment.