From: Krzysztof Wicher Date: Fri, 12 Apr 2019 13:42:31 +0000 (-0700) Subject: Nullable: Globalization native interop + some missing files (dotnet/coreclr#23914) X-Git-Tag: submit/tizen/20210909.063632~11030^2~1801^2~14 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b40c5b0141ffcc70cb30ddf05b88e982ad181ad3;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Nullable: Globalization native interop + some missing files (dotnet/coreclr#23914) * Nullable: globalization native + some missing files * address feedback Commit migrated from https://github.com/dotnet/coreclr/commit/bc69ecd0169b49b7e40f64a42551176191086c6c --- diff --git a/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Calendar.cs b/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Calendar.cs index 764bdaf..c5ec71a7 100644 --- a/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Calendar.cs +++ b/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Calendar.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System; using System.Globalization; using System.Runtime.InteropServices; diff --git a/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Casing.cs b/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Casing.cs index 503a864..2878161 100644 --- a/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Casing.cs +++ b/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Casing.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System; using System.Runtime.InteropServices; using System.Security; diff --git a/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Collation.cs b/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Collation.cs index aea7615..9d21d23 100644 --- a/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Collation.cs +++ b/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Collation.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System; using System.Globalization; using System.Runtime.InteropServices; diff --git a/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.ICU.cs b/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.ICU.cs index a16c813..f122d51 100644 --- a/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.ICU.cs +++ b/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.ICU.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; diff --git a/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Idna.cs b/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Idna.cs index 89b6c3c..9a0cd92 100644 --- a/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Idna.cs +++ b/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Idna.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System; using System.Runtime.InteropServices; diff --git a/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Locale.cs b/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Locale.cs index 417b71e..40de099 100644 --- a/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Locale.cs +++ b/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Locale.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System; using System.Runtime.InteropServices; @@ -34,6 +35,6 @@ internal static partial class Interop internal static extern bool GetLocaleInfoGroupingSizes(string localeName, uint localeGroupingData, ref int primaryGroupSize, ref int secondaryGroupSize); [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocales")] - internal static extern int GetLocales([Out] char[] value, int valueLength); + internal static extern int GetLocales([Out] char[]? value, int valueLength); } } diff --git a/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Normalization.cs b/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Normalization.cs index d442da0..2cfc374 100644 --- a/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Normalization.cs +++ b/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Normalization.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System; using System.Runtime.InteropServices; using System.Text; diff --git a/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.ResultCode.cs b/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.ResultCode.cs index 4a9933f..d5261ac 100644 --- a/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.ResultCode.cs +++ b/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.ResultCode.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable internal static partial class Interop { internal static partial class Globalization diff --git a/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.TimeZoneInfo.cs b/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.TimeZoneInfo.cs index 6c69268..583599f 100644 --- a/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.TimeZoneInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.TimeZoneInfo.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System.Runtime.InteropServices; using System.Text; diff --git a/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Utils.cs b/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Utils.cs index 9698be9..058f07e 100644 --- a/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Utils.cs +++ b/src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Utils.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System; using System.Diagnostics; using System.Buffers; @@ -17,7 +18,7 @@ internal static partial class Interop internal static bool CallStringMethod( SpanFunc interopCall, TArg1 arg1, TArg2 arg2, TArg3 arg3, - out string result) + out string? result) { const int InitialSize = 256; // arbitrary stack allocation size const int MaxHeapSize = 1280; // max from previous version of the code, starting at 80 and doubling four times diff --git a/src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.FILE_INFO_BY_HANDLE_CLASS.cs b/src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.FILE_INFO_BY_HANDLE_CLASS.cs index e31a453..c619115 100644 --- a/src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.FILE_INFO_BY_HANDLE_CLASS.cs +++ b/src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.FILE_INFO_BY_HANDLE_CLASS.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using Microsoft.Win32.SafeHandles; using System; using System.Runtime.InteropServices; diff --git a/src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.GetCurrentThreadId.cs b/src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.GetCurrentThreadId.cs index d456db7..0599f4c 100644 --- a/src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.GetCurrentThreadId.cs +++ b/src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.GetCurrentThreadId.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System; using System.Runtime.InteropServices; diff --git a/src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.Globalization.cs b/src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.Globalization.cs index 1797cec..1312454 100644 --- a/src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.Globalization.cs +++ b/src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.Globalization.cs @@ -120,10 +120,10 @@ internal static partial class Interop internal delegate BOOL EnumTimeFormatsProcEx(char* lpTimeFormatString, void* lParam); [DllImport("kernel32.dll", CharSet = CharSet.Unicode)] - internal static extern int GetCalendarInfoEx(string lpLocaleName, uint Calendar, IntPtr lpReserved, uint CalType, IntPtr lpCalData, int cchData, out int lpValue); + internal static extern int GetCalendarInfoEx(string? lpLocaleName, uint Calendar, IntPtr lpReserved, uint CalType, IntPtr lpCalData, int cchData, out int lpValue); [DllImport("kernel32.dll", CharSet = CharSet.Unicode)] - internal static extern int GetCalendarInfoEx(string lpLocaleName, uint Calendar, IntPtr lpReserved, uint CalType, IntPtr lpCalData, int cchData, IntPtr lpValue); + internal static extern int GetCalendarInfoEx(string? lpLocaleName, uint Calendar, IntPtr lpReserved, uint CalType, IntPtr lpCalData, int cchData, IntPtr lpValue); [DllImport("kernel32.dll", CharSet = CharSet.Unicode)] internal static extern bool EnumCalendarInfoExEx(EnumCalendarInfoProcExEx pCalInfoEnumProcExEx, string lpLocaleName, uint Calendar, string? lpReserved, uint CalType, void* lParam); diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Unix.cs index e57e0c5..80e3853 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Unix.cs @@ -108,7 +108,7 @@ namespace System.Globalization // PAL Layer ends here - private static unsafe bool GetCalendarInfo(string localeName, CalendarId calendarId, CalendarDataType dataType, out string calendarString) + private static unsafe bool GetCalendarInfo(string localeName, CalendarId calendarId, CalendarDataType dataType, out string? calendarString) { Debug.Assert(!GlobalizationMode.Invariant); diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Windows.cs index 403e0e3..84e4ddf 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Windows.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable using System; using System.Diagnostics; using System.Runtime.InteropServices; @@ -56,11 +57,11 @@ namespace System.Globalization // String Arrays // Formats - ret &= CallEnumCalendarInfo(localeName, calendarId, CAL_SSHORTDATE, LOCALE_SSHORTDATE | useOverrides, out this.saShortDates); - ret &= CallEnumCalendarInfo(localeName, calendarId, CAL_SLONGDATE, LOCALE_SLONGDATE | useOverrides, out this.saLongDates); + ret &= CallEnumCalendarInfo(localeName, calendarId, CAL_SSHORTDATE, LOCALE_SSHORTDATE | useOverrides, out this.saShortDates!); + ret &= CallEnumCalendarInfo(localeName, calendarId, CAL_SLONGDATE, LOCALE_SLONGDATE | useOverrides, out this.saLongDates!); // Get the YearMonth pattern. - ret &= CallEnumCalendarInfo(localeName, calendarId, CAL_SYEARMONTH, LOCALE_SYEARMONTH, out this.saYearMonths); + ret &= CallEnumCalendarInfo(localeName, calendarId, CAL_SYEARMONTH, LOCALE_SYEARMONTH, out this.saYearMonths!); // Day & Month Names // These are all single calType entries, 1 per day, so we have to make 7 or 13 calls to collect all the names @@ -90,8 +91,8 @@ namespace System.Globalization // Calendar Parts Names // This doesn't get always get localized names for gregorian (not available in windows < 7) // so: eg: coreclr on win < 7 won't get these - CallEnumCalendarInfo(localeName, calendarId, CAL_SERASTRING, 0, out this.saEraNames); - CallEnumCalendarInfo(localeName, calendarId, CAL_SABBREVERASTRING, 0, out this.saAbbrevEraNames); + CallEnumCalendarInfo(localeName, calendarId, CAL_SERASTRING, 0, out this.saEraNames!); + CallEnumCalendarInfo(localeName, calendarId, CAL_SABBREVERASTRING, 0, out this.saAbbrevEraNames!); // // Calendar Era Info @@ -100,10 +101,10 @@ namespace System.Globalization // // Clean up the escaping of the formats - this.saShortDates = CultureData.ReescapeWin32Strings(this.saShortDates); - this.saLongDates = CultureData.ReescapeWin32Strings(this.saLongDates); - this.saYearMonths = CultureData.ReescapeWin32Strings(this.saYearMonths); - this.sMonthDay = CultureData.ReescapeWin32String(this.sMonthDay); + this.saShortDates = CultureData.ReescapeWin32Strings(this.saShortDates)!; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761 + this.saLongDates = CultureData.ReescapeWin32Strings(this.saLongDates)!; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761 + this.saYearMonths = CultureData.ReescapeWin32Strings(this.saYearMonths)!; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761 + this.sMonthDay = CultureData.ReescapeWin32String(this.sMonthDay)!; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761 return ret; } @@ -247,7 +248,7 @@ namespace System.Globalization } } - private static bool CallGetCalendarInfoEx(string localeName, CalendarId calendar, uint calType, out int data) + private static bool CallGetCalendarInfoEx(string? localeName, CalendarId calendar, uint calType, out int data) { return (Interop.Kernel32.GetCalendarInfoEx(localeName, (uint)calendar, IntPtr.Zero, calType | CAL_RETURN_NUMBER, IntPtr.Zero, 0, out data) != 0); } @@ -276,8 +277,8 @@ namespace System.Globalization // Context for EnumCalendarInfoExEx callback. private struct EnumData { - public string userOverride; - public List strings; + public string? userOverride; + public List? strings; } // EnumCalendarInfoExEx callback itself. @@ -291,7 +292,10 @@ namespace System.Globalization // If we had a user override, check to make sure this differs if (context.userOverride != calendarInfo) + { + Debug.Assert(context.strings != null); context.strings.Add(calendarInfo); + } return Interop.BOOL.TRUE; } @@ -301,7 +305,7 @@ namespace System.Globalization } } - private static unsafe bool CallEnumCalendarInfo(string localeName, CalendarId calendar, uint calType, uint lcType, out string[] data) + private static unsafe bool CallEnumCalendarInfo(string localeName, CalendarId calendar, uint calType, uint lcType, out string[]? data) { EnumData context = new EnumData(); context.userOverride = null; @@ -319,7 +323,7 @@ namespace System.Globalization if (userCalendar == calendar) { // They matched, get the user override since locale & calendar match - string res = CultureData.GetLocaleInfoEx(localeName, lcType); + string? res = CultureData.GetLocaleInfoEx(localeName, lcType); // if it succeeded remember the override for the later callers if (res != null) @@ -340,6 +344,7 @@ namespace System.Globalization } // Now we have a list of data, fail if we didn't find anything. + Debug.Assert(context.strings != null); if (context.strings.Count == 0) { data = null; diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Windows.cs index f27b97e..f92f119 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Windows.cs @@ -431,8 +431,7 @@ namespace System.Globalization { for (int i = 0; i < array.Length; i++) { - // only returns null when null is passed - array[i] = ReescapeWin32String(array[i])!; + array[i] = ReescapeWin32String(array[i])!; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761 } } diff --git a/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.cs index 78c6894..0e831d1 100644 --- a/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.cs @@ -115,7 +115,7 @@ namespace System return; } - string timeZoneDisplayName; + string? timeZoneDisplayName; bool result = Interop.CallStringMethod( (buffer, locale, id, type) => {