Skip to content

Commit 4c3253a

Browse files
committed
Enable nullable annotations in module PythonSignal
1 parent 9d6fa23 commit 4c3253a

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/core/IronPython.Modules/NtSignalState.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable enable
6+
57
using System;
68
using System.Runtime.InteropServices;
79
using System.Runtime.Versioning;

src/core/IronPython.Modules/signal.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable enable
6+
57
using System;
68
using System.Collections.Generic;
79
using System.Diagnostics;
@@ -102,7 +104,7 @@ private static PythonSignalState MakePosixSignalState(PythonContext context) {
102104
103105
The default handler for SIGINT installed by Python.
104106
It raises KeyboardInterrupt.")]
105-
public static object default_int_handlerImpl(int signalnum, TraceBackFrame frame) {
107+
public static object default_int_handlerImpl(int signalnum, TraceBackFrame? frame) {
106108
throw new KeyboardInterruptException("");
107109
}
108110

@@ -113,12 +115,12 @@ public static object default_int_handlerImpl(int signalnum, TraceBackFrame frame
113115
SIG_DFL -- if the default action for the signal is in effect
114116
None -- if an unknown handler is in effect
115117
anything else -- the callable Python object used as a handler")]
116-
public static object getsignal(CodeContext/*!*/ context, int signalnum) {
118+
public static object? getsignal(CodeContext/*!*/ context, int signalnum) {
117119
lock (GetPythonSignalState(context).PySignalToPyHandler) {
118120
//Negative Scenarios
119121
if (signalnum < 1 || signalnum > 22) {
120122
throw PythonOps.ValueError("signal number out of range");
121-
} else if (GetPythonSignalState(context).PySignalToPyHandler.TryGetValue(signalnum, out object value)) {
123+
} else if (GetPythonSignalState(context).PySignalToPyHandler.TryGetValue(signalnum, out object? value)) {
122124
//Default
123125
return value;
124126
} else {
@@ -138,7 +140,7 @@ public static object getsignal(CodeContext/*!*/ context, int signalnum) {
138140
*** IMPORTANT NOTICE ***
139141
A signal handler function is called with two arguments:
140142
the first is the signal number, the second is the interrupted stack frame.")]
141-
public static object signal(CodeContext/*!*/ context, int sig, object action) {
143+
public static object? signal(CodeContext/*!*/ context, int sig, object? action) {
142144
//Negative scenarios - sig
143145
if (sig < 1 || sig >= NSIG) {
144146
throw PythonOps.ValueError("signal number out of range");
@@ -157,7 +159,7 @@ public static object signal(CodeContext/*!*/ context, int sig, object action) {
157159
//no-op
158160
} else {
159161
//Must match the signature of PySignalHandler
160-
PythonFunction result = action as PythonFunction;
162+
PythonFunction? result = action as PythonFunction;
161163
if (result == null) {
162164
//It could still be something like a type that implements __call__
163165
if (! PythonOps.IsCallable(context, action)) {
@@ -166,7 +168,7 @@ public static object signal(CodeContext/*!*/ context, int sig, object action) {
166168
}
167169
}
168170

169-
object last_handler = null;
171+
object? last_handler = null;
170172
lock (GetPythonSignalState(context).PySignalToPyHandler) {
171173
//CPython returns the previous handler for the signal
172174
last_handler = getsignal(context, sig);
@@ -225,7 +227,7 @@ public PythonSignalState(PythonContext pc) {
225227
private static readonly int[] _PySupportedSignals = { SIGABRT, SIGBREAK, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM, 6 };
226228

227229
//Signature of Python functions that signal.signal(...) expects to be given
228-
private delegate object PySignalHandler(int signalnum, TraceBackFrame frame);
230+
private delegate object PySignalHandler(int signalnum, TraceBackFrame? frame);
229231
}
230232
}
231233

0 commit comments

Comments
 (0)