Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 318d768

Browse files
committed
Merge pull request #2066 from stephentoub/unsafe_tests
Remove <AllowUnsafeBlocks/> from various test projects
2 parents c80e1a9 + 3ae04f6 commit 318d768

File tree

18 files changed

+13
-25
lines changed

18 files changed

+13
-25
lines changed

src/Common/src/Interop/Interop.PlatformDetection.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
using System;
55
using System.Runtime.InteropServices;
66

7-
// TODO: This implementation is temporary until Environment.OSVersion is officially exposed,
8-
// at which point that should be used instead.
7+
// TODO: This implementation is temporary until System.Runtime.InteropServices.RuntimeInformation
8+
// is available, at which point that should be used instead.
99

1010
internal static partial class Interop
1111
{
@@ -39,22 +39,27 @@ internal static class PlatformDetection
3939
{
4040
if (Environment.NewLine != "\r\n")
4141
{
42-
unsafe
42+
IntPtr buffer = Marshal.AllocHGlobal(8192); // the size of the uname struct is platform-specific; this should be large enough for any OS
43+
try
4344
{
44-
byte* buffer = stackalloc byte[8192]; // the size use with uname is platform specific; this should be large enough for any OS
4545
if (uname(buffer) == 0)
4646
{
47-
return Marshal.PtrToStringAnsi((IntPtr)buffer) == "Darwin" ?
48-
OperatingSystem.OSX :
49-
OperatingSystem.Linux;
47+
switch (Marshal.PtrToStringAnsi((IntPtr)buffer))
48+
{
49+
case "Darwin":
50+
return OperatingSystem.OSX;
51+
default:
52+
return OperatingSystem.Linux;
53+
}
5054
}
5155
}
56+
finally { Marshal.FreeHGlobal(buffer); }
5257
}
5358
return OperatingSystem.Windows;
5459
});
5560

5661
// not in src\Interop\Unix to avoiding pulling platform-dependent files into all projects
5762
[DllImport("libc")]
58-
private static extern unsafe uint uname(byte* buf);
63+
private static extern uint uname(IntPtr buf);
5964
}
6065
}

src/System.Diagnostics.Contracts/tests/System.Diagnostics.Contracts.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
<ProjectGuid>{0C4E7FF1-54C6-49B7-9700-18F5F3EB8E65}</ProjectGuid>
88
<OutputType>Library</OutputType>
99
<AssemblyName>System.Diagnostics.Contracts.Tests</AssemblyName>
10-
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1110
</PropertyGroup>
1211
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'" />
1312
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'" />

src/System.Diagnostics.FileVersionInfo/tests/System.Diagnostics.FileVersionInfo.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<AssemblyName>System.Diagnostics.FileVersionInfo.Tests</AssemblyName>
1111
<SignAssembly>false</SignAssembly>
12-
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1312
<ProjectGuid>{6DFDB760-CC88-48AE-BD81-C64844EA3CBC}</ProjectGuid>
1413
<NuGetPackageImportStamp>2fda0f27</NuGetPackageImportStamp>
1514
</PropertyGroup>

src/System.Diagnostics.Process/tests/System.Diagnostics.Process.Tests/System.Diagnostics.Process.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<RootNamespace>System.Diagnostics.Process.Tests</RootNamespace>
1010
<AssemblyName>System.Diagnostics.Process.Tests</AssemblyName>
1111
<NuGetPackageImportStamp>b62eec4b</NuGetPackageImportStamp>
12-
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1312
</PropertyGroup>
1413
<!-- Default configurations to help VS understand the configurations -->
1514
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">

src/System.IO.Compression.ZipFile/tests/System.IO.Compression.ZipFile.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
<ProjectGuid>{ED453083-A80F-480C-AD25-5B8618E8A303}</ProjectGuid>
88
<OutputType>Library</OutputType>
99
<AssemblyName>System.IO.Compression.ZipFile.Tests</AssemblyName>
10-
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1110
</PropertyGroup>
1211
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'" />
1312
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'" />

src/System.IO.Compression/tests/System.IO.Compression.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
<ProjectGuid>{BC2E1649-291D-412E-9529-EDDA94FA7AD6}</ProjectGuid>
88
<OutputType>Library</OutputType>
99
<AssemblyName>System.IO.Compression.Tests</AssemblyName>
10-
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1110
</PropertyGroup>
1211
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'" />
1312
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'" />

src/System.IO.FileSystem.Watcher/tests/System.IO.FileSystem.Watcher.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
99
<OutputType>Library</OutputType>
1010
<AssemblyName>System.IO.FileSystem.Watcher.Tests</AssemblyName>
11-
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1211
</PropertyGroup>
1312
<ItemGroup>
1413
<ProjectReference Include="..\src\System.IO.FileSystem.Watcher.csproj">

src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
<ProjectGuid>{57E8F8D4-0766-4CC7-B3F9-B243B81DB6A5}</ProjectGuid>
88
<OutputType>Library</OutputType>
99
<AssemblyName>System.IO.FileSystem.Tests</AssemblyName>
10-
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1110
<TestCategories>InnerLoop;OuterLoop</TestCategories>
1211
</PropertyGroup>
1312
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">

src/System.IO.MemoryMappedFiles/tests/MemoryMappedFile/System.IO.MemoryMappedFiles.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<FileAlignment>512</FileAlignment>
1010
<MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
1111
<ProjectGuid>{9D6F6254-B5A3-40FF-8925-68AA8D1CE933}</ProjectGuid>
12-
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1312
</PropertyGroup>
1413
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1514
<DebugSymbols>true</DebugSymbols>

src/System.IO.MemoryMappedFiles/tests/MemoryMappedViewAccessor/System.IO.MemoryMappedViewAccessor.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
<FileAlignment>512</FileAlignment>
1212
<MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
1313
<ProjectGuid>{F26FBD53-C04A-4FFC-90C9-AA804285A7AD}</ProjectGuid>
14-
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1514
</PropertyGroup>
1615
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1716
<DebugSymbols>true</DebugSymbols>

0 commit comments

Comments
 (0)