From 6455328acb5c3984f8672206be48124613e041e6 Mon Sep 17 00:00:00 2001 From: Maryam Ariyan Date: Thu, 7 Jun 2018 12:40:40 -0700 Subject: [PATCH] Moves CurrentSystemTimeZone, ICastable, RegistryView and RegistryValueKind to shared (dotnet/coreclr#18337) * Moves CurrentSystemTimeZone to shared completely * Moves ICastable to shared * Moves RegistryView and RegistryValueKind to shared * Moves ICastableHelpers to its own file Commit migrated from https://github.com/dotnet/coreclr/commit/56fe6435387089b6b219c52096cafd3c277478c6 --- .../System.Private.CoreLib.csproj | 5 +--- .../src/Microsoft/Win32/RegistryKey.cs | 7 ++++- .../src/Microsoft/Win32/RegistryValueKind.cs | 20 ------------- .../src/Microsoft/Win32/RegistryView.cs | 22 -------------- .../src/Microsoft/Win32/Win32Native.cs | 2 -- .../src/System/CurrentSystemTimeZone.Cache.cs | 35 ---------------------- .../Runtime/CompilerServices/ICastableHelpers.cs | 27 +++++++++++++++++ .../Windows/Kernel32/Interop.RegistryValues.cs | 21 +++++++++++++ .../Windows/Kernel32/Interop.RegistryView.cs | 15 ++++++++++ .../src/Microsoft/Win32/RegistryValueKind.cs | 24 +++++++++++++++ .../src/Microsoft/Win32/RegistryView.cs | 20 +++++++++++++ .../src/System.Private.CoreLib.Shared.projitems | 7 ++++- .../src/System/CurrentSystemTimeZone.cs | 28 ++++++++++++++--- .../System/Runtime/CompilerServices/ICastable.cs | 31 ++++--------------- 14 files changed, 149 insertions(+), 115 deletions(-) delete mode 100644 src/coreclr/src/System.Private.CoreLib/src/Microsoft/Win32/RegistryValueKind.cs delete mode 100644 src/coreclr/src/System.Private.CoreLib/src/Microsoft/Win32/RegistryView.cs delete mode 100644 src/coreclr/src/System.Private.CoreLib/src/System/CurrentSystemTimeZone.Cache.cs create mode 100644 src/coreclr/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/ICastableHelpers.cs create mode 100644 src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.RegistryValues.cs create mode 100644 src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.RegistryView.cs create mode 100644 src/libraries/System.Private.CoreLib/src/Microsoft/Win32/RegistryValueKind.cs create mode 100644 src/libraries/System.Private.CoreLib/src/Microsoft/Win32/RegistryView.cs rename src/{coreclr/src => libraries}/System.Private.CoreLib/src/System/Runtime/CompilerServices/ICastable.cs (77%) diff --git a/src/coreclr/src/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/coreclr/src/System.Private.CoreLib/System.Private.CoreLib.csproj index a6536c0..dd29c08 100644 --- a/src/coreclr/src/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/coreclr/src/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -118,10 +118,10 @@ + - @@ -310,7 +310,6 @@ - @@ -541,8 +540,6 @@ - - diff --git a/src/coreclr/src/System.Private.CoreLib/src/Microsoft/Win32/RegistryKey.cs b/src/coreclr/src/System.Private.CoreLib/src/Microsoft/Win32/RegistryKey.cs index 1df495e..f861e5f 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/Microsoft/Win32/RegistryKey.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/Microsoft/Win32/RegistryKey.cs @@ -1121,7 +1121,12 @@ namespace Microsoft.Win32 } [Flags] - internal enum RegistryValueOptions +#if REGISTRY_ASSEMBLY + public +#else + internal +#endif + enum RegistryValueOptions { None = 0, DoNotExpandEnvironmentNames = 1 diff --git a/src/coreclr/src/System.Private.CoreLib/src/Microsoft/Win32/RegistryValueKind.cs b/src/coreclr/src/System.Private.CoreLib/src/Microsoft/Win32/RegistryValueKind.cs deleted file mode 100644 index 6e2a4f3..0000000 --- a/src/coreclr/src/System.Private.CoreLib/src/Microsoft/Win32/RegistryValueKind.cs +++ /dev/null @@ -1,20 +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 Microsoft.Win32 -{ - internal enum RegistryValueKind - { - String = Win32Native.REG_SZ, - ExpandString = Win32Native.REG_EXPAND_SZ, - Binary = Win32Native.REG_BINARY, - DWord = Win32Native.REG_DWORD, - MultiString = Win32Native.REG_MULTI_SZ, - QWord = Win32Native.REG_QWORD, - Unknown = 0, // REG_NONE is defined as zero but BCL - None = unchecked((int)0xFFFFFFFF), // mistakingly overrode this value. - } // Now instead of using Win32Native.REG_NONE we use "-1" and play games internally. -} - diff --git a/src/coreclr/src/System.Private.CoreLib/src/Microsoft/Win32/RegistryView.cs b/src/coreclr/src/System.Private.CoreLib/src/Microsoft/Win32/RegistryView.cs deleted file mode 100644 index e415865..0000000 --- a/src/coreclr/src/System.Private.CoreLib/src/Microsoft/Win32/RegistryView.cs +++ /dev/null @@ -1,22 +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. - -// -// -// -// Implements Microsoft.Win32.RegistryView -// -// ====================================================================================== - -using System; - -namespace Microsoft.Win32 -{ - internal enum RegistryView - { - Default = 0, // 0x0000 operate on the default registry view - Registry64 = Win32Native.KEY_WOW64_64KEY, // 0x0100 operate on the 64-bit registry view - Registry32 = Win32Native.KEY_WOW64_32KEY, // 0x0200 operate on the 32-bit registry view - }; -} diff --git a/src/coreclr/src/System.Private.CoreLib/src/Microsoft/Win32/Win32Native.cs b/src/coreclr/src/System.Private.CoreLib/src/Microsoft/Win32/Win32Native.cs index 3545328..9a2678f 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/Microsoft/Win32/Win32Native.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/Microsoft/Win32/Win32Native.cs @@ -130,8 +130,6 @@ namespace Microsoft.Win32 KEY_CREATE_SUB_KEY) & (~SYNCHRONIZE)); - internal const int KEY_WOW64_64KEY = 0x0100; // - internal const int KEY_WOW64_32KEY = 0x0200; // internal const int REG_OPTION_NON_VOLATILE = 0x0000; // (default) keys are persisted beyond reboot/unload internal const int REG_OPTION_VOLATILE = 0x0001; // All keys created by the function are volatile internal const int REG_OPTION_CREATE_LINK = 0x0002; // They key is a symbolic link diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/CurrentSystemTimeZone.Cache.cs b/src/coreclr/src/System.Private.CoreLib/src/System/CurrentSystemTimeZone.Cache.cs deleted file mode 100644 index 744c697..0000000 --- a/src/coreclr/src/System.Private.CoreLib/src/System/CurrentSystemTimeZone.Cache.cs +++ /dev/null @@ -1,35 +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 System.Collections; -using System.Globalization; - -namespace System -{ - internal partial class CurrentSystemTimeZone - { - private DaylightTime GetCachedDaylightChanges(int year) - { - Object objYear = (Object)year; - - if (!m_CachedDaylightChanges.Contains(objYear)) - { - DaylightTime currentDaylightChanges = CreateDaylightChanges(year); - lock (m_CachedDaylightChanges) - { - if (!m_CachedDaylightChanges.Contains(objYear)) - { - m_CachedDaylightChanges.Add(objYear, currentDaylightChanges); - } - } - } - - return (DaylightTime)m_CachedDaylightChanges[objYear]; - } - - // The per-year information is cached in in this instance value. As a result it can - // be cleaned up by CultureInfo.ClearCachedData, which will clear the instance of this object - private readonly Hashtable m_CachedDaylightChanges = new Hashtable(); - } -} diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/ICastableHelpers.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/ICastableHelpers.cs new file mode 100644 index 0000000..9343915 --- /dev/null +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/ICastableHelpers.cs @@ -0,0 +1,27 @@ +// 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 System; + +namespace System.Runtime.CompilerServices +{ + + /// + /// Helpers that allows VM to call into ICastable methods without having to deal with RuntimeTypeHandle. + /// RuntimeTypeHandle is a struct and is always passed in stack in x86, which our VM call helpers don't + /// particularly like. + /// + internal class ICastableHelpers + { + internal static bool IsInstanceOfInterface(ICastable castable, RuntimeType type, out Exception castError) + { + return castable.IsInstanceOfInterface(new RuntimeTypeHandle(type), out castError); + } + + internal static RuntimeType GetImplType(ICastable castable, RuntimeType interfaceType) + { + return castable.GetImplType(new RuntimeTypeHandle(interfaceType)).GetRuntimeType(); + } + } +} \ No newline at end of file diff --git a/src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.RegistryValues.cs b/src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.RegistryValues.cs new file mode 100644 index 0000000..8a4b84d --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.RegistryValues.cs @@ -0,0 +1,21 @@ +// 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 RegistryValues + { + internal const int REG_NONE = 0; // No value type + internal const int REG_SZ = 1; // Unicode nul terminated string + internal const int REG_EXPAND_SZ = 2; // Unicode nul terminated string + // (with environment variable references) + internal const int REG_BINARY = 3; // Free form binary + internal const int REG_DWORD = 4; // 32-bit number + internal const int REG_MULTI_SZ = 7; // Multiple Unicode strings + internal const int REG_QWORD = 11; // 64-bit number + } + } +} diff --git a/src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.RegistryView.cs b/src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.RegistryView.cs new file mode 100644 index 0000000..2e67868 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/Interop/Windows/Kernel32/Interop.RegistryView.cs @@ -0,0 +1,15 @@ +// 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 RegistryView + { + internal const int KEY_WOW64_64KEY = 0x0100; + internal const int KEY_WOW64_32KEY = 0x0200; + } + } +} diff --git a/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/RegistryValueKind.cs b/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/RegistryValueKind.cs new file mode 100644 index 0000000..1d8d561 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/RegistryValueKind.cs @@ -0,0 +1,24 @@ +// 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 Microsoft.Win32 +{ +#if REGISTRY_ASSEMBLY + public +#else + internal +#endif + enum RegistryValueKind + { + String = Interop.Kernel32.RegistryValues.REG_SZ, + ExpandString = Interop.Kernel32.RegistryValues.REG_EXPAND_SZ, + Binary = Interop.Kernel32.RegistryValues.REG_BINARY, + DWord = Interop.Kernel32.RegistryValues.REG_DWORD, + MultiString = Interop.Kernel32.RegistryValues.REG_MULTI_SZ, + QWord = Interop.Kernel32.RegistryValues.REG_QWORD, + Unknown = 0, // REG_NONE is defined as zero but BCL + None = unchecked((int)0xFFFFFFFF), // mistakenly overrode this value. + } // Now instead of using Interop.Kernel32.RegistryValues.REG_NONE we use "-1". +} diff --git a/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/RegistryView.cs b/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/RegistryView.cs new file mode 100644 index 0000000..3cc4a78 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/RegistryView.cs @@ -0,0 +1,20 @@ +// 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 System; + +namespace Microsoft.Win32 +{ +#if REGISTRY_ASSEMBLY + public +#else + internal +#endif + enum RegistryView + { + Default = 0, // 0x0000 operate on the default registry view + Registry64 = Interop.Kernel32.RegistryView.KEY_WOW64_64KEY, // 0x0100 operate on the 64-bit registry view + Registry32 = Interop.Kernel32.RegistryView.KEY_WOW64_32KEY, // 0x0200 operate on the 32-bit registry view + }; +} diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 26dfbd8..98f9d1e 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -413,6 +413,7 @@ + @@ -724,18 +725,20 @@ + + + - @@ -743,6 +746,8 @@ + + diff --git a/src/libraries/System.Private.CoreLib/src/System/CurrentSystemTimeZone.cs b/src/libraries/System.Private.CoreLib/src/System/CurrentSystemTimeZone.cs index bab6a92..8327bd2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/CurrentSystemTimeZone.cs +++ b/src/libraries/System.Private.CoreLib/src/System/CurrentSystemTimeZone.cs @@ -17,12 +17,8 @@ ** ============================================================*/ -using System; -using System.Text; using System.Collections; using System.Globalization; -using System.Runtime.CompilerServices; -using System.Runtime.Versioning; namespace System { @@ -193,5 +189,29 @@ namespace System return new TimeSpan(TimeZone.CalculateUtcOffset(time, GetDaylightChanges(time.Year)).Ticks + m_ticksOffset); } } + + private DaylightTime GetCachedDaylightChanges(int year) + { + Object objYear = (Object)year; + + if (!m_CachedDaylightChanges.Contains(objYear)) + { + DaylightTime currentDaylightChanges = CreateDaylightChanges(year); + lock (m_CachedDaylightChanges) + { + if (!m_CachedDaylightChanges.Contains(objYear)) + { + m_CachedDaylightChanges.Add(objYear, currentDaylightChanges); + } + } + } + + return (DaylightTime)m_CachedDaylightChanges[objYear]; + } + + // The per-year information is cached in in this instance value. As a result it can + // be cleaned up by CultureInfo.ClearCachedData, which will clear the instance of this object + private readonly Hashtable m_CachedDaylightChanges = new Hashtable(); + } // class CurrentSystemTimeZone } diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/ICastable.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/ICastable.cs similarity index 77% rename from src/coreclr/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/ICastable.cs rename to src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/ICastable.cs index e2b76ed..37e7735 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/ICastable.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/ICastable.cs @@ -2,18 +2,15 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. - - -// -// Support for dynamic interface casting. Specifically implementing this interface on a type will allow the -// type to support interfaces (for the purposes of casting and interface dispatch) that do not appear in its -// interface map. -// - using System; namespace System.Runtime.CompilerServices { + /// + /// Support for dynamic interface casting. Specifically implementing this interface on a type will allow the + /// type to support interfaces (for the purposes of casting and interface dispatch) that do not appear in its + /// interface map. + /// public interface ICastable { // This is called if casting this object to the given interface type would otherwise fail. Casting @@ -61,22 +58,4 @@ namespace System.Runtime.CompilerServices // IsInstanceOfInterface. RuntimeTypeHandle GetImplType(RuntimeTypeHandle interfaceType); } - - /// - /// Helpers that allows VM to call into ICastable methods without having to deal with RuntimeTypeHandle. - /// RuntimeTypeHandle is a struct and is always passed in stack in x86, which our VM call helpers don't - /// particularly like. - /// - internal class ICastableHelpers - { - internal static bool IsInstanceOfInterface(ICastable castable, RuntimeType type, out Exception castError) - { - return castable.IsInstanceOfInterface(new RuntimeTypeHandle(type), out castError); - } - - internal static RuntimeType GetImplType(ICastable castable, RuntimeType interfaceType) - { - return castable.GetImplType(new RuntimeTypeHandle(interfaceType)).GetRuntimeType(); - } - } } -- 2.7.4