@@ -3,6 +3,7 @@ use crate::{builtins::PyModule, PyRef, VirtualMachine};
33pub ( crate ) fn make_module ( vm : & VirtualMachine ) -> PyRef < PyModule > {
44 let module = _signal:: make_module ( vm) ;
55
6+ #[ cfg( any( unix, windows) ) ]
67 _signal:: init_signal_handlers ( & module, vm) ;
78
89 module
@@ -11,12 +12,17 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {
1112#[ pymodule]
1213pub ( crate ) mod _signal {
1314 use crate :: {
14- builtins:: PyModule ,
1515 convert:: { IntoPyException , TryFromBorrowedObject } ,
1616 signal, Py , PyObjectRef , PyResult , VirtualMachine ,
1717 } ;
1818 use std:: sync:: atomic:: { self , Ordering } ;
1919
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+
2026 cfg_if:: cfg_if! {
2127 if #[ cfg( windows) ] {
2228 type WakeupFd = libc:: SOCKET ;
@@ -33,23 +39,23 @@ pub(crate) mod _signal {
3339 }
3440
3541 #[ cfg( unix) ]
36- pub use nix:: unistd:: alarm as sig_alarm;
37-
38- #[ cfg( not( windows) ) ]
3942 pub use libc:: SIG_ERR ;
43+ #[ cfg( unix) ]
44+ pub use nix:: unistd:: alarm as sig_alarm;
4045
41- #[ cfg( not ( windows ) ) ]
46+ #[ cfg( unix ) ]
4247 #[ pyattr]
4348 pub use libc:: { SIG_DFL , SIG_IGN } ;
4449
45- #[ cfg( windows ) ]
50+ #[ cfg( not ( unix ) ) ]
4651 #[ 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 ) ) ]
4954 #[ 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 _ ;
5359
5460 #[ cfg( all( unix, not( target_os = "redox" ) ) ) ]
5561 extern "C" {
@@ -59,6 +65,7 @@ pub(crate) mod _signal {
5965 #[ pyattr]
6066 use crate :: signal:: NSIG ;
6167
68+ #[ cfg( any( unix, windows) ) ]
6269 #[ pyattr]
6370 pub use libc:: { SIGABRT , SIGFPE , SIGILL , SIGINT , SIGSEGV , SIGTERM } ;
6471
@@ -80,7 +87,11 @@ pub(crate) mod _signal {
8087 #[ pyattr]
8188 use libc:: { SIGPWR , SIGSTKFLT } ;
8289
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+ ) {
8495 let sig_dfl = vm. new_pyobj ( SIG_DFL as u8 ) ;
8596 let sig_ign = vm. new_pyobj ( SIG_IGN as u8 ) ;
8697
@@ -107,6 +118,17 @@ pub(crate) mod _signal {
107118 }
108119 }
109120
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) ) ]
110132 #[ pyfunction]
111133 pub fn signal (
112134 signalnum : i32 ,
@@ -123,7 +145,7 @@ pub(crate) mod _signal {
123145 match usize:: try_from_borrowed_object ( vm, & handler) . ok ( ) {
124146 Some ( SIG_DFL ) => SIG_DFL ,
125147 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 ,
127149 _ => return Err ( vm. new_type_error (
128150 "signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable object"
129151 . to_owned ( ) ,
@@ -226,7 +248,7 @@ pub(crate) mod _signal {
226248 } else {
227249 false
228250 } ;
229- #[ cfg( not ( windows ) ) ]
251+ #[ cfg( unix ) ]
230252 if fd != INVALID_WAKEUP {
231253 use nix:: fcntl;
232254 let oflags = fcntl:: fcntl ( fd, fcntl:: F_GETFL ) . map_err ( |e| e. into_pyexception ( vm) ) ?;
@@ -256,6 +278,7 @@ pub(crate) mod _signal {
256278 }
257279 }
258280
281+ #[ cfg( any( unix, windows) ) ]
259282 pub extern "C" fn run_signal ( signum : i32 ) {
260283 signal:: TRIGGERS [ signum as usize ] . store ( true , Ordering :: Relaxed ) ;
261284 signal:: set_triggered ( ) ;
0 commit comments