From 9a6713b901e69175494ca3838bb54391a8ec0510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sun, 15 Oct 2017 11:27:08 +0300 Subject: [PATCH] Store pointers for static caps and pad templates We don't own them, we don't want to copy them. They're *statically* allocated things in C. --- gstreamer/src/static_caps.rs | 22 +++++++++----------- gstreamer/src/static_pad_template.rs | 30 ++++++++++++---------------- 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/gstreamer/src/static_caps.rs b/gstreamer/src/static_caps.rs index 5292899df..6026125ee 100644 --- a/gstreamer/src/static_caps.rs +++ b/gstreamer/src/static_caps.rs @@ -12,17 +12,15 @@ use ffi; use glib_ffi; use gobject_ffi; -use std::ptr; use glib; -use glib::translate::{from_glib_full, from_glib_none, mut_override, FromGlibPtrNone, ToGlibPtr, - ToGlibPtrMut}; +use glib::translate::{from_glib_full, FromGlibPtrNone, ToGlibPtr, ToGlibPtrMut}; #[repr(C)] -pub struct StaticCaps(ffi::GstStaticCaps); +pub struct StaticCaps(*mut ffi::GstStaticCaps); impl StaticCaps { pub fn get(&self) -> Caps { - unsafe { from_glib_full(ffi::gst_static_caps_get(mut_override(&self.0))) } + unsafe { from_glib_full(ffi::gst_static_caps_get(self.0)) } } } @@ -76,7 +74,7 @@ impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstStaticCaps> for StaticCap type Storage = &'a StaticCaps; fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const ffi::GstStaticCaps, Self> { - glib::translate::Stash(&self.0, self) + glib::translate::Stash(self.0, self) } fn to_glib_full(&self) -> *const ffi::GstStaticCaps { @@ -88,7 +86,7 @@ impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstStaticCaps> for StaticCap impl glib::translate::FromGlibPtrNone<*const ffi::GstStaticCaps> for StaticCaps { #[inline] unsafe fn from_glib_none(ptr: *const ffi::GstStaticCaps) -> Self { - StaticCaps(ptr::read(ptr)) + StaticCaps(ptr as *mut _) } } @@ -96,7 +94,7 @@ impl glib::translate::FromGlibPtrNone<*const ffi::GstStaticCaps> for StaticCaps impl glib::translate::FromGlibPtrNone<*mut ffi::GstStaticCaps> for StaticCaps { #[inline] unsafe fn from_glib_none(ptr: *mut ffi::GstStaticCaps) -> Self { - StaticCaps(ptr::read(ptr)) + StaticCaps(ptr) } } @@ -104,16 +102,14 @@ impl glib::translate::FromGlibPtrNone<*mut ffi::GstStaticCaps> for StaticCaps { impl glib::translate::FromGlibPtrBorrow<*mut ffi::GstStaticCaps> for StaticCaps { #[inline] unsafe fn from_glib_borrow(ptr: *mut ffi::GstStaticCaps) -> Self { - StaticCaps(ptr::read(ptr)) + StaticCaps(ptr) } } #[doc(hidden)] impl glib::translate::FromGlibPtrFull<*mut ffi::GstStaticCaps> for StaticCaps { #[inline] - unsafe fn from_glib_full(ptr: *mut ffi::GstStaticCaps) -> Self { - let caps = from_glib_none(ptr); - glib_ffi::g_free(ptr as *mut _); - caps + unsafe fn from_glib_full(_ptr: *mut ffi::GstStaticCaps) -> Self { + unimplemented!(); } } diff --git a/gstreamer/src/static_pad_template.rs b/gstreamer/src/static_pad_template.rs index 4cbb82e60..7a46b137e 100644 --- a/gstreamer/src/static_pad_template.rs +++ b/gstreamer/src/static_pad_template.rs @@ -14,33 +14,31 @@ use glib_ffi; use gobject_ffi; use std::ffi::CStr; -use std::ptr; use glib; -use glib::translate::{from_glib, from_glib_full, from_glib_none, mut_override, FromGlibPtrNone, - ToGlibPtr, ToGlibPtrMut}; +use glib::translate::{from_glib, from_glib_full, FromGlibPtrNone, ToGlibPtr, ToGlibPtrMut}; #[repr(C)] -pub struct StaticPadTemplate(ffi::GstStaticPadTemplate); +pub struct StaticPadTemplate(*mut ffi::GstStaticPadTemplate); impl StaticPadTemplate { pub fn get(&self) -> PadTemplate { - unsafe { from_glib_full(ffi::gst_static_pad_template_get(mut_override(&self.0))) } + unsafe { from_glib_full(ffi::gst_static_pad_template_get(self.0)) } } pub fn get_caps(&self) -> Caps { - unsafe { from_glib_full(ffi::gst_static_pad_template_get_caps(mut_override(&self.0))) } + unsafe { from_glib_full(ffi::gst_static_pad_template_get_caps(self.0)) } } pub fn name_template<'a>(&self) -> &'a str { - unsafe { CStr::from_ptr(self.0.name_template).to_str().unwrap() } + unsafe { CStr::from_ptr((*self.0).name_template).to_str().unwrap() } } pub fn direction(&self) -> ::PadDirection { - from_glib(self.0.direction) + unsafe { from_glib((*self.0).direction) } } pub fn presence(&self) -> ::PadPresence { - from_glib(self.0.presence) + unsafe { from_glib((*self.0).presence) } } } @@ -97,7 +95,7 @@ impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstStaticPadTemplate> for St fn to_glib_none( &'a self, ) -> glib::translate::Stash<'a, *const ffi::GstStaticPadTemplate, Self> { - glib::translate::Stash(&self.0, self) + glib::translate::Stash(self.0, self) } fn to_glib_full(&self) -> *const ffi::GstStaticPadTemplate { @@ -109,7 +107,7 @@ impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstStaticPadTemplate> for St impl glib::translate::FromGlibPtrNone<*const ffi::GstStaticPadTemplate> for StaticPadTemplate { #[inline] unsafe fn from_glib_none(ptr: *const ffi::GstStaticPadTemplate) -> Self { - StaticPadTemplate(ptr::read(ptr)) + StaticPadTemplate(ptr as *mut _) } } @@ -117,7 +115,7 @@ impl glib::translate::FromGlibPtrNone<*const ffi::GstStaticPadTemplate> for Stat impl glib::translate::FromGlibPtrNone<*mut ffi::GstStaticPadTemplate> for StaticPadTemplate { #[inline] unsafe fn from_glib_none(ptr: *mut ffi::GstStaticPadTemplate) -> Self { - StaticPadTemplate(ptr::read(ptr)) + StaticPadTemplate(ptr) } } @@ -125,16 +123,14 @@ impl glib::translate::FromGlibPtrNone<*mut ffi::GstStaticPadTemplate> for Static impl glib::translate::FromGlibPtrBorrow<*mut ffi::GstStaticPadTemplate> for StaticPadTemplate { #[inline] unsafe fn from_glib_borrow(ptr: *mut ffi::GstStaticPadTemplate) -> Self { - StaticPadTemplate(ptr::read(ptr)) + StaticPadTemplate(ptr) } } #[doc(hidden)] impl glib::translate::FromGlibPtrFull<*mut ffi::GstStaticPadTemplate> for StaticPadTemplate { #[inline] - unsafe fn from_glib_full(ptr: *mut ffi::GstStaticPadTemplate) -> Self { - let templ = from_glib_none(ptr); - glib_ffi::g_free(ptr as *mut _); - templ + unsafe fn from_glib_full(_ptr: *mut ffi::GstStaticPadTemplate) -> Self { + unimplemented!(); } }