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

Commit ba8b1dc

Browse files
committed
Deprecate CallbackGuard
1 parent 842ef2a commit ba8b1dc

File tree

4 files changed

+5
-13
lines changed

4 files changed

+5
-13
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) {
@@ -49,15 +49,13 @@ 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();
5352
let func: &mut Option<Box<F>> = transmute(func);
5453
let func = func.take().expect("MainContext::invoke() closure called multiple times");
5554
func();
5655
glib_ffi::G_SOURCE_REMOVE
5756
}
5857

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

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`.
@@ -89,7 +88,6 @@ pub fn signal_stop_emission_by_name<T: IsA<Object>>(instance: &T, signal_name: &
8988
}
9089

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

src/source.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,24 @@ 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")]
5758
pub struct CallbackGuard(());
5859

60+
#[allow(deprecated)]
5961
impl CallbackGuard {
6062
pub fn new() -> CallbackGuard {
6163
CallbackGuard(())
6264
}
6365
}
6466

67+
#[allow(deprecated)]
6568
impl Default for CallbackGuard {
6669
fn default() -> Self {
6770
Self::new()
6871
}
6972
}
7073

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

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

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

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

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

108109
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,13 +944,11 @@ impl AnyValue {
944944
}
945945

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

952951
unsafe extern "C" fn free(v: *mut c_void) {
953-
let _guard = ::source::CallbackGuard::new();
954952
let _ = Box::from_raw(v as *mut AnyValue);
955953
}
956954
}
@@ -1021,13 +1019,11 @@ impl AnySendValue {
10211019
}
10221020

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

10291026
unsafe extern "C" fn free(v: *mut c_void) {
1030-
let _guard = ::source::CallbackGuard::new();
10311027
let _ = Box::from_raw(v as *mut AnySendValue);
10321028
}
10331029
}

0 commit comments

Comments
 (0)