@@ -3,6 +3,7 @@ use crate::{builtins::PyModule, PyRef, VirtualMachine};
3
3
pub ( crate ) fn make_module ( vm : & VirtualMachine ) -> PyRef < PyModule > {
4
4
let module = _signal:: make_module ( vm) ;
5
5
6
+ #[ cfg( any( unix, windows) ) ]
6
7
_signal:: init_signal_handlers ( & module, vm) ;
7
8
8
9
module
@@ -11,12 +12,17 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {
11
12
#[ pymodule]
12
13
pub ( crate ) mod _signal {
13
14
use crate :: {
14
- builtins:: PyModule ,
15
15
convert:: { IntoPyException , TryFromBorrowedObject } ,
16
16
signal, Py , PyObjectRef , PyResult , VirtualMachine ,
17
17
} ;
18
18
use std:: sync:: atomic:: { self , Ordering } ;
19
19
20
+ #[ cfg( any( unix, windows) ) ]
21
+ use libc:: sighandler_t;
22
+ #[ allow( non_camel_case_types) ]
23
+ #[ cfg( not( any( unix, windows) ) ) ]
24
+ type sighandler_t = usize ;
25
+
20
26
cfg_if:: cfg_if! {
21
27
if #[ cfg( windows) ] {
22
28
type WakeupFd = libc:: SOCKET ;
@@ -33,23 +39,23 @@ pub(crate) mod _signal {
33
39
}
34
40
35
41
#[ cfg( unix) ]
36
- pub use nix:: unistd:: alarm as sig_alarm;
37
-
38
- #[ cfg( not( windows) ) ]
39
42
pub use libc:: SIG_ERR ;
43
+ #[ cfg( unix) ]
44
+ pub use nix:: unistd:: alarm as sig_alarm;
40
45
41
- #[ cfg( not ( windows ) ) ]
46
+ #[ cfg( unix ) ]
42
47
#[ pyattr]
43
48
pub use libc:: { SIG_DFL , SIG_IGN } ;
44
49
45
- #[ cfg( windows ) ]
50
+ #[ cfg( not ( unix ) ) ]
46
51
#[ pyattr]
47
- pub const SIG_DFL : libc :: sighandler_t = 0 ;
48
- #[ cfg( windows ) ]
52
+ pub const SIG_DFL : sighandler_t = 0 ;
53
+ #[ cfg( not ( unix ) ) ]
49
54
#[ pyattr]
50
- pub const SIG_IGN : libc:: sighandler_t = 1 ;
51
- #[ cfg( windows) ]
52
- pub const SIG_ERR : libc:: sighandler_t = !0 ;
55
+ pub const SIG_IGN : sighandler_t = 1 ;
56
+ #[ cfg( not( unix) ) ]
57
+ #[ allow( dead_code) ]
58
+ pub const SIG_ERR : sighandler_t = -1 as _ ;
53
59
54
60
#[ cfg( all( unix, not( target_os = "redox" ) ) ) ]
55
61
extern "C" {
@@ -59,6 +65,7 @@ pub(crate) mod _signal {
59
65
#[ pyattr]
60
66
use crate :: signal:: NSIG ;
61
67
68
+ #[ cfg( any( unix, windows) ) ]
62
69
#[ pyattr]
63
70
pub use libc:: { SIGABRT , SIGFPE , SIGILL , SIGINT , SIGSEGV , SIGTERM } ;
64
71
@@ -80,7 +87,11 @@ pub(crate) mod _signal {
80
87
#[ pyattr]
81
88
use libc:: { SIGPWR , SIGSTKFLT } ;
82
89
83
- pub ( super ) fn init_signal_handlers ( module : & Py < PyModule > , vm : & VirtualMachine ) {
90
+ #[ cfg( any( unix, windows) ) ]
91
+ pub ( super ) fn init_signal_handlers (
92
+ module : & Py < crate :: builtins:: PyModule > ,
93
+ vm : & VirtualMachine ,
94
+ ) {
84
95
let sig_dfl = vm. new_pyobj ( SIG_DFL as u8 ) ;
85
96
let sig_ign = vm. new_pyobj ( SIG_IGN as u8 ) ;
86
97
@@ -107,6 +118,17 @@ pub(crate) mod _signal {
107
118
}
108
119
}
109
120
121
+ #[ cfg( not( any( unix, windows) ) ) ]
122
+ #[ pyfunction]
123
+ pub fn signal (
124
+ _signalnum : i32 ,
125
+ _handler : PyObjectRef ,
126
+ vm : & VirtualMachine ,
127
+ ) -> PyResult < Option < PyObjectRef > > {
128
+ Err ( vm. new_not_implemented_error ( "signal is not implemented on this platform" . to_owned ( ) ) )
129
+ }
130
+
131
+ #[ cfg( any( unix, windows) ) ]
110
132
#[ pyfunction]
111
133
pub fn signal (
112
134
signalnum : i32 ,
@@ -123,7 +145,7 @@ pub(crate) mod _signal {
123
145
match usize:: try_from_borrowed_object ( vm, & handler) . ok ( ) {
124
146
Some ( SIG_DFL ) => SIG_DFL ,
125
147
Some ( SIG_IGN ) => SIG_IGN ,
126
- None if handler. is_callable ( ) => run_signal as libc :: sighandler_t ,
148
+ None if handler. is_callable ( ) => run_signal as sighandler_t ,
127
149
_ => return Err ( vm. new_type_error (
128
150
"signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable object"
129
151
. to_owned ( ) ,
@@ -226,7 +248,7 @@ pub(crate) mod _signal {
226
248
} else {
227
249
false
228
250
} ;
229
- #[ cfg( not ( windows ) ) ]
251
+ #[ cfg( unix ) ]
230
252
if fd != INVALID_WAKEUP {
231
253
use nix:: fcntl;
232
254
let oflags = fcntl:: fcntl ( fd, fcntl:: F_GETFL ) . map_err ( |e| e. into_pyexception ( vm) ) ?;
@@ -256,6 +278,7 @@ pub(crate) mod _signal {
256
278
}
257
279
}
258
280
281
+ #[ cfg( any( unix, windows) ) ]
259
282
pub extern "C" fn run_signal ( signum : i32 ) {
260
283
signal:: TRIGGERS [ signum as usize ] . store ( true , Ordering :: Relaxed ) ;
261
284
signal:: set_triggered ( ) ;
0 commit comments