未验证 提交 760b7c61 编写于 作者: S Stephen Toub 提交者: GitHub

Annotate System.IO.MemoryMappedFiles for nullable reference types (#220)

上级 7bc6a674
......@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.InteropServices;
......@@ -17,7 +18,7 @@ internal partial class Kernel32
int flProtect,
int dwMaximumSizeHigh,
int dwMaximumSizeLow,
string lpName);
string? lpName);
[DllImport(Libraries.Kernel32, EntryPoint = "CreateFileMappingW", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern SafeMemoryMappedFileHandle CreateFileMapping(
......@@ -26,6 +27,6 @@ internal partial class Kernel32
int flProtect,
int dwMaximumSizeHigh,
int dwMaximumSizeLow,
string lpName);
string? lpName);
}
}
......@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.InteropServices;
......
......@@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.InteropServices;
internal partial class Interop
......
......@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.InteropServices;
......
......@@ -25,15 +25,15 @@ public partial class MemoryMappedFile : System.IDisposable
{
internal MemoryMappedFile() { }
public Microsoft.Win32.SafeHandles.SafeMemoryMappedFileHandle SafeMemoryMappedFileHandle { get { throw null; } }
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateFromFile(System.IO.FileStream fileStream, string mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access, System.IO.HandleInheritability inheritability, bool leaveOpen) { throw null; }
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateFromFile(System.IO.FileStream fileStream, string? mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access, System.IO.HandleInheritability inheritability, bool leaveOpen) { throw null; }
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateFromFile(string path) { throw null; }
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateFromFile(string path, System.IO.FileMode mode) { throw null; }
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateFromFile(string path, System.IO.FileMode mode, string mapName) { throw null; }
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateFromFile(string path, System.IO.FileMode mode, string mapName, long capacity) { throw null; }
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateFromFile(string path, System.IO.FileMode mode, string mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access) { throw null; }
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateNew(string mapName, long capacity) { throw null; }
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateNew(string mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access) { throw null; }
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateNew(string mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access, System.IO.MemoryMappedFiles.MemoryMappedFileOptions options, System.IO.HandleInheritability inheritability) { throw null; }
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateFromFile(string path, System.IO.FileMode mode, string? mapName) { throw null; }
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateFromFile(string path, System.IO.FileMode mode, string? mapName, long capacity) { throw null; }
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateFromFile(string path, System.IO.FileMode mode, string? mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access) { throw null; }
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateNew(string? mapName, long capacity) { throw null; }
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateNew(string? mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access) { throw null; }
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateNew(string? mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access, System.IO.MemoryMappedFiles.MemoryMappedFileOptions options, System.IO.HandleInheritability inheritability) { throw null; }
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateOrOpen(string mapName, long capacity) { throw null; }
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateOrOpen(string mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access) { throw null; }
public static System.IO.MemoryMappedFiles.MemoryMappedFile CreateOrOpen(string mapName, long capacity, System.IO.MemoryMappedFiles.MemoryMappedFileAccess access, System.IO.MemoryMappedFiles.MemoryMappedFileOptions options, System.IO.HandleInheritability inheritability) { throw null; }
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Nullable>enable</Nullable>
<Configurations>netcoreapp-Debug;netcoreapp-Release</Configurations>
</PropertyGroup>
<ItemGroup>
......
......@@ -6,8 +6,6 @@
using System.Diagnostics;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Runtime.InteropServices;
using System.Security;
using System.Threading;
namespace Microsoft.Win32.SafeHandles
......@@ -22,7 +20,7 @@ public sealed partial class SafeMemoryMappedFileHandle : SafeHandleZeroOrMinusOn
/// onto the underlying handle to ensure that logic associated with disposing the stream
/// (e.g. deleting the file for DeleteOnClose) happens at the appropriate time.
/// </summary>
internal readonly FileStream _fileStream;
internal readonly FileStream? _fileStream;
/// <summary>Whether this SafeHandle owns the _fileStream and should Dispose it when disposed.</summary>
internal readonly bool _ownsFileStream;
......@@ -47,7 +45,7 @@ public sealed partial class SafeMemoryMappedFileHandle : SafeHandleZeroOrMinusOn
/// <param name="options">The options for the memory-mapped file.</param>
/// <param name="capacity">The capacity of the memory-mapped file.</param>
internal SafeMemoryMappedFileHandle(
FileStream fileStream, bool ownsFileStream, HandleInheritability inheritability,
FileStream? fileStream, bool ownsFileStream, HandleInheritability inheritability,
MemoryMappedFileAccess access, MemoryMappedFileOptions options,
long capacity)
: base(ownsHandle: true)
......@@ -72,7 +70,7 @@ protected override void Dispose(bool disposing)
if (disposing && _ownsFileStream)
{
// Clean up the file descriptor (either for a file on disk or a shared memory object) if we created it
_fileStream.Dispose();
_fileStream!.Dispose();
}
base.Dispose(disposing);
}
......
......@@ -2,10 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime.InteropServices;
using System.Security;
namespace Microsoft.Win32.SafeHandles
{
public sealed partial class SafeMemoryMappedFileHandle : SafeHandleZeroOrMinusOneIsInvalid
......
......@@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime.InteropServices;
namespace Microsoft.Win32.SafeHandles
{
......
......@@ -2,9 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime.InteropServices;
using System.Security;
namespace Microsoft.Win32.SafeHandles
{
......
......@@ -2,6 +2,7 @@
<PropertyGroup>
<AssemblyName>System.IO.MemoryMappedFiles</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>enable</Nullable>
<Configurations>netcoreapp-Unix-Debug;netcoreapp-Unix-Release;netcoreapp-Windows_NT-Debug;netcoreapp-Windows_NT-Release</Configurations>
</PropertyGroup>
<!-- Compiled Source Files -->
......
......@@ -27,7 +27,7 @@ public static unsafe void CheckForAvailableVirtualMemory(ulong nativeSize)
ref Kernel32.SECURITY_ATTRIBUTES securityAttributes,
int pageProtection,
long maximumSize,
string name)
string? name)
{
// split the long into two ints
int capacityHigh, capacityLow;
......@@ -41,7 +41,7 @@ public static unsafe void CheckForAvailableVirtualMemory(ulong nativeSize)
ref Kernel32.SECURITY_ATTRIBUTES securityAttributes,
int pageProtection,
long maximumSize,
string name)
string? name)
{
// split the long into two ints
int capacityHigh, capacityLow;
......
......@@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using Microsoft.Win32.SafeHandles;
using System.Security;
namespace System.IO.MemoryMappedFiles
{
......@@ -15,7 +14,7 @@ public partial class MemoryMappedFile
/// out empty).
/// </summary>
private static unsafe SafeMemoryMappedFileHandle CreateCore(
FileStream fileStream, string mapName,
FileStream? fileStream, string? mapName,
HandleInheritability inheritability, MemoryMappedFileAccess access,
MemoryMappedFileOptions options, long capacity)
{
......@@ -138,7 +137,7 @@ private static FileStream CreateSharedBackingObject(Interop.Sys.MemoryMappedProt
// ---- PAL layer ends here ----
// -----------------------------
private static FileStream CreateSharedBackingObjectUsingMemory(
private static FileStream? CreateSharedBackingObjectUsingMemory(
Interop.Sys.MemoryMappedProtections protections, long capacity, HandleInheritability inheritability)
{
// The POSIX shared memory object name must begin with '/'. After that we just want something short and unique.
......
......@@ -5,7 +5,6 @@
using Microsoft.Win32.SafeHandles;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Security;
using System.Threading;
namespace System.IO.MemoryMappedFiles
......@@ -19,10 +18,10 @@ public partial class MemoryMappedFile
/// </summary>
private static SafeMemoryMappedFileHandle CreateCore(
FileStream fileStream, string mapName, HandleInheritability inheritability,
FileStream? fileStream, string? mapName, HandleInheritability inheritability,
MemoryMappedFileAccess access, MemoryMappedFileOptions options, long capacity)
{
SafeFileHandle fileHandle = fileStream != null ? fileStream.SafeFileHandle : null;
SafeFileHandle? fileHandle = fileStream != null ? fileStream.SafeFileHandle : null;
Interop.Kernel32.SECURITY_ATTRIBUTES secAttrs = GetSecAttrs(inheritability);
......@@ -89,7 +88,7 @@ public partial class MemoryMappedFile
Debug.Assert(access != MemoryMappedFileAccess.Write, "Callers requesting write access shouldn't try to create a mmf");
SafeMemoryMappedFileHandle handle = null;
SafeMemoryMappedFileHandle? handle = null;
Interop.Kernel32.SECURITY_ATTRIBUTES secAttrs = GetSecAttrs(inheritability);
int waitRetries = 14; //((2^13)-1)*10ms == approximately 1.4mins
......
......@@ -4,7 +4,6 @@
using Microsoft.Win32.SafeHandles;
using System.Diagnostics;
using System.Security;
namespace System.IO.MemoryMappedFiles
{
......@@ -12,7 +11,7 @@ public partial class MemoryMappedFile : IDisposable
{
private readonly SafeMemoryMappedFileHandle _handle;
private readonly bool _leaveOpen;
private readonly FileStream _fileStream;
private readonly FileStream? _fileStream;
internal const int DefaultSize = 0;
// Private constructors to be used by the factory methods.
......@@ -99,17 +98,17 @@ public static MemoryMappedFile CreateFromFile(string path, FileMode mode)
return CreateFromFile(path, mode, null, DefaultSize, MemoryMappedFileAccess.ReadWrite);
}
public static MemoryMappedFile CreateFromFile(string path, FileMode mode, string mapName)
public static MemoryMappedFile CreateFromFile(string path, FileMode mode, string? mapName)
{
return CreateFromFile(path, mode, mapName, DefaultSize, MemoryMappedFileAccess.ReadWrite);
}
public static MemoryMappedFile CreateFromFile(string path, FileMode mode, string mapName, long capacity)
public static MemoryMappedFile CreateFromFile(string path, FileMode mode, string? mapName, long capacity)
{
return CreateFromFile(path, mode, mapName, capacity, MemoryMappedFileAccess.ReadWrite);
}
public static MemoryMappedFile CreateFromFile(string path, FileMode mode, string mapName, long capacity,
public static MemoryMappedFile CreateFromFile(string path, FileMode mode, string? mapName, long capacity,
MemoryMappedFileAccess access)
{
if (path == null)
......@@ -173,7 +172,7 @@ public static MemoryMappedFile CreateFromFile(string path, FileMode mode, string
throw new ArgumentOutOfRangeException(nameof(capacity), SR.ArgumentOutOfRange_CapacityGEFileSizeRequired);
}
SafeMemoryMappedFileHandle handle = null;
SafeMemoryMappedFileHandle? handle = null;
try
{
handle = CreateCore(fileStream, mapName, HandleInheritability.None,
......@@ -190,7 +189,7 @@ public static MemoryMappedFile CreateFromFile(string path, FileMode mode, string
return new MemoryMappedFile(handle, fileStream, false);
}
public static MemoryMappedFile CreateFromFile(FileStream fileStream, string mapName, long capacity,
public static MemoryMappedFile CreateFromFile(FileStream fileStream, string? mapName, long capacity,
MemoryMappedFileAccess access,
HandleInheritability inheritability, bool leaveOpen)
{
......@@ -257,19 +256,19 @@ public static MemoryMappedFile CreateFromFile(string path, FileMode mode, string
// Factory Method Group #3: Creates a new empty memory mapped file. Such memory mapped files are ideal
// for IPC, when mapName != null.
public static MemoryMappedFile CreateNew(string mapName, long capacity)
public static MemoryMappedFile CreateNew(string? mapName, long capacity)
{
return CreateNew(mapName, capacity, MemoryMappedFileAccess.ReadWrite, MemoryMappedFileOptions.None,
HandleInheritability.None);
}
public static MemoryMappedFile CreateNew(string mapName, long capacity, MemoryMappedFileAccess access)
public static MemoryMappedFile CreateNew(string? mapName, long capacity, MemoryMappedFileAccess access)
{
return CreateNew(mapName, capacity, access, MemoryMappedFileOptions.None,
HandleInheritability.None);
}
public static MemoryMappedFile CreateNew(string mapName, long capacity, MemoryMappedFileAccess access,
public static MemoryMappedFile CreateNew(string? mapName, long capacity, MemoryMappedFileAccess access,
MemoryMappedFileOptions options,
HandleInheritability inheritability)
{
......
......@@ -4,8 +4,6 @@
using Microsoft.Win32.SafeHandles;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Security;
namespace System.IO.MemoryMappedFiles
{
......
......@@ -5,9 +5,7 @@
using Microsoft.Win32.SafeHandles;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Security;
using System.Threading;
using System.Threading.Tasks;
namespace System.IO.MemoryMappedFiles
{
......
......@@ -4,7 +4,6 @@
using Microsoft.Win32.SafeHandles;
using System.Diagnostics;
using System.Security;
namespace System.IO.MemoryMappedFiles
{
......
......@@ -4,7 +4,6 @@
using Microsoft.Win32.SafeHandles;
using System.Diagnostics;
using System.Security;
namespace System.IO.MemoryMappedFiles
{
......
......@@ -4,7 +4,6 @@
using Microsoft.Win32.SafeHandles;
using System.Diagnostics;
using System.Security;
namespace System.IO.MemoryMappedFiles
{
......
......@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Diagnostics;
using Microsoft.DotNet.RemoteExecutor;
using Xunit;
......
......@@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Xunit;
......
......@@ -5,7 +5,6 @@
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using Xunit;
namespace System.IO.MemoryMappedFiles.Tests
......
......@@ -7,7 +7,6 @@
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
internal static partial class Interop
{
......
......@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime.InteropServices;
internal static partial class Interop
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册