From fcf2805fd887857ea727b7dd2658848427daaf9c Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Sun, 6 Jan 2019 08:47:06 -0800 Subject: Delete redundant S.R.InteropServices.PInvokeMap and S.R.InteropServices.PInvokeMarshal (#21831) --- .../System.Private.CoreLib.csproj | 2 -- .../shared/System/Security/SecureString.Unix.cs | 4 +-- .../shared/System/Security/SecureString.Windows.cs | 4 +-- .../src/System/Reflection/Emit/TypeBuilder.cs | 18 +++++----- .../src/System/Runtime/InteropServices/Marshal.cs | 10 ++++++ .../System/Runtime/InteropServices/PInvokeMap.cs | 41 ---------------------- .../Runtime/InteropServices/PInvokeMarshal.cs | 24 ------------- 7 files changed, 23 insertions(+), 80 deletions(-) delete mode 100644 src/System.Private.CoreLib/src/System/Runtime/InteropServices/PInvokeMap.cs delete mode 100644 src/System.Private.CoreLib/src/System/Runtime/InteropServices/PInvokeMarshal.cs diff --git a/src/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/System.Private.CoreLib/System.Private.CoreLib.csproj index bd9d6501ce..9717214e46 100644 --- a/src/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -290,8 +290,6 @@ - - diff --git a/src/System.Private.CoreLib/shared/System/Security/SecureString.Unix.cs b/src/System.Private.CoreLib/shared/System/Security/SecureString.Unix.cs index ad14bcd296..0c44cf3df2 100644 --- a/src/System.Private.CoreLib/shared/System/Security/SecureString.Unix.cs +++ b/src/System.Private.CoreLib/shared/System/Security/SecureString.Unix.cs @@ -147,7 +147,7 @@ namespace System.Security _buffer.AcquirePointer(ref bufferPtr); int resultByteLength = (length + 1) * sizeof(char); - ptr = PInvokeMarshal.AllocBSTR(length); + ptr = Marshal.AllocBSTR(length); Buffer.MemoryCopy(bufferPtr, (byte*)ptr, resultByteLength, length * sizeof(char)); @@ -159,7 +159,7 @@ namespace System.Security if (result == IntPtr.Zero && ptr != IntPtr.Zero) { RuntimeImports.RhZeroMemory(ptr, (UIntPtr)(length * sizeof(char))); - PInvokeMarshal.FreeBSTR(ptr); + Marshal.FreeBSTR(ptr); } if (bufferPtr != null) diff --git a/src/System.Private.CoreLib/shared/System/Security/SecureString.Windows.cs b/src/System.Private.CoreLib/shared/System/Security/SecureString.Windows.cs index a78fbc222c..8174dbfb7f 100644 --- a/src/System.Private.CoreLib/shared/System/Security/SecureString.Windows.cs +++ b/src/System.Private.CoreLib/shared/System/Security/SecureString.Windows.cs @@ -157,7 +157,7 @@ namespace System.Security _buffer.AcquirePointer(ref bufferPtr); int resultByteLength = (length + 1) * sizeof(char); - ptr = PInvokeMarshal.AllocBSTR(length); + ptr = Marshal.AllocBSTR(length); Buffer.MemoryCopy(bufferPtr, (byte*)ptr, resultByteLength, length * sizeof(char)); @@ -171,7 +171,7 @@ namespace System.Security if (result == IntPtr.Zero && ptr != IntPtr.Zero) { RuntimeImports.RhZeroMemory(ptr, (UIntPtr)(length * sizeof(char))); - PInvokeMarshal.FreeBSTR(ptr); + Marshal.FreeBSTR(ptr); } if (bufferPtr != null) diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs index 7b96786a4b..8eba214c08 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs @@ -1496,34 +1496,34 @@ namespace System.Reflection.Emit switch (nativeCallConv) { case CallingConvention.Winapi: - linkFlags = (int)PInvokeMap.CallConvWinapi; + linkFlags = (int)PInvokeAttributes.CallConvWinapi; break; case CallingConvention.Cdecl: - linkFlags = (int)PInvokeMap.CallConvCdecl; + linkFlags = (int)PInvokeAttributes.CallConvCdecl; break; case CallingConvention.StdCall: - linkFlags = (int)PInvokeMap.CallConvStdcall; + linkFlags = (int)PInvokeAttributes.CallConvStdcall; break; case CallingConvention.ThisCall: - linkFlags = (int)PInvokeMap.CallConvThiscall; + linkFlags = (int)PInvokeAttributes.CallConvThiscall; break; case CallingConvention.FastCall: - linkFlags = (int)PInvokeMap.CallConvFastcall; + linkFlags = (int)PInvokeAttributes.CallConvFastcall; break; } switch (nativeCharSet) { case CharSet.None: - linkFlags |= (int)PInvokeMap.CharSetNotSpec; + linkFlags |= (int)PInvokeAttributes.CharSetNotSpec; break; case CharSet.Ansi: - linkFlags |= (int)PInvokeMap.CharSetAnsi; + linkFlags |= (int)PInvokeAttributes.CharSetAnsi; break; case CharSet.Unicode: - linkFlags |= (int)PInvokeMap.CharSetUnicode; + linkFlags |= (int)PInvokeAttributes.CharSetUnicode; break; case CharSet.Auto: - linkFlags |= (int)PInvokeMap.CharSetAuto; + linkFlags |= (int)PInvokeAttributes.CharSetAuto; break; } diff --git a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs index 1ac33e00ba..ff9844e206 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs @@ -1262,6 +1262,16 @@ namespace System.Runtime.InteropServices return pNewMem; } + internal static IntPtr AllocBSTR(int length) + { + IntPtr bstr = Win32Native.SysAllocStringLen(null, length); + if (bstr == IntPtr.Zero) + { + throw new OutOfMemoryException(); + } + return bstr; + } + public static void FreeBSTR(IntPtr ptr) { if (!IsWin32Atom(ptr)) diff --git a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/PInvokeMap.cs b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/PInvokeMap.cs deleted file mode 100644 index c0db0111bc..0000000000 --- a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/PInvokeMap.cs +++ /dev/null @@ -1,41 +0,0 @@ -// 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. - -namespace System.Runtime.InteropServices -{ - /// - /// An enum that defines the PInvoke attributes. These values - /// values are defined in and must match CorHdr.h. - /// - internal enum PInvokeMap - { - NoMangle = 0x0001, // Pinvoke is to use the member name as specified. - CharSetMask = 0x0006, // Heuristic used in data type & name mapping. - CharSetNotSpec = 0x0000, - CharSetAnsi = 0x0002, - CharSetUnicode = 0x0004, - CharSetAuto = 0x0006, - - PinvokeOLE = 0x0020, // Heuristic: pinvoke will return hresult, with return value becoming the retval param. Not relevant for fields. - SupportsLastError = 0x0040, // Information about target function. Not relevant for fields. - - BestFitMask = 0x0030, - BestFitEnabled = 0x0010, - BestFitDisabled = 0x0020, - BestFitUseAsm = 0x0030, - - ThrowOnUnmappableCharMask = 0x3000, - ThrowOnUnmappableCharEnabled = 0x1000, - ThrowOnUnmappableCharDisabled = 0x2000, - ThrowOnUnmappableCharUseAsm = 0x3000, - - // None of the calling convention flags is relevant for fields. - CallConvMask = 0x0700, - CallConvWinapi = 0x0100, // Pinvoke will use native callconv appropriate to target windows platform. - CallConvCdecl = 0x0200, - CallConvStdcall = 0x0300, - CallConvThiscall = 0x0400, // In M9, pinvoke will raise exception. - CallConvFastcall = 0x0500, - } -} diff --git a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/PInvokeMarshal.cs b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/PInvokeMarshal.cs deleted file mode 100644 index 9eb60bdce7..0000000000 --- a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/PInvokeMarshal.cs +++ /dev/null @@ -1,24 +0,0 @@ -// 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. - -using Microsoft.Win32; - -namespace System.Runtime.InteropServices -{ - internal static class PInvokeMarshal - { - public static IntPtr AllocBSTR(int length) - { - IntPtr bstr = Win32Native.SysAllocStringLen(null, length); - if (bstr == IntPtr.Zero) - throw new OutOfMemoryException(); - return bstr; - } - - public static void FreeBSTR(IntPtr ptr) - { - Win32Native.SysFreeString(ptr); - } - } -} -- cgit v1.2.3