From 814b2b836f5cf420a1c0ffd1c8b6df143fad4995 Mon Sep 17 00:00:00 2001 From: Niko Date: Wed, 13 Aug 2025 01:27:28 -0700 Subject: [PATCH] Make `WhisperState::new` unsafe --- src/whisper_ctx_wrapper.rs | 2 +- src/whisper_state.rs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/whisper_ctx_wrapper.rs b/src/whisper_ctx_wrapper.rs index 5d2eec8..3635538 100644 --- a/src/whisper_ctx_wrapper.rs +++ b/src/whisper_ctx_wrapper.rs @@ -421,7 +421,7 @@ impl WhisperContext { Err(WhisperError::InitError) } else { // SAFETY: this is known to be a valid pointer to a `whisper_state` struct - Ok(WhisperState::new(self.ctx.clone(), state)) + Ok(unsafe { WhisperState::new(self.ctx.clone(), state) }) } } } diff --git a/src/whisper_state.rs b/src/whisper_state.rs index b5aee36..d6e09ea 100644 --- a/src/whisper_state.rs +++ b/src/whisper_state.rs @@ -29,7 +29,10 @@ impl Drop for WhisperState { } impl WhisperState { - pub(crate) fn new( + /// # Safety + /// * `ptr` must be non-null + /// * `ptr` must be a valid pointer to a `whisper_state`. + pub(crate) unsafe fn new( ctx: Arc, ptr: *mut whisper_rs_sys::whisper_state, ) -> Self {