diff options
author | Jan Kotas <jkotas@microsoft.com> | 2019-04-02 14:41:49 -0700 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2019-04-02 18:17:04 -0700 |
commit | aab338efb65808acc1ff9b7f95bd3dd5f0a6a3be (patch) | |
tree | cc51c8b443c76c096ba0b4e5a85758ef15549a54 /src/System.Private.CoreLib | |
parent | c007aec8171b74858147da283754a0ba85bff750 (diff) | |
download | coreclr-aab338efb65808acc1ff9b7f95bd3dd5f0a6a3be.tar.gz coreclr-aab338efb65808acc1ff9b7f95bd3dd5f0a6a3be.tar.bz2 coreclr-aab338efb65808acc1ff9b7f95bd3dd5f0a6a3be.zip |
Avoid unnecessary SetLastError on PInvokes (dotnet/corefx#36544)
These console PInvokes are used in nearly every app. Omitting unnecessary SetLastError
will save us from generating marshalling stub for them.
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
Diffstat (limited to 'src/System.Private.CoreLib')
4 files changed, 20 insertions, 7 deletions
diff --git a/src/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/System.Private.CoreLib/System.Private.CoreLib.csproj index e75a0fc2e4..e8cb0b8345 100644 --- a/src/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -271,6 +271,7 @@ <Compile Include="$(BclSourcesRoot)\System\ValueType.cs" /> <Compile Include="$(BclSourcesRoot)\System\WeakReference.cs" /> <Compile Include="$(BclSourcesRoot)\System\WeakReferenceOfT.cs" /> + <Compile Include="shared\Interop\Windows\Kernel32\Interop.HandleTypes.cs" /> <Compile Include="shared\Interop\Windows\Kernel32\Interop.GetStdHandle.cs" /> <Compile Include="shared\Interop\Windows\Kernel32\Interop.LocalAlloc.cs" /> <Compile Include="shared\Interop\Windows\Kernel32\Interop.QueryUnbiasedInterruptTime.cs" /> diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetStdHandle.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetStdHandle.cs index 9637ca9716..f2b54c9728 100644 --- a/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetStdHandle.cs +++ b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetStdHandle.cs @@ -9,11 +9,7 @@ internal partial class Interop { internal partial class Kernel32 { - internal const int STD_INPUT_HANDLE = -10; - internal const int STD_OUTPUT_HANDLE = -11; - internal const int STD_ERROR_HANDLE = -12; - - [DllImport(Libraries.Kernel32, SetLastError = true)] - internal static extern IntPtr GetStdHandle(int nStdHandle); + [DllImport(Libraries.Kernel32)] + internal static extern IntPtr GetStdHandle(int nStdHandle); // param is NOT a handle, but it returns one! } } diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.HandleTypes.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.HandleTypes.cs new file mode 100644 index 0000000000..c2096aa62b --- /dev/null +++ b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.HandleTypes.cs @@ -0,0 +1,16 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +internal partial class Interop +{ + internal partial class Kernel32 + { + internal partial class HandleTypes + { + internal const int STD_INPUT_HANDLE = -10; + internal const int STD_OUTPUT_HANDLE = -11; + internal const int STD_ERROR_HANDLE = -12; + } + } +} diff --git a/src/System.Private.CoreLib/src/Internal/Console.cs b/src/System.Private.CoreLib/src/Internal/Console.cs index ecb751f8b3..ecdd0569ac 100644 --- a/src/System.Private.CoreLib/src/Internal/Console.cs +++ b/src/System.Private.CoreLib/src/Internal/Console.cs @@ -16,7 +16,7 @@ namespace Internal public static class Console { private static readonly SafeFileHandle _outputHandle = - new SafeFileHandle(Interop.Kernel32.GetStdHandle(Interop.Kernel32.STD_OUTPUT_HANDLE), ownsHandle: false); + new SafeFileHandle(Interop.Kernel32.GetStdHandle(Interop.Kernel32.HandleTypes.STD_OUTPUT_HANDLE), ownsHandle: false); public static unsafe void Write(string s) { |