@@ -87,19 +87,191 @@ private static PythonSignalState MakeSimpleSignalState(PythonContext context) {
8787 }
8888
8989
90- //Python signals
91- public const int NSIG = 23 ;
92- public const int SIGABRT = 22 ;
93- public const int SIGBREAK = 21 ;
94- public const int SIGFPE = 8 ;
95- public const int SIGILL = 4 ;
96- public const int SIGINT = 2 ;
97- public const int SIGSEGV = 11 ;
98- public const int SIGTERM = 15 ;
90+ #region Generated Signal Codes
91+
92+ // *** BEGIN GENERATED CODE ***
93+ // generated by function: generate_signal_codes from: generate_os_codes.py
94+
95+
96+ public static int SIGABRT => RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ? 22 : 6 ;
97+
98+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows ) ]
99+ [ SupportedOSPlatform ( "linux" ) ]
100+ [ SupportedOSPlatform ( "macos" ) ]
101+ public static int SIGALRM => 14 ;
102+
103+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Unix ) ]
104+ [ SupportedOSPlatform ( "windows" ) ]
105+ public static int SIGBREAK => 21 ;
106+
107+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows ) ]
108+ [ SupportedOSPlatform ( "linux" ) ]
109+ [ SupportedOSPlatform ( "macos" ) ]
110+ public static int SIGBUS => RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) ? 10 : 7 ;
111+
112+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows ) ]
113+ [ SupportedOSPlatform ( "linux" ) ]
114+ [ SupportedOSPlatform ( "macos" ) ]
115+ public static int SIGCHLD => RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) ? 20 : 17 ;
116+
117+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows , PlatformID . MacOSX ) ]
118+ [ SupportedOSPlatform ( "linux" ) ]
119+ public static int SIGCLD => 17 ;
120+
121+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows ) ]
122+ [ SupportedOSPlatform ( "linux" ) ]
123+ [ SupportedOSPlatform ( "macos" ) ]
124+ public static int SIGCONT => RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) ? 19 : 18 ;
125+
126+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows , PlatformID . Unix ) ]
127+ [ SupportedOSPlatform ( "macos" ) ]
128+ public static int SIGEMT => 7 ;
129+
130+ public static int SIGFPE => 8 ;
131+
132+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows ) ]
133+ [ SupportedOSPlatform ( "linux" ) ]
134+ [ SupportedOSPlatform ( "macos" ) ]
135+ public static int SIGHUP => 1 ;
136+
137+ public static int SIGILL => 4 ;
138+
139+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows , PlatformID . Unix ) ]
140+ [ SupportedOSPlatform ( "macos" ) ]
141+ public static int SIGINFO => 29 ;
142+
143+ public static int SIGINT => 2 ;
144+
145+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows ) ]
146+ [ SupportedOSPlatform ( "linux" ) ]
147+ [ SupportedOSPlatform ( "macos" ) ]
148+ public static int SIGIO => RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) ? 23 : 29 ;
149+
150+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows ) ]
151+ [ SupportedOSPlatform ( "linux" ) ]
152+ [ SupportedOSPlatform ( "macos" ) ]
153+ public static int SIGIOT => 6 ;
154+
155+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows ) ]
156+ [ SupportedOSPlatform ( "linux" ) ]
157+ [ SupportedOSPlatform ( "macos" ) ]
158+ public static int SIGKILL => 9 ;
159+
160+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows ) ]
161+ [ SupportedOSPlatform ( "linux" ) ]
162+ [ SupportedOSPlatform ( "macos" ) ]
163+ public static int SIGPIPE => 13 ;
164+
165+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows , PlatformID . MacOSX ) ]
166+ [ SupportedOSPlatform ( "linux" ) ]
167+ public static int SIGPOLL => 29 ;
168+
169+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows ) ]
170+ [ SupportedOSPlatform ( "linux" ) ]
171+ [ SupportedOSPlatform ( "macos" ) ]
172+ public static int SIGPROF => 27 ;
173+
174+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows , PlatformID . MacOSX ) ]
175+ [ SupportedOSPlatform ( "linux" ) ]
176+ public static int SIGPWR => 30 ;
177+
178+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows ) ]
179+ [ SupportedOSPlatform ( "linux" ) ]
180+ [ SupportedOSPlatform ( "macos" ) ]
181+ public static int SIGQUIT => 3 ;
182+
183+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows , PlatformID . MacOSX ) ]
184+ [ SupportedOSPlatform ( "linux" ) ]
185+ public static int SIGRTMAX => 64 ;
186+
187+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows , PlatformID . MacOSX ) ]
188+ [ SupportedOSPlatform ( "linux" ) ]
189+ public static int SIGRTMIN => 34 ;
190+
191+ public static int SIGSEGV => 11 ;
192+
193+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows , PlatformID . MacOSX ) ]
194+ [ SupportedOSPlatform ( "linux" ) ]
195+ public static int SIGSTKFLT => 16 ;
196+
197+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows ) ]
198+ [ SupportedOSPlatform ( "linux" ) ]
199+ [ SupportedOSPlatform ( "macos" ) ]
200+ public static int SIGSTOP => RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) ? 17 : 19 ;
201+
202+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows ) ]
203+ [ SupportedOSPlatform ( "linux" ) ]
204+ [ SupportedOSPlatform ( "macos" ) ]
205+ public static int SIGSYS => RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) ? 12 : 31 ;
206+
207+ public static int SIGTERM => 15 ;
208+
209+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows ) ]
210+ [ SupportedOSPlatform ( "linux" ) ]
211+ [ SupportedOSPlatform ( "macos" ) ]
212+ public static int SIGTRAP => 5 ;
213+
214+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows ) ]
215+ [ SupportedOSPlatform ( "linux" ) ]
216+ [ SupportedOSPlatform ( "macos" ) ]
217+ public static int SIGTSTP => RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) ? 18 : 20 ;
218+
219+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows ) ]
220+ [ SupportedOSPlatform ( "linux" ) ]
221+ [ SupportedOSPlatform ( "macos" ) ]
222+ public static int SIGTTIN => 21 ;
223+
224+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows ) ]
225+ [ SupportedOSPlatform ( "linux" ) ]
226+ [ SupportedOSPlatform ( "macos" ) ]
227+ public static int SIGTTOU => 22 ;
228+
229+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows ) ]
230+ [ SupportedOSPlatform ( "linux" ) ]
231+ [ SupportedOSPlatform ( "macos" ) ]
232+ public static int SIGURG => RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) ? 16 : 23 ;
233+
234+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows ) ]
235+ [ SupportedOSPlatform ( "linux" ) ]
236+ [ SupportedOSPlatform ( "macos" ) ]
237+ public static int SIGUSR1 => RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) ? 30 : 10 ;
238+
239+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows ) ]
240+ [ SupportedOSPlatform ( "linux" ) ]
241+ [ SupportedOSPlatform ( "macos" ) ]
242+ public static int SIGUSR2 => RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) ? 31 : 12 ;
243+
244+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows ) ]
245+ [ SupportedOSPlatform ( "linux" ) ]
246+ [ SupportedOSPlatform ( "macos" ) ]
247+ public static int SIGVTALRM => 26 ;
248+
249+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows ) ]
250+ [ SupportedOSPlatform ( "linux" ) ]
251+ [ SupportedOSPlatform ( "macos" ) ]
252+ public static int SIGWINCH => 28 ;
253+
254+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows ) ]
255+ [ SupportedOSPlatform ( "linux" ) ]
256+ [ SupportedOSPlatform ( "macos" ) ]
257+ public static int SIGXCPU => 24 ;
258+
259+ [ PythonHidden ( PlatformsAttribute . PlatformFamily . Windows ) ]
260+ [ SupportedOSPlatform ( "linux" ) ]
261+ [ SupportedOSPlatform ( "macos" ) ]
262+ public static int SIGXFSZ => 25 ;
263+
264+ // *** END GENERATED CODE ***
265+
266+ #endregion
267+
268+ public static int NSIG => RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ? 23 : RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) ? 32 : 65 ;
269+
99270 public const int SIG_DFL = 0 ;
100271 public const int SIG_IGN = 1 ;
101272
102- //Windows signals
273+
274+ // Windows signals
103275 [ SupportedOSPlatform ( "windows" ) , PythonHidden ( PlatformsAttribute . PlatformFamily . Unix ) ]
104276 public const int CTRL_C_EVENT = 0 ;
105277 [ SupportedOSPlatform ( "windows" ) , PythonHidden ( PlatformsAttribute . PlatformFamily . Unix ) ]
@@ -174,8 +346,8 @@ public static object default_int_handlerImpl(int signalnum, TraceBackFrame? fram
174346 // Negative scenarios - signalnum
175347 if ( signalnum <= 0 || signalnum >= NSIG ) {
176348 throw PythonOps . ValueError ( "signal number out of range" ) ;
177- } else if ( Array . IndexOf ( _PySupportedSignals , signalnum ) == - 1 ) {
178- throw new RuntimeException ( "no IronPython support for given signal") ;
349+ } else if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) && Array . IndexOf ( _PySupportedSignals_Windows , signalnum ) == - 1 ) {
350+ throw PythonOps . ValueError ( "invalid signal value ") ;
179351 }
180352 // Negative scenarios - action
181353 if ( action == null ) {
@@ -250,20 +422,44 @@ private class PythonSignalState {
250422
251423 public PythonSignalState ( PythonContext pc ) {
252424 SignalPythonContext = pc ;
253- PySignalToPyHandler = new Dictionary < int , object > ( ) {
254- { SIGABRT , SIG_DFL } ,
255- { SIGBREAK , SIG_DFL } ,
256- { SIGFPE , SIG_DFL } ,
257- { SIGILL , SIG_DFL } ,
258- { SIGINT , default_int_handler } ,
259- { SIGSEGV , SIG_DFL } ,
260- { SIGTERM , SIG_DFL } ,
261- } ;
425+ int [ ] sigs = RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ? _PySupportedSignals_Windows
426+ : RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) ? _PySupportedSignals_MacOS
427+ : RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) ? _PySupportedSignals_Linux
428+ : throw new NotSupportedException ( "Unsupported platform for signal module" ) ;
429+
430+ PySignalToPyHandler = new Dictionary < int , object > ( sigs . Length ) ;
431+ foreach ( int sig in sigs ) {
432+ PySignalToPyHandler [ sig ] = SIG_DFL ;
433+ }
434+ PySignalToPyHandler [ SIGINT ] = default_int_handler ;
262435 }
263436 }
264437
265- // List of all Signals CPython supports on Windows. Notice the addition of '6'
266- private static readonly int [ ] _PySupportedSignals = { SIGABRT , SIGBREAK , SIGFPE , SIGILL , SIGINT , SIGSEGV , SIGTERM , 6 } ;
438+
439+ #region Generated Supported Signals
440+
441+ // *** BEGIN GENERATED CODE ***
442+ // generated by function: generate_supported_signals from: generate_os_codes.py
443+
444+ [ SupportedOSPlatform ( "linux" ) ]
445+ private static readonly int [ ] _PySupportedSignals_Linux = [
446+ SIGABRT , SIGALRM , SIGBUS , SIGCHLD , SIGCLD , SIGCONT , SIGFPE , SIGHUP , SIGILL , SIGINT , SIGIO , SIGIOT , SIGKILL , SIGPIPE , SIGPOLL , SIGPROF , SIGPWR , SIGQUIT , SIGRTMAX , SIGRTMIN , SIGSEGV , SIGSTKFLT , SIGSTOP , SIGSYS , SIGTERM , SIGTRAP , SIGTSTP , SIGTTIN , SIGTTOU , SIGURG , SIGUSR1 , SIGUSR2 , SIGVTALRM , SIGWINCH , SIGXCPU , SIGXFSZ
447+ ] ;
448+
449+ [ SupportedOSPlatform ( "macos" ) ]
450+ private static readonly int [ ] _PySupportedSignals_MacOS = [
451+ SIGABRT , SIGALRM , SIGBUS , SIGCHLD , SIGCONT , SIGEMT , SIGFPE , SIGHUP , SIGILL , SIGINFO , SIGINT , SIGIO , SIGIOT , SIGKILL , SIGPIPE , SIGPROF , SIGQUIT , SIGSEGV , SIGSTOP , SIGSYS , SIGTERM , SIGTRAP , SIGTSTP , SIGTTIN , SIGTTOU , SIGURG , SIGUSR1 , SIGUSR2 , SIGVTALRM , SIGWINCH , SIGXCPU , SIGXFSZ
452+ ] ;
453+
454+ [ SupportedOSPlatform ( "windows" ) ]
455+ private static readonly int [ ] _PySupportedSignals_Windows = [
456+ SIGABRT , SIGBREAK , SIGFPE , SIGILL , SIGINT , SIGSEGV , SIGTERM
457+ ] ;
458+
459+
460+ // *** END GENERATED CODE ***
461+
462+ #endregion
267463
268464 // Signature of Python functions that signal.signal(...) expects to be given
269465 private delegate object PySignalHandler ( int signalnum , TraceBackFrame ? frame ) ;
0 commit comments