diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs index 97b71a989ee9..cc594304715a 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs @@ -230,6 +230,8 @@ internal static unsafe nuint GetRawObjectDataSize(object obj) return rawSize; } + // Returns array element size. + // Callers are required to keep obj alive internal static unsafe ushort GetElementSize(this Array array) { Debug.Assert(ObjectHasComponentSize(array)); diff --git a/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs b/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs index 117a322a5e59..dbcc1ce868f8 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs @@ -140,7 +140,7 @@ internal static unsafe void ConvertFixedToNative(int flags, string strManaged, I // Flags defined in ILFixedCSTRMarshaler::EmitConvertContentsCLRToNative(ILCodeStream* pslILEmit). bool throwOnUnmappableChar = 0 != (flags >> 8); bool bestFit = 0 != (flags & 0xFF); - uint defaultCharUsed = 0; + Interop.BOOL defaultCharUsed = Interop.BOOL.FALSE; int cbWritten; @@ -154,14 +154,14 @@ internal static unsafe void ConvertFixedToNative(int flags, string strManaged, I numChars, buffer, length, - IntPtr.Zero, - throwOnUnmappableChar ? new IntPtr(&defaultCharUsed) : IntPtr.Zero); + null, + throwOnUnmappableChar ? &defaultCharUsed : null); #else cbWritten = Encoding.UTF8.GetBytes(pwzChar, numChars, buffer, length); #endif } - if (defaultCharUsed != 0) + if (defaultCharUsed != Interop.BOOL.FALSE) { throw new ArgumentException(SR.Interop_Marshal_Unmappable_Char); } diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/PInvokeMarshal.Windows.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/PInvokeMarshal.Windows.cs index 458914cfc577..44a66b8f0d3e 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/PInvokeMarshal.Windows.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/PInvokeMarshal.Windows.cs @@ -38,9 +38,8 @@ public static unsafe int ConvertWideCharToMultiByte(char* wideCharStr, int wideC wideCharLen, multiByteStr, multiByteLen, - default(IntPtr), - default(IntPtr) - ); + null, + null); } // Convert a UTF16 string to ANSI byte array using flags @@ -52,17 +51,16 @@ public static unsafe int ConvertWideCharToMultiByte(char* wideCharStr, int wideC bool throwOnUnmappableChar) { uint flags = (bestFit ? 0 : Interop.Kernel32.WC_NO_BEST_FIT_CHARS); - int defaultCharUsed = 0; + Interop.BOOL defaultCharUsed = Interop.BOOL.FALSE; int ret = Interop.Kernel32.WideCharToMultiByte(Interop.Kernel32.CP_ACP, flags, wideCharStr, wideCharLen, multiByteStr, multiByteLen, - default(IntPtr), - throwOnUnmappableChar ? new System.IntPtr(&defaultCharUsed) : default(IntPtr) - ); - if (defaultCharUsed != 0) + null, + throwOnUnmappableChar ? &defaultCharUsed : null); + if (defaultCharUsed != Interop.BOOL.FALSE) { throw new ArgumentException(SR.Interop_Marshal_Unmappable_Char); } @@ -79,9 +77,8 @@ public static unsafe int GetByteCount(char* wStr, int wideStrLen) wideStrLen, default(byte*), 0, - default(IntPtr), - default(IntPtr) - ); + null, + null); } // Return number of charaters encoded in native byte array lpMultiByteStr diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.WideCharToMultiByte.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.WideCharToMultiByte.cs index a41117556240..b45ee7704373 100644 --- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.WideCharToMultiByte.cs +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.WideCharToMultiByte.cs @@ -13,7 +13,7 @@ internal static partial class Kernel32 uint CodePage, uint dwFlags, char* lpWideCharStr, int cchWideChar, byte* lpMultiByteStr, int cbMultiByte, - IntPtr lpDefaultChar, IntPtr lpUsedDefaultChar); + byte* lpDefaultChar, BOOL* lpUsedDefaultChar); internal const uint CP_ACP = 0; internal const uint WC_NO_BEST_FIT_CHARS = 0x00000400; diff --git a/src/libraries/Common/src/System/Text/OSEncoding.Windows.cs b/src/libraries/Common/src/System/Text/OSEncoding.Windows.cs index 076cb19b5813..b1ddcdd903e7 100644 --- a/src/libraries/Common/src/System/Text/OSEncoding.Windows.cs +++ b/src/libraries/Common/src/System/Text/OSEncoding.Windows.cs @@ -235,7 +235,7 @@ public override Decoder GetDecoder() internal static unsafe int WideCharToMultiByte(int codePage, char* pChars, int count, byte* pBytes, int byteCount) { - int result = Interop.Kernel32.WideCharToMultiByte((uint)codePage, 0, pChars, count, pBytes, byteCount, IntPtr.Zero, IntPtr.Zero); + int result = Interop.Kernel32.WideCharToMultiByte((uint)codePage, 0, pChars, count, pBytes, byteCount, null, null); if (result <= 0) throw new ArgumentException(SR.Argument_InvalidCharSequenceNoIndex); return result; diff --git a/src/libraries/System.Private.CoreLib/src/Internal/Console.Windows.cs b/src/libraries/System.Private.CoreLib/src/Internal/Console.Windows.cs index 84dc329a22a3..3017d11cf82d 100644 --- a/src/libraries/System.Private.CoreLib/src/Internal/Console.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/Internal/Console.Windows.cs @@ -32,7 +32,7 @@ private static unsafe void WriteCore(IntPtr handle, string s) { cbytes = Interop.Kernel32.WideCharToMultiByte( Interop.Kernel32.GetConsoleOutputCP(), - 0, pChars, s.Length, pBytes, bytes.Length, IntPtr.Zero, IntPtr.Zero); + 0, pChars, s.Length, pBytes, bytes.Length, null, null); } fixed (byte* pBytes = bytes) diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Windows.cs index 575404c2d6b1..1ea992b0a7f2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.Windows.cs @@ -56,7 +56,7 @@ internal static unsafe int StringToAnsiString(string s, byte* buffer, int buffer int nb; uint flags = bestFit ? 0 : Interop.Kernel32.WC_NO_BEST_FIT_CHARS; - uint defaultCharUsed = 0; + Interop.BOOL defaultCharUsed = Interop.BOOL.FALSE; fixed (char* pwzChar = s) { @@ -67,11 +67,11 @@ internal static unsafe int StringToAnsiString(string s, byte* buffer, int buffer s.Length, buffer, bufferLength, - IntPtr.Zero, - throwOnUnmappableChar ? new IntPtr(&defaultCharUsed) : IntPtr.Zero); + null, + throwOnUnmappableChar ? &defaultCharUsed : null); } - if (defaultCharUsed != 0) + if (defaultCharUsed != Interop.BOOL.FALSE) { throw new ArgumentException(SR.Interop_Marshal_Unmappable_Char); } @@ -94,7 +94,7 @@ internal static unsafe int GetAnsiStringByteCount(ReadOnlySpan chars) fixed (char* pChars = chars) { byteLength = Interop.Kernel32.WideCharToMultiByte( - Interop.Kernel32.CP_ACP, Interop.Kernel32.WC_NO_BEST_FIT_CHARS, pChars, chars.Length, null, 0, IntPtr.Zero, IntPtr.Zero); + Interop.Kernel32.CP_ACP, Interop.Kernel32.WC_NO_BEST_FIT_CHARS, pChars, chars.Length, null, 0, null, null); if (byteLength <= 0) throw new ArgumentException(); } @@ -118,7 +118,7 @@ internal static unsafe void GetAnsiStringBytes(ReadOnlySpan chars, Span