Skip to content

Commit

Permalink
Enable nullable annotations in mmap
Browse files Browse the repository at this point in the history
  • Loading branch information
BCSharp committed Jan 16, 2025
1 parent 72c4a09 commit 0bd86cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
27 changes: 13 additions & 14 deletions Src/IronPython.Modules/mmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

#nullable enable

#if FEATURE_MMAP

using System;
Expand Down Expand Up @@ -202,7 +204,7 @@ public static class MmapModule {
public static readonly int ALLOCATIONGRANULARITY = GetAllocationGranularity();
public static readonly int PAGESIZE = System.Environment.SystemPageSize;

public static readonly string __doc__ = null;
public static readonly string? __doc__;

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

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

private static MemoryMappedFileAccess ToMmapFileAccess(int access) {
Expand All @@ -280,17 +282,17 @@ public class MmapDefault : IWeakReferenceable {
private MemoryMappedFile _file;
private MemoryMappedViewAccessor _view;
private long _position;
private FileStream _sourceStream;
private FileStream? _sourceStream;

private readonly long _offset;
private readonly string _mapName;
private readonly string? _mapName;
private readonly MemoryMappedFileAccess _fileAccess;
private readonly SafeFileHandle _handle;
private readonly SafeFileHandle? _handle;

private volatile bool _isClosed;
private int _refCount = 1;

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

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

PythonContext pContext = context.LanguageContext;
if (pContext.FileManager.TryGetStreams(fileno, out StreamBox streams)) {
if (pContext.FileManager.TryGetStreams(fileno, out StreamBox? streams)) {
Stream stream = streams.ReadStream;
if (stream is FileStream fs) {
_sourceStream = fs;
Expand Down Expand Up @@ -395,7 +397,6 @@ public MmapDefault(CodeContext/*!*/ context, int fileno, long length, string tag
_view = _file.CreateViewAccessor(_offset, length, _fileAccess);
} catch {
_file.Dispose();
_file = null;
CloseFileHandle();
throw;
}
Expand Down Expand Up @@ -563,8 +564,6 @@ private void CloseWorker() {
_file.Dispose();
CloseFileHandle();
_sourceStream = null;
_view = null;
_file = null;
}
}

Expand Down Expand Up @@ -1086,7 +1085,7 @@ private void CheckSeekIndex(long index) {
}
}

private static long? GetLong(object o) {
private static long? GetLong(object? o) {
if (o == null) {
return null;
} else if (o is int) {
Expand Down Expand Up @@ -1169,9 +1168,9 @@ public void Dispose() {

#region IWeakReferenceable Members

private WeakRefTracker _tracker;
private WeakRefTracker? _tracker;

WeakRefTracker IWeakReferenceable.GetWeakRef() {
WeakRefTracker? IWeakReferenceable.GetWeakRef() {
return _tracker;
}

Expand Down Expand Up @@ -1222,7 +1221,7 @@ private static int GetAllocationGranularityWorker() {

#endregion

private static MemoryMappedFile CreateFromFile(System.IO.FileStream fileStream, string mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access, System.IO.HandleInheritability inheritability, bool leaveOpen) {
private static MemoryMappedFile CreateFromFile(System.IO.FileStream fileStream, string? mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access, System.IO.HandleInheritability inheritability, bool leaveOpen) {
return MemoryMappedFile.CreateFromFile(fileStream, mapName, capacity, access, inheritability, leaveOpen);
}
}
Expand Down
5 changes: 2 additions & 3 deletions Src/IronPython/Modules/_fileio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

#nullable enable

using System;
using System.Dynamic;
using System.IO;
Expand All @@ -19,9 +21,6 @@

using Microsoft.Scripting;
using Microsoft.Scripting.Runtime;
using Mono.Unix.Native;

#nullable enable


namespace IronPython.Modules {
Expand Down

0 comments on commit 0bd86cd

Please sign in to comment.