Skip to content

Commit a8de36f

Browse files
tests: Use c_char in more places and clean up casts
1 parent 2afdb55 commit a8de36f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

tests/tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
use core::{ffi::*, ptr::null_mut};
44

55
extern "C" {
6-
fn asprintf(s: *mut *mut u8, format: *const u8, ...) -> c_int;
6+
fn asprintf(s: *mut *mut c_char, format: *const c_char, ...) -> c_int;
77
fn free(p: *mut c_void);
88
}
99

10-
unsafe extern "C" fn rust_fmt(str: *const u8, mut args: ...) -> Box<(c_int, String)> {
10+
unsafe extern "C" fn rust_fmt(str: *const c_char, mut args: ...) -> Box<(c_int, String)> {
1111
let mut s = String::new();
1212
let bytes_written = printf_compat::format(
13-
str as _,
13+
str,
1414
args.clone().as_va_list(),
1515
printf_compat::output::fmt_write(&mut s),
1616
);
@@ -19,7 +19,7 @@ unsafe extern "C" fn rust_fmt(str: *const u8, mut args: ...) -> Box<(c_int, Stri
1919
assert_eq!(
2020
bytes_written,
2121
printf_compat::format(
22-
str as _,
22+
str,
2323
args.as_va_list(),
2424
printf_compat::output::io_write(&mut s2),
2525
)
@@ -33,8 +33,8 @@ macro_rules! c_fmt {
3333
let mut ptr = null_mut();
3434
let bytes_written = asprintf(&mut ptr, $format $(, $p)*);
3535
assert!(bytes_written >= 0);
36-
let s: String = CStr::from_ptr(ptr as *const _).to_string_lossy().into();
37-
free(ptr as _);
36+
let s: String = CStr::from_ptr(ptr).to_string_lossy().into();
37+
free(ptr.cast());
3838
(bytes_written, s)
3939
}};
4040
}

0 commit comments

Comments
 (0)