From 268ea6cfbf7226a4f23e54cda7e14a14afd7bf4c Mon Sep 17 00:00:00 2001 From: est31 Date: Sat, 10 Aug 2019 15:08:21 +0200 Subject: [PATCH 1/2] Remove mem::uninitialized from alsa backend uninitialized is being deprecated in favour of MaybeUninit and friends. --- src/host/alsa/enumerate.rs | 8 ++++---- src/host/alsa/mod.rs | 26 +++++++++++++------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/host/alsa/enumerate.rs b/src/host/alsa/enumerate.rs index 1c9ed04..b8b53df 100644 --- a/src/host/alsa/enumerate.rs +++ b/src/host/alsa/enumerate.rs @@ -3,7 +3,7 @@ use super::Device; use super::alsa; use super::check_errors; use std::ffi::CString; -use std::mem; +use std::ptr; /// ALSA implementation for `Devices`. pub struct Devices { @@ -20,7 +20,7 @@ impl Devices { // TODO: check in which situation this can fail. let card = -1; // -1 means all cards. let iface = b"pcm\0"; // Interface identification. - let mut hints = mem::uninitialized(); // Array of device name hints. + let mut hints = ptr::null_mut(); // Array of device name hints. let res = alsa::snd_device_name_hint(card, iface.as_ptr() as *const _, &mut hints); if let Err(description) = check_errors(res) { let err = BackendSpecificError { description }; @@ -107,7 +107,7 @@ impl Iterator for Devices { let name_zeroed = CString::new(&name[..]).unwrap(); // See if the device has an available output stream. - let mut playback_handle = mem::uninitialized(); + let mut playback_handle = ptr::null_mut(); let has_available_output = alsa::snd_pcm_open( &mut playback_handle, name_zeroed.as_ptr() as *const _, @@ -119,7 +119,7 @@ impl Iterator for Devices { } // See if the device has an available input stream. - let mut capture_handle = mem::uninitialized(); + let mut capture_handle = ptr::null_mut(); let has_available_input = alsa::snd_pcm_open( &mut capture_handle, name_zeroed.as_ptr() as *const _, diff --git a/src/host/alsa/mod.rs b/src/host/alsa/mod.rs index ac68914..05e1607 100644 --- a/src/host/alsa/mod.rs +++ b/src/host/alsa/mod.rs @@ -23,7 +23,7 @@ use UnknownTypeInputBuffer; use UnknownTypeOutputBuffer; use traits::{DeviceTrait, EventLoopTrait, HostTrait, StreamIdTrait}; -use std::{cmp, ffi, mem, ptr}; +use std::{cmp, ffi, ptr}; use std::sync::Mutex; use std::sync::mpsc::{channel, Sender, Receiver}; use std::sync::atomic::{AtomicUsize, Ordering}; @@ -193,7 +193,7 @@ impl Device { stream_t: alsa::snd_pcm_stream_t, ) -> Result, SupportedFormatsError> { - let mut handle = mem::uninitialized(); + let mut handle = ptr::null_mut(); let device_name = match ffi::CString::new(&self.0[..]) { Ok(name) => name, Err(err) => { @@ -279,7 +279,7 @@ impl Device { } } - let mut min_rate = mem::uninitialized(); + let mut min_rate = 0; if let Err(desc) = check_errors(alsa::snd_pcm_hw_params_get_rate_min( hw_params.0, &mut min_rate, @@ -290,7 +290,7 @@ impl Device { return Err(err.into()); } - let mut max_rate = mem::uninitialized(); + let mut max_rate = 0; if let Err(desc) = check_errors(alsa::snd_pcm_hw_params_get_rate_max( hw_params.0, &mut max_rate, @@ -344,14 +344,14 @@ impl Device { } }; - let mut min_channels = mem::uninitialized(); + let mut min_channels = 0; if let Err(desc) = check_errors(alsa::snd_pcm_hw_params_get_channels_min(hw_params.0, &mut min_channels)) { let description = format!("unable to get minimum supported channel count: {}", desc); let err = BackendSpecificError { description }; return Err(err.into()); } - let mut max_channels = mem::uninitialized(); + let mut max_channels = 0; if let Err(desc) = check_errors(alsa::snd_pcm_hw_params_get_channels_max(hw_params.0, &mut max_channels)) { let description = format!("unable to get maximum supported channel count: {}", desc); let err = BackendSpecificError { description }; @@ -759,7 +759,7 @@ impl EventLoop { unsafe { let name = ffi::CString::new(device.0.clone()).expect("unable to clone device"); - let mut capture_handle = mem::uninitialized(); + let mut capture_handle = ptr::null_mut(); match alsa::snd_pcm_open( &mut capture_handle, name.as_ptr(), @@ -838,7 +838,7 @@ impl EventLoop { unsafe { let name = ffi::CString::new(device.0.clone()).expect("unable to clone device"); - let mut playback_handle = mem::uninitialized(); + let mut playback_handle = ptr::null_mut(); match alsa::snd_pcm_open( &mut playback_handle, name.as_ptr(), @@ -1027,7 +1027,7 @@ fn check_for_pollout_or_pollin( stream_descriptor_ptr: *mut libc::pollfd, ) -> Result, BackendSpecificError> { let (revent, res) = unsafe { - let mut revent = mem::uninitialized(); + let mut revent = 0; let res = alsa::snd_pcm_poll_descriptors_revents( stream.channel, stream_descriptor_ptr, @@ -1140,7 +1140,7 @@ unsafe fn set_sw_params_from_format( format: &Format, ) -> Result<(usize, usize), String> { - let mut sw_params = mem::uninitialized(); // TODO: RAII + let mut sw_params = ptr::null_mut(); // TODO: RAII if let Err(e) = check_errors(alsa::snd_pcm_sw_params_malloc(&mut sw_params)) { return Err(format!("snd_pcm_sw_params_malloc failed: {}", e)); } @@ -1152,8 +1152,8 @@ unsafe fn set_sw_params_from_format( } let (buffer_len, period_len) = { - let mut buffer = mem::uninitialized(); - let mut period = mem::uninitialized(); + let mut buffer = 0; + let mut period = 0; if let Err(e) = check_errors(alsa::snd_pcm_get_params(pcm_handle, &mut buffer, &mut period)) { return Err(format!("failed to initialize buffer: {}", e)); } @@ -1182,7 +1182,7 @@ struct HwParams(*mut alsa::snd_pcm_hw_params_t); impl HwParams { pub fn alloc() -> HwParams { unsafe { - let mut hw_params = mem::uninitialized(); + let mut hw_params = ptr::null_mut(); check_errors(alsa::snd_pcm_hw_params_malloc(&mut hw_params)) .expect("unable to get hardware parameters"); HwParams(hw_params) From 14c1258a57a64d719d05752f980ee8ea29ac1809 Mon Sep 17 00:00:00 2001 From: est31 Date: Sat, 10 Aug 2019 15:10:43 +0200 Subject: [PATCH 2/2] Remove uninitalized from coreaudio backend uninitialized is being deprecated in favour of MaybeUninit and friends. In fact, using mem::zeroed() here is the initialization method that apple docs recommend. https://developer.apple.com/documentation/coreaudiotypes/audiostreambasicdescription --- src/host/coreaudio/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/host/coreaudio/mod.rs b/src/host/coreaudio/mod.rs index 491b4b8..1c4903b 100644 --- a/src/host/coreaudio/mod.rs +++ b/src/host/coreaudio/mod.rs @@ -360,7 +360,7 @@ impl Device { }; unsafe { - let asbd: AudioStreamBasicDescription = mem::uninitialized(); + let asbd: AudioStreamBasicDescription = mem::zeroed(); let data_size = mem::size_of::() as u32; let status = AudioObjectGetPropertyData( self.audio_device_id,