Use uninitialized stack memory for out parameters instead of zeroed memory if applicable

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1187>
This commit is contained in:
Sebastian Dröge 2023-01-06 14:11:45 +02:00 committed by GStreamer Marge Bot
parent 1b022a6b7c
commit f07727ee6d
26 changed files with 61 additions and 61 deletions

View file

@ -100,13 +100,13 @@ impl<O: IsA<AudioDecoder>> AudioDecoderExtManual for O {
fn allocator(&self) -> (Option<gst::Allocator>, gst::AllocationParams) {
unsafe {
let mut allocator = ptr::null_mut();
let mut params = mem::zeroed();
let mut params = mem::MaybeUninit::uninit();
ffi::gst_audio_decoder_get_allocator(
self.as_ref().to_glib_none().0,
&mut allocator,
&mut params,
params.as_mut_ptr(),
);
(from_glib_full(allocator), params.into())
(from_glib_full(allocator), params.assume_init().into())
}
}

View file

@ -56,13 +56,13 @@ impl<O: IsA<AudioEncoder>> AudioEncoderExtManual for O {
fn allocator(&self) -> (Option<gst::Allocator>, gst::AllocationParams) {
unsafe {
let mut allocator = ptr::null_mut();
let mut params = mem::zeroed();
let mut params = mem::MaybeUninit::uninit();
ffi::gst_audio_encoder_get_allocator(
self.as_ref().to_glib_none().0,
&mut allocator,
&mut params,
params.as_mut_ptr(),
);
(from_glib_full(allocator), params.into())
(from_glib_full(allocator), params.assume_init().into())
}
}

View file

@ -84,13 +84,13 @@ impl<O: IsA<Aggregator>> AggregatorExtManual for O {
fn allocator(&self) -> (Option<gst::Allocator>, gst::AllocationParams) {
unsafe {
let mut allocator = ptr::null_mut();
let mut params = mem::zeroed();
let mut params = mem::MaybeUninit::uninit();
ffi::gst_aggregator_get_allocator(
self.as_ref().to_glib_none().0,
&mut allocator,
&mut params,
params.as_mut_ptr(),
);
(from_glib_full(allocator), params.into())
(from_glib_full(allocator), params.assume_init().into())
}
}

View file

@ -31,13 +31,13 @@ impl<O: IsA<BaseSrc>> BaseSrcExtManual for O {
fn allocator(&self) -> (Option<gst::Allocator>, gst::AllocationParams) {
unsafe {
let mut allocator = ptr::null_mut();
let mut params = mem::zeroed();
let mut params = mem::MaybeUninit::uninit();
ffi::gst_base_src_get_allocator(
self.as_ref().to_glib_none().0,
&mut allocator,
&mut params,
params.as_mut_ptr(),
);
(from_glib_full(allocator), params.into())
(from_glib_full(allocator), params.assume_init().into())
}
}

View file

@ -23,13 +23,13 @@ impl<O: IsA<BaseTransform>> BaseTransformExtManual for O {
fn allocator(&self) -> (Option<gst::Allocator>, gst::AllocationParams) {
unsafe {
let mut allocator = ptr::null_mut();
let mut params = mem::zeroed();
let mut params = mem::MaybeUninit::uninit();
ffi::gst_base_transform_get_allocator(
self.as_ref().to_glib_none().0,
&mut allocator,
&mut params,
params.as_mut_ptr(),
);
(from_glib_full(allocator), params.into())
(from_glib_full(allocator), params.assume_init().into())
}
}

View file

@ -62,7 +62,7 @@ impl<'a> VideoFrameGLExt for gst_video::VideoFrameRef<&'a gst::BufferRef> {
}
unsafe {
let mut frame = mem::MaybeUninit::zeroed();
let mut frame = mem::MaybeUninit::uninit();
let res: bool = from_glib(gst_video::ffi::gst_video_frame_map(
frame.as_mut_ptr(),
info.to_glib_none().0 as *mut _,
@ -108,7 +108,7 @@ impl<'a> VideoFrameGLExt for gst_video::VideoFrameRef<&'a gst::BufferRef> {
}
unsafe {
let mut frame = mem::MaybeUninit::zeroed();
let mut frame = mem::MaybeUninit::uninit();
let res: bool = from_glib(gst_video::ffi::gst_video_frame_map(
frame.as_mut_ptr(),
info.to_glib_none().0 as *mut _,

View file

@ -15,7 +15,7 @@ impl SDPAttribute {
pub fn new(key: &str, value: Option<&str>) -> Self {
assert_initialized_main_thread!();
unsafe {
let mut attr = mem::MaybeUninit::zeroed();
let mut attr = mem::MaybeUninit::uninit();
ffi::gst_sdp_attribute_set(
attr.as_mut_ptr(),
key.to_glib_none().0,

View file

@ -15,7 +15,7 @@ impl SDPBandwidth {
pub fn new(bwtype: &str, bandwidth: u32) -> Self {
assert_initialized_main_thread!();
unsafe {
let mut bw = mem::MaybeUninit::zeroed();
let mut bw = mem::MaybeUninit::uninit();
ffi::gst_sdp_bandwidth_set(bw.as_mut_ptr(), bwtype.to_glib_none().0, bandwidth);
SDPBandwidth(bw.assume_init())
}
@ -40,7 +40,7 @@ impl Clone for SDPBandwidth {
fn clone(&self) -> Self {
assert_initialized_main_thread!();
unsafe {
let mut bw = mem::MaybeUninit::zeroed();
let mut bw = mem::MaybeUninit::uninit();
ffi::gst_sdp_bandwidth_set(bw.as_mut_ptr(), self.0.bwtype, self.0.bandwidth);
SDPBandwidth(bw.assume_init())
}

View file

@ -15,7 +15,7 @@ impl SDPConnection {
pub fn new(nettype: &str, addrtype: &str, address: &str, ttl: u32, addr_number: u32) -> Self {
assert_initialized_main_thread!();
unsafe {
let mut conn = mem::MaybeUninit::zeroed();
let mut conn = mem::MaybeUninit::uninit();
ffi::gst_sdp_connection_set(
conn.as_mut_ptr(),
nettype.to_glib_none().0,
@ -71,7 +71,7 @@ impl Clone for SDPConnection {
fn clone(&self) -> Self {
assert_initialized_main_thread!();
unsafe {
let mut conn = mem::MaybeUninit::zeroed();
let mut conn = mem::MaybeUninit::uninit();
ffi::gst_sdp_connection_set(
conn.as_mut_ptr(),
self.0.nettype,

View file

@ -15,7 +15,7 @@ impl SDPTime {
pub fn new(start: &str, stop: &str, repeat: &[&str]) -> Self {
assert_initialized_main_thread!();
unsafe {
let mut time = mem::MaybeUninit::zeroed();
let mut time = mem::MaybeUninit::uninit();
ffi::gst_sdp_time_set(
time.as_mut_ptr(),
start.to_glib_none().0,
@ -69,7 +69,7 @@ impl Clone for SDPTime {
assert_initialized_main_thread!();
#[allow(clippy::cast_ptr_alignment)]
unsafe {
let mut time = mem::MaybeUninit::zeroed();
let mut time = mem::MaybeUninit::uninit();
ffi::gst_sdp_time_set(
time.as_mut_ptr(),
self.0.start,

View file

@ -15,7 +15,7 @@ impl SDPZone {
pub fn new(time: &str, typed_time: &str) -> Self {
assert_initialized_main_thread!();
unsafe {
let mut zone = mem::MaybeUninit::zeroed();
let mut zone = mem::MaybeUninit::uninit();
ffi::gst_sdp_zone_set(
zone.as_mut_ptr(),
time.to_glib_none().0,
@ -50,7 +50,7 @@ impl Clone for SDPZone {
fn clone(&self) -> Self {
assert_initialized_main_thread!();
unsafe {
let mut zone = mem::MaybeUninit::zeroed();
let mut zone = mem::MaybeUninit::uninit();
ffi::gst_sdp_zone_set(zone.as_mut_ptr(), self.0.time, self.0.typed_time);
SDPZone(zone.assume_init())
}

View file

@ -126,7 +126,7 @@ impl<T: VideoAggregatorImpl> VideoAggregatorImplExt for T {
let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoAggregatorClass;
(*parent_class).find_best_format.and_then(|f| {
let mut info = mem::MaybeUninit::zeroed();
let mut info = mem::MaybeUninit::uninit();
ffi::gst_video_info_init(info.as_mut_ptr());
let mut info = info.assume_init();

View file

@ -107,7 +107,7 @@ impl VideoBufferPoolConfig for gst::BufferPoolConfigRef {
#[doc(alias = "gst_buffer_pool_config_get_video_alignment")]
fn video_alignment(&self) -> Option<VideoAlignment> {
unsafe {
let mut alignment = mem::MaybeUninit::zeroed();
let mut alignment = mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gst_buffer_pool_config_get_video_alignment(
self.as_ref().as_mut_ptr(),
alignment.as_mut_ptr(),

View file

@ -116,13 +116,13 @@ impl<O: IsA<VideoDecoder>> VideoDecoderExtManual for O {
fn allocator(&self) -> (Option<gst::Allocator>, gst::AllocationParams) {
unsafe {
let mut allocator = ptr::null_mut();
let mut params = mem::zeroed();
let mut params = mem::MaybeUninit::uninit();
ffi::gst_video_decoder_get_allocator(
self.as_ref().to_glib_none().0,
&mut allocator,
&mut params,
params.as_mut_ptr(),
);
(from_glib_full(allocator), params.into())
(from_glib_full(allocator), params.assume_init().into())
}
}

View file

@ -89,13 +89,13 @@ impl<O: IsA<VideoEncoder>> VideoEncoderExtManual for O {
fn allocator(&self) -> (Option<gst::Allocator>, gst::AllocationParams) {
unsafe {
let mut allocator = ptr::null_mut();
let mut params = mem::zeroed();
let mut params = mem::MaybeUninit::uninit();
ffi::gst_video_encoder_get_allocator(
self.as_ref().to_glib_none().0,
&mut allocator,
&mut params,
params.as_mut_ptr(),
);
(from_glib_full(allocator), params.into())
(from_glib_full(allocator), params.assume_init().into())
}
}

View file

@ -268,7 +268,7 @@ impl VideoFrame<Readable> {
assert!(info.is_valid());
unsafe {
let mut frame = mem::MaybeUninit::zeroed();
let mut frame = mem::MaybeUninit::uninit();
let res: bool = from_glib(ffi::gst_video_frame_map(
frame.as_mut_ptr(),
info.to_glib_none().0 as *mut _,
@ -301,7 +301,7 @@ impl VideoFrame<Readable> {
assert!(info.is_valid());
unsafe {
let mut frame = mem::MaybeUninit::zeroed();
let mut frame = mem::MaybeUninit::uninit();
let res: bool = from_glib(ffi::gst_video_frame_map_id(
frame.as_mut_ptr(),
info.to_glib_none().0 as *mut _,
@ -340,7 +340,7 @@ impl VideoFrame<Writable> {
assert!(info.is_valid());
unsafe {
let mut frame = mem::MaybeUninit::zeroed();
let mut frame = mem::MaybeUninit::uninit();
let res: bool = from_glib(ffi::gst_video_frame_map(
frame.as_mut_ptr(),
info.to_glib_none().0 as *mut _,
@ -375,7 +375,7 @@ impl VideoFrame<Writable> {
assert!(info.is_valid());
unsafe {
let mut frame = mem::MaybeUninit::zeroed();
let mut frame = mem::MaybeUninit::uninit();
let res: bool = from_glib(ffi::gst_video_frame_map_id(
frame.as_mut_ptr(),
info.to_glib_none().0 as *mut _,
@ -693,7 +693,7 @@ impl<'a> VideoFrameRef<&'a gst::BufferRef> {
assert!(info.is_valid());
unsafe {
let mut frame = mem::MaybeUninit::zeroed();
let mut frame = mem::MaybeUninit::uninit();
let res: bool = from_glib(ffi::gst_video_frame_map(
frame.as_mut_ptr(),
info.to_glib_none().0 as *mut _,
@ -726,7 +726,7 @@ impl<'a> VideoFrameRef<&'a gst::BufferRef> {
assert!(info.is_valid());
unsafe {
let mut frame = mem::MaybeUninit::zeroed();
let mut frame = mem::MaybeUninit::uninit();
let res: bool = from_glib(ffi::gst_video_frame_map_id(
frame.as_mut_ptr(),
info.to_glib_none().0 as *mut _,
@ -788,7 +788,7 @@ impl<'a> VideoFrameRef<&'a mut gst::BufferRef> {
assert!(info.is_valid());
unsafe {
let mut frame = mem::MaybeUninit::zeroed();
let mut frame = mem::MaybeUninit::uninit();
let res: bool = from_glib(ffi::gst_video_frame_map(
frame.as_mut_ptr(),
info.to_glib_none().0 as *mut _,
@ -823,7 +823,7 @@ impl<'a> VideoFrameRef<&'a mut gst::BufferRef> {
assert!(info.is_valid());
unsafe {
let mut frame = mem::MaybeUninit::zeroed();
let mut frame = mem::MaybeUninit::uninit();
let res: bool = from_glib(ffi::gst_video_frame_map_id(
frame.as_mut_ptr(),
info.to_glib_none().0 as *mut _,

View file

@ -47,7 +47,7 @@ impl VideoContentLightLevel {
skip_assert_initialized!();
unsafe {
let mut info = mem::MaybeUninit::zeroed();
let mut info = mem::MaybeUninit::uninit();
let res: bool = from_glib(ffi::gst_video_content_light_level_from_caps(
info.as_mut_ptr(),
caps.as_ptr(),
@ -101,7 +101,7 @@ impl str::FromStr for VideoContentLightLevel {
assert_initialized_main_thread!();
unsafe {
let mut colorimetry = mem::MaybeUninit::zeroed();
let mut colorimetry = mem::MaybeUninit::uninit();
let valid: bool = from_glib(ffi::gst_video_content_light_level_from_string(
colorimetry.as_mut_ptr(),
s.to_glib_none().0,
@ -206,7 +206,7 @@ impl VideoMasteringDisplayInfo {
skip_assert_initialized!();
unsafe {
let mut info = mem::MaybeUninit::zeroed();
let mut info = mem::MaybeUninit::uninit();
let res: bool = from_glib(ffi::gst_video_mastering_display_info_from_caps(
info.as_mut_ptr(),
caps.as_ptr(),
@ -254,7 +254,7 @@ impl str::FromStr for VideoMasteringDisplayInfo {
assert_initialized_main_thread!();
unsafe {
let mut colorimetry = mem::MaybeUninit::zeroed();
let mut colorimetry = mem::MaybeUninit::uninit();
let valid: bool = from_glib(ffi::gst_video_mastering_display_info_from_string(
colorimetry.as_mut_ptr(),
s.to_glib_none().0,

View file

@ -158,7 +158,7 @@ impl str::FromStr for crate::VideoColorimetry {
assert_initialized_main_thread!();
unsafe {
let mut colorimetry = mem::MaybeUninit::zeroed();
let mut colorimetry = mem::MaybeUninit::uninit();
let valid: bool = from_glib(ffi::gst_video_colorimetry_from_string(
colorimetry.as_mut_ptr(),
s.to_glib_none().0,

View file

@ -77,7 +77,7 @@ impl VideoTimeCode {
) -> Self {
assert_initialized_main_thread!();
unsafe {
let mut v = mem::MaybeUninit::zeroed();
let mut v = mem::MaybeUninit::uninit();
ffi::gst_video_time_code_init(
v.as_mut_ptr(),
fps.numer() as u32,

View file

@ -17,7 +17,7 @@ impl VideoTimeCodeInterval {
pub fn new(hours: u32, minutes: u32, seconds: u32, frames: u32) -> Self {
assert_initialized_main_thread!();
unsafe {
let mut v = mem::MaybeUninit::zeroed();
let mut v = mem::MaybeUninit::uninit();
ffi::gst_video_time_code_interval_init(v.as_mut_ptr(), hours, minutes, seconds, frames);
Self {
inner: v.assume_init(),

View file

@ -110,7 +110,7 @@ impl Buffer {
#[doc(alias = "gst_buffer_map")]
pub fn into_mapped_buffer_readable(self) -> Result<MappedBuffer<Readable>, Self> {
unsafe {
let mut map_info = mem::MaybeUninit::zeroed();
let mut map_info = mem::MaybeUninit::uninit();
let res: bool = from_glib(ffi::gst_buffer_map(
self.as_mut_ptr(),
map_info.as_mut_ptr(),
@ -131,7 +131,7 @@ impl Buffer {
#[doc(alias = "gst_buffer_map")]
pub fn into_mapped_buffer_writable(self) -> Result<MappedBuffer<Writable>, Self> {
unsafe {
let mut map_info = mem::MaybeUninit::zeroed();
let mut map_info = mem::MaybeUninit::uninit();
let res: bool = from_glib(ffi::gst_buffer_map(
self.as_mut_ptr(),
map_info.as_mut_ptr(),
@ -177,7 +177,7 @@ impl BufferRef {
#[doc(alias = "gst_buffer_map")]
pub fn map_readable(&self) -> Result<BufferMap<Readable>, glib::BoolError> {
unsafe {
let mut map_info = mem::MaybeUninit::zeroed();
let mut map_info = mem::MaybeUninit::uninit();
let res =
ffi::gst_buffer_map(self.as_mut_ptr(), map_info.as_mut_ptr(), ffi::GST_MAP_READ);
if res == glib::ffi::GTRUE {
@ -195,7 +195,7 @@ impl BufferRef {
#[doc(alias = "gst_buffer_map")]
pub fn map_writable(&mut self) -> Result<BufferMap<Writable>, glib::BoolError> {
unsafe {
let mut map_info = mem::MaybeUninit::zeroed();
let mut map_info = mem::MaybeUninit::uninit();
let res = ffi::gst_buffer_map(
self.as_mut_ptr(),
map_info.as_mut_ptr(),

View file

@ -207,7 +207,7 @@ impl BufferPoolConfigRef {
pub fn allocator(&self) -> Option<(Option<Allocator>, AllocationParams)> {
unsafe {
let mut allocator = ptr::null_mut();
let mut params = mem::MaybeUninit::zeroed();
let mut params = mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gst_buffer_pool_config_get_allocator(
self.0.as_mut_ptr(),
&mut allocator,

View file

@ -28,7 +28,7 @@ impl UnixBusExtManual for Bus {
fn pollfd(&self) -> unix::io::RawFd {
#[cfg(unix)]
unsafe {
let mut pollfd = mem::MaybeUninit::zeroed();
let mut pollfd = mem::MaybeUninit::uninit();
ffi::gst_bus_get_pollfd(self.to_glib_none().0, pollfd.as_mut_ptr());
let pollfd = pollfd.assume_init();
pollfd.fd

View file

@ -28,7 +28,7 @@ impl WindowsBusExtManual for Bus {
fn pollfd(&self) -> windows::io::RawHandle {
#[cfg(windows)]
unsafe {
let mut pollfd = mem::MaybeUninit::zeroed();
let mut pollfd = mem::MaybeUninit::uninit();
ffi::gst_bus_get_pollfd(self.to_glib_none().0, pollfd.as_mut_ptr());
let pollfd = pollfd.assume_init();
pollfd.fd as *mut _

View file

@ -125,7 +125,7 @@ impl Memory {
pub fn into_mapped_memory_readable(self) -> Result<MappedMemory<Readable>, Self> {
unsafe {
let mut map_info = mem::MaybeUninit::zeroed();
let mut map_info = mem::MaybeUninit::uninit();
let res: bool = from_glib(ffi::gst_memory_map(
self.as_mut_ptr(),
map_info.as_mut_ptr(),
@ -145,7 +145,7 @@ impl Memory {
pub fn into_mapped_memory_writable(self) -> Result<MappedMemory<Writable>, Self> {
unsafe {
let mut map_info = mem::MaybeUninit::zeroed();
let mut map_info = mem::MaybeUninit::uninit();
let res: bool = from_glib(ffi::gst_memory_map(
self.as_mut_ptr(),
map_info.as_mut_ptr(),
@ -259,7 +259,7 @@ impl MemoryRef {
pub fn map_readable(&self) -> Result<MemoryMap<Readable>, glib::BoolError> {
unsafe {
let mut map_info = mem::MaybeUninit::zeroed();
let mut map_info = mem::MaybeUninit::uninit();
let res =
ffi::gst_memory_map(self.as_mut_ptr(), map_info.as_mut_ptr(), ffi::GST_MAP_READ);
if res == glib::ffi::GTRUE {
@ -276,7 +276,7 @@ impl MemoryRef {
pub fn map_writable(&mut self) -> Result<MemoryMap<Writable>, glib::BoolError> {
unsafe {
let mut map_info = mem::MaybeUninit::zeroed();
let mut map_info = mem::MaybeUninit::uninit();
let res = ffi::gst_memory_map(
self.as_mut_ptr(),
map_info.as_mut_ptr(),

View file

@ -76,7 +76,7 @@ impl<T: FormattedValueIntrinsic> FormattedSegment<T> {
pub fn new() -> Self {
assert_initialized_main_thread!();
let segment = unsafe {
let mut segment = mem::MaybeUninit::zeroed();
let mut segment = mem::MaybeUninit::uninit();
ffi::gst_segment_init(segment.as_mut_ptr(), T::default_format().into_glib());
segment.assume_init()
};