Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Deprecate CallbackGuard #293

Merged
merged 1 commit into from
Feb 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/main_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use MainContext;
use Source;
use SourceId;

use source::{CallbackGuard, Priority};
use source::Priority;

impl MainContext {
pub fn prepare(&self) -> (bool, i32) {
Expand Down Expand Up @@ -49,15 +49,13 @@ impl MainContext {

#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
unsafe extern "C" fn trampoline<F: FnOnce() + Send + 'static>(func: gpointer) -> gboolean {
let _guard = CallbackGuard::new();
let func: &mut Option<Box<F>> = transmute(func);
let func = func.take().expect("MainContext::invoke() closure called multiple times");
func();
glib_ffi::G_SOURCE_REMOVE
}

unsafe extern "C" fn destroy_closure<F: FnOnce() + Send + 'static>(ptr: gpointer) {
let _guard = CallbackGuard::new();
Box::<Option<Box<F>>>::from_raw(ptr as *mut _);
}

Expand Down
2 changes: 0 additions & 2 deletions src/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use libc::{c_void, c_uint, c_ulong};
use gobject_ffi::{self, GCallback};
use ffi::{gboolean, GQuark};
use object::{IsA, Object};
use source::CallbackGuard;
use translate::{from_glib, FromGlib, ToGlib, ToGlibPtr};

/// The id of a signal that is returned by `connect`.
Expand Down Expand Up @@ -89,7 +88,6 @@ pub fn signal_stop_emission_by_name<T: IsA<Object>>(instance: &T, signal_name: &
}

unsafe extern "C" fn destroy_closure(ptr: *mut c_void, _: *mut gobject_ffi::GClosure) {
let _guard = CallbackGuard::new();
// destroy
Box::<Box<Fn()>>::from_raw(ptr as *mut _);
}
8 changes: 4 additions & 4 deletions src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,24 @@ impl ToGlib for Continue {

/// Unwinding propagation guard. Aborts the process if destroyed while
/// panicking.
#[deprecated(note="Rustc has this functionality built-in since 1.24.0")]
pub struct CallbackGuard(());

#[allow(deprecated)]
impl CallbackGuard {
pub fn new() -> CallbackGuard {
CallbackGuard(())
}
}

#[allow(deprecated)]
impl Default for CallbackGuard {
fn default() -> Self {
Self::new()
}
}

#[allow(deprecated)]
impl Drop for CallbackGuard {
fn drop(&mut self) {
use std::io::stderr;
Expand All @@ -82,13 +86,11 @@ impl Drop for CallbackGuard {

#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
unsafe extern "C" fn trampoline(func: gpointer) -> gboolean {
let _guard = CallbackGuard::new();
let func: &RefCell<Box<FnMut() -> Continue + 'static>> = transmute(func);
(&mut *func.borrow_mut())().to_glib()
}

unsafe extern "C" fn destroy_closure(ptr: gpointer) {
let _guard = CallbackGuard::new();
Box::<RefCell<Box<FnMut() -> Continue + 'static>>>::from_raw(ptr as *mut _);
}

Expand All @@ -100,13 +102,11 @@ fn into_raw<F: FnMut() -> Continue + Send + 'static>(func: F) -> gpointer {

#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
unsafe extern "C" fn trampoline_child_watch(pid: u32, status: i32, func: gpointer) {
let _guard = CallbackGuard::new();
let func: &RefCell<Box<FnMut(u32, i32) + 'static>> = transmute(func);
(&mut *func.borrow_mut())(pid, status)
}

unsafe extern "C" fn destroy_closure_child_watch(ptr: gpointer) {
let _guard = CallbackGuard::new();
Box::<RefCell<Box<FnMut(u32, i32) + 'static>>>::from_raw(ptr as *mut _);
}

Expand Down
4 changes: 0 additions & 4 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,13 +944,11 @@ impl AnyValue {
}

unsafe extern "C" fn copy(v: *mut c_void) -> *mut c_void {
let _guard = ::source::CallbackGuard::new();
let v = &*(v as *mut AnyValue);
Box::into_raw(Box::new(v.clone())) as *mut c_void
}

unsafe extern "C" fn free(v: *mut c_void) {
let _guard = ::source::CallbackGuard::new();
let _ = Box::from_raw(v as *mut AnyValue);
}
}
Expand Down Expand Up @@ -1021,13 +1019,11 @@ impl AnySendValue {
}

unsafe extern "C" fn copy(v: *mut c_void) -> *mut c_void {
let _guard = ::source::CallbackGuard::new();
let v = &*(v as *mut AnySendValue);
Box::into_raw(Box::new(v.clone())) as *mut c_void
}

unsafe extern "C" fn free(v: *mut c_void) {
let _guard = ::source::CallbackGuard::new();
let _ = Box::from_raw(v as *mut AnySendValue);
}
}
Expand Down