Skip to content

Commit 85f8f6f

Browse files
author
ferris
committed
Moved into_raw call into safe code
Along with some other code in the render_callback function
1 parent f60c3c9 commit 85f8f6f

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/audio_unit/mod.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -164,35 +164,35 @@ impl AudioUnit {
164164
/// Pass a render callback (aka "Input Procedure") to the audio unit.
165165
pub fn render_callback(&mut self, f: Option<Box<RenderCallback>>) -> Result<(), Error>
166166
{
167-
unsafe {
168-
// Setup render callback. Notice that we relinquish ownership of the Callback
169-
// 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 convert back to a
171-
// Box<Box<RenderCallback>> within our AudioUnit's Drop implementation
172-
// (otherwise it would leak). The double-boxing is due to incompleteness with
173-
// Rust's FnMut implemetation and is necessary to be able to convert to the
174-
// correct pointer size.
175-
let callback_ptr = match f {
176-
Some(x) => Box::into_raw(Box::new(x)) as *mut libc::c_void,
177-
_ => ptr::null_mut()
178-
};
179-
let render_callback = au::AURenderCallbackStruct {
180-
inputProc: Some(input_proc),
181-
inputProcRefCon: callback_ptr
182-
};
167+
// Setup render callback. Notice that we relinquish ownership of the Callback
168+
// here so that it can be used as the C render callback via a void pointer.
169+
// We do however store the *mut so that we can convert back to a
170+
// Box<Box<RenderCallback>> within our AudioUnit's Drop implementation
171+
// (otherwise it would leak). The double-boxing is due to incompleteness with
172+
// Rust's FnMut implemetation and is necessary to be able to convert to the
173+
// correct pointer size.
174+
let callback_ptr = match f {
175+
Some(x) => Box::into_raw(Box::new(x)) as *mut libc::c_void,
176+
_ => ptr::null_mut()
177+
};
178+
let render_callback = au::AURenderCallbackStruct {
179+
inputProc: Some(input_proc),
180+
inputProcRefCon: callback_ptr
181+
};
183182

183+
unsafe {
184184
try_os_status!(au::AudioUnitSetProperty(
185185
self.instance,
186186
au::kAudioUnitProperty_SetRenderCallback,
187187
Scope::Input as libc::c_uint,
188188
Element::Output as libc::c_uint,
189189
&render_callback as *const _ as *const libc::c_void,
190190
mem::size_of::<au::AURenderCallbackStruct>() as u32));
191-
192-
self.free_render_callback();
193-
self.callback = if !callback_ptr.is_null() { Some(callback_ptr) } else { None };
194-
Ok(())
195191
}
192+
193+
self.free_render_callback();
194+
self.callback = if !callback_ptr.is_null() { Some(callback_ptr) } else { None };
195+
Ok(())
196196
}
197197

198198
/// Start the audio unit.

0 commit comments

Comments
 (0)