Remove unneeded PhantomData markers

And as a side-effect also get rid of the lifetime parameter of
gst::TypeFind that was completely unused anyway.
This commit is contained in:
Sebastian Dröge 2020-10-24 19:56:48 +03:00 committed by Sebastian Dröge
parent d815e85440
commit 4c216bca3a
6 changed files with 34 additions and 89 deletions

View file

@ -22,10 +22,7 @@ use std::ptr;
use TestClock; use TestClock;
#[derive(Debug)] #[derive(Debug)]
pub struct Harness( pub struct Harness(ptr::NonNull<gst_check_sys::GstHarness>);
ptr::NonNull<gst_check_sys::GstHarness>,
PhantomData<gst_check_sys::GstHarness>,
);
impl Drop for Harness { impl Drop for Harness {
fn drop(&mut self) { fn drop(&mut self) {
@ -567,7 +564,7 @@ impl Harness {
unsafe fn from_glib_full(ptr: *mut gst_check_sys::GstHarness) -> Harness { unsafe fn from_glib_full(ptr: *mut gst_check_sys::GstHarness) -> Harness {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
Harness(ptr::NonNull::new_unchecked(ptr), PhantomData) Harness(ptr::NonNull::new_unchecked(ptr))
} }
pub fn new(element_name: &str) -> Harness { pub fn new(element_name: &str) -> Harness {
@ -728,10 +725,7 @@ impl Harness {
None None
} else { } else {
Some(Ref( Some(Ref(
mem::ManuallyDrop::new(Harness( mem::ManuallyDrop::new(Harness(ptr::NonNull::new_unchecked(sink_harness))),
ptr::NonNull::new_unchecked(sink_harness),
PhantomData,
)),
PhantomData, PhantomData,
)) ))
} }
@ -745,10 +739,7 @@ impl Harness {
None None
} else { } else {
Some(Ref( Some(Ref(
mem::ManuallyDrop::new(Harness( mem::ManuallyDrop::new(Harness(ptr::NonNull::new_unchecked(src_harness))),
ptr::NonNull::new_unchecked(src_harness),
PhantomData,
)),
PhantomData, PhantomData,
)) ))
} }
@ -762,10 +753,7 @@ impl Harness {
None None
} else { } else {
Some(RefMut( Some(RefMut(
mem::ManuallyDrop::new(Harness( mem::ManuallyDrop::new(Harness(ptr::NonNull::new_unchecked(sink_harness))),
ptr::NonNull::new_unchecked(sink_harness),
PhantomData,
)),
PhantomData, PhantomData,
)) ))
} }
@ -779,10 +767,7 @@ impl Harness {
None None
} else { } else {
Some(RefMut( Some(RefMut(
mem::ManuallyDrop::new(Harness( mem::ManuallyDrop::new(Harness(ptr::NonNull::new_unchecked(src_harness))),
ptr::NonNull::new_unchecked(src_harness),
PhantomData,
)),
PhantomData, PhantomData,
)) ))
} }

View file

@ -54,7 +54,6 @@ impl<'a> VideoCodecStateContext<'a> for Readable {
pub struct VideoCodecState<'a, T: VideoCodecStateContext<'a>> { pub struct VideoCodecState<'a, T: VideoCodecStateContext<'a>> {
state: *mut gst_video_sys::GstVideoCodecState, state: *mut gst_video_sys::GstVideoCodecState,
pub(crate) context: T, pub(crate) context: T,
/* FIXME: should not be needed because lifetime is actually used */
phantom: PhantomData<&'a T>, phantom: PhantomData<&'a T>,
} }

View file

@ -9,7 +9,6 @@
use std::borrow::{Borrow, BorrowMut, ToOwned}; use std::borrow::{Borrow, BorrowMut, ToOwned};
use std::ffi::CStr; use std::ffi::CStr;
use std::fmt; use std::fmt;
use std::marker::PhantomData;
use std::mem; use std::mem;
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use std::ptr; use std::ptr;
@ -26,7 +25,7 @@ use glib_sys::gpointer;
use gobject_sys; use gobject_sys;
use gst_sys; use gst_sys;
pub struct CapsFeatures(ptr::NonNull<CapsFeaturesRef>, PhantomData<CapsFeaturesRef>); pub struct CapsFeatures(ptr::NonNull<CapsFeaturesRef>);
unsafe impl Send for CapsFeatures {} unsafe impl Send for CapsFeatures {}
unsafe impl Sync for CapsFeatures {} unsafe impl Sync for CapsFeatures {}
@ -45,24 +44,18 @@ impl CapsFeatures {
pub fn new_empty() -> Self { pub fn new_empty() -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
CapsFeatures( CapsFeatures(ptr::NonNull::new_unchecked(
ptr::NonNull::new_unchecked( gst_sys::gst_caps_features_new_empty() as *mut CapsFeaturesRef,
gst_sys::gst_caps_features_new_empty() as *mut CapsFeaturesRef ))
),
PhantomData,
)
} }
} }
pub fn new_any() -> Self { pub fn new_any() -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
CapsFeatures( CapsFeatures(ptr::NonNull::new_unchecked(
ptr::NonNull::new_unchecked( gst_sys::gst_caps_features_new_any() as *mut CapsFeaturesRef,
gst_sys::gst_caps_features_new_any() as *mut CapsFeaturesRef ))
),
PhantomData,
)
} }
} }
@ -103,7 +96,7 @@ impl Clone for CapsFeatures {
unsafe { unsafe {
let ptr = gst_sys::gst_caps_features_copy(&self.0.as_ref().0) as *mut CapsFeaturesRef; let ptr = gst_sys::gst_caps_features_copy(&self.0.as_ref().0) as *mut CapsFeaturesRef;
assert!(!ptr.is_null()); assert!(!ptr.is_null());
CapsFeatures(ptr::NonNull::new_unchecked(ptr), PhantomData) CapsFeatures(ptr::NonNull::new_unchecked(ptr))
} }
} }
} }
@ -143,10 +136,9 @@ impl str::FromStr for CapsFeatures {
)); ));
} }
Ok(CapsFeatures( Ok(CapsFeatures(ptr::NonNull::new_unchecked(
ptr::NonNull::new_unchecked(ptr as *mut CapsFeaturesRef), ptr as *mut CapsFeaturesRef,
PhantomData, )))
))
} }
} }
} }
@ -206,10 +198,7 @@ impl FromGlibPtrNone<*const gst_sys::GstCapsFeatures> for CapsFeatures {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
let ptr = gst_sys::gst_caps_features_copy(ptr); let ptr = gst_sys::gst_caps_features_copy(ptr);
assert!(!ptr.is_null()); assert!(!ptr.is_null());
CapsFeatures( CapsFeatures(ptr::NonNull::new_unchecked(ptr as *mut CapsFeaturesRef))
ptr::NonNull::new_unchecked(ptr as *mut CapsFeaturesRef),
PhantomData,
)
} }
} }
@ -218,30 +207,21 @@ impl FromGlibPtrNone<*mut gst_sys::GstCapsFeatures> for CapsFeatures {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
let ptr = gst_sys::gst_caps_features_copy(ptr); let ptr = gst_sys::gst_caps_features_copy(ptr);
assert!(!ptr.is_null()); assert!(!ptr.is_null());
CapsFeatures( CapsFeatures(ptr::NonNull::new_unchecked(ptr as *mut CapsFeaturesRef))
ptr::NonNull::new_unchecked(ptr as *mut CapsFeaturesRef),
PhantomData,
)
} }
} }
impl FromGlibPtrFull<*const gst_sys::GstCapsFeatures> for CapsFeatures { impl FromGlibPtrFull<*const gst_sys::GstCapsFeatures> for CapsFeatures {
unsafe fn from_glib_full(ptr: *const gst_sys::GstCapsFeatures) -> Self { unsafe fn from_glib_full(ptr: *const gst_sys::GstCapsFeatures) -> Self {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
CapsFeatures( CapsFeatures(ptr::NonNull::new_unchecked(ptr as *mut CapsFeaturesRef))
ptr::NonNull::new_unchecked(ptr as *mut CapsFeaturesRef),
PhantomData,
)
} }
} }
impl FromGlibPtrFull<*mut gst_sys::GstCapsFeatures> for CapsFeatures { impl FromGlibPtrFull<*mut gst_sys::GstCapsFeatures> for CapsFeatures {
unsafe fn from_glib_full(ptr: *mut gst_sys::GstCapsFeatures) -> Self { unsafe fn from_glib_full(ptr: *mut gst_sys::GstCapsFeatures) -> Self {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
CapsFeatures( CapsFeatures(ptr::NonNull::new_unchecked(ptr as *mut CapsFeaturesRef))
ptr::NonNull::new_unchecked(ptr as *mut CapsFeaturesRef),
PhantomData,
)
} }
} }

