@@ -872,10 +872,13 @@ pub trait ObjectExt: ObjectType {
872
872
873
873
fn connect < ' a , N , F > ( & self , signal_name : N , after : bool , callback : F ) -> Result < SignalHandlerId , BoolError >
874
874
where N : Into < & ' a str > , F : Fn ( & [ Value ] ) -> Option < Value > + Send + Sync + ' static ;
875
+ unsafe fn connect_unsafe < ' a , N , F > ( & self , signal_name : N , after : bool , callback : F ) -> Result < SignalHandlerId , BoolError >
876
+ where N : Into < & ' a str > , F : Fn ( & [ Value ] ) -> Option < Value > ;
875
877
fn emit < ' a , N : Into < & ' a str > > ( & self , signal_name : N , args : & [ & ToValue ] ) -> Result < Option < Value > , BoolError > ;
876
878
fn disconnect ( & self , handler_id : SignalHandlerId ) ;
877
879
878
880
fn connect_notify < ' a , P : Into < Option < & ' a str > > , F : Fn ( & Self , & :: ParamSpec ) + Send + Sync + ' static > ( & self , name : P , f : F ) -> SignalHandlerId ;
881
+ unsafe fn connect_notify_unsafe < ' a , P : Into < Option < & ' a str > > , F : Fn ( & Self , & :: ParamSpec ) > ( & self , name : P , f : F ) -> SignalHandlerId ;
879
882
fn notify < ' a , N : Into < & ' a str > > ( & self , property_name : N ) ;
880
883
fn notify_by_pspec ( & self , pspec : & :: ParamSpec ) ;
881
884
@@ -999,11 +1002,17 @@ impl<T: ObjectType> ObjectExt for T {
999
1002
}
1000
1003
1001
1004
fn connect_notify < ' a , P : Into < Option < & ' a str > > , F : Fn ( & Self , & :: ParamSpec ) + Send + Sync + ' static > ( & self , name : P , f : F ) -> SignalHandlerId {
1005
+ unsafe {
1006
+ self . connect_notify_unsafe ( name, f)
1007
+ }
1008
+ }
1009
+
1010
+ unsafe fn connect_notify_unsafe < ' a , P : Into < Option < & ' a str > > , F : Fn ( & Self , & :: ParamSpec ) > ( & self , name : P , f : F ) -> SignalHandlerId {
1002
1011
use std:: mem:: transmute;
1003
1012
1004
1013
unsafe extern "C" fn notify_trampoline < P > ( this : * mut gobject_ffi:: GObject , param_spec : * mut gobject_ffi:: GParamSpec , f : glib_ffi:: gpointer )
1005
1014
where P : ObjectType {
1006
- let f: & & ( Fn ( & P , & :: ParamSpec ) + Send + Sync + ' static ) = transmute ( f) ;
1015
+ let f: & & ( Fn ( & P , & :: ParamSpec ) + ' static ) = transmute ( f) ;
1007
1016
f ( & Object :: from_glib_borrow ( this) . unsafe_cast ( ) , & from_glib_borrow ( param_spec) )
1008
1017
}
1009
1018
@@ -1014,11 +1023,9 @@ impl<T: ObjectType> ObjectExt for T {
1014
1023
"notify" . into ( )
1015
1024
} ;
1016
1025
1017
- unsafe {
1018
- let f: Box < Box < Fn ( & Self , & :: ParamSpec ) + Send + Sync + ' static > > = Box :: new ( Box :: new ( f) ) ;
1019
- :: signal:: connect ( self . as_object_ref ( ) . to_glib_none ( ) . 0 , & signal_name,
1020
- transmute ( notify_trampoline :: < Self > as usize ) , Box :: into_raw ( f) as * mut _ )
1021
- }
1026
+ let f: Box < Box < Fn ( & Self , & :: ParamSpec ) > > = Box :: new ( Box :: new ( f) ) ;
1027
+ :: signal:: connect ( self . as_object_ref ( ) . to_glib_none ( ) . 0 , & signal_name,
1028
+ transmute ( notify_trampoline :: < Self > as usize ) , Box :: into_raw ( f) as * mut _ )
1022
1029
}
1023
1030
1024
1031
fn notify < ' a , N : Into < & ' a str > > ( & self , property_name : N ) {
@@ -1053,64 +1060,69 @@ impl<T: ObjectType> ObjectExt for T {
1053
1060
1054
1061
fn connect < ' a , N , F > ( & self , signal_name : N , after : bool , callback : F ) -> Result < SignalHandlerId , BoolError >
1055
1062
where N : Into < & ' a str > , F : Fn ( & [ Value ] ) -> Option < Value > + Send + Sync + ' static {
1063
+ unsafe {
1064
+ self . connect_unsafe ( signal_name, after, callback)
1065
+ }
1066
+ }
1067
+
1068
+ unsafe fn connect_unsafe < ' a , N , F > ( & self , signal_name : N , after : bool , callback : F ) -> Result < SignalHandlerId , BoolError >
1069
+ where N : Into < & ' a str > , F : Fn ( & [ Value ] ) -> Option < Value > {
1056
1070
let signal_name: & str = signal_name. into ( ) ;
1057
1071
1058
- unsafe {
1059
- let type_ = self . get_type ( ) ;
1072
+ let type_ = self . get_type ( ) ;
1060
1073
1061
- let mut signal_id = 0 ;
1062
- let mut signal_detail = 0 ;
1074
+ let mut signal_id = 0 ;
1075
+ let mut signal_detail = 0 ;
1063
1076
1064
- let found: bool = from_glib ( gobject_ffi:: g_signal_parse_name ( signal_name. to_glib_none ( ) . 0 ,
1065
- type_. to_glib ( ) , & mut signal_id,
1066
- & mut signal_detail, true . to_glib ( ) ) ) ;
1077
+ let found: bool = from_glib ( gobject_ffi:: g_signal_parse_name ( signal_name. to_glib_none ( ) . 0 ,
1078
+ type_. to_glib ( ) , & mut signal_id,
1079
+ & mut signal_detail, true . to_glib ( ) ) ) ;
1067
1080
1068
- if !found {
1069
- return Err ( glib_bool_error ! ( "Signal not found" ) ) ;
1070
- }
1081
+ if !found {
1082
+ return Err ( glib_bool_error ! ( "Signal not found" ) ) ;
1083
+ }
1071
1084
1072
- let mut details = mem:: zeroed ( ) ;
1073
- gobject_ffi:: g_signal_query ( signal_id, & mut details) ;
1074
- if details. signal_id != signal_id {
1075
- return Err ( glib_bool_error ! ( "Signal not found" ) ) ;
1076
- }
1085
+ let mut details = mem:: zeroed ( ) ;
1086
+ gobject_ffi:: g_signal_query ( signal_id, & mut details) ;
1087
+ if details. signal_id != signal_id {
1088
+ return Err ( glib_bool_error ! ( "Signal not found" ) ) ;
1089
+ }
1077
1090
1078
- // This is actually G_SIGNAL_TYPE_STATIC_SCOPE
1079
- let return_type: Type = from_glib ( details. return_type & ( !gobject_ffi:: G_TYPE_FLAG_RESERVED_ID_BIT ) ) ;
1080
- let closure = Closure :: new ( move |values| {
1081
- let ret = callback ( values) ;
1091
+ // This is actually G_SIGNAL_TYPE_STATIC_SCOPE
1092
+ let return_type: Type = from_glib ( details. return_type & ( !gobject_ffi:: G_TYPE_FLAG_RESERVED_ID_BIT ) ) ;
1093
+ let closure = Closure :: new_unsafe ( move |values| {
1094
+ let ret = callback ( values) ;
1082
1095
1083
- if return_type == Type :: Unit {
1084
- if let Some ( ret) = ret {
1085
- panic ! ( "Signal required no return value but got value of type {}" , ret. type_( ) . name( ) ) ;
1096
+ if return_type == Type :: Unit {
1097
+ if let Some ( ret) = ret {
1098
+ panic ! ( "Signal required no return value but got value of type {}" , ret. type_( ) . name( ) ) ;
1099
+ }
1100
+ None
1101
+ } else {
1102
+ match ret {
1103
+ Some ( ret) => {
1104
+ let valid_type: bool = from_glib ( gobject_ffi:: g_type_check_value_holds (
1105
+ mut_override ( ret. to_glib_none ( ) . 0 ) ,
1106
+ return_type. to_glib ( ) ) ) ;
1107
+ if !valid_type {
1108
+ panic ! ( "Signal required return value of type {} but got {}" ,
1109
+ return_type. name( ) , ret. type_( ) . name( ) ) ;
1110
+ }
1111
+ Some ( ret)
1086
1112
}
1087
- None
1088
- } else {
1089
- match ret {
1090
- Some ( ret) => {
1091
- let valid_type: bool = from_glib ( gobject_ffi:: g_type_check_value_holds (
1092
- mut_override ( ret. to_glib_none ( ) . 0 ) ,
1093
- return_type. to_glib ( ) ) ) ;
1094
- if !valid_type {
1095
- panic ! ( "Signal required return value of type {} but got {}" ,
1096
- return_type. name( ) , ret. type_( ) . name( ) ) ;
1097
- }
1098
- Some ( ret)
1099
- } ,
1100
- None => {
1101
- panic ! ( "Signal required return value of type {} but got None" , return_type. name( ) ) ;
1102
- } ,
1113
+ None => {
1114
+ panic ! ( "Signal required return value of type {} but got None" , return_type. name( ) ) ;
1103
1115
}
1104
1116
}
1105
- } ) ;
1106
- let handler = gobject_ffi:: g_signal_connect_closure_by_id ( self . as_object_ref ( ) . to_glib_none ( ) . 0 , signal_id, signal_detail,
1107
- closure. to_glib_none ( ) . 0 , after. to_glib ( ) ) ;
1108
-
1109
- if handler == 0 {
1110
- Err ( glib_bool_error ! ( "Failed to connect to signal" ) )
1111
- } else {
1112
- Ok ( from_glib ( handler) )
1113
1117
}
1118
+ } ) ;
1119
+ let handler = gobject_ffi:: g_signal_connect_closure_by_id ( self . as_object_ref ( ) . to_glib_none ( ) . 0 , signal_id, signal_detail,
1120
+ closure. to_glib_none ( ) . 0 , after. to_glib ( ) ) ;
1121
+
1122
+ if handler == 0 {
1123
+ Err ( glib_bool_error ! ( "Failed to connect to signal" ) )
1124
+ } else {
1125
+ Ok ( from_glib ( handler) )
1114
1126
}
1115
1127
}
1116
1128
0 commit comments