Make miniobject ToOwned impls actually safe

Previously it was possible to create a new reference from a mutable
reference, which is not good. Now a copy is always created to prevent
that.
This commit is contained in:
Sebastian Dröge 2017-08-04 18:51:27 +03:00
parent c23498039d
commit 3395203a53
6 changed files with 35 additions and 9 deletions

View file

@ -330,6 +330,17 @@ impl glib::types::StaticType for Buffer {
}
}
impl ToOwned for BufferRef {
type Owned = GstRc<BufferRef>;
fn to_owned(&self) -> GstRc<BufferRef> {
unsafe {
from_glib_full(ffi::gst_mini_object_copy(self.as_ptr() as *const _) as
*mut _)
}
}
}
impl fmt::Debug for BufferRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", unsafe { self.as_ptr() })

View file

@ -9,7 +9,7 @@
use ffi;
use glib;
use glib::StaticType;
use glib::translate::{from_glib, from_glib_full, from_glib_none};
use glib::translate::{from_glib, from_glib_full};
use miniobject::*;
use Buffer;
@ -77,7 +77,10 @@ impl ToOwned for BufferListRef {
type Owned = GstRc<BufferListRef>;
fn to_owned(&self) -> GstRc<BufferListRef> {
unsafe { from_glib_none(self.as_ptr()) }
unsafe {
from_glib_full(ffi::gst_mini_object_copy(self.as_ptr() as *const _) as
*mut _)
}
}
}

View file

@ -15,7 +15,7 @@ use CapsIntersectMode;
use glib;
use ffi;
use glib::translate::{from_glib, from_glib_full, from_glib_none, ToGlib, ToGlibPtr};
use glib::translate::{from_glib, from_glib_full, ToGlib, ToGlibPtr};
use glib::value::ToValue;
#[repr(C)]
@ -348,7 +348,10 @@ impl ToOwned for CapsRef {
type Owned = GstRc<CapsRef>;
fn to_owned(&self) -> GstRc<CapsRef> {
unsafe { from_glib_none(self.as_ptr()) }
unsafe {
from_glib_full(ffi::gst_mini_object_copy(self.as_ptr() as *const _) as
*mut _)
}
}
}

View file

@ -12,7 +12,7 @@ use ffi;
use glib;
use glib::StaticType;
use glib::translate::{from_glib, from_glib_full, from_glib_none, ToGlib, ToGlibPtr};
use glib::translate::{from_glib, from_glib_full, ToGlib, ToGlibPtr};
use miniobject::*;
use StructureRef;
@ -80,7 +80,10 @@ impl ToOwned for ContextRef {
type Owned = GstRc<ContextRef>;
fn to_owned(&self) -> GstRc<ContextRef> {
unsafe { from_glib_none(self.as_ptr()) }
unsafe {
from_glib_full(ffi::gst_mini_object_copy(self.as_ptr() as *const _) as
*mut _)
}
}
}

View file

@ -88,7 +88,10 @@ impl ToOwned for SampleRef {
type Owned = GstRc<SampleRef>;
fn to_owned(&self) -> GstRc<SampleRef> {
unsafe { from_glib_none(self.as_ptr()) }
unsafe {
from_glib_full(ffi::gst_mini_object_copy(self.as_ptr() as *const _) as
*mut _)
}
}
}

View file

@ -15,7 +15,7 @@ use ffi;
use glib;
use glib::StaticType;
use glib::value::{FromValueOptional, SetValue, ToValue, TypedValue, Value};
use glib::translate::{from_glib, from_glib_full, from_glib_none, ToGlib, ToGlibPtr, ToGlibPtrMut};
use glib::translate::{from_glib, from_glib_full, ToGlib, ToGlibPtr, ToGlibPtrMut};
use miniobject::*;
@ -326,7 +326,10 @@ impl ToOwned for TagListRef {
type Owned = GstRc<TagListRef>;
fn to_owned(&self) -> GstRc<TagListRef> {
unsafe { from_glib_none(self.as_ptr()) }
unsafe {
from_glib_full(ffi::gst_mini_object_copy(self.as_ptr() as *const _) as
*mut _)
}
}
}