Skip to content

Commit 72e4156

Browse files
committed
Use mem::MaybeUninit also for iOS
1 parent 5c499ae commit 72e4156

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

examples/ios/src/feedback.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ extern crate coreaudio;
55
use std::collections::VecDeque;
66
use std::sync::{Arc, Mutex};
77

8-
use coreaudio::audio_unit::{AudioUnit, Element, SampleFormat, Scope, StreamFormat};
98
use coreaudio::audio_unit::audio_format::LinearPcmFlags;
109
use coreaudio::audio_unit::render_callback::{self, data};
10+
use coreaudio::audio_unit::{AudioUnit, Element, SampleFormat, Scope, StreamFormat};
1111
use coreaudio::sys::*;
1212

13-
14-
type S = f32; const SAMPLE_FORMAT: SampleFormat = SampleFormat::F32;
13+
type S = f32;
14+
const SAMPLE_FORMAT: SampleFormat = SampleFormat::F32;
1515
// type S = i32; const SAMPLE_FORMAT: SampleFormat = SampleFormat::I32;
1616
// type S = i16; const SAMPLE_FORMAT: SampleFormat = SampleFormat::I16;
1717
// type S = i8; const SAMPLE_FORMAT: SampleFormat = SampleFormat::I8;
@@ -34,7 +34,9 @@ pub fn run_example() -> Result<(), coreaudio::Error> {
3434

3535
let format_flag = match SAMPLE_FORMAT {
3636
SampleFormat::F32 => LinearPcmFlags::IS_FLOAT,
37-
SampleFormat::I32 | SampleFormat::I16 | SampleFormat::I8 => LinearPcmFlags::IS_SIGNED_INTEGER,
37+
SampleFormat::I32 | SampleFormat::I16 | SampleFormat::I8 => {
38+
LinearPcmFlags::IS_SIGNED_INTEGER
39+
}
3840
};
3941

4042
// Using IS_NON_INTERLEAVED everywhere because data::Interleaved is commented out / not implemented
@@ -61,8 +63,18 @@ pub fn run_example() -> Result<(), coreaudio::Error> {
6163
println!("output_asbd={:#?}", &out_stream_format.to_asbd());
6264

6365
let id = kAudioUnitProperty_StreamFormat;
64-
input_audio_unit.set_property(id, Scope::Output, Element::Input, Some(&in_stream_format.to_asbd()))?;
65-
output_audio_unit.set_property(id, Scope::Input, Element::Output, Some(&out_stream_format.to_asbd()))?;
66+
input_audio_unit.set_property(
67+
id,
68+
Scope::Output,
69+
Element::Input,
70+
Some(&in_stream_format.to_asbd()),
71+
)?;
72+
output_audio_unit.set_property(
73+
id,
74+
Scope::Input,
75+
Element::Output,
76+
Some(&out_stream_format.to_asbd()),
77+
)?;
6678

6779
let buffer_left = Arc::new(Mutex::new(VecDeque::<S>::new()));
6880
let producer_left = buffer_left.clone();

examples/ios/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ mod feedback;
22

33
#[no_mangle]
44
pub extern "C" fn rust_ios_main() {
5-
feedback::run_example().unwrap();
5+
feedback::run_example().unwrap();
66
}

src/audio_unit/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,11 @@ pub fn get_property<T>(
424424
pub fn audio_session_get_property<T>(id: u32) -> Result<T, Error> {
425425
let mut size = ::std::mem::size_of::<T>() as u32;
426426
unsafe {
427-
let mut data: T = ::std::mem::uninitialized();
428-
let data_ptr = &mut data as *mut _ as *mut c_void;
427+
let mut data_uninit = ::std::mem::MaybeUninit::<T>::uninit();
428+
let data_ptr = data_uninit.as_mut_ptr() as *mut _ as *mut c_void;
429429
let size_ptr = &mut size as *mut _;
430430
try_os_status!(sys::AudioSessionGetProperty(id, size_ptr, data_ptr));
431+
let data: T = data_uninit.assume_init();
431432
Ok(data)
432433
}
433434
}

0 commit comments

Comments
 (0)