Use Box::from/into_raw()

This commit is contained in:
Sebastian Dröge 2016-05-13 17:43:32 +03:00
parent 6a3a42717f
commit 833148cef6

View file

@ -1,17 +1,12 @@
use std::mem;
#[no_mangle] #[no_mangle]
pub extern "C" fn filesrc_new() -> *mut FileSrc { pub extern "C" fn filesrc_new() -> *mut FileSrc {
let mut instance = Box::new(FileSrc::new()); let instance = Box::new(FileSrc::new());
return &mut *instance; return Box::into_raw(instance);
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn filesrc_drop(ptr: *mut FileSrc) { pub extern "C" fn filesrc_drop(ptr: *mut FileSrc) {
let filesrc: &mut FileSrc = unsafe { &mut *ptr }; unsafe { Box::from_raw(ptr) };
println!("drop");
drop(filesrc);
} }
#[no_mangle] #[no_mangle]