View file

@ -11,7 +11,6 @@ macro_rules! gst_define_mini_object_wrapper(
($name:ident, $ref_name:ident, $gst_sys_name:path, $get_type:expr) => { ($name:ident, $ref_name:ident, $gst_sys_name:path, $get_type:expr) => {
pub struct $name { pub struct $name {
obj: ::std::ptr::NonNull<$ref_name>, obj: ::std::ptr::NonNull<$ref_name>,
phantom: ::std::marker::PhantomData<$ref_name>,
} }
#[repr(C)] #[repr(C)]
@ -26,7 +25,6 @@ macro_rules! gst_define_mini_object_wrapper(
$name { $name {
obj: ::std::ptr::NonNull::new_unchecked(ptr as *mut $gst_sys_name as *mut $ref_name), obj: ::std::ptr::NonNull::new_unchecked(ptr as *mut $gst_sys_name as *mut $ref_name),
phantom: ::std::marker::PhantomData,
} }
} }
@ -36,7 +34,6 @@ macro_rules! gst_define_mini_object_wrapper(
$name { $name {
obj: ::std::ptr::NonNull::new_unchecked(ptr as *mut $gst_sys_name as *mut $ref_name), obj: ::std::ptr::NonNull::new_unchecked(ptr as *mut $gst_sys_name as *mut $ref_name),
phantom: ::std::marker::PhantomData,
} }
} }
@ -46,7 +43,6 @@ macro_rules! gst_define_mini_object_wrapper(
$crate::glib::translate::Borrowed::new($name { $crate::glib::translate::Borrowed::new($name {
obj: ::std::ptr::NonNull::new_unchecked(ptr as *mut $gst_sys_name as *mut $ref_name), obj: ::std::ptr::NonNull::new_unchecked(ptr as *mut $gst_sys_name as *mut $ref_name),
phantom: ::std::marker::PhantomData,
}) })
} }

