Commit a3b294f0 authored by Sebastian Dröge's avatar Sebastian Dröge 🍵

Add back callback guards

parent 808ff293
...@@ -11,6 +11,7 @@ use ffi; ...@@ -11,6 +11,7 @@ use ffi;
use gst_ffi; use gst_ffi;
use glib::translate::*; use glib::translate::*;
use gst; use gst;
use glib::source::CallbackGuard;
use glib_ffi::gpointer; use glib_ffi::gpointer;
use std::ptr; use std::ptr;
...@@ -102,6 +103,7 @@ impl AppSinkCallbacksBuilder { ...@@ -102,6 +103,7 @@ impl AppSinkCallbacksBuilder {
} }
unsafe extern "C" fn trampoline_eos(appsink: *mut ffi::GstAppSink, callbacks: gpointer) { unsafe extern "C" fn trampoline_eos(appsink: *mut ffi::GstAppSink, callbacks: gpointer) {
let _guard = CallbackGuard::new();
let callbacks = &*(callbacks as *const AppSinkCallbacks); let callbacks = &*(callbacks as *const AppSinkCallbacks);
callbacks callbacks
...@@ -114,6 +116,7 @@ unsafe extern "C" fn trampoline_new_preroll( ...@@ -114,6 +116,7 @@ unsafe extern "C" fn trampoline_new_preroll(
appsink: *mut ffi::GstAppSink, appsink: *mut ffi::GstAppSink,
callbacks: gpointer, callbacks: gpointer,
) -> gst_ffi::GstFlowReturn { ) -> gst_ffi::GstFlowReturn {
let _guard = CallbackGuard::new();
let callbacks = &*(callbacks as *const AppSinkCallbacks); let callbacks = &*(callbacks as *const AppSinkCallbacks);
callbacks callbacks
...@@ -128,6 +131,7 @@ unsafe extern "C" fn trampoline_new_sample( ...@@ -128,6 +131,7 @@ unsafe extern "C" fn trampoline_new_sample(
appsink: *mut ffi::GstAppSink, appsink: *mut ffi::GstAppSink,
callbacks: gpointer, callbacks: gpointer,
) -> gst_ffi::GstFlowReturn { ) -> gst_ffi::GstFlowReturn {
let _guard = CallbackGuard::new();
let callbacks = &*(callbacks as *const AppSinkCallbacks); let callbacks = &*(callbacks as *const AppSinkCallbacks);
callbacks callbacks
...@@ -139,6 +143,7 @@ unsafe extern "C" fn trampoline_new_sample( ...@@ -139,6 +143,7 @@ unsafe extern "C" fn trampoline_new_sample(
} }
unsafe extern "C" fn destroy_callbacks(ptr: gpointer) { unsafe extern "C" fn destroy_callbacks(ptr: gpointer) {
let _guard = CallbackGuard::new();
Box::<AppSinkCallbacks>::from_raw(ptr as *mut _); Box::<AppSinkCallbacks>::from_raw(ptr as *mut _);
} }
......
...@@ -10,6 +10,7 @@ use AppSrc; ...@@ -10,6 +10,7 @@ use AppSrc;
use ffi; use ffi;
use glib::translate::*; use glib::translate::*;
use gst; use gst;
use glib::source::CallbackGuard;
use glib_ffi::{gboolean, gpointer}; use glib_ffi::{gboolean, gpointer};
use std::ptr; use std::ptr;
use std::mem; use std::mem;
...@@ -108,6 +109,7 @@ unsafe extern "C" fn trampoline_need_data( ...@@ -108,6 +109,7 @@ unsafe extern "C" fn trampoline_need_data(
length: u32, length: u32,
callbacks: gpointer, callbacks: gpointer,
) { ) {
let _guard = CallbackGuard::new();
let callbacks = &*(callbacks as *const AppSrcCallbacks); let callbacks = &*(callbacks as *const AppSrcCallbacks);
callbacks callbacks
...@@ -117,6 +119,7 @@ unsafe extern "C" fn trampoline_need_data( ...@@ -117,6 +119,7 @@ unsafe extern "C" fn trampoline_need_data(
} }
unsafe extern "C" fn trampoline_enough_data(appsrc: *mut ffi::GstAppSrc, callbacks: gpointer) { unsafe extern "C" fn trampoline_enough_data(appsrc: *mut ffi::GstAppSrc, callbacks: gpointer) {
let _guard = CallbackGuard::new();
let callbacks = &*(callbacks as *const AppSrcCallbacks); let callbacks = &*(callbacks as *const AppSrcCallbacks);
callbacks callbacks
...@@ -130,6 +133,7 @@ unsafe extern "C" fn trampoline_seek_data( ...@@ -130,6 +133,7 @@ unsafe extern "C" fn trampoline_seek_data(
offset: u64, offset: u64,
callbacks: gpointer, callbacks: gpointer,
) -> gboolean { ) -> gboolean {
let _guard = CallbackGuard::new();
let callbacks = &*(callbacks as *const AppSrcCallbacks); let callbacks = &*(callbacks as *const AppSrcCallbacks);
callbacks callbacks
...@@ -141,6 +145,7 @@ unsafe extern "C" fn trampoline_seek_data( ...@@ -141,6 +145,7 @@ unsafe extern "C" fn trampoline_seek_data(
} }
unsafe extern "C" fn destroy_callbacks(ptr: gpointer) { unsafe extern "C" fn destroy_callbacks(ptr: gpointer) {
let _guard = CallbackGuard::new();
Box::<AppSrcCallbacks>::from_raw(ptr as *mut _); Box::<AppSrcCallbacks>::from_raw(ptr as *mut _);
} }
......
...@@ -19,6 +19,12 @@ extern crate gstreamer_sys as gst_ffi; ...@@ -19,6 +19,12 @@ extern crate gstreamer_sys as gst_ffi;
#[macro_use] #[macro_use]
extern crate glib; extern crate glib;
macro_rules! callback_guard {
() => (
let _guard = ::glib::CallbackGuard::new();
)
}
macro_rules! skip_assert_initialized { macro_rules! skip_assert_initialized {
() => ( () => (
) )
......
...@@ -18,6 +18,12 @@ extern crate gstreamer as gst; ...@@ -18,6 +18,12 @@ extern crate gstreamer as gst;
extern crate gstreamer_audio_sys as ffi; extern crate gstreamer_audio_sys as ffi;
extern crate gstreamer_sys as gst_ffi; extern crate gstreamer_sys as gst_ffi;
macro_rules! callback_guard {
() => (
let _guard = ::glib::CallbackGuard::new();
)
}
macro_rules! assert_initialized_main_thread { macro_rules! assert_initialized_main_thread {
() => ( () => (
if unsafe {::gst_ffi::gst_is_initialized()} != ::glib_ffi::GTRUE { if unsafe {::gst_ffi::gst_is_initialized()} != ::glib_ffi::GTRUE {
......
...@@ -15,6 +15,12 @@ extern crate gstreamer_sys as gst_ffi; ...@@ -15,6 +15,12 @@ extern crate gstreamer_sys as gst_ffi;
#[macro_use] #[macro_use]
extern crate glib; extern crate glib;
macro_rules! callback_guard {
() => (
let _guard = ::glib::CallbackGuard::new();
)
}
macro_rules! assert_initialized_main_thread { macro_rules! assert_initialized_main_thread {
() => ( () => (
if unsafe {::gst_ffi::gst_is_initialized()} != ::glib_ffi::GTRUE { if unsafe {::gst_ffi::gst_is_initialized()} != ::glib_ffi::GTRUE {
......
...@@ -15,6 +15,12 @@ extern crate gstreamer_sys as gst_ffi; ...@@ -15,6 +15,12 @@ extern crate gstreamer_sys as gst_ffi;
#[macro_use] #[macro_use]
extern crate glib; extern crate glib;
macro_rules! callback_guard {
() => (
let _guard = ::glib::CallbackGuard::new();
)
}
macro_rules! assert_initialized_main_thread { macro_rules! assert_initialized_main_thread {
() => ( () => (
if unsafe {::gst_ffi::gst_is_initialized()} != ::glib_ffi::GTRUE { if unsafe {::gst_ffi::gst_is_initialized()} != ::glib_ffi::GTRUE {
......
...@@ -18,6 +18,12 @@ extern crate gstreamer_video as gst_video; ...@@ -18,6 +18,12 @@ extern crate gstreamer_video as gst_video;
#[macro_use] #[macro_use]
extern crate glib; extern crate glib;
macro_rules! callback_guard {
() => (
let _guard = ::glib::CallbackGuard::new();
)
}
macro_rules! skip_assert_initialized { macro_rules! skip_assert_initialized {
() => ( () => (
) )
......
...@@ -105,6 +105,7 @@ unsafe extern "C" fn duration_changed_trampoline( ...@@ -105,6 +105,7 @@ unsafe extern "C" fn duration_changed_trampoline(
object: u64, object: u64,
f: glib_ffi::gpointer, f: glib_ffi::gpointer,
) { ) {
callback_guard!();
let f: &&(Fn(&Player, gst::ClockTime) + Send + 'static) = transmute(f); let f: &&(Fn(&Player, gst::ClockTime) + Send + 'static) = transmute(f);
f(&from_glib_borrow(this), gst::ClockTime(Some(object))) f(&from_glib_borrow(this), gst::ClockTime(Some(object)))
} }
...@@ -114,6 +115,7 @@ unsafe extern "C" fn position_updated_trampoline( ...@@ -114,6 +115,7 @@ unsafe extern "C" fn position_updated_trampoline(
object: u64, object: u64,
f: glib_ffi::gpointer, f: glib_ffi::gpointer,
) { ) {
callback_guard!();
let f: &&(Fn(&Player, gst::ClockTime) + Send + Sync + 'static) = transmute(f); let f: &&(Fn(&Player, gst::ClockTime) + Send + Sync + 'static) = transmute(f);
f(&from_glib_borrow(this), gst::ClockTime(Some(object))) f(&from_glib_borrow(this), gst::ClockTime(Some(object)))
} }
...@@ -123,6 +125,7 @@ unsafe extern "C" fn seek_done_trampoline( ...@@ -123,6 +125,7 @@ unsafe extern "C" fn seek_done_trampoline(
object: u64, object: u64,
f: glib_ffi::gpointer, f: glib_ffi::gpointer,
) { ) {
callback_guard!();
let f: &&(Fn(&Player, gst::ClockTime) + Send + 'static) = transmute(f); let f: &&(Fn(&Player, gst::ClockTime) + Send + 'static) = transmute(f);
f(&from_glib_borrow(this), gst::ClockTime(Some(object))) f(&from_glib_borrow(this), gst::ClockTime(Some(object)))
} }
...@@ -27,6 +27,12 @@ extern crate gstreamer_rtsp_server_sys as ffi; ...@@ -27,6 +27,12 @@ extern crate gstreamer_rtsp_server_sys as ffi;
extern crate gstreamer_rtsp_sys as gst_rtsp_ffi; extern crate gstreamer_rtsp_sys as gst_rtsp_ffi;
extern crate gstreamer_sys as gst_ffi; extern crate gstreamer_sys as gst_ffi;
macro_rules! callback_guard {
() => (
let _guard = ::glib::CallbackGuard::new();
)
}
macro_rules! assert_initialized_main_thread { macro_rules! assert_initialized_main_thread {
() => ( () => (
if unsafe {::gst_ffi::gst_is_initialized()} != ::glib_ffi::GTRUE { if unsafe {::gst_ffi::gst_is_initialized()} != ::glib_ffi::GTRUE {
......
...@@ -6,19 +6,21 @@ use glib; ...@@ -6,19 +6,21 @@ use glib;
use glib_ffi; use glib_ffi;
use glib::object::IsA; use glib::object::IsA;
use glib::translate::*; use glib::translate::*;
use glib::source::{Continue, Priority}; use glib::source::{CallbackGuard, Continue, Priority};
use glib_ffi::{gboolean, gpointer}; use glib_ffi::{gboolean, gpointer};
unsafe extern "C" fn trampoline_watch( unsafe extern "C" fn trampoline_watch(
pool: *mut ffi::GstRTSPSessionPool, pool: *mut ffi::GstRTSPSessionPool,
func: gpointer, func: gpointer,
) -> gboolean { ) -> gboolean {
let _guard = CallbackGuard::new();
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &RefCell<Box<FnMut(&RTSPSessionPool) -> Continue + Send + 'static>> = transmute(func); let func: &RefCell<Box<FnMut(&RTSPSessionPool) -> Continue + Send + 'static>> = transmute(func);
(&mut *func.borrow_mut())(&from_glib_borrow(pool)).to_glib() (&mut *func.borrow_mut())(&from_glib_borrow(pool)).to_glib()
} }
unsafe extern "C" fn destroy_closure_watch(ptr: gpointer) { unsafe extern "C" fn destroy_closure_watch(ptr: gpointer) {
let _guard = CallbackGuard::new();
Box::<RefCell<Box<FnMut(&RTSPSessionPool) -> Continue + Send + 'static>>>::from_raw( Box::<RefCell<Box<FnMut(&RTSPSessionPool) -> Continue + Send + 'static>>>::from_raw(
ptr as *mut _, ptr as *mut _,
); );
......
...@@ -54,6 +54,7 @@ pub fn convert_sample_async<F>( ...@@ -54,6 +54,7 @@ pub fn convert_sample_async<F>(
) where ) where
F: FnOnce(Result<gst::Sample, glib::Error>) + Send + 'static, F: FnOnce(Result<gst::Sample, glib::Error>) + Send + 'static,
{ {
callback_guard!();
let callback: &mut Option<Box<F>> = mem::transmute(user_data); let callback: &mut Option<Box<F>> = mem::transmute(user_data);
let callback = callback.take().unwrap(); let callback = callback.take().unwrap();
...@@ -67,6 +68,7 @@ pub fn convert_sample_async<F>( ...@@ -67,6 +68,7 @@ pub fn convert_sample_async<F>(
where where
F: FnOnce(Result<gst::Sample, glib::Error>) + Send + 'static, F: FnOnce(Result<gst::Sample, glib::Error>) + Send + 'static,
{ {
callback_guard!();
let _: Box<Option<Box<F>>> = Box::from_raw(user_data as *mut _); let _: Box<Option<Box<F>>> = Box::from_raw(user_data as *mut _);
} }
......
...@@ -33,6 +33,12 @@ macro_rules! skip_assert_initialized { ...@@ -33,6 +33,12 @@ macro_rules! skip_assert_initialized {
) )
} }
macro_rules! callback_guard {
() => (
let _guard = ::glib::CallbackGuard::new();
)
}
pub use glib::{Cast, Continue, Error, IsA, StaticType, ToValue, Type, TypedValue, Value}; pub use glib::{Cast, Continue, Error, IsA, StaticType, ToValue, Type, TypedValue, Value};
#[cfg_attr(feature = "cargo-clippy", allow(unreadable_literal))] #[cfg_attr(feature = "cargo-clippy", allow(unreadable_literal))]
......
...@@ -67,6 +67,7 @@ impl GstRc<BufferRef> { ...@@ -67,6 +67,7 @@ impl GstRc<BufferRef> {
} }
unsafe extern "C" fn drop_box<T>(vec: glib_ffi::gpointer) { unsafe extern "C" fn drop_box<T>(vec: glib_ffi::gpointer) {
callback_guard!();
let slice: Box<T> = Box::from_raw(vec as *mut T); let slice: Box<T> = Box::from_raw(vec as *mut T);
drop(slice); drop(slice);
} }
......
...@@ -11,7 +11,7 @@ use std::mem::transmute; ...@@ -11,7 +11,7 @@ use std::mem::transmute;
use ffi; use ffi;
use glib; use glib;
use glib::translate::*; use glib::translate::*;
use glib::source::{Continue, Priority, SourceId}; use glib::source::{CallbackGuard, Continue, Priority, SourceId};
use glib_ffi; use glib_ffi;
use glib_ffi::{gboolean, gpointer}; use glib_ffi::{gboolean, gpointer};
use std::ptr; use std::ptr;
...@@ -25,12 +25,14 @@ unsafe extern "C" fn trampoline_watch( ...@@ -25,12 +25,14 @@ unsafe extern "C" fn trampoline_watch(
msg: *mut ffi::GstMessage, msg: *mut ffi::GstMessage,
func: gpointer, func: gpointer,
) -> gboolean { ) -> gboolean {
let _guard = CallbackGuard::new();
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &RefCell<Box<FnMut(&Bus, &Message) -> Continue + Send + 'static>> = transmute(func); let func: &RefCell<Box<FnMut(&Bus, &Message) -> Continue + Send + 'static>> = transmute(func);
(&mut *func.borrow_mut())(&from_glib_borrow(bus), &Message::from_glib_borrow(msg)).to_glib() (&mut *func.borrow_mut())(&from_glib_borrow(bus), &Message::from_glib_borrow(msg)).to_glib()
} }
unsafe extern "C" fn destroy_closure_watch(ptr: gpointer) { unsafe extern "C" fn destroy_closure_watch(ptr: gpointer) {
let _guard = CallbackGuard::new();
Box::<RefCell<Box<FnMut(&Bus, &Message) -> Continue + Send + 'static>>>::from_raw( Box::<RefCell<Box<FnMut(&Bus, &Message) -> Continue + Send + 'static>>>::from_raw(
ptr as *mut _, ptr as *mut _,
); );
...@@ -48,12 +50,14 @@ unsafe extern "C" fn trampoline_sync( ...@@ -48,12 +50,14 @@ unsafe extern "C" fn trampoline_sync(
msg: *mut ffi::GstMessage, msg: *mut ffi::GstMessage,
func: gpointer, func: gpointer,
) -> ffi::GstBusSyncReply { ) -> ffi::GstBusSyncReply {
let _guard = CallbackGuard::new();
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let f: &&(Fn(&Bus, &Message) -> BusSyncReply + Send + Sync + 'static) = transmute(func); let f: &&(Fn(&Bus, &Message) -> BusSyncReply + Send + Sync + 'static) = transmute(func);
f(&from_glib_borrow(bus), &Message::from_glib_borrow(msg)).to_glib() f(&from_glib_borrow(bus), &Message::from_glib_borrow(msg)).to_glib()
} }
unsafe extern "C" fn destroy_closure_sync(ptr: gpointer) { unsafe extern "C" fn destroy_closure_sync(ptr: gpointer) {
let _guard = CallbackGuard::new();
Box::<Box<Fn(&Bus, &Message) -> BusSyncReply + Send + Sync + 'static>>::from_raw(ptr as *mut _); Box::<Box<Fn(&Bus, &Message) -> BusSyncReply + Send + Sync + 'static>>::from_raw(ptr as *mut _);
} }
......
...@@ -18,6 +18,7 @@ use ffi; ...@@ -18,6 +18,7 @@ use ffi;
use glib; use glib;
use glib::IsA; use glib::IsA;
use glib::translate::*; use glib::translate::*;
use glib::source::CallbackGuard;
use glib_ffi; use glib_ffi;
use glib_ffi::{gboolean, gpointer}; use glib_ffi::{gboolean, gpointer};
use libc::c_void; use libc::c_void;
...@@ -37,6 +38,7 @@ unsafe extern "C" fn trampoline_wait_async( ...@@ -37,6 +38,7 @@ unsafe extern "C" fn trampoline_wait_async(
id: gpointer, id: gpointer,
func: gpointer, func: gpointer,
) -> gboolean { ) -> gboolean {
let _guard = CallbackGuard::new();
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let f: &&(Fn(&Clock, ClockTime, &ClockId) -> bool + Send + 'static) = transmute(func); let f: &&(Fn(&Clock, ClockTime, &ClockId) -> bool + Send + 'static) = transmute(func);
f( f(
...@@ -47,6 +49,7 @@ unsafe extern "C" fn trampoline_wait_async( ...@@ -47,6 +49,7 @@ unsafe extern "C" fn trampoline_wait_async(
} }
unsafe extern "C" fn destroy_closure_wait_async(ptr: gpointer) { unsafe extern "C" fn destroy_closure_wait_async(ptr: gpointer) {
let _guard = CallbackGuard::new();
Box::<Box<Fn(&Clock, ClockTime, &ClockId) -> bool + Send + 'static>>::from_raw(ptr as *mut _); Box::<Box<Fn(&Clock, ClockTime, &ClockId) -> bool + Send + 'static>>::from_raw(ptr as *mut _);
} }
......
...@@ -261,6 +261,7 @@ unsafe extern "C" fn rs_iterator_copy<T, I: IteratorImpl<T>>( ...@@ -261,6 +261,7 @@ unsafe extern "C" fn rs_iterator_copy<T, I: IteratorImpl<T>>(
) where ) where
for<'a> T: FromValueOptional<'a> + StaticType + ToValue + Send + 'static, for<'a> T: FromValueOptional<'a> + StaticType + ToValue + Send + 'static,
{ {
callback_guard!();
let it = it as *const RsIterator<T, I>; let it = it as *const RsIterator<T, I>;
let copy = copy as *mut RsIterator<T, I>; let copy = copy as *mut RsIterator<T, I>;
...@@ -271,6 +272,7 @@ unsafe extern "C" fn rs_iterator_free<T, I: IteratorImpl<T>>(it: *mut ffi::GstIt ...@@ -271,6 +272,7 @@ unsafe extern "C" fn rs_iterator_free<T, I: IteratorImpl<T>>(it: *mut ffi::GstIt
where where
for<'a> T: FromValueOptional<'a> + StaticType + ToValue + Send + 'static, for<'a> T: FromValueOptional<'a> + StaticType + ToValue + Send + 'static,
{ {
callback_guard!();
let it = it as *mut RsIterator<T, I>; let it = it as *mut RsIterator<T, I>;
let _ = (*it).imp.take(); let _ = (*it).imp.take();
} }
...@@ -282,6 +284,7 @@ unsafe extern "C" fn rs_iterator_next<T, I: IteratorImpl<T>>( ...@@ -282,6 +284,7 @@ unsafe extern "C" fn rs_iterator_next<T, I: IteratorImpl<T>>(
where where
for<'a> T: FromValueOptional<'a> + StaticType + ToValue + Send + 'static, for<'a> T: FromValueOptional<'a> + StaticType + ToValue + Send + 'static,
{ {
callback_guard!();
let it = it as *mut RsIterator<T, I>; let it = it as *mut RsIterator<T, I>;
match (*it).imp.as_mut().map(|imp| imp.next()).unwrap() { match (*it).imp.as_mut().map(|imp| imp.next()).unwrap() {
Some(Ok(value)) => { Some(Ok(value)) => {
...@@ -302,6 +305,7 @@ unsafe extern "C" fn rs_iterator_resync<T, I: IteratorImpl<T>>(it: *mut ffi::Gst ...@@ -302,6 +305,7 @@ unsafe extern "C" fn rs_iterator_resync<T, I: IteratorImpl<T>>(it: *mut ffi::Gst
where where
for<'a> T: FromValueOptional<'a> + StaticType + ToValue + Send + 'static, for<'a> T: FromValueOptional<'a> + StaticType + ToValue + Send + 'static,
{ {
callback_guard!();
let it = it as *mut RsIterator<T, I>; let it = it as *mut RsIterator<T, I>;
(*it).imp.as_mut().map(|imp| imp.resync()).unwrap(); (*it).imp.as_mut().map(|imp| imp.resync()).unwrap();
} }
...@@ -349,6 +353,7 @@ unsafe extern "C" fn filter_trampoline<T>(value: gconstpointer, func: gconstpoin ...@@ -349,6 +353,7 @@ unsafe extern "C" fn filter_trampoline<T>(value: gconstpointer, func: gconstpoin
where where
for<'a> T: FromValueOptional<'a> + 'static, for<'a> T: FromValueOptional<'a> + 'static,
{ {
callback_guard!();
let value = value as *const gobject_ffi::GValue; let value = value as *const gobject_ffi::GValue;
let func = func as *const gobject_ffi::GValue; let func = func as *const gobject_ffi::GValue;
...@@ -367,6 +372,8 @@ where ...@@ -367,6 +372,8 @@ where
} }
unsafe extern "C" fn filter_boxed_ref<T: 'static>(boxed: gpointer) -> gpointer { unsafe extern "C" fn filter_boxed_ref<T: 'static>(boxed: gpointer) -> gpointer {
callback_guard!();
let boxed = Arc::from_raw(boxed as *const (Box<Fn(T) -> bool + Send + Sync + 'static>)); let boxed = Arc::from_raw(boxed as *const (Box<Fn(T) -> bool + Send + Sync + 'static>));
let copy = Arc::clone(&boxed); let copy = Arc::clone(&boxed);
...@@ -377,12 +384,16 @@ unsafe extern "C" fn filter_boxed_ref<T: 'static>(boxed: gpointer) -> gpointer { ...@@ -377,12 +384,16 @@ unsafe extern "C" fn filter_boxed_ref<T: 'static>(boxed: gpointer) -> gpointer {
} }
unsafe extern "C" fn filter_boxed_unref<T: 'static>(boxed: gpointer) { unsafe extern "C" fn filter_boxed_unref<T: 'static>(boxed: gpointer) {
callback_guard!();
let _ = Arc::from_raw(boxed as *const (Box<Fn(T) -> bool + Send + Sync + 'static>)); let _ = Arc::from_raw(boxed as *const (Box<Fn(T) -> bool + Send + Sync + 'static>));
} }
unsafe extern "C" fn filter_boxed_get_type<T: StaticType + 'static>() -> glib_ffi::GType { unsafe extern "C" fn filter_boxed_get_type<T: StaticType + 'static>() -> glib_ffi::GType {
use std::sync::{Once, ONCE_INIT}; use std::sync::{Once, ONCE_INIT};
callback_guard!();
static mut TYPE: glib_ffi::GType = gobject_ffi::G_TYPE_INVALID; static mut TYPE: glib_ffi::GType = gobject_ffi::G_TYPE_INVALID;
static ONCE: Once = ONCE_INIT; static ONCE: Once = ONCE_INIT;
...@@ -418,6 +429,7 @@ unsafe extern "C" fn find_trampoline<T>(value: gconstpointer, func: gconstpointe ...@@ -418,6 +429,7 @@ unsafe extern "C" fn find_trampoline<T>(value: gconstpointer, func: gconstpointe
where where
for<'a> T: FromValueOptional<'a> + 'static, for<'a> T: FromValueOptional<'a> + 'static,
{ {
callback_guard!();
let value = value as *const gobject_ffi::GValue; let value = value as *const gobject_ffi::GValue;
let func = func as *const &mut (FnMut(T) -> bool); let func = func as *const &mut (FnMut(T) -> bool);
...@@ -435,6 +447,7 @@ unsafe extern "C" fn foreach_trampoline<T>(value: *const gobject_ffi::GValue, fu ...@@ -435,6 +447,7 @@ unsafe extern "C" fn foreach_trampoline<T>(value: *const gobject_ffi::GValue, fu
where where
for<'a> T: FromValueOptional<'a> + 'static, for<'a> T: FromValueOptional<'a> + 'static,
{ {
callback_guard!();
let func = func as *const &mut (FnMut(T)); let func = func as *const &mut (FnMut(T));
let value = &*(value as *const glib::Value); let value = &*(value as *const glib::Value);
let value = value.get::<T>().unwrap(); let value = value.get::<T>().unwrap();
...@@ -450,6 +463,7 @@ unsafe extern "C" fn fold_trampoline<T, U>( ...@@ -450,6 +463,7 @@ unsafe extern "C" fn fold_trampoline<T, U>(
where where
for<'a> T: FromValueOptional<'a> + 'static, for<'a> T: FromValueOptional<'a> + 'static,
{ {
callback_guard!();
let func = func as *const &mut (FnMut(U, T) -> Result<U, U>); let func = func as *const &mut (FnMut(U, T) -> Result<U, U>);
let value = &*(value as *const glib::Value); let value = &*(value as *const glib::Value);
let value = value.get::<T>().unwrap(); let value = value.get::<T>().unwrap();
......
...@@ -29,6 +29,12 @@ extern crate muldiv; ...@@ -29,6 +29,12 @@ extern crate muldiv;
use glib::translate::{from_glib, from_glib_full}; use glib::translate::{from_glib, from_glib_full};
macro_rules! callback_guard {
() => (
let _guard = ::glib::CallbackGuard::new();
)
}
macro_rules! assert_initialized_main_thread { macro_rules! assert_initialized_main_thread {
() => ( () => (
if unsafe {::ffi::gst_is_initialized()} != ::glib_ffi::GTRUE { if unsafe {::ffi::gst_is_initialized()} != ::glib_ffi::GTRUE {
......
...@@ -31,6 +31,7 @@ use glib; ...@@ -31,6 +31,7 @@ use glib;
use glib::{IsA, StaticType}; use glib::{IsA, StaticType};
use glib::translate::{from_glib, from_glib_borrow, from_glib_full, from_glib_none, mut_override, use glib::translate::{from_glib, from_glib_borrow, from_glib_full, from_glib_none, mut_override,
FromGlib, ToGlib, ToGlibPtr}; FromGlib, ToGlib, ToGlibPtr};
use glib::source::CallbackGuard;
use glib_ffi; use glib_ffi;
use glib_ffi::gpointer; use glib_ffi::gpointer;
use glib::Object; use glib::Object;
...@@ -856,6 +857,7 @@ unsafe extern "C" fn trampoline_pad_probe( ...@@ -856,6 +857,7 @@ unsafe extern "C" fn trampoline_pad_probe(
info: *mut ffi::GstPadProbeInfo, info: *mut ffi::GstPadProbeInfo,
func: gpointer, func: gpointer,
) -> ffi::GstPadProbeReturn { ) -> ffi::GstPadProbeReturn {
let _guard = CallbackGuard::new();
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(&Pad, &mut PadProbeInfo) -> PadProbeReturn + Send + Sync + 'static) = let func: &&(Fn(&Pad, &mut PadProbeInfo) -> PadProbeReturn + Send + Sync + 'static) =
transmute(func); transmute(func);
...@@ -937,6 +939,7 @@ unsafe extern "C" fn trampoline_activate_function( ...@@ -937,6 +939,7 @@ unsafe extern "C" fn trampoline_activate_function(
pad: *mut ffi::GstPad, pad: *mut ffi::GstPad,
parent: *mut ffi::GstObject, parent: *mut ffi::GstObject,
) -> glib_ffi::gboolean { ) -> glib_ffi::gboolean {
let _guard = CallbackGuard::new();
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(&Pad, &Option<::Object>) -> bool + Send + Sync + 'static) = let func: &&(Fn(&Pad, &Option<::Object>) -> bool + Send + Sync + 'static) =
transmute((*pad).activatedata); transmute((*pad).activatedata);
...@@ -950,6 +953,7 @@ unsafe extern "C" fn trampoline_activatemode_function( ...@@ -950,6 +953,7 @@ unsafe extern "C" fn trampoline_activatemode_function(
mode: ffi::GstPadMode, mode: ffi::GstPadMode,
active: glib_ffi::gboolean, active: glib_ffi::gboolean,
) -> glib_ffi::gboolean { ) -> glib_ffi::gboolean {
let _guard = CallbackGuard::new();
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(&Pad, &Option<::Object>, ::PadMode, bool) -> bool let func: &&(Fn(&Pad, &Option<::Object>, ::PadMode, bool) -> bool
+ Send + Send
...@@ -969,6 +973,7 @@ unsafe extern "C" fn trampoline_chain_function( ...@@ -969,6 +973,7 @@ unsafe extern "C" fn trampoline_chain_function(
parent: *mut ffi::GstObject, parent: *mut ffi::GstObject,
buffer: *mut ffi::GstBuffer, buffer: *mut ffi::GstBuffer,
) -> ffi::GstFlowReturn { ) -> ffi::GstFlowReturn {
let _guard = CallbackGuard::new();
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(&Pad, &Option<::Object>, ::Buffer) -> ::FlowReturn let func: &&(Fn(&Pad, &Option<::Object>, ::Buffer) -> ::FlowReturn
+ Send + Send
...@@ -987,6 +992,7 @@ unsafe extern "C" fn trampoline_chain_list_function( ...@@ -987,6 +992,7 @@ unsafe extern "C" fn trampoline_chain_list_function(
parent: *mut ffi::GstObject, parent: *mut ffi::GstObject,
list: *mut ffi::GstBufferList, list: *mut ffi::GstBufferList,
) -> ffi::GstFlowReturn { ) -> ffi::GstFlowReturn {
let _guard = CallbackGuard::new();
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))] #[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(&Pad, &Option<::Object>, ::BufferList) -> ::FlowReturn let func: &&(Fn(&Pad, &Option<::Object>, ::BufferList) -> ::FlowReturn
+ Send + Send
...@@ -1005,6 +1011,7 @@ unsafe extern "C" fn trampoline_event_function( ...@@ -1005,6 +1011,7 @@ unsafe extern "C" fn trampoline_event_function(
parent: *mut ffi::GstObject, parent: *mut ffi::GstObject,
event: