From bb64c78e933dfabdfeb9db36c6c6406d9962f5db Mon Sep 17 00:00:00 2001 From: edwloef Date: Wed, 17 Sep 2025 18:33:11 +0200 Subject: [PATCH] fix various safety comments and small bugs --- common/src/events/io/buffer.rs | 3 ++- extensions/src/gui/host.rs | 4 ++-- extensions/src/gui/window.rs | 4 ++-- host/src/process.rs | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/common/src/events/io/buffer.rs b/common/src/events/io/buffer.rs index 9b126d28..6e7cfea8 100644 --- a/common/src/events/io/buffer.rs +++ b/common/src/events/io/buffer.rs @@ -145,7 +145,8 @@ impl EventBuffer { /// /// It is necessary to sort the events before passing them to a plugin. pub fn sort(&mut self) { - self.indexes.sort_by_key(|i| { + // this needs to be an unstable sort, as the std stable sort might allocate + self.indexes.sort_unstable_by_key(|i| { // SAFETY: Registered indexes always have actual event headers written by append_header_data // PANIC: We used registered indexes, this should never panic let event = unsafe { self.headers[*i as usize].assume_init_ref() }; diff --git a/extensions/src/gui/host.rs b/extensions/src/gui/host.rs index b438eda2..ae942c65 100644 --- a/extensions/src/gui/host.rs +++ b/extensions/src/gui/host.rs @@ -288,10 +288,10 @@ impl PluginGui { plugin .use_extension(&self.0) .hide - .ok_or(GuiError::ShowError)?(plugin.as_raw()) + .ok_or(GuiError::HideError)?(plugin.as_raw()) } .then_some(()) - .ok_or(GuiError::ShowError) + .ok_or(GuiError::HideError) } } diff --git a/extensions/src/gui/window.rs b/extensions/src/gui/window.rs index a2768d60..6b70c8ac 100644 --- a/extensions/src/gui/window.rs +++ b/extensions/src/gui/window.rs @@ -119,8 +119,8 @@ impl<'a> Window<'a> { /// Returns the window's handle as an X11 window handle, if this is an X11 window. /// Otherwise, this returns `None`. pub fn as_x11_handle(&self) -> Option { - if self.api_type() == GuiApiType::COCOA { - // SAFETY: We just checked this was a COCOA window + if self.api_type() == GuiApiType::X11 { + // SAFETY: We just checked this was an X11 window unsafe { Some(self.raw.specific.x11) } } else { None diff --git a/host/src/process.rs b/host/src/process.rs index d3d0a7c2..bfeceb72 100644 --- a/host/src/process.rs +++ b/host/src/process.rs @@ -522,7 +522,7 @@ impl StartedPluginAudioProcessor { /// to jump backwards. #[inline] pub fn reset(&mut self) { - // SAFETY: This type ensures this can only be called in the main thread. + // SAFETY: This type ensures this can only be called on the audio thread. unsafe { self.inner.reset() } } @@ -672,7 +672,7 @@ impl StoppedPluginAudioProcessor { /// to jump backwards. #[inline] pub fn reset(&mut self) { - // SAFETY: This type ensures this can only be called in the main thread. + // SAFETY: This type ensures this can only be called on the audio thread. unsafe { self.inner.reset() } }