@@ -157,42 +157,42 @@ 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
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 transmute 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 transmute to the
174- // correct pointer size.
175- let callback_ptr: * mut libc:: c_void = match f {
176- Some ( x) => mem:: transmute ( Box :: new ( x) ) ,
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