style(util/frame): only mark functions as unsafe if their invocation can directly cause memory unsafety

This commit is contained in:
tilpner
2023-05-24 17:22:59 +02:00
committed by Till Höppner
parent f93cae5802
commit 572f120d42
4 changed files with 34 additions and 34 deletions
+2 -4
View File
@@ -134,10 +134,8 @@ impl Context {
return Err(Error::InputChanged);
}
unsafe {
if output.is_empty() {
output.alloc(self.output.format, self.output.width, self.output.height);
}
if output.is_empty() {
output.alloc(self.output.format, self.output.width, self.output.height);
}
if output.format() != self.output.format
+11 -11
View File
@@ -19,29 +19,29 @@ impl Audio {
}
#[inline]
pub unsafe fn alloc(&mut self, format: format::Sample, samples: usize, layout: ChannelLayout) {
self.set_format(format);
self.set_samples(samples);
self.set_channel_layout(layout);
pub fn alloc(&mut self, format: format::Sample, samples: usize, layout: ChannelLayout) {
unsafe {
self.set_format(format);
self.set_samples(samples);
self.set_channel_layout(layout);
av_frame_get_buffer(self.as_mut_ptr(), 0);
av_frame_get_buffer(self.as_mut_ptr(), 0);
}
}
}
impl Audio {
#[inline(always)]
pub fn empty() -> Self {
unsafe { Audio(Frame::empty()) }
Audio(Frame::empty())
}
#[inline]
pub fn new(format: format::Sample, samples: usize, layout: ChannelLayout) -> Self {
unsafe {
let mut frame = Audio::empty();
frame.alloc(format, samples, layout);
let mut frame = Audio::empty();
frame.alloc(format, samples, layout);
frame
}
frame
}
#[inline]
+10 -8
View File
@@ -40,26 +40,28 @@ impl Frame {
}
#[inline(always)]
pub unsafe fn empty() -> Self {
Frame {
ptr: av_frame_alloc(),
_own: true,
pub fn empty() -> Self {
unsafe {
Frame {
ptr: av_frame_alloc(),
_own: true,
}
}
}
#[inline(always)]
pub unsafe fn as_ptr(&self) -> *const AVFrame {
pub fn as_ptr(&self) -> *const AVFrame {
self.ptr as *const _
}
#[inline(always)]
pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFrame {
pub fn as_mut_ptr(&mut self) -> *mut AVFrame {
self.ptr
}
#[inline(always)]
pub unsafe fn is_empty(&self) -> bool {
(*self.as_ptr()).data[0].is_null()
pub fn is_empty(&self) -> bool {
unsafe { (*self.as_ptr()).data[0].is_null() }
}
}
+11 -11
View File
@@ -25,29 +25,29 @@ impl Video {
}
#[inline]
pub unsafe fn alloc(&mut self, format: format::Pixel, width: u32, height: u32) {
self.set_format(format);
self.set_width(width);
self.set_height(height);
pub fn alloc(&mut self, format: format::Pixel, width: u32, height: u32) {
unsafe {
self.set_format(format);
self.set_width(width);
self.set_height(height);
av_frame_get_buffer(self.as_mut_ptr(), 32);
av_frame_get_buffer(self.as_mut_ptr(), 32);
}
}
}
impl Video {
#[inline(always)]
pub fn empty() -> Self {
unsafe { Video(Frame::empty()) }
Video(Frame::empty())
}
#[inline]
pub fn new(format: format::Pixel, width: u32, height: u32) -> Self {
unsafe {
let mut frame = Video::empty();
frame.alloc(format, width, height);
let mut frame = Video::empty();
frame.alloc(format, width, height);
frame
}
frame
}
#[inline]