Skip to content

Commit

Permalink
Use Box::{into_raw, from_raw} instead of mem::transmute.
Browse files Browse the repository at this point in the history
These methods, stabilized in rustc 1.4, reflect what we want
to do more accurately, including the safety of mp4parse_new(),
and are more succinct.

Thanks to Simon Sapin for the suggestion.
  • Loading branch information
rillian committed Oct 29, 2015
1 parent b584de0 commit 70f4569
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/capi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,14 @@ use Error;
#[no_mangle]
pub extern "C" fn mp4parse_new() -> *mut MediaContext {
let context = Box::new(MediaContext::new());
unsafe {
// transmute is unsafe, but context is always valid.
std::mem::transmute(context)
}
Box::into_raw(context)
}

/// Free a rust-side parser context.
#[no_mangle]
pub unsafe extern "C" fn mp4parse_free(context: *mut MediaContext) {
assert!(!context.is_null());
let _: Box<MediaContext> = std::mem::transmute(context);
let _ = Box::from_raw(context);
}

/// Feed a buffer through `read_box()` with the given rust-side
Expand Down

0 comments on commit 70f4569

Please sign in to comment.