From 88d3cce1154502f6e1a226134b40b49638683f44 Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Fri, 15 Jan 2021 12:22:10 +0100 Subject: [PATCH 1/4] mark FileStream.Lock and Unlock as unsupported on macOS --- .../System.Private.CoreLib/src/System/IO/FileStream.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/FileStream.cs b/src/libraries/System.Private.CoreLib/src/System/IO/FileStream.cs index 415419f85b4bb..9842cf1329fd4 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/FileStream.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/FileStream.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.Runtime.InteropServices; using System.Runtime.Serialization; +using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; using Microsoft.Win32.SafeHandles; @@ -256,6 +257,7 @@ public FileStream(string path, FileMode mode, FileAccess access, FileShare share [Obsolete("This property has been deprecated. Please use FileStream's SafeFileHandle property instead. https://go.microsoft.com/fwlink/?linkid=14202")] public virtual IntPtr Handle => SafeFileHandle.DangerousGetHandle(); + [UnsupportedOSPlatform("macos")] public virtual void Lock(long position, long length) { if (position < 0 || length < 0) @@ -271,6 +273,7 @@ public virtual void Lock(long position, long length) LockInternal(position, length); } + [UnsupportedOSPlatform("macos")] public virtual void Unlock(long position, long length) { if (position < 0 || length < 0) From f5ad1f3e7e34299bfd44890e9a9205b0f04e5fbb Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Tue, 26 Jan 2021 16:56:38 +0100 Subject: [PATCH 2/4] update ref assembly --- src/libraries/System.Runtime/ref/System.Runtime.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index 061044b871ea4..14d0db34b0b5c 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -7139,6 +7139,7 @@ public override void EndWrite(System.IAsyncResult asyncResult) { } public override void Flush() { } public virtual void Flush(bool flushToDisk) { } public override System.Threading.Tasks.Task FlushAsync(System.Threading.CancellationToken cancellationToken) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatform("macos")] public virtual void Lock(long position, long length) { } public override int Read(byte[] buffer, int offset, int count) { throw null; } public override int Read(System.Span buffer) { throw null; } @@ -7147,6 +7148,7 @@ public virtual void Lock(long position, long length) { } public override int ReadByte() { throw null; } public override long Seek(long offset, System.IO.SeekOrigin origin) { throw null; } public override void SetLength(long value) { } + [System.Runtime.Versioning.UnsupportedOSPlatform("macos")] public virtual void Unlock(long position, long length) { } public override void Write(byte[] buffer, int offset, int count) { } public override void Write(System.ReadOnlySpan buffer) { } From 8dfc82b42846e006dec11e7cbc88abf9986e8fb6 Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Tue, 26 Jan 2021 17:05:32 +0100 Subject: [PATCH 3/4] annotate types derived from FileStream --- .../System.IO.IsolatedStorage/ref/System.IO.IsolatedStorage.cs | 2 ++ .../src/System/IO/IsolatedStorage/IsolatedStorageFileStream.cs | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/libraries/System.IO.IsolatedStorage/ref/System.IO.IsolatedStorage.cs b/src/libraries/System.IO.IsolatedStorage/ref/System.IO.IsolatedStorage.cs index 776534a95f04f..1732e73b42584 100644 --- a/src/libraries/System.IO.IsolatedStorage/ref/System.IO.IsolatedStorage.cs +++ b/src/libraries/System.IO.IsolatedStorage/ref/System.IO.IsolatedStorage.cs @@ -119,6 +119,7 @@ public override void EndWrite(System.IAsyncResult asyncResult) { } public override void Flush() { } public override void Flush(bool flushToDisk) { } public override System.Threading.Tasks.Task FlushAsync(System.Threading.CancellationToken cancellationToken) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatform("macos")] public override void Lock(long position, long length) { } public override int Read(byte[] buffer, int offset, int count) { throw null; } public override int Read(System.Span buffer) { throw null; } @@ -127,6 +128,7 @@ public override void Lock(long position, long length) { } public override int ReadByte() { throw null; } public override long Seek(long offset, System.IO.SeekOrigin origin) { throw null; } public override void SetLength(long value) { } + [System.Runtime.Versioning.UnsupportedOSPlatform("macos")] public override void Unlock(long position, long length) { } public override void Write(byte[] buffer, int offset, int count) { } public override void Write(System.ReadOnlySpan buffer) { } diff --git a/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFileStream.cs b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFileStream.cs index 54f0f83375d44..4b403b196140a 100644 --- a/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFileStream.cs +++ b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFileStream.cs @@ -4,6 +4,7 @@ using Microsoft.Win32.SafeHandles; using System.Threading; using System.Threading.Tasks; +using System.Runtime.Versioning; namespace System.IO.IsolatedStorage { @@ -327,11 +328,13 @@ public override IntPtr Handle get { return _fs.Handle; } } + [UnsupportedOSPlatform("macos")] public override void Unlock(long position, long length) { _fs.Unlock(position, length); } + [UnsupportedOSPlatform("macos")] public override void Lock(long position, long length) { _fs.Lock(position, length); From 6a54dfc44ba3c48972b2adfd2f213e8a5265f7da Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Tue, 26 Jan 2021 18:07:04 +0100 Subject: [PATCH 4/4] annotate VisualBasic parts as wekk --- .../ref/Microsoft.VisualBasic.Core.cs | 7 +++++++ .../VisualBasic/CompilerServices/VB6BinaryFile.vb | 3 +++ .../src/Microsoft/VisualBasic/CompilerServices/VB6File.vb | 7 +++++++ .../VisualBasic/CompilerServices/VB6RandomFile.vb | 3 +++ .../src/Microsoft/VisualBasic/FileSystem.vb | 7 +++++++ 5 files changed, 27 insertions(+) diff --git a/src/libraries/Microsoft.VisualBasic.Core/ref/Microsoft.VisualBasic.Core.cs b/src/libraries/Microsoft.VisualBasic.Core/ref/Microsoft.VisualBasic.Core.cs index e1f95bc2580b5..9f25426ea1ab0 100644 --- a/src/libraries/Microsoft.VisualBasic.Core/ref/Microsoft.VisualBasic.Core.cs +++ b/src/libraries/Microsoft.VisualBasic.Core/ref/Microsoft.VisualBasic.Core.cs @@ -394,12 +394,16 @@ public static void Input(int FileNumber, ref long Value) { } public static void Input(int FileNumber, ref object Value) { } public static void Input(int FileNumber, ref float Value) { } public static void Input(int FileNumber, ref string Value) { } + [System.Runtime.Versioning.UnsupportedOSPlatform("macos")] public static string InputString(int FileNumber, int CharCount) { throw null; } public static void Kill(string PathName) { } public static string LineInput(int FileNumber) { throw null; } public static long Loc(int FileNumber) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatform("macos")] public static void Lock(int FileNumber) { } + [System.Runtime.Versioning.UnsupportedOSPlatform("macos")] public static void Lock(int FileNumber, long Record) { } + [System.Runtime.Versioning.UnsupportedOSPlatform("macos")] public static void Lock(int FileNumber, long FromRecord, long ToRecord) { } public static long LOF(int FileNumber) { throw null; } public static void MkDir(string Path) { } @@ -415,8 +419,11 @@ public static void SetAttr(string PathName, Microsoft.VisualBasic.FileAttribute public static Microsoft.VisualBasic.SpcInfo SPC(short Count) { throw null; } public static Microsoft.VisualBasic.TabInfo TAB() { throw null; } public static Microsoft.VisualBasic.TabInfo TAB(short Column) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatform("macos")] public static void Unlock(int FileNumber) { } + [System.Runtime.Versioning.UnsupportedOSPlatform("macos")] public static void Unlock(int FileNumber, long Record) { } + [System.Runtime.Versioning.UnsupportedOSPlatform("macos")] public static void Unlock(int FileNumber, long FromRecord, long ToRecord) { } public static void Write(int FileNumber, params object[] Output) { } public static void WriteLine(int FileNumber, params object[] Output) { } diff --git a/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/VB6BinaryFile.vb b/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/VB6BinaryFile.vb index 0d21e7fbf6232..298fe844183c6 100644 --- a/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/VB6BinaryFile.vb +++ b/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/VB6BinaryFile.vb @@ -4,6 +4,7 @@ Imports System Imports Microsoft.VisualBasic.CompilerServices.ExceptionUtils Imports Microsoft.VisualBasic.CompilerServices.Utils +Imports System.Runtime.Versioning Namespace Microsoft.VisualBasic.CompilerServices @@ -24,6 +25,7 @@ Namespace Microsoft.VisualBasic.CompilerServices End Sub ' the implementation of Lock in base class VB6RandomFile does not handle m_lRecordLen=-1 + Friend Overloads Overrides Sub Lock(ByVal lStart As Long, ByVal lEnd As Long) If lStart > lEnd Then Throw New ArgumentException(SR.Format(SR.Argument_InvalidValue1, "Start")) @@ -47,6 +49,7 @@ Namespace Microsoft.VisualBasic.CompilerServices End Sub ' see Lock description + Friend Overloads Overrides Sub Unlock(ByVal lStart As Long, ByVal lEnd As Long) If lStart > lEnd Then Throw New ArgumentException(SR.Format(SR.Argument_InvalidValue1, "Start")) diff --git a/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/VB6File.vb b/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/VB6File.vb index c8e02071fe1b8..a1073a5e6eda3 100644 --- a/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/VB6File.vb +++ b/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/VB6File.vb @@ -7,6 +7,7 @@ Imports System.Security Imports System.Globalization Imports System.IO Imports System.Text +Imports System.Runtime.Versioning Imports Microsoft.VisualBasic.CompilerServices.StructUtils Imports Microsoft.VisualBasic.CompilerServices.ExceptionUtils @@ -595,15 +596,18 @@ Namespace Microsoft.VisualBasic.CompilerServices Return m_position End Function + Friend Overridable Overloads Sub Lock() 'Lock the whole file, not just the current size of file, since file could change. m_file.Lock(0, Int32.MaxValue) End Sub + Friend Overridable Overloads Sub Unlock() m_file.Unlock(0, Int32.MaxValue) End Sub + Friend Overridable Overloads Sub Lock(ByVal Record As Long) If m_lRecordLen = -1 Then m_file.Lock((Record - 1), 1) @@ -612,6 +616,7 @@ Namespace Microsoft.VisualBasic.CompilerServices End If End Sub + Friend Overridable Overloads Sub Unlock(ByVal Record As Long) If m_lRecordLen = -1 Then m_file.Unlock((Record - 1), 1) @@ -620,6 +625,7 @@ Namespace Microsoft.VisualBasic.CompilerServices End If End Sub + Friend Overridable Overloads Sub Lock(ByVal RecordStart As Long, ByVal RecordEnd As Long) If m_lRecordLen = -1 Then m_file.Lock((RecordStart - 1), (RecordEnd - RecordStart) + 1) @@ -628,6 +634,7 @@ Namespace Microsoft.VisualBasic.CompilerServices End If End Sub + Friend Overridable Overloads Sub Unlock(ByVal RecordStart As Long, ByVal RecordEnd As Long) If m_lRecordLen = -1 Then m_file.Unlock((RecordStart - 1), (RecordEnd - RecordStart) + 1) diff --git a/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/VB6RandomFile.vb b/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/VB6RandomFile.vb index 47a273e82f546..0829939a4c067 100644 --- a/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/VB6RandomFile.vb +++ b/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/CompilerServices/VB6RandomFile.vb @@ -3,6 +3,7 @@ Imports System Imports System.IO +Imports System.Runtime.Versioning Imports Microsoft.VisualBasic.CompilerServices.ExceptionUtils Imports Microsoft.VisualBasic.CompilerServices.Utils @@ -120,6 +121,7 @@ Namespace Microsoft.VisualBasic.CompilerServices CloseTheFile() End Sub + Friend Overloads Overrides Sub Lock(ByVal lStart As Long, ByVal lEnd As Long) If lStart > lEnd Then Throw New ArgumentException(SR.Format(SR.Argument_InvalidValue1, "Start")) @@ -134,6 +136,7 @@ Namespace Microsoft.VisualBasic.CompilerServices m_file.Lock(lStartByte, lLength) End Sub + Friend Overloads Overrides Sub Unlock(ByVal lStart As Long, ByVal lEnd As Long) If lStart > lEnd Then Throw New ArgumentException(SR.Format(SR.Argument_InvalidValue1, "Start")) diff --git a/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/FileSystem.vb b/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/FileSystem.vb index a1939f1f2c028..24dbdd64d9946 100644 --- a/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/FileSystem.vb +++ b/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/FileSystem.vb @@ -1000,6 +1000,7 @@ Namespace Microsoft.VisualBasic End Try End Sub + Public Function InputString(ByVal FileNumber As Integer, ByVal CharCount As Integer) As String Try Dim oFile As VB6File @@ -1037,31 +1038,37 @@ Namespace Microsoft.VisualBasic Return oFile.LineInput() End Function + Public Sub Lock(ByVal FileNumber As Integer) Dim assem As System.Reflection.Assembly = System.Reflection.Assembly.GetCallingAssembly() GetStream(assem, FileNumber).Lock() End Sub + Public Sub Lock(ByVal FileNumber As Integer, ByVal Record As Long) Dim assem As System.Reflection.Assembly = System.Reflection.Assembly.GetCallingAssembly() GetStream(assem, FileNumber).Lock(Record) End Sub + Public Sub Lock(ByVal FileNumber As Integer, ByVal FromRecord As Long, ByVal ToRecord As Long) Dim assem As System.Reflection.Assembly = System.Reflection.Assembly.GetCallingAssembly() GetStream(assem, FileNumber).Lock(FromRecord, ToRecord) End Sub + Public Sub Unlock(ByVal FileNumber As Integer) Dim assem As System.Reflection.Assembly = System.Reflection.Assembly.GetCallingAssembly() GetStream(assem, FileNumber).Unlock() End Sub + Public Sub Unlock(ByVal FileNumber As Integer, ByVal Record As Long) Dim assem As System.Reflection.Assembly = System.Reflection.Assembly.GetCallingAssembly() GetStream(assem, FileNumber).Unlock(Record) End Sub + Public Sub Unlock(ByVal FileNumber As Integer, ByVal FromRecord As Long, ByVal ToRecord As Long) Dim assem As System.Reflection.Assembly = System.Reflection.Assembly.GetCallingAssembly() GetStream(assem, FileNumber).Unlock(FromRecord, ToRecord)