mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-12-22 18:16:28 +00:00
Make overriding of vfuncs safer
It can only be called from the correct class_init() now
This commit is contained in:
parent
41d6343682
commit
ec1903a571
4 changed files with 14 additions and 15 deletions
|
@ -75,7 +75,7 @@ pub unsafe trait BaseSinkClass<T: BaseSink>
|
||||||
where
|
where
|
||||||
T::ImplType: BaseSinkImpl<T>,
|
T::ImplType: BaseSinkImpl<T>,
|
||||||
{
|
{
|
||||||
fn override_vfuncs(&mut self) {
|
fn override_vfuncs(&mut self, _: &ClassInitToken) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let klass = &mut *(self as *const Self as *mut gst_base_ffi::GstBaseSinkClass);
|
let klass = &mut *(self as *const Self as *mut gst_base_ffi::GstBaseSinkClass);
|
||||||
klass.start = Some(base_sink_start::<T>);
|
klass.start = Some(base_sink_start::<T>);
|
||||||
|
@ -149,9 +149,9 @@ impl ObjectType for RsBaseSink {
|
||||||
unsafe { from_glib(gst_base_ffi::gst_base_sink_get_type()) }
|
unsafe { from_glib(gst_base_ffi::gst_base_sink_get_type()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn class_init(klass: &mut RsBaseSinkClass) {
|
fn class_init(token: &ClassInitToken, klass: &mut RsBaseSinkClass) {
|
||||||
ElementClass::override_vfuncs(klass);
|
ElementClass::override_vfuncs(klass, token);
|
||||||
BaseSinkClass::override_vfuncs(klass);
|
BaseSinkClass::override_vfuncs(klass, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
object_type_fns!();
|
object_type_fns!();
|
||||||
|
|
|
@ -103,7 +103,7 @@ pub unsafe trait BaseSrcClass<T: BaseSrc>
|
||||||
where
|
where
|
||||||
T::ImplType: BaseSrcImpl<T>,
|
T::ImplType: BaseSrcImpl<T>,
|
||||||
{
|
{
|
||||||
fn override_vfuncs(&mut self) {
|
fn override_vfuncs(&mut self, _: &ClassInitToken) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let klass = &mut *(self as *const Self as *mut gst_base_ffi::GstBaseSrcClass);
|
let klass = &mut *(self as *const Self as *mut gst_base_ffi::GstBaseSrcClass);
|
||||||
klass.start = Some(base_src_start::<T>);
|
klass.start = Some(base_src_start::<T>);
|
||||||
|
@ -201,9 +201,9 @@ impl ObjectType for RsBaseSrc {
|
||||||
unsafe { from_glib(gst_base_ffi::gst_base_src_get_type()) }
|
unsafe { from_glib(gst_base_ffi::gst_base_src_get_type()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn class_init(klass: &mut RsBaseSrcClass) {
|
fn class_init(token: &ClassInitToken, klass: &mut RsBaseSrcClass) {
|
||||||
ElementClass::override_vfuncs(klass);
|
ElementClass::override_vfuncs(klass, token);
|
||||||
BaseSrcClass::override_vfuncs(klass);
|
BaseSrcClass::override_vfuncs(klass, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
object_type_fns!();
|
object_type_fns!();
|
||||||
|
|
|
@ -76,7 +76,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn override_vfuncs(&mut self) {
|
fn override_vfuncs(&mut self, _: &ClassInitToken) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let klass = &mut *(self as *const Self as *mut gst_ffi::GstElementClass);
|
let klass = &mut *(self as *const Self as *mut gst_ffi::GstElementClass);
|
||||||
klass.change_state = Some(element_change_state::<T>);
|
klass.change_state = Some(element_change_state::<T>);
|
||||||
|
@ -129,8 +129,8 @@ impl ObjectType for RsElement {
|
||||||
unsafe { from_glib(gst_ffi::gst_element_get_type()) }
|
unsafe { from_glib(gst_ffi::gst_element_get_type()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn class_init(klass: &mut RsElementClass) {
|
fn class_init(token: &ClassInitToken, klass: &mut RsElementClass) {
|
||||||
klass.override_vfuncs();
|
klass.override_vfuncs(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
object_type_fns!();
|
object_type_fns!();
|
||||||
|
|
|
@ -56,12 +56,11 @@ macro_rules! box_object_impl(
|
||||||
pub trait ImplTypeStatic<T: ObjectType>: Send + Sync + 'static {
|
pub trait ImplTypeStatic<T: ObjectType>: Send + Sync + 'static {
|
||||||
fn get_name(&self) -> &str;
|
fn get_name(&self) -> &str;
|
||||||
fn new(&self, &T) -> T::ImplType;
|
fn new(&self, &T) -> T::ImplType;
|
||||||
// FIXME: Needs token, needs to become override_vfuncs()
|
|
||||||
// override_vfuncs() functions need to take token
|
|
||||||
fn class_init(&self, &mut ClassStruct<T>);
|
fn class_init(&self, &mut ClassStruct<T>);
|
||||||
fn type_init(&self, _: &TypeInitToken, _type_: glib::Type) {}
|
fn type_init(&self, _: &TypeInitToken, _type_: glib::Type) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct ClassInitToken(());
|
||||||
pub struct TypeInitToken(());
|
pub struct TypeInitToken(());
|
||||||
|
|
||||||
pub trait ObjectType: FromGlibPtrBorrow<*mut InstanceStruct<Self>> + 'static
|
pub trait ObjectType: FromGlibPtrBorrow<*mut InstanceStruct<Self>> + 'static
|
||||||
|
@ -75,7 +74,7 @@ where
|
||||||
|
|
||||||
fn glib_type() -> glib::Type;
|
fn glib_type() -> glib::Type;
|
||||||
|
|
||||||
fn class_init(klass: &mut ClassStruct<Self>);
|
fn class_init(token: &ClassInitToken, klass: &mut ClassStruct<Self>);
|
||||||
|
|
||||||
fn set_property(_obj: &Self, _id: u32, _value: &glib::Value) {
|
fn set_property(_obj: &Self, _id: u32, _value: &glib::Value) {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
|
@ -381,7 +380,7 @@ unsafe extern "C" fn class_init<T: ObjectType>(
|
||||||
klass.parent_class = gobject_ffi::g_type_class_peek_parent(
|
klass.parent_class = gobject_ffi::g_type_class_peek_parent(
|
||||||
klass as *mut _ as glib_ffi::gpointer,
|
klass as *mut _ as glib_ffi::gpointer,
|
||||||
) as *const T::GlibClassType;
|
) as *const T::GlibClassType;
|
||||||
T::class_init(klass);
|
T::class_init(&ClassInitToken(()), klass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue