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

Commit 8ff31df

Browse files
Merge pull request #295 from EPashkin/restore_callback_guard
Revert "Deprecate CallbackGuard"
2 parents d36c43a + 7e31862 commit 8ff31df

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

src/main_context.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use MainContext;
1313
use Source;
1414
use SourceId;
1515

16-
use source::Priority;
16+
use source::{CallbackGuard, Priority};
1717

1818
impl MainContext {
1919
pub fn prepare(&self) -> (bool, i32) {
@@ -49,13 +49,15 @@ impl MainContext {
4949

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

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

src/signal.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use libc::{c_void, c_uint, c_ulong};
99
use gobject_ffi::{self, GCallback};
1010
use ffi::{gboolean, GQuark};
1111
use object::{IsA, Object};
12+
use source::CallbackGuard;
1213
use translate::{from_glib, FromGlib, ToGlib, ToGlibPtr};
1314

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

9091
unsafe extern "C" fn destroy_closure(ptr: *mut c_void, _: *mut gobject_ffi::GClosure) {
92+
let _guard = CallbackGuard::new();
9193
// destroy
9294
Box::<Box<Fn()>>::from_raw(ptr as *mut _);
9395
}

src/source.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,20 @@ impl ToGlib for Continue {
5454

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

60-
#[allow(deprecated)]
6159
impl CallbackGuard {
6260
pub fn new() -> CallbackGuard {
6361
CallbackGuard(())
6462
}
6563
}
6664

67-
#[allow(deprecated)]
6865
impl Default for CallbackGuard {
6966
fn default() -> Self {
7067
Self::new()
7168
}
7269
}
7370

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

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

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

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

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

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

src/value.rs

+4
Original file line numberDiff line numberDiff line change
@@ -944,11 +944,13 @@ impl AnyValue {
944944
}
945945

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

951952
unsafe extern "C" fn free(v: *mut c_void) {
953+
let _guard = ::source::CallbackGuard::new();
952954
let _ = Box::from_raw(v as *mut AnyValue);
953955
}
954956
}
@@ -1019,11 +1021,13 @@ impl AnySendValue {
10191021
}
10201022

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

10261029
unsafe extern "C" fn free(v: *mut c_void) {
1030+
let _guard = ::source::CallbackGuard::new();
10271031
let _ = Box::from_raw(v as *mut AnySendValue);
10281032
}
10291033
}

0 commit comments

Comments
 (0)