View file

@ -9,7 +9,6 @@
use std::borrow::{Borrow, BorrowMut, ToOwned}; use std::borrow::{Borrow, BorrowMut, ToOwned};
use std::ffi::CStr; use std::ffi::CStr;
use std::fmt; use std::fmt;
use std::marker::PhantomData;
use std::mem; use std::mem;
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use std::ptr; use std::ptr;
@ -56,7 +55,7 @@ impl<'name> GetError<'name> {
} }
} }
pub struct Structure(ptr::NonNull<StructureRef>, PhantomData<StructureRef>); pub struct Structure(ptr::NonNull<StructureRef>);
unsafe impl Send for Structure {} unsafe impl Send for Structure {}
unsafe impl Sync for Structure {} unsafe impl Sync for Structure {}
@ -71,7 +70,7 @@ impl Structure {
unsafe { unsafe {
let ptr = gst_sys::gst_structure_new_empty(name.to_glib_none().0) as *mut StructureRef; let ptr = gst_sys::gst_structure_new_empty(name.to_glib_none().0) as *mut StructureRef;
assert!(!ptr.is_null()); assert!(!ptr.is_null());
Structure(ptr::NonNull::new_unchecked(ptr), PhantomData) Structure(ptr::NonNull::new_unchecked(ptr))
} }
} }
@ -143,7 +142,7 @@ impl Clone for Structure {
unsafe { unsafe {
let ptr = gst_sys::gst_structure_copy(&self.0.as_ref().0) as *mut StructureRef; let ptr = gst_sys::gst_structure_copy(&self.0.as_ref().0) as *mut StructureRef;
assert!(!ptr.is_null()); assert!(!ptr.is_null());
Structure(ptr::NonNull::new_unchecked(ptr), PhantomData) Structure(ptr::NonNull::new_unchecked(ptr))
} }
} }
} }
@ -192,10 +191,9 @@ impl str::FromStr for Structure {
if structure.is_null() { if structure.is_null() {
Err(glib_bool_error!("Failed to parse structure from string")) Err(glib_bool_error!("Failed to parse structure from string"))
} else { } else {
Ok(Structure( Ok(Structure(ptr::NonNull::new_unchecked(
ptr::NonNull::new_unchecked(structure as *mut StructureRef), structure as *mut StructureRef,
PhantomData, )))
))
} }
} }
} }
@ -220,7 +218,7 @@ impl ToOwned for StructureRef {
unsafe { unsafe {
let ptr = gst_sys::gst_structure_copy(&self.0) as *mut StructureRef; let ptr = gst_sys::gst_structure_copy(&self.0) as *mut StructureRef;
assert!(!ptr.is_null()); assert!(!ptr.is_null());
Structure(ptr::NonNull::new_unchecked(ptr), PhantomData) Structure(ptr::NonNull::new_unchecked(ptr))
} }
} }
} }
@ -268,10 +266,7 @@ impl FromGlibPtrNone<*const gst_sys::GstStructure> for Structure {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
let ptr = gst_sys::gst_structure_copy(ptr); let ptr = gst_sys::gst_structure_copy(ptr);
assert!(!ptr.is_null()); assert!(!ptr.is_null());
Structure( Structure(ptr::NonNull::new_unchecked(ptr as *mut StructureRef))
ptr::NonNull::new_unchecked(ptr as *mut StructureRef),
PhantomData,
)
} }
} }
@ -280,30 +275,21 @@ impl FromGlibPtrNone<*mut gst_sys::GstStructure> for Structure {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
let ptr = gst_sys::gst_structure_copy(ptr); let ptr = gst_sys::gst_structure_copy(ptr);
assert!(!ptr.is_null()); assert!(!ptr.is_null());
Structure( Structure(ptr::NonNull::new_unchecked(ptr as *mut StructureRef))
ptr::NonNull::new_unchecked(ptr as *mut StructureRef),
PhantomData,
)
} }
} }
impl FromGlibPtrFull<*const gst_sys::GstStructure> for Structure { impl FromGlibPtrFull<*const gst_sys::GstStructure> for Structure {
unsafe fn from_glib_full(ptr: *const gst_sys::GstStructure) -> Self { unsafe fn from_glib_full(ptr: *const gst_sys::GstStructure) -> Self {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
Structure( Structure(ptr::NonNull::new_unchecked(ptr as *mut StructureRef))
ptr::NonNull::new_unchecked(ptr as *mut StructureRef),
PhantomData,
)
} }
} }
impl FromGlibPtrFull<*mut gst_sys::GstStructure> for Structure { impl FromGlibPtrFull<*mut gst_sys::GstStructure> for Structure {
unsafe fn from_glib_full(ptr: *mut gst_sys::GstStructure) -> Self { unsafe fn from_glib_full(ptr: *mut gst_sys::GstStructure) -> Self {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
Structure( Structure(ptr::NonNull::new_unchecked(ptr as *mut StructureRef))
ptr::NonNull::new_unchecked(ptr as *mut StructureRef),
PhantomData,
)
} }
} }

View file

@ -16,13 +16,12 @@ use TypeFindProbability;
use glib; use glib;
use glib::translate::*; use glib::translate::*;
use glib_sys; use glib_sys;
use std::marker::PhantomData;
use std::ptr; use std::ptr;
use std::slice; use std::slice;
#[repr(C)] #[repr(C)]
#[derive(Debug)] #[derive(Debug)]
pub struct TypeFind<'a>(gst_sys::GstTypeFind, PhantomData<&'a ()>); pub struct TypeFind(gst_sys::GstTypeFind);
pub trait TypeFindImpl { pub trait TypeFindImpl {
fn peek(&mut self, offset: i64, size: u32) -> Option<&[u8]>; fn peek(&mut self, offset: i64, size: u32) -> Option<&[u8]>;
@ -32,7 +31,7 @@ pub trait TypeFindImpl {
} }
} }
impl<'a> TypeFind<'a> { impl TypeFind {
pub fn register<F>( pub fn register<F>(
plugin: Option<&Plugin>, plugin: Option<&Plugin>,
name: &str, name: &str,