Introduce SafePtr trait, cleanup

This commit is contained in:
Matthias Schiffer 2020-04-05 14:22:59 +02:00
parent de9bc974a6
commit fff906a78b
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C
2 changed files with 60 additions and 75 deletions

View file

@ -9,17 +9,26 @@ use core::fmt::Write;
#[no_mangle]
pub extern "C" fn main(_nargs: libc::c_int, _args: *const *const libc::c_char) -> libc::c_int {
let mut stdout = unsafe { libc::stdio::stdout() };
let x = libc::string::CString::from("foo");
let l = x.len();
let y = x.into_raw();
let z = unsafe {
libc::boxed::CBox::slice_from_raw_parts(y, l)
};
let foo = cstr!("Foo!\n");
stdout.puts(foo);
let _ = writeln!(stdout, "Foo: {} {} {}", z[0], z[1], z[2]);
let b = libc::boxed::CBox::new(42);
let _ = writeln!(stdout, "Bar: {}", b);
{
let foo = cstr!("Foo!\n");
stdout.puts(foo);
}
{
let x = libc::string::CString::from("foo");
let l = x.len();
let y = x.into_raw();
let z = unsafe {
libc::boxed::CBox::slice_from_raw_parts(y, l)
};
let _ = writeln!(stdout, "Foo: {} {} {}", z[0], z[1], z[2]);
}
{
let b = libc::boxed::CBox::new(42);
let _ = writeln!(stdout, "Bar: {}", b);
}
0
}