rollup merge of #19787: akiss77/fix-i8-c_char

On AArch64, libc::c_char is u8. There are some places in the code where i8 is assumed, which causes compilation errors.

(AArch64 is not officially supported yet, but this change does not hurt any other targets and makes the code future-proof.)
This commit is contained in:
Brian Anderson 2014-12-13 18:24:05 -08:00
commit 53982b64f3
4 changed files with 4 additions and 4 deletions

View File

@ -140,7 +140,7 @@ pub fn run(sess: &session::Session, llmod: ModuleRef,
// Internalize everything but the reachable symbols of the current module
let cstrs: Vec<::std::c_str::CString> =
reachable.iter().map(|s| s.to_c_str()).collect();
let arr: Vec<*const i8> = cstrs.iter().map(|c| c.as_ptr()).collect();
let arr: Vec<*const libc::c_char> = cstrs.iter().map(|c| c.as_ptr()).collect();
let ptr = arr.as_ptr();
unsafe {
llvm::LLVMRustRunRestrictionPass(llmod,

View File

@ -603,7 +603,7 @@ mod tests {
assert_eq!(*buf.offset(0), 'f' as libc::c_char);
assert_eq!(*buf.offset(1), 'o' as libc::c_char);
assert_eq!(*buf.offset(2), 'o' as libc::c_char);
assert_eq!(*buf.offset(3), 0xffu8 as i8);
assert_eq!(*buf.offset(3), 0xffu8 as libc::c_char);
assert_eq!(*buf.offset(4), 0);
}
}

View File

@ -378,7 +378,7 @@ pub fn getenv_as_bytes(n: &str) -> Option<Vec<u8>> {
if s.is_null() {
None
} else {
Some(CString::new(s as *const i8, false).as_bytes_no_nul().to_vec())
Some(CString::new(s as *const libc::c_char, false).as_bytes_no_nul().to_vec())
}
})
}

View File

@ -19,7 +19,7 @@ extern {
}
unsafe fn check<T>(expected: &str, f: |*mut c_char| -> T) {
let mut x = [0i8, ..50];
let mut x = [0 as c_char, ..50];
f(&mut x[0] as *mut c_char);
let res = CString::new(&x[0], false);
assert_eq!(expected, res.as_str().unwrap());