Remove mem::uninitialized from alsa backend

uninitialized is being deprecated in favour of
MaybeUninit and friends.
This commit is contained in:
est31 2019-08-10 15:08:21 +02:00
parent a04d869eaa
commit 268ea6cfbf
2 changed files with 17 additions and 17 deletions

View File

@ -3,7 +3,7 @@ use super::Device;
use super::alsa; use super::alsa;
use super::check_errors; use super::check_errors;
use std::ffi::CString; use std::ffi::CString;
use std::mem; use std::ptr;
/// ALSA implementation for `Devices`. /// ALSA implementation for `Devices`.
pub struct Devices { pub struct Devices {
@ -20,7 +20,7 @@ impl Devices {
// TODO: check in which situation this can fail. // TODO: check in which situation this can fail.
let card = -1; // -1 means all cards. let card = -1; // -1 means all cards.
let iface = b"pcm\0"; // Interface identification. 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); let res = alsa::snd_device_name_hint(card, iface.as_ptr() as *const _, &mut hints);
if let Err(description) = check_errors(res) { if let Err(description) = check_errors(res) {
let err = BackendSpecificError { description }; let err = BackendSpecificError { description };
@ -107,7 +107,7 @@ impl Iterator for Devices {
let name_zeroed = CString::new(&name[..]).unwrap(); let name_zeroed = CString::new(&name[..]).unwrap();
// See if the device has an available output stream. // 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( let has_available_output = alsa::snd_pcm_open(
&mut playback_handle, &mut playback_handle,
name_zeroed.as_ptr() as *const _, name_zeroed.as_ptr() as *const _,
@ -119,7 +119,7 @@ impl Iterator for Devices {
} }
// See if the device has an available input stream. // 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( let has_available_input = alsa::snd_pcm_open(
&mut capture_handle, &mut capture_handle,
name_zeroed.as_ptr() as *const _, name_zeroed.as_ptr() as *const _,

View File

@ -23,7 +23,7 @@ use UnknownTypeInputBuffer;
use UnknownTypeOutputBuffer; use UnknownTypeOutputBuffer;
use traits::{DeviceTrait, EventLoopTrait, HostTrait, StreamIdTrait}; use traits::{DeviceTrait, EventLoopTrait, HostTrait, StreamIdTrait};
use std::{cmp, ffi, mem, ptr}; use std::{cmp, ffi, ptr};
use std::sync::Mutex; use std::sync::Mutex;
use std::sync::mpsc::{channel, Sender, Receiver}; use std::sync::mpsc::{channel, Sender, Receiver};
use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::atomic::{AtomicUsize, Ordering};
@ -193,7 +193,7 @@ impl Device {
stream_t: alsa::snd_pcm_stream_t, stream_t: alsa::snd_pcm_stream_t,
) -> Result<VecIntoIter<SupportedFormat>, SupportedFormatsError> ) -> Result<VecIntoIter<SupportedFormat>, SupportedFormatsError>
{ {
let mut handle = mem::uninitialized(); let mut handle = ptr::null_mut();
let device_name = match ffi::CString::new(&self.0[..]) { let device_name = match ffi::CString::new(&self.0[..]) {
Ok(name) => name, Ok(name) => name,
Err(err) => { 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( if let Err(desc) = check_errors(alsa::snd_pcm_hw_params_get_rate_min(
hw_params.0, hw_params.0,
&mut min_rate, &mut min_rate,
@ -290,7 +290,7 @@ impl Device {
return Err(err.into()); 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( if let Err(desc) = check_errors(alsa::snd_pcm_hw_params_get_rate_max(
hw_params.0, hw_params.0,
&mut max_rate, &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)) { 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 description = format!("unable to get minimum supported channel count: {}", desc);
let err = BackendSpecificError { description }; let err = BackendSpecificError { description };
return Err(err.into()); 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)) { 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 description = format!("unable to get maximum supported channel count: {}", desc);
let err = BackendSpecificError { description }; let err = BackendSpecificError { description };
@ -759,7 +759,7 @@ impl EventLoop {
unsafe { unsafe {
let name = ffi::CString::new(device.0.clone()).expect("unable to clone device"); 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( match alsa::snd_pcm_open(
&mut capture_handle, &mut capture_handle,
name.as_ptr(), name.as_ptr(),
@ -838,7 +838,7 @@ impl EventLoop {
unsafe { unsafe {
let name = ffi::CString::new(device.0.clone()).expect("unable to clone device"); 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( match alsa::snd_pcm_open(
&mut playback_handle, &mut playback_handle,
name.as_ptr(), name.as_ptr(),
@ -1027,7 +1027,7 @@ fn check_for_pollout_or_pollin(
stream_descriptor_ptr: *mut libc::pollfd, stream_descriptor_ptr: *mut libc::pollfd,
) -> Result<Option<StreamType>, BackendSpecificError> { ) -> Result<Option<StreamType>, BackendSpecificError> {
let (revent, res) = unsafe { let (revent, res) = unsafe {
let mut revent = mem::uninitialized(); let mut revent = 0;
let res = alsa::snd_pcm_poll_descriptors_revents( let res = alsa::snd_pcm_poll_descriptors_revents(
stream.channel, stream.channel,
stream_descriptor_ptr, stream_descriptor_ptr,
@ -1140,7 +1140,7 @@ unsafe fn set_sw_params_from_format(
format: &Format, format: &Format,
) -> Result<(usize, usize), String> ) -> 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)) { 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)); 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 (buffer_len, period_len) = {
let mut buffer = mem::uninitialized(); let mut buffer = 0;
let mut period = mem::uninitialized(); let mut period = 0;
if let Err(e) = check_errors(alsa::snd_pcm_get_params(pcm_handle, &mut buffer, &mut period)) { 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)); return Err(format!("failed to initialize buffer: {}", e));
} }
@ -1182,7 +1182,7 @@ struct HwParams(*mut alsa::snd_pcm_hw_params_t);
impl HwParams { impl HwParams {
pub fn alloc() -> HwParams { pub fn alloc() -> HwParams {
unsafe { 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)) check_errors(alsa::snd_pcm_hw_params_malloc(&mut hw_params))
.expect("unable to get hardware parameters"); .expect("unable to get hardware parameters");
HwParams(hw_params) HwParams(hw_params)