From fb56af8d8439edd203cee25201b5cb967622b181 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 8 Dec 2020 15:07:12 +0100 Subject: [PATCH] Update from_glib calls and put them in unsafe blocks --- examples/src/bin/gtkvideooverlay.rs | 2 -- gstreamer-audio/src/audio_channel_position.rs | 4 ++-- gstreamer-audio/src/audio_format_info.rs | 11 +++++----- gstreamer-audio/src/audio_info.rs | 4 ++-- gstreamer-audio/src/audio_meta.rs | 4 ++-- gstreamer-audio/src/audio_ring_buffer_spec.rs | 2 +- gstreamer-base/src/base_parse_frame.rs | 2 +- gstreamer-video/src/video_format.rs | 2 +- gstreamer-video/src/video_format_info.rs | 8 +++---- gstreamer-video/src/video_frame.rs | 4 ++-- gstreamer-video/src/video_info.rs | 20 ++++++++--------- gstreamer-video/src/video_meta.rs | 14 ++++++------ gstreamer-video/src/video_time_code.rs | 2 +- gstreamer/src/allocation_params.rs | 2 +- gstreamer/src/buffer.rs | 6 ++--- gstreamer/src/buffer_pool.rs | 8 +++---- gstreamer/src/clock.rs | 16 ++++++++------ gstreamer/src/clock_time.rs | 4 ++-- gstreamer/src/date_time_serde.rs | 2 +- gstreamer/src/device_monitor.rs | 6 ++--- gstreamer/src/element.rs | 4 ++-- gstreamer/src/enums.rs | 22 +++++++++---------- gstreamer/src/log.rs | 2 +- gstreamer/src/memory.rs | 2 +- gstreamer/src/meta.rs | 4 ++-- gstreamer/src/pad.rs | 4 ++-- gstreamer/src/segment.rs | 4 ++-- 27 files changed, 83 insertions(+), 82 deletions(-) diff --git a/examples/src/bin/gtkvideooverlay.rs b/examples/src/bin/gtkvideooverlay.rs index a69b78f60..95ccfbbe5 100644 --- a/examples/src/bin/gtkvideooverlay.rs +++ b/examples/src/bin/gtkvideooverlay.rs @@ -25,8 +25,6 @@ use gio::prelude::*; use gtk::prelude::*; -use gdk::prelude::*; - use std::env; use std::os::raw::c_void; diff --git a/gstreamer-audio/src/audio_channel_position.rs b/gstreamer-audio/src/audio_channel_position.rs index 71e319e15..9684a31e6 100644 --- a/gstreamer-audio/src/audio_channel_position.rs +++ b/gstreamer-audio/src/audio_channel_position.rs @@ -82,7 +82,7 @@ impl AudioChannelPosition { if valid { for (d, s) in positions.iter_mut().zip(positions_raw.iter()) { - *d = from_glib(*s); + *d = unsafe { from_glib(*s) }; } Ok(()) } else { @@ -119,7 +119,7 @@ impl AudioChannelPosition { if valid { for (d, s) in positions.iter_mut().zip(positions_raw.iter()) { - *d = from_glib(*s); + *d = unsafe { from_glib(*s) }; } Ok(()) } else { diff --git a/gstreamer-audio/src/audio_format_info.rs b/gstreamer-audio/src/audio_format_info.rs index 9c845447d..0354ab065 100644 --- a/gstreamer-audio/src/audio_format_info.rs +++ b/gstreamer-audio/src/audio_format_info.rs @@ -21,7 +21,8 @@ pub enum AudioEndianness { } impl FromGlib for AudioEndianness { - fn from_glib(value: i32) -> Self { + #[allow(unused_unsafe)] + unsafe fn from_glib(value: i32) -> Self { assert_initialized_main_thread!(); match value { @@ -59,7 +60,7 @@ impl AudioFormatInfo { } pub fn format(&self) -> crate::AudioFormat { - from_glib(self.0.format) + unsafe { from_glib(self.0.format) } } pub fn name<'a>(&self) -> &'a str { @@ -71,11 +72,11 @@ impl AudioFormatInfo { } pub fn flags(&self) -> crate::AudioFormatFlags { - from_glib(self.0.flags) + unsafe { from_glib(self.0.flags) } } pub fn endianness(&self) -> AudioEndianness { - from_glib(self.0.endianness) + unsafe { from_glib(self.0.endianness) } } pub fn width(&self) -> u32 { @@ -87,7 +88,7 @@ impl AudioFormatInfo { } pub fn unpack_format(&self) -> crate::AudioFormat { - from_glib(self.0.unpack_format) + unsafe { from_glib(self.0.unpack_format) } } pub fn silence<'a>(&self) -> &'a [u8] { diff --git a/gstreamer-audio/src/audio_info.rs b/gstreamer-audio/src/audio_info.rs index 9c596471d..6e0161750 100644 --- a/gstreamer-audio/src/audio_info.rs +++ b/gstreamer-audio/src/audio_info.rs @@ -243,11 +243,11 @@ impl AudioInfo { } pub fn layout(&self) -> crate::AudioLayout { - from_glib(self.0.layout) + unsafe { from_glib(self.0.layout) } } pub fn flags(&self) -> crate::AudioFlags { - from_glib(self.0.flags) + unsafe { from_glib(self.0.flags) } } pub fn rate(&self) -> u32 { diff --git a/gstreamer-audio/src/audio_meta.rs b/gstreamer-audio/src/audio_meta.rs index fa3ba53b5..e8307a762 100644 --- a/gstreamer-audio/src/audio_meta.rs +++ b/gstreamer-audio/src/audio_meta.rs @@ -50,11 +50,11 @@ impl AudioClippingMeta { } pub fn get_start(&self) -> gst::GenericFormattedValue { - gst::GenericFormattedValue::new(from_glib(self.0.format), self.0.start as i64) + unsafe { gst::GenericFormattedValue::new(from_glib(self.0.format), self.0.start as i64) } } pub fn get_end(&self) -> gst::GenericFormattedValue { - gst::GenericFormattedValue::new(from_glib(self.0.format), self.0.end as i64) + unsafe { gst::GenericFormattedValue::new(from_glib(self.0.format), self.0.end as i64) } } } diff --git a/gstreamer-audio/src/audio_ring_buffer_spec.rs b/gstreamer-audio/src/audio_ring_buffer_spec.rs index 191fc8a5a..fa4aeea2a 100644 --- a/gstreamer-audio/src/audio_ring_buffer_spec.rs +++ b/gstreamer-audio/src/audio_ring_buffer_spec.rs @@ -12,7 +12,7 @@ pub struct AudioRingBufferSpec(pub(crate) GstAudioRingBufferSpec); impl AudioRingBufferSpec { pub fn get_type(&self) -> AudioRingBufferFormatType { - AudioRingBufferFormatType::from_glib(self.0.type_) + unsafe { AudioRingBufferFormatType::from_glib(self.0.type_) } } pub fn set_type(&mut self, value: AudioRingBufferFormatType) { diff --git a/gstreamer-base/src/base_parse_frame.rs b/gstreamer-base/src/base_parse_frame.rs index d35283a91..0713d2346 100644 --- a/gstreamer-base/src/base_parse_frame.rs +++ b/gstreamer-base/src/base_parse_frame.rs @@ -45,7 +45,7 @@ impl ToGlib for Overhead { impl FromGlib for Overhead { #[inline] - fn from_glib(val: i32) -> Overhead { + unsafe fn from_glib(val: i32) -> Overhead { skip_assert_initialized!(); match val { 0 => Overhead::None, diff --git a/gstreamer-video/src/video_format.rs b/gstreamer-video/src/video_format.rs index 1d71790e5..12082bfe5 100644 --- a/gstreamer-video/src/video_format.rs +++ b/gstreamer-video/src/video_format.rs @@ -264,7 +264,7 @@ pub enum VideoEndianness { } impl FromGlib for VideoEndianness { - fn from_glib(value: i32) -> Self { + unsafe fn from_glib(value: i32) -> Self { skip_assert_initialized!(); match value { diff --git a/gstreamer-video/src/video_format_info.rs b/gstreamer-video/src/video_format_info.rs index 5ec00f9cb..5639a152a 100644 --- a/gstreamer-video/src/video_format_info.rs +++ b/gstreamer-video/src/video_format_info.rs @@ -28,7 +28,7 @@ impl VideoFormatInfo { } pub fn format(&self) -> crate::VideoFormat { - from_glib(self.0.format) + unsafe { from_glib(self.0.format) } } pub fn name<'a>(&self) -> &'a str { @@ -40,7 +40,7 @@ impl VideoFormatInfo { } pub fn flags(&self) -> crate::VideoFormatFlags { - from_glib(self.0.flags) + unsafe { from_glib(self.0.flags) } } pub fn bits(&self) -> u32 { @@ -84,7 +84,7 @@ impl VideoFormatInfo { } pub fn tile_mode(&self) -> crate::VideoTileMode { - from_glib(self.0.tile_mode) + unsafe { from_glib(self.0.tile_mode) } } pub fn tile_ws(&self) -> u32 { @@ -96,7 +96,7 @@ impl VideoFormatInfo { } pub fn unpack_format(&self) -> crate::VideoFormat { - from_glib(self.0.unpack_format) + unsafe { from_glib(self.0.unpack_format) } } pub fn pack_lines(&self) -> i32 { diff --git a/gstreamer-video/src/video_frame.rs b/gstreamer-video/src/video_frame.rs index 2773006f7..388ed4684 100644 --- a/gstreamer-video/src/video_frame.rs +++ b/gstreamer-video/src/video_frame.rs @@ -45,7 +45,7 @@ impl VideoFrame { } pub fn flags(&self) -> crate::VideoFrameFlags { - from_glib(self.frame.flags) + unsafe { from_glib(self.frame.flags) } } pub fn id(&self) -> i32 { @@ -420,7 +420,7 @@ impl VideoFrameRef { } pub fn flags(&self) -> crate::VideoFrameFlags { - from_glib(self.frame.flags) + unsafe { from_glib(self.frame.flags) } } pub fn id(&self) -> i32 { diff --git a/gstreamer-video/src/video_info.rs b/gstreamer-video/src/video_info.rs index 689b222cb..58c8d93d9 100644 --- a/gstreamer-video/src/video_info.rs +++ b/gstreamer-video/src/video_info.rs @@ -48,7 +48,7 @@ impl ToGlib for VideoColorRange { #[doc(hidden)] impl FromGlib for VideoColorRange { - fn from_glib(value: ffi::GstVideoColorRange) -> Self { + unsafe fn from_glib(value: ffi::GstVideoColorRange) -> Self { skip_assert_initialized!(); match value as i32 { 0 => VideoColorRange::Unknown, @@ -109,19 +109,19 @@ impl VideoColorimetry { } pub fn range(&self) -> crate::VideoColorRange { - from_glib(self.0.range) + unsafe { from_glib(self.0.range) } } pub fn matrix(&self) -> crate::VideoColorMatrix { - from_glib(self.0.matrix) + unsafe { from_glib(self.0.matrix) } } pub fn transfer(&self) -> crate::VideoTransferFunction { - from_glib(self.0.transfer) + unsafe { from_glib(self.0.transfer) } } pub fn primaries(&self) -> crate::VideoColorPrimaries { - from_glib(self.0.primaries) + unsafe { from_glib(self.0.primaries) } } } @@ -209,7 +209,7 @@ impl fmt::Display for crate::VideoChromaSite { impl From for crate::VideoMultiviewMode { fn from(v: crate::VideoMultiviewFramePacking) -> Self { skip_assert_initialized!(); - from_glib(v.to_glib()) + unsafe { from_glib(v.to_glib()) } } } @@ -221,7 +221,7 @@ impl std::convert::TryFrom for crate::VideoMultiviewF ) -> Result { skip_assert_initialized!(); - let v2 = from_glib(v.to_glib()); + let v2 = unsafe { from_glib(v.to_glib()) }; if let crate::VideoMultiviewFramePacking::__Unknown(_) = v2 { Err(glib::glib_bool_error!("Invalid frame packing mode")) @@ -647,11 +647,11 @@ impl VideoInfo { } pub fn interlace_mode(&self) -> crate::VideoInterlaceMode { - from_glib(self.0.interlace_mode) + unsafe { from_glib(self.0.interlace_mode) } } pub fn flags(&self) -> crate::VideoFlags { - from_glib(self.0.flags) + unsafe { from_glib(self.0.flags) } } pub fn size(&self) -> usize { @@ -663,7 +663,7 @@ impl VideoInfo { } pub fn chroma_site(&self) -> crate::VideoChromaSite { - from_glib(self.0.chroma_site) + unsafe { from_glib(self.0.chroma_site) } } pub fn colorimetry(&self) -> VideoColorimetry { diff --git a/gstreamer-video/src/video_meta.rs b/gstreamer-video/src/video_meta.rs index 38d060d3b..9683e19ae 100644 --- a/gstreamer-video/src/video_meta.rs +++ b/gstreamer-video/src/video_meta.rs @@ -123,11 +123,11 @@ impl VideoMeta { } pub fn get_flags(&self) -> crate::VideoFrameFlags { - from_glib(self.0.flags) + unsafe { from_glib(self.0.flags) } } pub fn get_format(&self) -> crate::VideoFormat { - from_glib(self.0.format) + unsafe { from_glib(self.0.format) } } pub fn get_id(&self) -> i32 { @@ -339,7 +339,7 @@ impl VideoRegionOfInterestMeta { } pub fn get_roi_type<'a>(&self) -> &'a str { - glib::Quark::from_glib(self.0.roi_type).to_string() + unsafe { glib::Quark::from_glib(self.0.roi_type).to_string() } } #[cfg(feature = "v1_14")] @@ -581,7 +581,7 @@ impl VideoCaptionMeta { } pub fn get_caption_type(&self) -> crate::VideoCaptionType { - from_glib(self.0.caption_type) + unsafe { from_glib(self.0.caption_type) } } pub fn get_data(&self) -> &[u8] { @@ -654,11 +654,11 @@ impl VideoAFDMeta { } pub fn get_spec(&self) -> crate::VideoAFDSpec { - from_glib(self.0.spec) + unsafe { from_glib(self.0.spec) } } pub fn get_afd(&self) -> crate::VideoAFDValue { - from_glib(self.0.afd) + unsafe { from_glib(self.0.afd) } } } @@ -726,7 +726,7 @@ impl VideoBarMeta { } pub fn is_letterbox(&self) -> bool { - from_glib(self.0.is_letterbox) + unsafe { from_glib(self.0.is_letterbox) } } pub fn get_bar_data1(&self) -> u32 { diff --git a/gstreamer-video/src/video_time_code.rs b/gstreamer-video/src/video_time_code.rs index deffb6f92..577beadf7 100644 --- a/gstreamer-video/src/video_time_code.rs +++ b/gstreamer-video/src/video_time_code.rs @@ -272,7 +272,7 @@ macro_rules! generic_impl { } pub fn get_flags(&self) -> VideoTimeCodeFlags { - from_glib(self.0.config.flags) + unsafe { from_glib(self.0.config.flags) } } pub fn get_latest_daily_jam(&self) -> Option { diff --git a/gstreamer/src/allocation_params.rs b/gstreamer/src/allocation_params.rs index 1cf872607..4e8329a65 100644 --- a/gstreamer/src/allocation_params.rs +++ b/gstreamer/src/allocation_params.rs @@ -20,7 +20,7 @@ unsafe impl Sync for AllocationParams {} impl AllocationParams { pub fn get_flags(&self) -> MemoryFlags { - from_glib(self.0.flags) + unsafe { from_glib(self.0.flags) } } pub fn get_align(&self) -> usize { diff --git a/gstreamer/src/buffer.rs b/gstreamer/src/buffer.rs index d57998e7d..0d9caee9d 100644 --- a/gstreamer/src/buffer.rs +++ b/gstreamer/src/buffer.rs @@ -346,7 +346,7 @@ impl BufferRef { } pub fn get_pts(&self) -> ClockTime { - from_glib(self.0.pts) + unsafe { from_glib(self.0.pts) } } pub fn set_pts(&mut self, pts: ClockTime) { @@ -354,7 +354,7 @@ impl BufferRef { } pub fn get_dts(&self) -> ClockTime { - from_glib(self.0.dts) + unsafe { from_glib(self.0.dts) } } pub fn set_dts(&mut self, dts: ClockTime) { @@ -371,7 +371,7 @@ impl BufferRef { } pub fn get_duration(&self) -> ClockTime { - from_glib(self.0.duration) + unsafe { from_glib(self.0.duration) } } pub fn set_duration(&mut self, duration: ClockTime) { diff --git a/gstreamer/src/buffer_pool.rs b/gstreamer/src/buffer_pool.rs index 27016a1b7..eab92dc23 100644 --- a/gstreamer/src/buffer_pool.rs +++ b/gstreamer/src/buffer_pool.rs @@ -217,19 +217,19 @@ impl BufferPoolAcquireParams { } pub fn flags(&self) -> crate::BufferPoolAcquireFlags { - from_glib(self.0.flags) + unsafe { from_glib(self.0.flags) } } pub fn format(&self) -> crate::Format { - from_glib(self.0.format) + unsafe { from_glib(self.0.format) } } pub fn start(&self) -> crate::GenericFormattedValue { - crate::GenericFormattedValue::new(from_glib(self.0.format), self.0.start) + unsafe { crate::GenericFormattedValue::new(from_glib(self.0.format), self.0.start) } } pub fn stop(&self) -> crate::GenericFormattedValue { - crate::GenericFormattedValue::new(from_glib(self.0.format), self.0.stop) + unsafe { crate::GenericFormattedValue::new(from_glib(self.0.format), self.0.stop) } } } diff --git a/gstreamer/src/clock.rs b/gstreamer/src/clock.rs index 82f1086dc..a7b0d2f23 100644 --- a/gstreamer/src/clock.rs +++ b/gstreamer/src/clock.rs @@ -313,7 +313,7 @@ pub struct AtomicClockReturn(AtomicI32); impl AtomicClockReturn { pub fn load(&self) -> ClockReturn { - from_glib(self.0.load(atomic::Ordering::SeqCst)) + unsafe { from_glib(self.0.load(atomic::Ordering::SeqCst)) } } pub fn store(&self, val: ClockReturn) { @@ -321,15 +321,17 @@ impl AtomicClockReturn { } pub fn swap(&self, val: ClockReturn) -> ClockReturn { - from_glib(self.0.swap(val.to_glib(), atomic::Ordering::SeqCst)) + unsafe { from_glib(self.0.swap(val.to_glib(), atomic::Ordering::SeqCst)) } } pub fn compare_and_swap(&self, current: ClockReturn, new: ClockReturn) -> ClockReturn { - from_glib(self.0.compare_and_swap( - current.to_glib(), - new.to_glib(), - atomic::Ordering::SeqCst, - )) + unsafe { + from_glib(self.0.compare_and_swap( + current.to_glib(), + new.to_glib(), + atomic::Ordering::SeqCst, + )) + } } } diff --git a/gstreamer/src/clock_time.rs b/gstreamer/src/clock_time.rs index 907521269..8c5a38a6e 100644 --- a/gstreamer/src/clock_time.rs +++ b/gstreamer/src/clock_time.rs @@ -192,7 +192,7 @@ impl ToGlib for ClockTime { #[doc(hidden)] impl FromGlib for ClockTime { - fn from_glib(value: ffi::GstClockTime) -> Self { + unsafe fn from_glib(value: ffi::GstClockTime) -> Self { skip_assert_initialized!(); match value { ffi::GST_CLOCK_TIME_NONE => ClockTime(None), @@ -205,7 +205,7 @@ impl FromGlib for ClockTime { impl<'a> glib::value::FromValueOptional<'a> for ClockTime { unsafe fn from_value_optional(value: &'a glib::Value) -> Option { ::from_value_optional(value) - .map(ClockTime::from_glib) + .map(|x| ClockTime::from_glib(x)) } } diff --git a/gstreamer/src/date_time_serde.rs b/gstreamer/src/date_time_serde.rs index 436906f35..3925ea6d8 100644 --- a/gstreamer/src/date_time_serde.rs +++ b/gstreamer/src/date_time_serde.rs @@ -118,7 +118,7 @@ impl TryFrom for Date { skip_assert_initialized!(); match dt_variant { DateTimeVariants::YMD(y, m, d) => { - let month = glib::DateMonth::from_glib(m); + let month = unsafe { glib::DateMonth::from_glib(m) }; if let glib::DateMonth::__Unknown(_) = month { return Err(glib::glib_bool_error!("Out of range `month` for `Date`")); } diff --git a/gstreamer/src/device_monitor.rs b/gstreamer/src/device_monitor.rs index e5ac085bb..da1e9b7e1 100644 --- a/gstreamer/src/device_monitor.rs +++ b/gstreamer/src/device_monitor.rs @@ -45,10 +45,10 @@ impl ToGlib for DeviceMonitorFilterId { } impl FromGlib for DeviceMonitorFilterId { - fn from_glib(val: libc::c_uint) -> DeviceMonitorFilterId { + unsafe fn from_glib(val: libc::c_uint) -> DeviceMonitorFilterId { skip_assert_initialized!(); assert_ne!(val, 0); - DeviceMonitorFilterId(unsafe { NonZeroU32::new_unchecked(val) }) + DeviceMonitorFilterId(NonZeroU32::new_unchecked(val)) } } @@ -80,7 +80,7 @@ impl> DeviceMonitorExtManual for O { if id == 0 { None } else { - Some(from_glib(id)) + Some(unsafe { from_glib(id) }) } } diff --git a/gstreamer/src/element.rs b/gstreamer/src/element.rs index 5fc9c3b47..6893daeea 100644 --- a/gstreamer/src/element.rs +++ b/gstreamer/src/element.rs @@ -121,10 +121,10 @@ impl ToGlib for NotifyWatchId { } impl FromGlib for NotifyWatchId { - fn from_glib(val: libc::c_ulong) -> NotifyWatchId { + unsafe fn from_glib(val: libc::c_ulong) -> NotifyWatchId { skip_assert_initialized!(); assert_ne!(val, 0); - NotifyWatchId(unsafe { NonZeroU64::new_unchecked(val as u64) }) + NotifyWatchId(NonZeroU64::new_unchecked(val as u64)) } } diff --git a/gstreamer/src/enums.rs b/gstreamer/src/enums.rs index 058329adb..c168cc673 100644 --- a/gstreamer/src/enums.rs +++ b/gstreamer/src/enums.rs @@ -377,14 +377,14 @@ impl ops::Add for crate::TypeFindProbability { fn add(self, rhs: u32) -> crate::TypeFindProbability { let res = (self.to_glib() as u32).saturating_add(rhs); - from_glib(res as i32) + unsafe { from_glib(res as i32) } } } impl ops::AddAssign for crate::TypeFindProbability { fn add_assign(&mut self, rhs: u32) { let res = (self.to_glib() as u32).saturating_add(rhs); - *self = from_glib(res as i32); + *self = unsafe { from_glib(res as i32) }; } } @@ -393,14 +393,14 @@ impl ops::Sub for crate::TypeFindProbability { fn sub(self, rhs: u32) -> crate::TypeFindProbability { let res = (self.to_glib() as u32).saturating_sub(rhs); - from_glib(res as i32) + unsafe { from_glib(res as i32) } } } impl ops::SubAssign for crate::TypeFindProbability { fn sub_assign(&mut self, rhs: u32) { let res = (self.to_glib() as u32).saturating_sub(rhs); - *self = from_glib(res as i32); + *self = unsafe { from_glib(res as i32) }; } } @@ -429,14 +429,14 @@ impl ops::Add for crate::Rank { fn add(self, rhs: u32) -> crate::Rank { let res = (self.to_glib() as u32).saturating_add(rhs); - from_glib(res as i32) + unsafe { from_glib(res as i32) } } } impl ops::AddAssign for crate::Rank { fn add_assign(&mut self, rhs: u32) { let res = (self.to_glib() as u32).saturating_add(rhs); - *self = from_glib(res as i32); + *self = unsafe { from_glib(res as i32) }; } } @@ -445,14 +445,14 @@ impl ops::Sub for crate::Rank { fn sub(self, rhs: u32) -> crate::Rank { let res = (self.to_glib() as u32).saturating_sub(rhs); - from_glib(res as i32) + unsafe { from_glib(res as i32) } } } impl ops::SubAssign for crate::Rank { fn sub_assign(&mut self, rhs: u32) { let res = (self.to_glib() as u32).saturating_sub(rhs); - *self = from_glib(res as i32); + *self = unsafe { from_glib(res as i32) }; } } @@ -563,7 +563,7 @@ impl ToGlib for MessageType { #[doc(hidden)] impl FromGlib for MessageType { #[allow(clippy::unreadable_literal)] - fn from_glib(value: ffi::GstMessageType) -> Self { + unsafe fn from_glib(value: ffi::GstMessageType) -> Self { skip_assert_initialized!(); match value { 0 => MessageType::Unknown, @@ -641,7 +641,7 @@ impl State { let sign = (pending - current).signum(); - from_glib(current + sign) + unsafe { from_glib(current + sign) } } } @@ -650,7 +650,7 @@ impl StateChange { skip_assert_initialized!(); let current = current.to_glib(); let next = next.to_glib(); - from_glib((current << 3) | next) + unsafe { from_glib((current << 3) | next) } } pub fn current(self) -> State { diff --git a/gstreamer/src/log.rs b/gstreamer/src/log.rs index 9ea50df32..98dd9696a 100644 --- a/gstreamer/src/log.rs +++ b/gstreamer/src/log.rs @@ -91,7 +91,7 @@ impl DebugCategory { } pub fn get_threshold(self) -> crate::DebugLevel { - from_glib(unsafe { ffi::gst_debug_category_get_threshold(self.0.as_ptr()) }) + unsafe { from_glib(ffi::gst_debug_category_get_threshold(self.0.as_ptr())) } } pub fn set_threshold(self, threshold: crate::DebugLevel) { diff --git a/gstreamer/src/memory.rs b/gstreamer/src/memory.rs index 986784553..d4ca4f08b 100644 --- a/gstreamer/src/memory.rs +++ b/gstreamer/src/memory.rs @@ -203,7 +203,7 @@ impl MemoryRef { } pub fn get_flags(&self) -> MemoryFlags { - from_glib(self.0.mini_object.flags) + unsafe { from_glib(self.0.mini_object.flags) } } pub fn copy_part(&self, offset: isize, size: Option) -> Memory { diff --git a/gstreamer/src/meta.rs b/gstreamer/src/meta.rs index 2e7167ba2..3d0d71d44 100644 --- a/gstreamer/src/meta.rs +++ b/gstreamer/src/meta.rs @@ -387,11 +387,11 @@ impl ReferenceTimestampMeta { } pub fn get_timestamp(&self) -> ClockTime { - from_glib(self.0.timestamp) + unsafe { from_glib(self.0.timestamp) } } pub fn get_duration(&self) -> ClockTime { - from_glib(self.0.duration) + unsafe { from_glib(self.0.duration) } } } diff --git a/gstreamer/src/pad.rs b/gstreamer/src/pad.rs index 5b69eaffe..2d394e234 100644 --- a/gstreamer/src/pad.rs +++ b/gstreamer/src/pad.rs @@ -53,10 +53,10 @@ impl ToGlib for PadProbeId { } impl FromGlib for PadProbeId { - fn from_glib(val: libc::c_ulong) -> PadProbeId { + unsafe fn from_glib(val: libc::c_ulong) -> PadProbeId { skip_assert_initialized!(); assert_ne!(val, 0); - PadProbeId(unsafe { NonZeroU64::new_unchecked(val as u64) }) + PadProbeId(NonZeroU64::new_unchecked(val as u64)) } } diff --git a/gstreamer/src/segment.rs b/gstreamer/src/segment.rs index bfe638540..763b679f5 100644 --- a/gstreamer/src/segment.rs +++ b/gstreamer/src/segment.rs @@ -364,7 +364,7 @@ impl FormattedSegment { } pub fn get_flags(&self) -> crate::SegmentFlags { - from_glib(self.0.flags) + unsafe { from_glib(self.0.flags) } } pub fn set_flags(&mut self, flags: crate::SegmentFlags) { @@ -392,7 +392,7 @@ impl FormattedSegment { } pub fn get_format(&self) -> Format { - from_glib(self.0.format) + unsafe { from_glib(self.0.format) } } pub fn get_base(&self) -> T {