From 02dc34fc3f65da4b1afd3d92504ef6a901f2d75d Mon Sep 17 00:00:00 2001 From: Miriam Zimmerman Date: Thu, 26 Sep 2024 11:24:22 -0400 Subject: [PATCH 1/5] Add empty [workspace] to Cargo.toml. This works around https://github.com/rust-lang/cargo/issues/6745 and allows cubeb-coreaudio-rs to appear as a subdirectory of a workspace member in another project (for instance, cubeb-rs). --- Cargo.toml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 24321691..95ebb14f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,3 +25,8 @@ itertools = "0.11" [features] audio-dump = [] + +# Workaround for https://github.com/rust-lang/cargo/issues/6745 to allow this +# Cargo.toml file to appear under a subdirectory of a workspace without being in +# that workspace (e.g. in cubeb-rs). +[workspace] From 05cd9e2cacaeaa963f143d4555326b45e1473000 Mon Sep 17 00:00:00 2001 From: Miriam Zimmerman Date: Tue, 8 Oct 2024 20:33:31 -0400 Subject: [PATCH 2/5] Fix trivial clippy errors, silence nontrival ones. --- .../src/audio_device_extensions.rs | 2 ++ coreaudio-sys-utils/src/audio_unit.rs | 15 +++++++++++++++ coreaudio-sys-utils/src/dispatch.rs | 4 ++-- coreaudio-sys-utils/src/string.rs | 2 +- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/coreaudio-sys-utils/src/audio_device_extensions.rs b/coreaudio-sys-utils/src/audio_device_extensions.rs index 8224d87c..3553e457 100644 --- a/coreaudio-sys-utils/src/audio_device_extensions.rs +++ b/coreaudio-sys-utils/src/audio_device_extensions.rs @@ -13,6 +13,8 @@ extern "C" { ) -> OSStatus; } +// See https://github.com/mozilla/cubeb-coreaudio-rs/issues/237 +#[allow(clippy::not_unsafe_ptr_arg_deref)] pub fn audio_device_duck( in_device: AudioDeviceID, in_ducked_level: f32, diff --git a/coreaudio-sys-utils/src/audio_unit.rs b/coreaudio-sys-utils/src/audio_unit.rs index 30e5a3cf..f59fba18 100644 --- a/coreaudio-sys-utils/src/audio_unit.rs +++ b/coreaudio-sys-utils/src/audio_unit.rs @@ -4,6 +4,9 @@ use std::convert::TryFrom; use std::os::raw::c_void; use std::ptr; +// See https://github.com/mozilla/cubeb-coreaudio-rs/issues/237 for this and +// all other such warning suppressions in this file. +#[allow(clippy::not_unsafe_ptr_arg_deref)] pub fn audio_unit_get_property_info( unit: AudioUnit, property: AudioUnitPropertyID, @@ -27,6 +30,7 @@ pub fn audio_unit_get_property_info( } } +#[allow(clippy::not_unsafe_ptr_arg_deref)] pub fn audio_unit_get_property( unit: AudioUnit, property: AudioUnitPropertyID, @@ -50,6 +54,7 @@ pub fn audio_unit_get_property( } } +#[allow(clippy::not_unsafe_ptr_arg_deref)] pub fn audio_unit_set_property( unit: AudioUnit, property: AudioUnitPropertyID, @@ -72,6 +77,7 @@ pub fn audio_unit_set_property( } } +#[allow(clippy::not_unsafe_ptr_arg_deref)] pub fn audio_unit_get_parameter( unit: AudioUnit, id: AudioUnitParameterID, @@ -92,6 +98,7 @@ pub fn audio_unit_get_parameter( } } +#[allow(clippy::not_unsafe_ptr_arg_deref)] pub fn audio_unit_set_parameter( unit: AudioUnit, id: AudioUnitParameterID, @@ -105,35 +112,41 @@ pub fn audio_unit_set_parameter( unsafe { AudioUnitSetParameter(unit, id, scope, element, value, buffer_offset_in_frames) } } +#[allow(clippy::not_unsafe_ptr_arg_deref)] pub fn audio_unit_initialize(unit: AudioUnit) -> OSStatus { assert!(!unit.is_null()); debug_assert_running_serially(); unsafe { AudioUnitInitialize(unit) } } +#[allow(clippy::not_unsafe_ptr_arg_deref)] pub fn audio_unit_uninitialize(unit: AudioUnit) -> OSStatus { assert!(!unit.is_null()); debug_assert_running_serially(); unsafe { AudioUnitUninitialize(unit) } } +#[allow(clippy::not_unsafe_ptr_arg_deref)] pub fn dispose_audio_unit(unit: AudioUnit) -> OSStatus { debug_assert_running_serially(); unsafe { AudioComponentInstanceDispose(unit) } } +#[allow(clippy::not_unsafe_ptr_arg_deref)] pub fn audio_output_unit_start(unit: AudioUnit) -> OSStatus { assert!(!unit.is_null()); debug_assert_running_serially(); unsafe { AudioOutputUnitStart(unit) } } +#[allow(clippy::not_unsafe_ptr_arg_deref)] pub fn audio_output_unit_stop(unit: AudioUnit) -> OSStatus { assert!(!unit.is_null()); debug_assert_running_serially(); unsafe { AudioOutputUnitStop(unit) } } +#[allow(clippy::not_unsafe_ptr_arg_deref)] pub fn audio_unit_render( in_unit: AudioUnit, io_action_flags: &mut AudioUnitRenderActionFlags, @@ -159,6 +172,7 @@ pub fn audio_unit_render( pub type audio_unit_property_listener_proc = extern "C" fn(*mut c_void, AudioUnit, AudioUnitPropertyID, AudioUnitScope, AudioUnitElement); +#[allow(clippy::not_unsafe_ptr_arg_deref)] pub fn audio_unit_add_property_listener( unit: AudioUnit, id: AudioUnitPropertyID, @@ -170,6 +184,7 @@ pub fn audio_unit_add_property_listener( unsafe { AudioUnitAddPropertyListener(unit, id, Some(listener), data as *mut c_void) } } +#[allow(clippy::not_unsafe_ptr_arg_deref)] pub fn audio_unit_remove_property_listener_with_user_data( unit: AudioUnit, id: AudioUnitPropertyID, diff --git a/coreaudio-sys-utils/src/dispatch.rs b/coreaudio-sys-utils/src/dispatch.rs index c5da137c..06469a31 100644 --- a/coreaudio-sys-utils/src/dispatch.rs +++ b/coreaudio-sys-utils/src/dispatch.rs @@ -32,14 +32,14 @@ pub fn run_serially(work: F) -> B where F: FnOnce() -> B, { - get_serial_queue_singleton().run_sync(|| work()).unwrap() + get_serial_queue_singleton().run_sync(work).unwrap() } pub fn run_serially_forward_panics(work: F) -> B where F: panic::UnwindSafe + FnOnce() -> B, { - match run_serially(|| panic::catch_unwind(|| work())) { + match run_serially(|| panic::catch_unwind(work)) { Ok(res) => res, Err(e) => panic::resume_unwind(e), } diff --git a/coreaudio-sys-utils/src/string.rs b/coreaudio-sys-utils/src/string.rs index 81517a1e..bdd243fc 100644 --- a/coreaudio-sys-utils/src/string.rs +++ b/coreaudio-sys-utils/src/string.rs @@ -102,7 +102,7 @@ fn utf8_from_cfstringref(string_ref: CFStringRef) -> Vec { kCFStringEncodingUTF8, 0, false as Boolean, - ptr::null_mut() as *mut u8, + ptr::null_mut(), 0, &mut size, ) From 1a9308319f241f3ada5699c6e15af1eba0e9d058 Mon Sep 17 00:00:00 2001 From: Miriam Zimmerman Date: Thu, 10 Oct 2024 11:33:41 -0400 Subject: [PATCH 3/5] Ignore manual_c_str_literals warning. Due to https://github.com/rust-lang/rust-clippy/issues/13531, this incorrectly applies here on nightly builds of clippy -- it should not, since this project is on edition 2015 by default. --- src/backend/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/backend/mod.rs b/src/backend/mod.rs index 5b242517..21fd4a41 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -2645,6 +2645,8 @@ impl ContextOps for AudioUnitContext { } fn backend_id(&mut self) -> &'static CStr { + // https://github.com/rust-lang/rust-clippy/issues/13531 + #[allow(clippy::manual_c_str_literals)] unsafe { CStr::from_ptr(b"audiounit-rust\0".as_ptr() as *const _) } } #[cfg(target_os = "ios")] From 811d61d0a2f596aef93aa958ef1f4b13820d7e59 Mon Sep 17 00:00:00 2001 From: Miriam Zimmerman Date: Thu, 10 Oct 2024 11:34:43 -0400 Subject: [PATCH 4/5] Automatically fix some new nightly clippy warnings. --- src/backend/mod.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/backend/mod.rs b/src/backend/mod.rs index 21fd4a41..564c98b4 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -3049,7 +3049,7 @@ struct CoreStreamData<'ctx> { audio_dump_output: ffi::cubeb_audio_dump_stream_t, } -impl<'ctx> Default for CoreStreamData<'ctx> { +impl Default for CoreStreamData<'_> { fn default() -> Self { Self { stm_ptr: ptr::null(), @@ -4556,7 +4556,7 @@ impl<'ctx> CoreStreamData<'ctx> { } } -impl<'ctx> Drop for CoreStreamData<'ctx> { +impl Drop for CoreStreamData<'_> { fn drop(&mut self) { self.debug_assert_is_on_stream_queue(); self.stop_audiounits(); @@ -4881,7 +4881,7 @@ impl<'ctx> AudioUnitStream<'ctx> { } } -impl<'ctx> Drop for AudioUnitStream<'ctx> { +impl Drop for AudioUnitStream<'_> { fn drop(&mut self) { // Execute destroy in serial queue to avoid collision with reinit when un/plug devices self.queue.clone().run_final(|| { @@ -4891,7 +4891,7 @@ impl<'ctx> Drop for AudioUnitStream<'ctx> { } } -impl<'ctx> StreamOps for AudioUnitStream<'ctx> { +impl StreamOps for AudioUnitStream<'_> { fn start(&mut self) -> Result<()> { let was_stopped = self.stopped.load(Ordering::SeqCst); let was_draining = self.draining.load(Ordering::SeqCst); @@ -5175,8 +5175,8 @@ impl<'ctx> StreamOps for AudioUnitStream<'ctx> { } #[allow(clippy::non_send_fields_in_send_ty)] -unsafe impl<'ctx> Send for AudioUnitStream<'ctx> {} -unsafe impl<'ctx> Sync for AudioUnitStream<'ctx> {} +unsafe impl Send for AudioUnitStream<'_> {} +unsafe impl Sync for AudioUnitStream<'_> {} #[cfg(test)] mod tests; From 6a875b78208ea28d2ac65c1b896c8cecb93fc3aa Mon Sep 17 00:00:00 2001 From: Miriam Zimmerman Date: Thu, 10 Oct 2024 19:13:15 -0400 Subject: [PATCH 5/5] cargo fmt --- src/backend/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/backend/mod.rs b/src/backend/mod.rs index 564c98b4..e320d020 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -2647,7 +2647,9 @@ impl ContextOps for AudioUnitContext { fn backend_id(&mut self) -> &'static CStr { // https://github.com/rust-lang/rust-clippy/issues/13531 #[allow(clippy::manual_c_str_literals)] - unsafe { CStr::from_ptr(b"audiounit-rust\0".as_ptr() as *const _) } + unsafe { + CStr::from_ptr(b"audiounit-rust\0".as_ptr() as *const _) + } } #[cfg(target_os = "ios")] fn max_channel_count(&mut self) -> Result {