mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-25 19:11:06 +00:00
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:
parent
c23498039d
commit
3395203a53
6 changed files with 35 additions and 9 deletions
|
@ -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 {
|
impl fmt::Debug for BufferRef {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "{:?}", unsafe { self.as_ptr() })
|
write!(f, "{:?}", unsafe { self.as_ptr() })
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
use ffi;
|
use ffi;
|
||||||
use glib;
|
use glib;
|
||||||
use glib::StaticType;
|
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 miniobject::*;
|
||||||
use Buffer;
|
use Buffer;
|
||||||
|
@ -77,7 +77,10 @@ impl ToOwned for BufferListRef {
|
||||||
type Owned = GstRc<BufferListRef>;
|
type Owned = GstRc<BufferListRef>;
|
||||||
|
|
||||||
fn to_owned(&self) -> 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 _)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ use CapsIntersectMode;
|
||||||
|
|
||||||
use glib;
|
use glib;
|
||||||
use ffi;
|
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;
|
use glib::value::ToValue;
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
@ -348,7 +348,10 @@ impl ToOwned for CapsRef {
|
||||||
type Owned = GstRc<CapsRef>;
|
type Owned = GstRc<CapsRef>;
|
||||||
|
|
||||||
fn to_owned(&self) -> 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 _)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ use ffi;
|
||||||
|
|
||||||
use glib;
|
use glib;
|
||||||
use glib::StaticType;
|
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 miniobject::*;
|
||||||
use StructureRef;
|
use StructureRef;
|
||||||
|
@ -80,7 +80,10 @@ impl ToOwned for ContextRef {
|
||||||
type Owned = GstRc<ContextRef>;
|
type Owned = GstRc<ContextRef>;
|
||||||
|
|
||||||
fn to_owned(&self) -> 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 _)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,10 @@ impl ToOwned for SampleRef {
|
||||||
type Owned = GstRc<SampleRef>;
|
type Owned = GstRc<SampleRef>;
|
||||||
|
|
||||||
fn to_owned(&self) -> 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 _)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ use ffi;
|
||||||
use glib;
|
use glib;
|
||||||
use glib::StaticType;
|
use glib::StaticType;
|
||||||
use glib::value::{FromValueOptional, SetValue, ToValue, TypedValue, Value};
|
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::*;
|
use miniobject::*;
|
||||||
|
|
||||||
|
@ -326,7 +326,10 @@ impl ToOwned for TagListRef {
|
||||||
type Owned = GstRc<TagListRef>;
|
type Owned = GstRc<TagListRef>;
|
||||||
|
|
||||||
fn to_owned(&self) -> 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 _)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue