Skip to content

Commit f60c3c9

Browse files
author
ferris
committed
Replaced transmute with Box::into_raw/from_raw
This is a bit more semantically clear and fixes #20.
1 parent e333c86 commit f60c3c9

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/audio_unit/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl AudioUnit {
157157
if let Some(callback) = self.callback {
158158
// Here, we transfer ownership of the callback back to the current scope so that it
159159
// is dropped and cleaned up. Without this line, we would leak the Boxed callback.
160-
let _: Box<Box<RenderCallback>> = unsafe { mem::transmute(callback) };
160+
let _: Box<Box<RenderCallback>> = unsafe { Box::from_raw(callback as *mut Box<RenderCallback>) };
161161
}
162162
}
163163

@@ -167,13 +167,13 @@ impl AudioUnit {
167167
unsafe {
168168
// Setup render callback. Notice that we relinquish ownership of the Callback
169169
// here so that it can be used as the C render callback via a void pointer.
170-
// We do however store the *mut so that we can transmute back to a
170+
// We do however store the *mut so that we can convert back to a
171171
// Box<Box<RenderCallback>> within our AudioUnit's Drop implementation
172172
// (otherwise it would leak). The double-boxing is due to incompleteness with
173-
// Rust's FnMut implemetation and is necessary to be able to transmute to the
173+
// Rust's FnMut implemetation and is necessary to be able to convert to the
174174
// correct pointer size.
175-
let callback_ptr: *mut libc::c_void = match f {
176-
Some(x) => mem::transmute(Box::new(x)),
175+
let callback_ptr = match f {
176+
Some(x) => Box::into_raw(Box::new(x)) as *mut libc::c_void,
177177
_ => ptr::null_mut()
178178
};
179179
let render_callback = au::AURenderCallbackStruct {

0 commit comments

Comments
 (0)