Make WhisperState::new unsafe

This commit is contained in:
Niko 2025-08-13 01:27:28 -07:00
parent 7e46c91cbd
commit 814b2b836f
No known key found for this signature in database
2 changed files with 5 additions and 2 deletions

View file

@ -421,7 +421,7 @@ impl WhisperContext {
Err(WhisperError::InitError) Err(WhisperError::InitError)
} else { } else {
// SAFETY: this is known to be a valid pointer to a `whisper_state` struct // 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) })
} }
} }
} }

View file

@ -29,7 +29,10 @@ impl Drop for WhisperState {
} }
impl 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<WhisperInnerContext>, ctx: Arc<WhisperInnerContext>,
ptr: *mut whisper_rs_sys::whisper_state, ptr: *mut whisper_rs_sys::whisper_state,
) -> Self { ) -> Self {