Skip to content

Commit a687be1

Browse files
authored
Enable nullable annotations in mmap (#1874)
1 parent 5a8d867 commit a687be1

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

Src/IronPython.Modules/mmap.cs

Lines changed: 13 additions & 14 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
#if FEATURE_MMAP
68

79
using System;
@@ -202,7 +204,7 @@ public static class MmapModule {
202204
public static readonly int ALLOCATIONGRANULARITY = GetAllocationGranularity();
203205
public static readonly int PAGESIZE = System.Environment.SystemPageSize;
204206

205-
public static readonly string __doc__ = null;
207+
public static readonly string? __doc__;
206208

207209
private static Exception WindowsError(int winerror) {
208210
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
@@ -261,7 +263,7 @@ private static MemoryMappedFileAccess ToMmapFileAccess(int flags, int prot, int
261263

262264
[PythonType("mmap"), PythonHidden]
263265
public class MmapWindows : MmapDefault {
264-
public MmapWindows(CodeContext context, int fileno, long length, string tagname = null, int access = ACCESS_DEFAULT, long offset = 0)
266+
public MmapWindows(CodeContext context, int fileno, long length, string? tagname = null, int access = ACCESS_DEFAULT, long offset = 0)
265267
: base(context, fileno, length, tagname, ToMmapFileAccess(access), offset) { }
266268

267269
private static MemoryMappedFileAccess ToMmapFileAccess(int access) {
@@ -280,17 +282,17 @@ public class MmapDefault : IWeakReferenceable {
280282
private MemoryMappedFile _file;
281283
private MemoryMappedViewAccessor _view;
282284
private long _position;
283-
private FileStream _sourceStream;
285+
private FileStream? _sourceStream;
284286

285287
private readonly long _offset;
286-
private readonly string _mapName;
288+
private readonly string? _mapName;
287289
private readonly MemoryMappedFileAccess _fileAccess;
288-
private readonly SafeFileHandle _handle;
290+
private readonly SafeFileHandle? _handle;
289291

290292
private volatile bool _isClosed;
291293
private int _refCount = 1;
292294

293-
public MmapDefault(CodeContext/*!*/ context, int fileno, long length, string tagname, MemoryMappedFileAccess fileAccess, long offset) {
295+
public MmapDefault(CodeContext/*!*/ context, int fileno, long length, string? tagname, MemoryMappedFileAccess fileAccess, long offset) {
294296
_fileAccess = fileAccess;
295297

296298
if (length < 0) {
@@ -329,7 +331,7 @@ public MmapDefault(CodeContext/*!*/ context, int fileno, long length, string tag
329331
_offset = offset;
330332

331333
PythonContext pContext = context.LanguageContext;
332-
if (pContext.FileManager.TryGetStreams(fileno, out StreamBox streams)) {
334+
if (pContext.FileManager.TryGetStreams(fileno, out StreamBox? streams)) {
333335
Stream stream = streams.ReadStream;
334336
if (stream is FileStream fs) {
335337
_sourceStream = fs;
@@ -395,7 +397,6 @@ public MmapDefault(CodeContext/*!*/ context, int fileno, long length, string tag
395397
_view = _file.CreateViewAccessor(_offset, length, _fileAccess);
396398
} catch {
397399
_file.Dispose();
398-
_file = null;
399400
CloseFileHandle();
400401
throw;
401402
}
@@ -563,8 +564,6 @@ private void CloseWorker() {
563564
_file.Dispose();
564565
CloseFileHandle();
565566
_sourceStream = null;
566-
_view = null;
567-
_file = null;
568567
}
569568
}
570569

@@ -1086,7 +1085,7 @@ private void CheckSeekIndex(long index) {
10861085
}
10871086
}
10881087

1089-
private static long? GetLong(object o) {
1088+
private static long? GetLong(object? o) {
10901089
if (o == null) {
10911090
return null;
10921091
} else if (o is int) {
@@ -1169,9 +1168,9 @@ public void Dispose() {
11691168

11701169
#region IWeakReferenceable Members
11711170

1172-
private WeakRefTracker _tracker;
1171+
private WeakRefTracker? _tracker;
11731172

1174-
WeakRefTracker IWeakReferenceable.GetWeakRef() {
1173+
WeakRefTracker? IWeakReferenceable.GetWeakRef() {
11751174
return _tracker;
11761175
}
11771176

@@ -1222,7 +1221,7 @@ private static int GetAllocationGranularityWorker() {
12221221

12231222
#endregion
12241223

1225-
private static MemoryMappedFile CreateFromFile(System.IO.FileStream fileStream, string mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access, System.IO.HandleInheritability inheritability, bool leaveOpen) {
1224+
private static MemoryMappedFile CreateFromFile(System.IO.FileStream fileStream, string? mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access, System.IO.HandleInheritability inheritability, bool leaveOpen) {
12261225
return MemoryMappedFile.CreateFromFile(fileStream, mapName, capacity, access, inheritability, leaveOpen);
12271226
}
12281227
}

Src/IronPython/Modules/_fileio.cs

Lines changed: 2 additions & 3 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.Dynamic;
79
using System.IO;
@@ -19,9 +21,6 @@
1921

2022
using Microsoft.Scripting;
2123
using Microsoft.Scripting.Runtime;
22-
using Mono.Unix.Native;
23-
24-
#nullable enable
2524

2625

2726
namespace IronPython.Modules {

0 commit comments

Comments
 (0)