2
2
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
3
3
// See the LICENSE file in the project root for more information.
4
4
5
+ #nullable enable
6
+
5
7
using System ;
6
8
using System . Runtime . InteropServices ;
7
9
using System . Runtime . Versioning ;
13
15
namespace IronPython . Modules {
14
16
public static partial class PythonSignal {
15
17
[ SupportedOSPlatform ( "windows" ) ]
16
- internal class NtSignalState : PythonSignalState {
17
- //We use a single Windows event handler to process all signals. This handler simply
18
- //delegates the work out to PySignalToPyHandler.
19
- public NativeSignal . WinSignalsHandler WinAllSignalsHandlerDelegate ;
18
+ private class NtSignalState : PythonSignalState {
19
+ // We use a single Windows event handler to process all signals. This handler simply
20
+ // delegates the work out to PySignalToPyHandler.
21
+ public NativeWindowsSignal . WinSignalsHandler WinAllSignalsHandlerDelegate ;
22
+
20
23
21
24
public NtSignalState ( PythonContext pc ) : base ( pc ) {
22
- WinAllSignalsHandlerDelegate = new NativeSignal . WinSignalsHandler ( WindowsEventHandler ) ;
23
- NativeSignal . SetConsoleCtrlHandler ( this . WinAllSignalsHandlerDelegate , true ) ;
25
+ WinAllSignalsHandlerDelegate = new NativeWindowsSignal . WinSignalsHandler ( WindowsEventHandler ) ;
26
+ NativeWindowsSignal . SetConsoleCtrlHandler ( this . WinAllSignalsHandlerDelegate , true ) ;
24
27
}
25
28
26
- //Our implementation of WinSignalsHandler
29
+
30
+ // Our implementation of WinSignalsHandler
27
31
private bool WindowsEventHandler ( uint winSignal ) {
28
32
bool retVal ;
29
33
int pySignal ;
@@ -53,27 +57,27 @@ private bool WindowsEventHandler(uint winSignal) {
53
57
int tempId = ( int ) PySignalToPyHandler [ pySignal ] ;
54
58
55
59
if ( tempId == SIG_DFL ) {
56
- //SIG_DFL - we let Windows do whatever it normally would
60
+ // SIG_DFL - we let Windows do whatever it normally would
57
61
retVal = false ;
58
62
} else if ( tempId == SIG_IGN ) {
59
- //SIG_IGN - we do nothing, but tell Windows we handled the signal
63
+ // SIG_IGN - we do nothing, but tell Windows we handled the signal
60
64
retVal = true ;
61
65
} else {
62
66
throw new Exception ( "unreachable" ) ;
63
67
}
64
68
} else if ( PySignalToPyHandler [ pySignal ] == default_int_handler ) {
65
69
if ( pySignal != SIGINT ) {
66
- //We're dealing with the default_int_handlerImpl which we
67
- //know doesn't care about the frame parameter
70
+ // We're dealing with the default_int_handlerImpl which we
71
+ // know doesn't care about the frame parameter
68
72
retVal = true ;
69
73
default_int_handlerImpl ( pySignal , null ) ;
70
74
} else {
71
- //Let the real interrupt handler throw a KeyboardInterrupt for SIGINT.
72
- //It handles this far more gracefully than we can
75
+ // Let the real interrupt handler throw a KeyboardInterrupt for SIGINT.
76
+ // It handles this far more gracefully than we can
73
77
retVal = false ;
74
78
}
75
79
} else {
76
- //We're dealing with a callable matching PySignalHandler's signature
80
+ // We're dealing with a callable matching PySignalHandler's signature
77
81
retVal = true ;
78
82
PySignalHandler temp = ( PySignalHandler ) Converter . ConvertToDelegate ( PySignalToPyHandler [ pySignal ] ,
79
83
typeof ( PySignalHandler ) ) ;
@@ -96,7 +100,9 @@ private bool WindowsEventHandler(uint winSignal) {
96
100
}
97
101
}
98
102
99
- internal static class NativeSignal {
103
+
104
+ [ SupportedOSPlatform ( "windows" ) ]
105
+ internal static class NativeWindowsSignal {
100
106
// Windows API expects to be given a function pointer like this to handle signals
101
107
internal delegate bool WinSignalsHandler ( uint winSignal ) ;
102
108
0 commit comments