Add back callback guards

This commit is contained in:
Sebastian Dröge 2018-03-02 21:33:41 +02:00
parent 808ff293ec
commit a3b294f0f2
19 changed files with 110 additions and 2 deletions

View file

@ -11,6 +11,7 @@ use ffi;
use gst_ffi;
use glib::translate::*;
use gst;
use glib::source::CallbackGuard;
use glib_ffi::gpointer;
use std::ptr;
@ -102,6 +103,7 @@ impl AppSinkCallbacksBuilder {
}
unsafe extern "C" fn trampoline_eos(appsink: *mut ffi::GstAppSink, callbacks: gpointer) {
let _guard = CallbackGuard::new();
let callbacks = &*(callbacks as *const AppSinkCallbacks);
callbacks
@ -114,6 +116,7 @@ unsafe extern "C" fn trampoline_new_preroll(
appsink: *mut ffi::GstAppSink,
callbacks: gpointer,
) -> gst_ffi::GstFlowReturn {
let _guard = CallbackGuard::new();
let callbacks = &*(callbacks as *const AppSinkCallbacks);
callbacks
@ -128,6 +131,7 @@ unsafe extern "C" fn trampoline_new_sample(
appsink: *mut ffi::GstAppSink,
callbacks: gpointer,
) -> gst_ffi::GstFlowReturn {
let _guard = CallbackGuard::new();
let callbacks = &*(callbacks as *const AppSinkCallbacks);
callbacks
@ -139,6 +143,7 @@ unsafe extern "C" fn trampoline_new_sample(
}
unsafe extern "C" fn destroy_callbacks(ptr: gpointer) {
let _guard = CallbackGuard::new();
Box::<AppSinkCallbacks>::from_raw(ptr as *mut _);
}

View file

@ -10,6 +10,7 @@ use AppSrc;
use ffi;
use glib::translate::*;
use gst;
use glib::source::CallbackGuard;
use glib_ffi::{gboolean, gpointer};
use std::ptr;
use std::mem;
@ -108,6 +109,7 @@ unsafe extern "C" fn trampoline_need_data(
length: u32,
callbacks: gpointer,
) {
let _guard = CallbackGuard::new();
let callbacks = &*(callbacks as *const AppSrcCallbacks);
callbacks
@ -117,6 +119,7 @@ unsafe extern "C" fn trampoline_need_data(
}
unsafe extern "C" fn trampoline_enough_data(appsrc: *mut ffi::GstAppSrc, callbacks: gpointer) {
let _guard = CallbackGuard::new();
let callbacks = &*(callbacks as *const AppSrcCallbacks);
callbacks
@ -130,6 +133,7 @@ unsafe extern "C" fn trampoline_seek_data(
offset: u64,
callbacks: gpointer,
) -> gboolean {
let _guard = CallbackGuard::new();
let callbacks = &*(callbacks as *const AppSrcCallbacks);
callbacks
@ -141,6 +145,7 @@ unsafe extern "C" fn trampoline_seek_data(
}
unsafe extern "C" fn destroy_callbacks(ptr: gpointer) {
let _guard = CallbackGuard::new();
Box::<AppSrcCallbacks>::from_raw(ptr as *mut _);
}

View file

@ -19,6 +19,12 @@ extern crate gstreamer_sys as gst_ffi;
#[macro_use]
extern crate glib;
macro_rules! callback_guard {
() => (
let _guard = ::glib::CallbackGuard::new();
)
}
macro_rules! skip_assert_initialized {
() => (
)

View file

@ -18,6 +18,12 @@ extern crate gstreamer as gst;
extern crate gstreamer_audio_sys as ffi;
extern crate gstreamer_sys as gst_ffi;
macro_rules! callback_guard {
() => (
let _guard = ::glib::CallbackGuard::new();
)
}
macro_rules! assert_initialized_main_thread {
() => (
if unsafe {::gst_ffi::gst_is_initialized()} != ::glib_ffi::GTRUE {

View file

@ -15,6 +15,12 @@ extern crate gstreamer_sys as gst_ffi;
#[macro_use]
extern crate glib;
macro_rules! callback_guard {
() => (
let _guard = ::glib::CallbackGuard::new();
)
}
macro_rules! assert_initialized_main_thread {
() => (
if unsafe {::gst_ffi::gst_is_initialized()} != ::glib_ffi::GTRUE {

View file

@ -15,6 +15,12 @@ extern crate gstreamer_sys as gst_ffi;
#[macro_use]
extern crate glib;
macro_rules! callback_guard {
() => (
let _guard = ::glib::CallbackGuard::new();
)
}
macro_rules! assert_initialized_main_thread {
() => (
if unsafe {::gst_ffi::gst_is_initialized()} != ::glib_ffi::GTRUE {

View file

@ -18,6 +18,12 @@ extern crate gstreamer_video as gst_video;
#[macro_use]
extern crate glib;
macro_rules! callback_guard {
() => (
let _guard = ::glib::CallbackGuard::new();
)
}
macro_rules! skip_assert_initialized {
() => (
)

View file

@ -105,6 +105,7 @@ unsafe extern "C" fn duration_changed_trampoline(
object: u64,
f: glib_ffi::gpointer,
) {
callback_guard!();
let f: &&(Fn(&Player, gst::ClockTime) + Send + 'static) = transmute(f);
f(&from_glib_borrow(this), gst::ClockTime(Some(object)))
}
@ -114,6 +115,7 @@ unsafe extern "C" fn position_updated_trampoline(
object: u64,
f: glib_ffi::gpointer,
) {
callback_guard!();
let f: &&(Fn(&Player, gst::ClockTime) + Send + Sync + 'static) = transmute(f);
f(&from_glib_borrow(this), gst::ClockTime(Some(object)))
}
@ -123,6 +125,7 @@ unsafe extern "C" fn seek_done_trampoline(
object: u64,
f: glib_ffi::gpointer,
) {
callback_guard!();
let f: &&(Fn(&Player, gst::ClockTime) + Send + 'static) = transmute(f);
f(&from_glib_borrow(this), gst::ClockTime(Some(object)))
}

View file

@ -27,6 +27,12 @@ extern crate gstreamer_rtsp_server_sys as ffi;
extern crate gstreamer_rtsp_sys as gst_rtsp_ffi;
extern crate gstreamer_sys as gst_ffi;
macro_rules! callback_guard {
() => (
let _guard = ::glib::CallbackGuard::new();
)
}
macro_rules! assert_initialized_main_thread {
() => (
if unsafe {::gst_ffi::gst_is_initialized()} != ::glib_ffi::GTRUE {

View file

@ -6,19 +6,21 @@ use glib;
use glib_ffi;
use glib::object::IsA;
use glib::translate::*;
use glib::source::{Continue, Priority};
use glib::source::{CallbackGuard, Continue, Priority};
use glib_ffi::{gboolean, gpointer};
unsafe extern "C" fn trampoline_watch(
pool: *mut ffi::GstRTSPSessionPool,
func: gpointer,
) -> gboolean {
let _guard = CallbackGuard::new();
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &RefCell<Box<FnMut(&RTSPSessionPool) -> Continue + Send + 'static>> = transmute(func);
(&mut *func.borrow_mut())(&from_glib_borrow(pool)).to_glib()
}
unsafe extern "C" fn destroy_closure_watch(ptr: gpointer) {
let _guard = CallbackGuard::new();
Box::<RefCell<Box<FnMut(&RTSPSessionPool) -> Continue + Send + 'static>>>::from_raw(
ptr as *mut _,
);

View file

@ -54,6 +54,7 @@ pub fn convert_sample_async<F>(
) where
F: FnOnce(Result<gst::Sample, glib::Error>) + Send + 'static,
{
callback_guard!();
let callback: &mut Option<Box<F>> = mem::transmute(user_data);
let callback = callback.take().unwrap();
@ -67,6 +68,7 @@ pub fn convert_sample_async<F>(
where
F: FnOnce(Result<gst::Sample, glib::Error>) + Send + 'static,
{
callback_guard!();
let _: Box<Option<Box<F>>> = Box::from_raw(user_data as *mut _);
}

View file

@ -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};
#[cfg_attr(feature = "cargo-clippy", allow(unreadable_literal))]

View file

@ -67,6 +67,7 @@ impl GstRc<BufferRef> {
}
unsafe extern "C" fn drop_box<T>(vec: glib_ffi::gpointer) {
callback_guard!();
let slice: Box<T> = Box::from_raw(vec as *mut T);
drop(slice);
}

View file

@ -11,7 +11,7 @@ use std::mem::transmute;
use ffi;
use glib;
use glib::translate::*;
use glib::source::{Continue, Priority, SourceId};
use glib::source::{CallbackGuard, Continue, Priority, SourceId};
use glib_ffi;
use glib_ffi::{gboolean, gpointer};
use std::ptr;
@ -25,12 +25,14 @@ unsafe extern "C" fn trampoline_watch(
msg: *mut ffi::GstMessage,
func: gpointer,
) -> gboolean {
let _guard = CallbackGuard::new();
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
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()
}
unsafe extern "C" fn destroy_closure_watch(ptr: gpointer) {
let _guard = CallbackGuard::new();
Box::<RefCell<Box<FnMut(&Bus, &Message) -> Continue + Send + 'static>>>::from_raw(
ptr as *mut _,
);
@ -48,12 +50,14 @@ unsafe extern "C" fn trampoline_sync(
msg: *mut ffi::GstMessage,
func: gpointer,
) -> ffi::GstBusSyncReply {
let _guard = CallbackGuard::new();
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let f: &&(Fn(&Bus, &Message) -> BusSyncReply + Send + Sync + 'static) = transmute(func);
f(&from_glib_borrow(bus), &Message::from_glib_borrow(msg)).to_glib()
}
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 _);
}

View file

@ -18,6 +18,7 @@ use ffi;
use glib;
use glib::IsA;
use glib::translate::*;
use glib::source::CallbackGuard;
use glib_ffi;
use glib_ffi::{gboolean, gpointer};
use libc::c_void;
@ -37,6 +38,7 @@ unsafe extern "C" fn trampoline_wait_async(
id: gpointer,
func: gpointer,
) -> gboolean {
let _guard = CallbackGuard::new();
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let f: &&(Fn(&Clock, ClockTime, &ClockId) -> bool + Send + 'static) = transmute(func);
f(
@ -47,6 +49,7 @@ unsafe extern "C" fn trampoline_wait_async(
}
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 _);
}

View file

@ -261,6 +261,7 @@ unsafe extern "C" fn rs_iterator_copy<T, I: IteratorImpl<T>>(
) where
for<'a> T: FromValueOptional<'a> + StaticType + ToValue + Send + 'static,
{
callback_guard!();
let it = it as *const 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
where
for<'a> T: FromValueOptional<'a> + StaticType + ToValue + Send + 'static,
{
callback_guard!();
let it = it as *mut RsIterator<T, I>;
let _ = (*it).imp.take();
}
@ -282,6 +284,7 @@ unsafe extern "C" fn rs_iterator_next<T, I: IteratorImpl<T>>(
where
for<'a> T: FromValueOptional<'a> + StaticType + ToValue + Send + 'static,
{
callback_guard!();
let it = it as *mut RsIterator<T, I>;
match (*it).imp.as_mut().map(|imp| imp.next()).unwrap() {
Some(Ok(value)) => {
@ -302,6 +305,7 @@ unsafe extern "C" fn rs_iterator_resync<T, I: IteratorImpl<T>>(it: *mut ffi::Gst
where
for<'a> T: FromValueOptional<'a> + StaticType + ToValue + Send + 'static,
{
callback_guard!();
let it = it as *mut RsIterator<T, I>;
(*it).imp.as_mut().map(|imp| imp.resync()).unwrap();
}
@ -349,6 +353,7 @@ unsafe extern "C" fn filter_trampoline<T>(value: gconstpointer, func: gconstpoin
where
for<'a> T: FromValueOptional<'a> + 'static,
{
callback_guard!();
let value = value as *const gobject_ffi::GValue;
let func = func as *const gobject_ffi::GValue;
@ -367,6 +372,8 @@ where
}
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 copy = Arc::clone(&boxed);
@ -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) {
callback_guard!();
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 {
use std::sync::{Once, ONCE_INIT};
callback_guard!();
static mut TYPE: glib_ffi::GType = gobject_ffi::G_TYPE_INVALID;
static ONCE: Once = ONCE_INIT;
@ -418,6 +429,7 @@ unsafe extern "C" fn find_trampoline<T>(value: gconstpointer, func: gconstpointe
where
for<'a> T: FromValueOptional<'a> + 'static,
{
callback_guard!();
let value = value as *const gobject_ffi::GValue;
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
where
for<'a> T: FromValueOptional<'a> + 'static,
{
callback_guard!();
let func = func as *const &mut (FnMut(T));
let value = &*(value as *const glib::Value);
let value = value.get::<T>().unwrap();
@ -450,6 +463,7 @@ unsafe extern "C" fn fold_trampoline<T, U>(
where
for<'a> T: FromValueOptional<'a> + 'static,
{
callback_guard!();
let func = func as *const &mut (FnMut(U, T) -> Result<U, U>);
let value = &*(value as *const glib::Value);
let value = value.get::<T>().unwrap();

View file

@ -29,6 +29,12 @@ extern crate muldiv;
use glib::translate::{from_glib, from_glib_full};
macro_rules! callback_guard {
() => (
let _guard = ::glib::CallbackGuard::new();
)
}
macro_rules! assert_initialized_main_thread {
() => (
if unsafe {::ffi::gst_is_initialized()} != ::glib_ffi::GTRUE {

View file

@ -31,6 +31,7 @@ use glib;
use glib::{IsA, StaticType};
use glib::translate::{from_glib, from_glib_borrow, from_glib_full, from_glib_none, mut_override,
FromGlib, ToGlib, ToGlibPtr};
use glib::source::CallbackGuard;
use glib_ffi;
use glib_ffi::gpointer;
use glib::Object;
@ -856,6 +857,7 @@ unsafe extern "C" fn trampoline_pad_probe(
info: *mut ffi::GstPadProbeInfo,
func: gpointer,
) -> ffi::GstPadProbeReturn {
let _guard = CallbackGuard::new();
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(&Pad, &mut PadProbeInfo) -> PadProbeReturn + Send + Sync + 'static) =
transmute(func);
@ -937,6 +939,7 @@ unsafe extern "C" fn trampoline_activate_function(
pad: *mut ffi::GstPad,
parent: *mut ffi::GstObject,
) -> glib_ffi::gboolean {
let _guard = CallbackGuard::new();
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(&Pad, &Option<::Object>) -> bool + Send + Sync + 'static) =
transmute((*pad).activatedata);
@ -950,6 +953,7 @@ unsafe extern "C" fn trampoline_activatemode_function(
mode: ffi::GstPadMode,
active: glib_ffi::gboolean,
) -> glib_ffi::gboolean {
let _guard = CallbackGuard::new();
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(&Pad, &Option<::Object>, ::PadMode, bool) -> bool
+ Send
@ -969,6 +973,7 @@ unsafe extern "C" fn trampoline_chain_function(
parent: *mut ffi::GstObject,
buffer: *mut ffi::GstBuffer,
) -> ffi::GstFlowReturn {
let _guard = CallbackGuard::new();
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(&Pad, &Option<::Object>, ::Buffer) -> ::FlowReturn
+ Send
@ -987,6 +992,7 @@ unsafe extern "C" fn trampoline_chain_list_function(
parent: *mut ffi::GstObject,
list: *mut ffi::GstBufferList,
) -> ffi::GstFlowReturn {
let _guard = CallbackGuard::new();
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(&Pad, &Option<::Object>, ::BufferList) -> ::FlowReturn
+ Send
@ -1005,6 +1011,7 @@ unsafe extern "C" fn trampoline_event_function(
parent: *mut ffi::GstObject,
event: *mut ffi::GstEvent,
) -> glib_ffi::gboolean {
let _guard = CallbackGuard::new();
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(&Pad, &Option<::Object>, ::Event) -> bool + Send + Sync + 'static) =
transmute((*pad).eventdata);
@ -1021,6 +1028,7 @@ unsafe extern "C" fn trampoline_event_full_function(
parent: *mut ffi::GstObject,
event: *mut ffi::GstEvent,
) -> ffi::GstFlowReturn {
let _guard = CallbackGuard::new();
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(&Pad, &Option<::Object>, ::Event) -> ::FlowReturn
+ Send
@ -1041,6 +1049,7 @@ unsafe extern "C" fn trampoline_getrange_function(
length: u32,
buffer: *mut *mut ffi::GstBuffer,
) -> ffi::GstFlowReturn {
let _guard = CallbackGuard::new();
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(&Pad, &Option<::Object>, u64, u32) -> Result<::Buffer, ::FlowReturn>
+ Send
@ -1065,6 +1074,7 @@ unsafe extern "C" fn trampoline_iterate_internal_links_function(
pad: *mut ffi::GstPad,
parent: *mut ffi::GstObject,
) -> *mut ffi::GstIterator {
let _guard = CallbackGuard::new();
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(&Pad, &Option<::Object>) -> ::Iterator<Pad> + Send + Sync + 'static) =
transmute((*pad).iterintlinkdata);
@ -1082,6 +1092,7 @@ unsafe extern "C" fn trampoline_link_function(
parent: *mut ffi::GstObject,
peer: *mut ffi::GstPad,
) -> ffi::GstPadLinkReturn {
let _guard = CallbackGuard::new();
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(&Pad, &Option<::Object>, &::Pad) -> ::PadLinkReturn
+ Send
@ -1100,6 +1111,7 @@ unsafe extern "C" fn trampoline_query_function(
parent: *mut ffi::GstObject,
query: *mut ffi::GstQuery,
) -> glib_ffi::gboolean {
let _guard = CallbackGuard::new();
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(&Pad, &Option<::Object>, &mut ::QueryRef) -> bool
+ Send
@ -1117,6 +1129,7 @@ unsafe extern "C" fn trampoline_unlink_function(
pad: *mut ffi::GstPad,
parent: *mut ffi::GstObject,
) {
let _guard = CallbackGuard::new();
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &&(Fn(&Pad, &Option<::Object>) + Send + Sync + 'static) =
transmute((*pad).unlinkdata);
@ -1125,16 +1138,19 @@ unsafe extern "C" fn trampoline_unlink_function(
}
unsafe extern "C" fn destroy_closure(ptr: gpointer) {
let _guard = CallbackGuard::new();
Box::<Box<Fn()>>::from_raw(ptr as *mut _);
}
unsafe extern "C" fn trampoline_pad_task(func: gpointer) {
let _guard = CallbackGuard::new();
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
let func: &RefCell<Box<FnMut() + Send + 'static>> = transmute(func);
(&mut *func.borrow_mut())()
}
unsafe extern "C" fn destroy_closure_pad_task(ptr: gpointer) {
let _guard = CallbackGuard::new();
Box::<RefCell<Box<FnMut() + Send + 'static>>>::from_raw(ptr as *mut _);
}

View file

@ -116,15 +116,18 @@ unsafe extern "C" fn type_find_trampoline(
find: *mut ffi::GstTypeFind,
user_data: glib_ffi::gpointer,
) {
callback_guard!();
let func: &&(Fn(&mut TypeFind) + Send + Sync + 'static) = mem::transmute(user_data);
func(&mut *(find as *mut TypeFind));
}
unsafe extern "C" fn type_find_closure_drop(data: glib_ffi::gpointer) {
callback_guard!();
Box::<Box<Fn(&mut TypeFind) + Send + Sync + 'static>>::from_raw(data as *mut _);
}
unsafe extern "C" fn type_find_peek(data: glib_ffi::gpointer, offset: i64, size: u32) -> *const u8 {
callback_guard!();
let find: &mut &mut TypeFindImpl = &mut *(data as *mut &mut TypeFindImpl);
match find.peek(offset, size) {
None => ptr::null(),
@ -137,6 +140,7 @@ unsafe extern "C" fn type_find_suggest(
probability: u32,
caps: *mut ffi::GstCaps,
) {
callback_guard!();
let find: &mut &mut TypeFindImpl = &mut *(data as *mut &mut TypeFindImpl);
find.suggest(from_glib(probability as i32), &from_glib_borrow(caps));
}
@ -144,6 +148,7 @@ unsafe extern "C" fn type_find_suggest(
unsafe extern "C" fn type_find_get_length(data: glib_ffi::gpointer) -> u64 {
use std::u64;
callback_guard!();
let find: &mut &mut TypeFindImpl = &mut *(data as *mut &mut TypeFindImpl);
find.get_length().unwrap_or(u64::MAX)
}