Nullable: Globalization native interop + some missing files (dotnet/coreclr#23914)
authorKrzysztof Wicher <mordotymoja@gmail.com>
Fri, 12 Apr 2019 13:42:31 +0000 (06:42 -0700)
committerStephen Toub <stoub@microsoft.com>
Fri, 12 Apr 2019 13:42:31 +0000 (09:42 -0400)
* Nullable: globalization native + some missing files

* address feedback

Commit migrated from https://github.com/dotnet/coreclr/commit/bc69ecd0169b49b7e40f64a42551176191086c6c

17 files changed:
src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Calendar.cs
src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Casing.cs
src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Collation.cs
src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.ICU.cs
src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Idna.cs
src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Locale.cs
src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Normalization.cs
src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.ResultCode.cs
src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.TimeZoneInfo.cs
src/libraries/System.Private.CoreLib/src/Interop/Unix/System.Globalization.Native/Interop.Utils.cs
src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.FILE_INFO_BY_HANDLE_CLASS.cs
src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.GetCurrentThreadId.cs
src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.Globalization.cs
src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Unix.cs
src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Windows.cs
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Windows.cs
src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.cs

index 764bdaf..c5ec71a 100644 (file)
@@ -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;
index 503a864..2878161 100644 (file)
@@ -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;
index aea7615..9d21d23 100644 (file)
@@ -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;
index a16c813..f122d51 100644 (file)
@@ -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;
index 89b6c3c..9a0cd92 100644 (file)
@@ -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;
 
index 417b71e..40de099 100644 (file)
@@ -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);
     }
 }
index d442da0..2cfc374 100644 (file)
@@ -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;
index 4a9933f..d5261ac 100644 (file)
@@ -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
index 6c69268..583599f 100644 (file)
@@ -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;
 
index 9698be9..058f07e 100644 (file)
@@ -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<TArg1, TArg2, TArg3>(
         SpanFunc<char, TArg1, TArg2, TArg3, Interop.Globalization.ResultCode> 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
index e31a453..c619115 100644 (file)
@@ -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;
index d456db7..0599f4c 100644 (file)
@@ -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;
 
index 1797cec..1312454 100644 (file)
@@ -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);
index e57e0c5..80e3853 100644 (file)
@@ -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);
 
index 403e0e3..84e4ddf 100644 (file)
@@ -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<string> strings;
+            public string? userOverride;
+            public List<string>? 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;
index f27b97e..f92f119 100644 (file)
@@ -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
                 }
             }
 
index 78c6894..0e831d1 100644 (file)
@@ -115,7 +115,7 @@ namespace System
                 return;
             }
 
-            string timeZoneDisplayName;
+            string? timeZoneDisplayName;
             bool result = Interop.CallStringMethod(
                 (buffer, locale, id, type) =>
                 {