Skip to content

Commit d4d7edf

Browse files
Use pointers to c_char instead of i8 in miri_host_to_target_path
This makes sure that the interface of `miri_host_to_target_path` is compatible with `CStr` for targets where `c_char` is unsigned (such as ARM). This commit changes the signature of `miri_host_to_target_path` in the README and in all test cases.
1 parent a80f527 commit d4d7edf

File tree

7 files changed

+28
-16
lines changed

7 files changed

+28
-16
lines changed

src/tools/miri/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ extern "Rust" {
590590
/// `out` must point to at least `out_size` many bytes, and the result will be stored there
591591
/// with a null terminator.
592592
/// Returns 0 if the `out` buffer was large enough, and the required size otherwise.
593-
fn miri_host_to_target_path(path: *const i8, out: *mut i8, out_size: usize) -> usize;
593+
fn miri_host_to_target_path(path: *const c_char, out: *mut c_char, out_size: usize) -> usize;
594594
}
595595
```
596596

src/tools/miri/test-cargo-miri/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ fn main() {
2323
// (We rely on the test runner to always disable isolation when passing no arguments.)
2424
if std::env::args().len() <= 1 {
2525
fn host_to_target_path(path: String) -> PathBuf {
26-
use std::ffi::{CStr, CString};
26+
use std::ffi::{c_char, CStr, CString};
2727

2828
let path = CString::new(path).unwrap();
2929
let mut out = Vec::with_capacity(1024);
3030

3131
unsafe {
3232
extern "Rust" {
3333
fn miri_host_to_target_path(
34-
path: *const i8,
35-
out: *mut i8,
34+
path: *const c_char,
35+
out: *mut c_char,
3636
out_size: usize,
3737
) -> usize;
3838
}

src/tools/miri/test-cargo-miri/subcrate/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ fn main() {
55
println!("subcrate running");
66

77
fn host_to_target_path(path: String) -> PathBuf {
8-
use std::ffi::{CStr, CString};
8+
use std::ffi::{c_char, CStr, CString};
99

1010
let path = CString::new(path).unwrap();
1111
let mut out = Vec::with_capacity(1024);
1212

1313
unsafe {
1414
extern "Rust" {
1515
fn miri_host_to_target_path(
16-
path: *const i8,
17-
out: *mut i8,
16+
path: *const c_char,
17+
out: *mut c_char,
1818
out_size: usize,
1919
) -> usize;
2020
}

src/tools/miri/test-cargo-miri/subcrate/test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ fn main() {
88
println!("subcrate testing");
99

1010
fn host_to_target_path(path: String) -> PathBuf {
11-
use std::ffi::{CStr, CString};
11+
use std::ffi::{c_char, CStr, CString};
1212

1313
let path = CString::new(path).unwrap();
1414
let mut out = Vec::with_capacity(1024);
1515

1616
unsafe {
1717
extern "Rust" {
1818
fn miri_host_to_target_path(
19-
path: *const i8,
20-
out: *mut i8,
19+
path: *const c_char,
20+
out: *mut c_char,
2121
out_size: usize,
2222
) -> usize;
2323
}

src/tools/miri/tests/pass-dep/shims/libc-fs.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#![feature(io_error_uncategorized)]
66

77
use std::convert::TryInto;
8-
use std::ffi::{CStr, CString};
8+
use std::ffi::{c_char, CStr, CString};
99
use std::fs::{canonicalize, remove_dir_all, remove_file, File};
1010
use std::io::{Error, ErrorKind, Write};
1111
use std::os::unix::ffi::OsStrExt;
@@ -31,7 +31,11 @@ fn tmp() -> PathBuf {
3131

3232
unsafe {
3333
extern "Rust" {
34-
fn miri_host_to_target_path(path: *const i8, out: *mut i8, out_size: usize) -> usize;
34+
fn miri_host_to_target_path(
35+
path: *const c_char,
36+
out: *mut c_char,
37+
out_size: usize,
38+
) -> usize;
3539
}
3640
let ret = miri_host_to_target_path(path.as_ptr(), out.as_mut_ptr(), out.capacity());
3741
assert_eq!(ret, 0);

src/tools/miri/tests/pass-dep/shims/libc-misc.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::os::unix::io::AsRawFd;
77
use std::path::PathBuf;
88

99
fn tmp() -> PathBuf {
10-
use std::ffi::{CStr, CString};
10+
use std::ffi::{c_char, CStr, CString};
1111

1212
let path = std::env::var("MIRI_TEMP")
1313
.unwrap_or_else(|_| std::env::temp_dir().into_os_string().into_string().unwrap());
@@ -17,7 +17,11 @@ fn tmp() -> PathBuf {
1717

1818
unsafe {
1919
extern "Rust" {
20-
fn miri_host_to_target_path(path: *const i8, out: *mut i8, out_size: usize) -> usize;
20+
fn miri_host_to_target_path(
21+
path: *const c_char,
22+
out: *mut c_char,
23+
out_size: usize,
24+
) -> usize;
2125
}
2226
let ret = miri_host_to_target_path(path.as_ptr(), out.as_mut_ptr(), out.capacity());
2327
assert_eq!(ret, 0);

src/tools/miri/tests/pass/shims/fs.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#![feature(is_terminal)]
77

88
use std::collections::HashMap;
9-
use std::ffi::OsString;
9+
use std::ffi::{c_char, OsString};
1010
use std::fs::{
1111
canonicalize, create_dir, read_dir, read_link, remove_dir, remove_dir_all, remove_file, rename,
1212
File, OpenOptions,
@@ -39,7 +39,11 @@ fn host_to_target_path(path: String) -> PathBuf {
3939

4040
unsafe {
4141
extern "Rust" {
42-
fn miri_host_to_target_path(path: *const i8, out: *mut i8, out_size: usize) -> usize;
42+
fn miri_host_to_target_path(
43+
path: *const c_char,
44+
out: *mut c_char,
45+
out_size: usize,
46+
) -> usize;
4347
}
4448
let ret = miri_host_to_target_path(path.as_ptr(), out.as_mut_ptr(), out.capacity());
4549
assert_eq!(ret, 0);

0 commit comments

Comments
 (0)