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

Commit 8769d2f

Browse files
committed
Deprecate CallbackGuard
1 parent f016524 commit 8769d2f

File tree

6 files changed

+6
-25
lines changed

6 files changed

+6
-25
lines changed

src/main_context.rs

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

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

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

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

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

src/main_context_futures.rs

-9
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use MainContext;
2222
use MainLoop;
2323
use Source;
2424
use Priority;
25-
use ::source::CallbackGuard;
2625

2726
#[cfg(feature = "futures-nightly")]
2827
type StoredFutureBox<T> = PinBox<T>;
@@ -68,8 +67,6 @@ unsafe extern "C" fn prepare(
6867
source: *mut glib_ffi::GSource,
6968
timeout: *mut i32,
7069
) -> glib_ffi::gboolean {
71-
let _guard = CallbackGuard::new();
72-
7370
let source = &mut *(source as *mut TaskSource);
7471

7572
*timeout = -1;
@@ -97,8 +94,6 @@ unsafe extern "C" fn prepare(
9794
}
9895

9996
unsafe extern "C" fn check(source: *mut glib_ffi::GSource) -> glib_ffi::gboolean {
100-
let _guard = CallbackGuard::new();
101-
10297
let source = &mut *(source as *mut TaskSource);
10398

10499
let cur = source.state.load(Ordering::SeqCst);
@@ -114,8 +109,6 @@ unsafe extern "C" fn dispatch(
114109
callback: glib_ffi::GSourceFunc,
115110
_user_data: glib_ffi::gpointer,
116111
) -> glib_ffi::gboolean {
117-
let _guard = CallbackGuard::new();
118-
119112
let source = &mut *(source as *mut TaskSource);
120113
assert!(callback.is_none());
121114

@@ -140,8 +133,6 @@ unsafe extern "C" fn dispatch(
140133
}
141134

142135
unsafe extern "C" fn finalize(source: *mut glib_ffi::GSource) {
143-
let _guard = CallbackGuard::new();
144-
145136
let source = source as *mut TaskSource;
146137
let _ = (*source).future.take();
147138
}

src/signal.rs

-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ 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;
1312
use translate::{from_glib, FromGlib, ToGlib, ToGlibPtr};
1413

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

9089
unsafe extern "C" fn destroy_closure(ptr: *mut c_void, _: *mut gobject_ffi::GClosure) {
91-
let _guard = CallbackGuard::new();
9290
// destroy
9391
Box::<Box<Fn()>>::from_raw(ptr as *mut _);
9492
}

src/source.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,24 @@ impl ToGlib for Continue {
6767

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

73+
#[allow(deprecated)]
7274
impl CallbackGuard {
7375
pub fn new() -> CallbackGuard {
7476
CallbackGuard(())
7577
}
7678
}
7779

80+
#[allow(deprecated)]
7881
impl Default for CallbackGuard {
7982
fn default() -> Self {
8083
Self::new()
8184
}
8285
}
8386

87+
#[allow(deprecated)]
8488
impl Drop for CallbackGuard {
8589
fn drop(&mut self) {
8690
use std::io::stderr;
@@ -95,13 +99,11 @@ impl Drop for CallbackGuard {
9599

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

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

@@ -113,13 +115,11 @@ fn into_raw<F: FnMut() -> Continue + Send + 'static>(func: F) -> gpointer {
113115

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

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

@@ -132,14 +132,12 @@ fn into_raw_child_watch<F: FnMut(Pid, i32) + Send + 'static>(func: F) -> gpointe
132132
#[cfg(any(all(feature = "v2_36", unix), feature = "dox"))]
133133
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
134134
unsafe extern "C" fn trampoline_unix_fd(fd: i32, condition: glib_ffi::GIOCondition, func: gpointer) -> gboolean {
135-
let _guard = CallbackGuard::new();
136135
let func: &RefCell<Box<FnMut(RawFd, IOCondition) -> Continue + 'static>> = transmute(func);
137136
(&mut *func.borrow_mut())(fd, from_glib(condition)).to_glib()
138137
}
139138

140139
#[cfg(any(all(feature = "v2_36", unix), feature = "dox"))]
141140
unsafe extern "C" fn destroy_closure_unix_fd(ptr: gpointer) {
142-
let _guard = CallbackGuard::new();
143141
Box::<RefCell<Box<FnMut(RawFd, IOCondition) + 'static>>>::from_raw(ptr as *mut _);
144142
}
145143

src/value.rs

-4
Original file line numberDiff line numberDiff line change
@@ -941,13 +941,11 @@ impl AnyValue {
941941
}
942942

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

949948
unsafe extern "C" fn free(v: *mut c_void) {
950-
let _guard = ::source::CallbackGuard::new();
951949
let _ = Box::from_raw(v as *mut AnyValue);
952950
}
953951
}
@@ -1018,13 +1016,11 @@ impl AnySendValue {
10181016
}
10191017

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

10261023
unsafe extern "C" fn free(v: *mut c_void) {
1027-
let _guard = ::source::CallbackGuard::new();
10281024
let _ = Box::from_raw(v as *mut AnySendValue);
10291025
}
10301026
}

src/variant_type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::fmt;
1212
use std::hash::{Hash, Hasher};
1313
use std::ops::Deref;
1414
use std::slice;
15-
use value::{Value, ToValue, SetValue, FromValueOptional, SetValueOptional};
15+
use value::{Value, SetValue, FromValueOptional, SetValueOptional};
1616
use gobject_ffi;
1717

1818
/// Describes `Variant` types.

0 commit comments

Comments
 (0)