Skip to content

Commit 3a97c0d

Browse files
committed
Add safety documentation for pointer methods in audio, video, and frame modules
1 parent edfc1d0 commit 3a97c0d

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

rustsynth/src/format/audio.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ pub struct AudioFormat {
7373
}
7474

7575
impl AudioInfo {
76+
/// # Safety
77+
/// The pointer must be valid and point to a [ffi::VSAudioInfo]
7678
pub unsafe fn from_ptr(from: *const ffi::VSAudioInfo) -> Self {
7779
let from = &*from;
7880
Self {
@@ -94,6 +96,8 @@ impl AudioInfo {
9496
}
9597

9698
impl AudioFormat {
99+
/// # Safety
100+
/// The pointer must be valid and point to a [ffi::VSAudioFormat]
97101
pub unsafe fn from_ptr(from: *const ffi::VSAudioFormat) -> Self {
98102
let from = &*from;
99103
let sample_type = if from.sampleType == 0 {

rustsynth/src/format/video.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use crate::{
55
use rustsynth_sys as ffi;
66

77
impl VideoFormat {
8+
/// # Safety
9+
/// The pointer must be valid and point to a [ffi::VSVideoFormat]
810
pub unsafe fn from_ptr(from: *const ffi::VSVideoFormat) -> Self {
911
let info = &*from;
1012

@@ -149,6 +151,8 @@ impl VideoFormat {
149151
}
150152

151153
impl VideoInfo {
154+
/// # Safety
155+
/// The pointer must be valid and point to a [ffi::VSVideoInfo]
152156
pub unsafe fn from_ptr(from: *const ffi::VSVideoInfo) -> Self {
153157
let from = &*from;
154158

rustsynth/src/frame/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl FrameContext {
4040
/// Creates a FrameContext from a raw pointer.
4141
///
4242
/// # Safety
43-
/// The pointer must be valid and point to a `VSFrameContext`.
43+
/// The pointer must be valid and point to a [ffi::VSFrameContext].
4444
#[inline]
4545
pub unsafe fn from_ptr(ptr: *mut ffi::VSFrameContext) -> Self {
4646
Self {
@@ -65,6 +65,8 @@ impl FrameContext {
6565
}
6666

6767
impl<'core> Frame<'core> {
68+
/// # Safety
69+
/// The pointer must be valid and point to a [ffi::VSFrame]
6870
#[inline]
6971
pub unsafe fn from_ptr(ptr: *const ffi::VSFrame) -> Self {
7072
Self {
@@ -217,13 +219,13 @@ impl<'core> Frame<'core> {
217219
}
218220

219221
/// Get read-only access to plane data
220-
#[inline]
222+
#[inline(always)]
221223
pub fn get_read_ptr(&self, plane: i32) -> *const u8 {
222224
unsafe { API::get_cached().get_frame_read_ptr(self.handle.as_ref(), plane) }
223225
}
224226

225227
/// Get mutable access to plane data (only for owned frames)
226-
#[inline]
228+
#[inline(always)]
227229
pub fn get_write_ptr(&mut self, plane: i32) -> *mut u8 {
228230
unsafe { API::get_cached().get_frame_write_ptr(self.handle.as_ptr(), plane) }
229231
}

rustsynth/src/map/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ impl<'elem> OwnedMap<'elem> {
162162
}
163163
}
164164

165-
pub fn as_ptr(&self) -> *mut ffi::VSMap {
166-
self.handle.as_ptr()
165+
pub const fn as_ptr(&self) -> *mut ffi::VSMap {
166+
self.map.as_ptr()
167167
}
168168
}
169169

@@ -231,6 +231,10 @@ impl<'elem> Default for OwnedMap<'elem> {
231231
}
232232

233233
impl<'elem> Map<'elem> {
234+
pub const fn as_ptr(&self) -> *mut ffi::VSMap {
235+
self.handle.as_ptr()
236+
}
237+
234238
/// Wraps pointer into `Map`.
235239
///
236240
/// # Safety

0 commit comments

Comments
 (0)