From: Jan Kotas Date: Wed, 22 Nov 2017 07:27:12 +0000 (-0800) Subject: Move ArraySegment and a few other files to shared CoreLib partition (#15158) X-Git-Tag: accepted/tizen/base/20180629.140029~497 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ff440aaee646319417522c11b34ab4fb668f4894;p=platform%2Fupstream%2Fcoreclr.git Move ArraySegment and a few other files to shared CoreLib partition (#15158) --- diff --git a/src/mscorlib/System.Private.CoreLib.csproj b/src/mscorlib/System.Private.CoreLib.csproj index 6fa4900..443a6bd 100644 --- a/src/mscorlib/System.Private.CoreLib.csproj +++ b/src/mscorlib/System.Private.CoreLib.csproj @@ -306,7 +306,6 @@ - @@ -331,13 +330,11 @@ - - @@ -358,7 +355,6 @@ - @@ -451,14 +447,10 @@ - - - - @@ -609,7 +601,6 @@ - diff --git a/src/mscorlib/shared/Microsoft/Win32/SafeHandles/CriticalHandleZeroOrMinusOneIsInvalid.cs b/src/mscorlib/shared/Microsoft/Win32/SafeHandles/CriticalHandleZeroOrMinusOneIsInvalid.cs index 195e48d..28d0219 100644 --- a/src/mscorlib/shared/Microsoft/Win32/SafeHandles/CriticalHandleZeroOrMinusOneIsInvalid.cs +++ b/src/mscorlib/shared/Microsoft/Win32/SafeHandles/CriticalHandleZeroOrMinusOneIsInvalid.cs @@ -15,6 +15,6 @@ namespace Microsoft.Win32.SafeHandles { } - public override bool IsInvalid => handle.IsNull() || handle == new IntPtr(-1); + public override bool IsInvalid => handle == IntPtr.Zero || handle == new IntPtr(-1); } } diff --git a/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems b/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems index f1eeb04..0c2b677 100644 --- a/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems +++ b/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems @@ -31,6 +31,7 @@ + @@ -114,6 +115,7 @@ + @@ -122,11 +124,13 @@ + + @@ -146,6 +150,7 @@ + @@ -155,6 +160,7 @@ + @@ -216,6 +222,7 @@ + @@ -545,6 +552,7 @@ + @@ -635,6 +643,7 @@ + diff --git a/src/mscorlib/src/System/ArraySegment.cs b/src/mscorlib/shared/System/ArraySegment.cs similarity index 100% rename from src/mscorlib/src/System/ArraySegment.cs rename to src/mscorlib/shared/System/ArraySegment.cs diff --git a/src/mscorlib/shared/System/Empty.cs b/src/mscorlib/shared/System/Empty.cs new file mode 100644 index 0000000..00fab0f --- /dev/null +++ b/src/mscorlib/shared/System/Empty.cs @@ -0,0 +1,25 @@ +// 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 +{ +#if CORERT + public // Needs to be public so that Reflection.Core can see it. +#else + internal +#endif + sealed class Empty + { + private Empty() + { + } + + public static readonly Empty Value = new Empty(); + + public override String ToString() + { + return String.Empty; + } + } +} diff --git a/src/mscorlib/src/System/Globalization/BidiCategory.cs b/src/mscorlib/shared/System/Globalization/BidiCategory.cs similarity index 86% rename from src/mscorlib/src/System/Globalization/BidiCategory.cs rename to src/mscorlib/shared/System/Globalization/BidiCategory.cs index 9d767c6..abe6950 100644 --- a/src/mscorlib/src/System/Globalization/BidiCategory.cs +++ b/src/mscorlib/shared/System/Globalization/BidiCategory.cs @@ -2,14 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -/*============================================================ -** -** -** Purpose: -** -** -============================================================*/ - namespace System.Globalization { internal enum BidiCategory diff --git a/src/mscorlib/src/System/Globalization/CalendarData.Windows.cs b/src/mscorlib/shared/System/Globalization/CalendarData.Windows.cs similarity index 98% rename from src/mscorlib/src/System/Globalization/CalendarData.Windows.cs rename to src/mscorlib/shared/System/Globalization/CalendarData.Windows.cs index 952f63f..ad7d2cb 100644 --- a/src/mscorlib/src/System/Globalization/CalendarData.Windows.cs +++ b/src/mscorlib/shared/System/Globalization/CalendarData.Windows.cs @@ -10,14 +10,6 @@ using System.Collections.Generic; namespace System.Globalization { -#if CORECLR - using IntList = List; - using StringList = List; -#else - using IntList = LowLevelList; - using StringList = LowLevelList; -#endif - internal partial class CalendarData { private bool LoadCalendarDataFromSystem(String localeName, CalendarId calendarId) @@ -140,7 +132,7 @@ namespace System.Globalization EnumCalendarsData data = new EnumCalendarsData(); data.userOverride = 0; - data.calendars = new IntList(); + data.calendars = new List(); // First call GetLocaleInfo if necessary if (useUserOverride) @@ -284,7 +276,7 @@ namespace System.Globalization private class EnumData { public string userOverride; - public StringList strings; + public List strings; } // EnumCalendarInfoExEx callback itself. @@ -312,7 +304,7 @@ namespace System.Globalization { EnumData context = new EnumData(); context.userOverride = null; - context.strings = new StringList(); + context.strings = new List(); // First call GetLocaleInfo if necessary if (((lcType != 0) && ((lcType & CAL_NOUSEROVERRIDE) == 0)) && // Get user locale, see if it matches localeName. @@ -437,7 +429,7 @@ namespace System.Globalization private class EnumCalendarsData { public int userOverride; // user override value (if found) - public IntList calendars; // list of calendars found so far + public List calendars; // list of calendars found so far } // [NativeCallable(CallingConvention = CallingConvention.StdCall)] diff --git a/src/mscorlib/src/System/Globalization/CharUnicodeInfo.cs b/src/mscorlib/shared/System/Globalization/CharUnicodeInfo.cs similarity index 100% rename from src/mscorlib/src/System/Globalization/CharUnicodeInfo.cs rename to src/mscorlib/shared/System/Globalization/CharUnicodeInfo.cs diff --git a/src/mscorlib/src/System/Globalization/IdnMapping.cs b/src/mscorlib/shared/System/Globalization/IdnMapping.cs similarity index 100% rename from src/mscorlib/src/System/Globalization/IdnMapping.cs rename to src/mscorlib/shared/System/Globalization/IdnMapping.cs diff --git a/src/mscorlib/src/System/Globalization/RegionInfo.cs b/src/mscorlib/shared/System/Globalization/RegionInfo.cs similarity index 100% rename from src/mscorlib/src/System/Globalization/RegionInfo.cs rename to src/mscorlib/shared/System/Globalization/RegionInfo.cs diff --git a/src/mscorlib/shared/System/IntPtr.cs b/src/mscorlib/shared/System/IntPtr.cs new file mode 100644 index 0000000..8626b56 --- /dev/null +++ b/src/mscorlib/shared/System/IntPtr.cs @@ -0,0 +1,235 @@ +// 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.Globalization; +using System.Runtime.CompilerServices; +using System.Runtime.Serialization; +using System.Runtime.Versioning; + +#if BIT64 +using nint = System.Int64; +#else +using nint = System.Int32; +#endif + +namespace System +{ + [Serializable] + [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] + public struct IntPtr : IEquatable, ISerializable + { + // WARNING: We allow diagnostic tools to directly inspect this member (_value). + // See https://github.com/dotnet/corert/blob/master/Documentation/design-docs/diagnostics/diagnostics-tools-contract.md for more details. + // Please do not change the type, the name, or the semantic usage of this member without understanding the implication for tools. + // Get in touch with the diagnostics team if you have questions. + unsafe private void* _value; // Do not rename (binary serialization) + + [Intrinsic] + public static readonly IntPtr Zero; + + [Intrinsic] + [NonVersionable] + public unsafe IntPtr(int value) + { + _value = (void*)value; + } + + [Intrinsic] + [NonVersionable] + public unsafe IntPtr(long value) + { +#if BIT64 + _value = (void*)value; +#else + _value = (void*)checked((int)value); +#endif + } + + [CLSCompliant(false)] + [Intrinsic] + [NonVersionable] + public unsafe IntPtr(void* value) + { + _value = value; + } + + private unsafe IntPtr(SerializationInfo info, StreamingContext context) + { + long l = info.GetInt64("value"); + + if (Size == 4 && (l > int.MaxValue || l < int.MinValue)) + throw new ArgumentException(SR.Serialization_InvalidPtrValue); + + _value = (void*)l; + } + + unsafe void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) + { + if (info == null) + throw new ArgumentNullException(nameof(info)); + + info.AddValue("value", ToInt64()); + } + + public unsafe override bool Equals(Object obj) + { + if (obj is IntPtr) + { + return (_value == ((IntPtr)obj)._value); + } + return false; + } + + unsafe bool IEquatable.Equals(IntPtr value) + { + return _value == value._value; + } + + public unsafe override int GetHashCode() + { +#if BIT64 + long l = (long)_value; + return (unchecked((int)l) ^ (int)(l >> 32)); +#else + return unchecked((int)_value); +#endif + } + + [Intrinsic] + [NonVersionable] + public unsafe int ToInt32() + { +#if BIT64 + long l = (long)_value; + return checked((int)l); +#else + return (int)_value; +#endif + } + + [Intrinsic] + [NonVersionable] + public unsafe long ToInt64() + { + return (nint)_value; + } + + [Intrinsic] + [NonVersionable] + public static unsafe explicit operator IntPtr(int value) + { + return new IntPtr(value); + } + + [Intrinsic] + [NonVersionable] + public static unsafe explicit operator IntPtr(long value) + { + return new IntPtr(value); + } + + [CLSCompliant(false)] + [Intrinsic] + [NonVersionable] + public static unsafe explicit operator IntPtr(void* value) + { + return new IntPtr(value); + } + + [CLSCompliant(false)] + [Intrinsic] + [NonVersionable] + public static unsafe explicit operator void* (IntPtr value) + { + return value._value; + } + + [Intrinsic] + [NonVersionable] + public static unsafe explicit operator int(IntPtr value) + { +#if BIT64 + long l = (long)value._value; + return checked((int)l); +#else + return (int)value._value; +#endif + } + + [Intrinsic] + [NonVersionable] + public static unsafe explicit operator long(IntPtr value) + { + return (nint)value._value; + } + + [Intrinsic] + [NonVersionable] + public static unsafe bool operator ==(IntPtr value1, IntPtr value2) + { + return value1._value == value2._value; + } + + [Intrinsic] + [NonVersionable] + public static unsafe bool operator !=(IntPtr value1, IntPtr value2) + { + return value1._value != value2._value; + } + + [NonVersionable] + public static IntPtr Add(IntPtr pointer, int offset) + { + return pointer + offset; + } + + [Intrinsic] + [NonVersionable] + public static unsafe IntPtr operator +(IntPtr pointer, int offset) + { + return new IntPtr((nint)pointer._value + offset); + } + + [NonVersionable] + public static IntPtr Subtract(IntPtr pointer, int offset) + { + return pointer - offset; + } + + [Intrinsic] + [NonVersionable] + public static unsafe IntPtr operator -(IntPtr pointer, int offset) + { + return new IntPtr((nint)pointer._value - offset); + } + + public static int Size + { + [Intrinsic] + [NonVersionable] + get + { + return sizeof(nint); + } + } + + [CLSCompliant(false)] + [Intrinsic] + [NonVersionable] + public unsafe void* ToPointer() + { + return _value; + } + + public unsafe override String ToString() + { + return ((nint)_value).ToString(CultureInfo.InvariantCulture); + } + + public unsafe String ToString(String format) + { + return ((nint)_value).ToString(format, CultureInfo.InvariantCulture); + } + } +} diff --git a/src/mscorlib/shared/System/Threading/Tasks/TaskCanceledException.cs b/src/mscorlib/shared/System/Threading/Tasks/TaskCanceledException.cs index 6f7fc68..a6ec030 100644 --- a/src/mscorlib/shared/System/Threading/Tasks/TaskCanceledException.cs +++ b/src/mscorlib/shared/System/Threading/Tasks/TaskCanceledException.cs @@ -24,7 +24,7 @@ namespace System.Threading.Tasks public class TaskCanceledException : OperationCanceledException { [NonSerialized] - private Task m_canceledTask; // The task which has been canceled. + private readonly Task _canceledTask; // The task which has been canceled. /// /// Initializes a new instance of the class. @@ -61,7 +61,7 @@ namespace System.Threading.Tasks public TaskCanceledException(Task task) : base(SR.TaskCanceledException_ctor_DefaultMessage, task != null ? task.CancellationToken : new CancellationToken()) { - m_canceledTask = task; + _canceledTask = task; } /// @@ -82,9 +82,6 @@ namespace System.Threading.Tasks /// , in which case /// this property will return null. /// - public Task Task - { - get { return m_canceledTask; } - } + public Task Task => _canceledTask; } } diff --git a/src/mscorlib/shared/System/Threading/Tasks/TaskCompletionSource.cs b/src/mscorlib/shared/System/Threading/Tasks/TaskCompletionSource.cs index dc59caf..992e9db 100644 --- a/src/mscorlib/shared/System/Threading/Tasks/TaskCompletionSource.cs +++ b/src/mscorlib/shared/System/Threading/Tasks/TaskCompletionSource.cs @@ -48,14 +48,14 @@ namespace System.Threading.Tasks /// cref="TaskCompletionSource{TResult}"/>. public class TaskCompletionSource { - private readonly Task m_task; + private readonly Task _task; /// /// Creates a . /// public TaskCompletionSource() { - m_task = new Task(); + _task = new Task(); } /// @@ -103,7 +103,7 @@ namespace System.Threading.Tasks /// public TaskCompletionSource(object state, TaskCreationOptions creationOptions) { - m_task = new Task(state, creationOptions); + _task = new Task(state, creationOptions); } @@ -119,10 +119,7 @@ namespace System.Threading.Tasks /// methods (and their "Try" variants) on this instance all result in the relevant state /// transitions on this underlying Task. /// - public Task Task - { - get { return m_task; } - } + public Task Task => _task; /// Spins until the underlying task is completed. /// This should only be called if the task is in the process of being completed by another thread. @@ -130,7 +127,7 @@ namespace System.Threading.Tasks { // Spin wait until the completion is finalized by another thread. var sw = new SpinWait(); - while (!m_task.IsCompleted) + while (!_task.IsCompleted) sw.SpinOnce(); } @@ -156,8 +153,8 @@ namespace System.Threading.Tasks { if (exception == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.exception); - bool rval = m_task.TrySetException(exception); - if (!rval && !m_task.IsCompleted) SpinUntilCompleted(); + bool rval = _task.TrySetException(exception); + if (!rval && !_task.IsCompleted) SpinUntilCompleted(); return rval; } @@ -196,8 +193,8 @@ namespace System.Threading.Tasks if (defensiveCopy.Count == 0) ThrowHelper.ThrowArgumentException(ExceptionResource.TaskCompletionSourceT_TrySetException_NoExceptions, ExceptionArgument.exceptions); - bool rval = m_task.TrySetException(defensiveCopy); - if (!rval && !m_task.IsCompleted) SpinUntilCompleted(); + bool rval = _task.TrySetException(defensiveCopy); + if (!rval && !_task.IsCompleted) SpinUntilCompleted(); return rval; } @@ -274,7 +271,7 @@ namespace System.Threading.Tasks /// The was disposed. public bool TrySetResult(TResult result) { - bool rval = m_task.TrySetResult(result); + bool rval = _task.TrySetResult(result); if (!rval) SpinUntilCompleted(); return rval; } @@ -324,8 +321,8 @@ namespace System.Threading.Tasks // Enables a token to be stored into the canceled task public bool TrySetCanceled(CancellationToken cancellationToken) { - bool rval = m_task.TrySetCanceled(cancellationToken); - if (!rval && !m_task.IsCompleted) SpinUntilCompleted(); + bool rval = _task.TrySetCanceled(cancellationToken); + if (!rval && !_task.IsCompleted) SpinUntilCompleted(); return rval; } diff --git a/src/mscorlib/src/System/UIntPtr.cs b/src/mscorlib/shared/System/UIntPtr.cs similarity index 57% rename from src/mscorlib/src/System/UIntPtr.cs rename to src/mscorlib/shared/System/UIntPtr.cs index d0fe263..d31728b 100644 --- a/src/mscorlib/src/System/UIntPtr.cs +++ b/src/mscorlib/shared/System/UIntPtr.cs @@ -2,50 +2,49 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -/*============================================================ -** -** -** -** Purpose: Platform independent integer -** -** -===========================================================*/ +using System.Globalization; +using System.Runtime.CompilerServices; +using System.Runtime.Serialization; +using System.Runtime.Versioning; + +#if BIT64 +using nuint = System.UInt64; +#else +using nuint = System.UInt32; +#endif namespace System { - using System; - using System.Globalization; - using System.Runtime.Serialization; - using System.Security; - [Serializable] [CLSCompliant(false)] - [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] + [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public struct UIntPtr : IEquatable, ISerializable { unsafe private void* _value; // Do not rename (binary serialization) + [Intrinsic] public static readonly UIntPtr Zero; - - [System.Runtime.Versioning.NonVersionable] + [Intrinsic] + [NonVersionable] public unsafe UIntPtr(uint value) { _value = (void*)value; } - [System.Runtime.Versioning.NonVersionable] + [Intrinsic] + [NonVersionable] public unsafe UIntPtr(ulong value) { #if BIT64 _value = (void*)value; -#else // 32 +#else _value = (void*)checked((uint)value); #endif } - [CLSCompliant(false)] - [System.Runtime.Versioning.NonVersionable] + [Intrinsic] + [NonVersionable] public unsafe UIntPtr(void* value) { _value = value; @@ -55,10 +54,8 @@ namespace System { ulong l = info.GetUInt64("value"); - if (Size == 4 && l > UInt32.MaxValue) - { + if (Size == 4 && l > uint.MaxValue) throw new ArgumentException(SR.Serialization_InvalidPtrValue); - } _value = (void*)l; } @@ -66,9 +63,8 @@ namespace System unsafe void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) - { throw new ArgumentNullException(nameof(info)); - } + info.AddValue("value", (ulong)_value); } @@ -81,9 +77,9 @@ namespace System return false; } - unsafe bool IEquatable.Equals(UIntPtr other) + unsafe bool IEquatable.Equals(UIntPtr value) { - return _value == other._value; + return _value == value._value; } public unsafe override int GetHashCode() @@ -91,144 +87,135 @@ namespace System #if BIT64 ulong l = (ulong)_value; return (unchecked((int)l) ^ (int)(l >> 32)); -#else // 32 +#else return unchecked((int)_value); #endif } - [System.Runtime.Versioning.NonVersionable] + [Intrinsic] + [NonVersionable] public unsafe uint ToUInt32() { #if BIT64 return checked((uint)_value); -#else // 32 +#else return (uint)_value; #endif } - [System.Runtime.Versioning.NonVersionable] + [Intrinsic] + [NonVersionable] public unsafe ulong ToUInt64() { return (ulong)_value; } - public unsafe override String ToString() - { -#if BIT64 - return ((ulong)_value).ToString(CultureInfo.InvariantCulture); -#else // 32 - return ((uint)_value).ToString(CultureInfo.InvariantCulture); -#endif - } - - [System.Runtime.Versioning.NonVersionable] + [Intrinsic] + [NonVersionable] public static explicit operator UIntPtr(uint value) { return new UIntPtr(value); } - [System.Runtime.Versioning.NonVersionable] + [Intrinsic] + [NonVersionable] public static explicit operator UIntPtr(ulong value) { return new UIntPtr(value); } - [System.Runtime.Versioning.NonVersionable] - public unsafe static explicit operator uint(UIntPtr value) + [Intrinsic] + [NonVersionable] + public static unsafe explicit operator UIntPtr(void* value) { -#if BIT64 - return checked((uint)value._value); -#else // 32 - return (uint)value._value; -#endif + return new UIntPtr(value); } - [System.Runtime.Versioning.NonVersionable] - public unsafe static explicit operator ulong(UIntPtr value) + [Intrinsic] + [NonVersionable] + public static unsafe explicit operator void* (UIntPtr value) { - return (ulong)value._value; + return value._value; } - [CLSCompliant(false)] - [System.Runtime.Versioning.NonVersionable] - public static unsafe explicit operator UIntPtr(void* value) + [Intrinsic] + [NonVersionable] + public static unsafe explicit operator uint(UIntPtr value) { - return new UIntPtr(value); +#if BIT64 + return checked((uint)value._value); +#else + return (uint)value._value; +#endif } - [CLSCompliant(false)] - [System.Runtime.Versioning.NonVersionable] - public static unsafe explicit operator void* (UIntPtr value) + [Intrinsic] + [NonVersionable] + public static unsafe explicit operator ulong(UIntPtr value) { - return value._value; + return (ulong)value._value; } - - [System.Runtime.Versioning.NonVersionable] - public unsafe static bool operator ==(UIntPtr value1, UIntPtr value2) + [Intrinsic] + [NonVersionable] + public static unsafe bool operator ==(UIntPtr value1, UIntPtr value2) { return value1._value == value2._value; } - - [System.Runtime.Versioning.NonVersionable] - public unsafe static bool operator !=(UIntPtr value1, UIntPtr value2) + [Intrinsic] + [NonVersionable] + public static unsafe bool operator !=(UIntPtr value1, UIntPtr value2) { return value1._value != value2._value; } - [System.Runtime.Versioning.NonVersionable] + [NonVersionable] public static UIntPtr Add(UIntPtr pointer, int offset) { return pointer + offset; } - [System.Runtime.Versioning.NonVersionable] - public static UIntPtr operator +(UIntPtr pointer, int offset) + [Intrinsic] + [NonVersionable] + public static unsafe UIntPtr operator +(UIntPtr pointer, int offset) { -#if BIT64 - return new UIntPtr(pointer.ToUInt64() + (ulong)offset); -#else // 32 - return new UIntPtr(pointer.ToUInt32() + (uint)offset); -#endif + return new UIntPtr((nuint)pointer._value + (nuint)offset); } - [System.Runtime.Versioning.NonVersionable] + [NonVersionable] public static UIntPtr Subtract(UIntPtr pointer, int offset) { return pointer - offset; } - [System.Runtime.Versioning.NonVersionable] - public static UIntPtr operator -(UIntPtr pointer, int offset) + [Intrinsic] + [NonVersionable] + public static unsafe UIntPtr operator -(UIntPtr pointer, int offset) { -#if BIT64 - return new UIntPtr(pointer.ToUInt64() - (ulong)offset); -#else // 32 - return new UIntPtr(pointer.ToUInt32() - (uint)offset); -#endif + return new UIntPtr((nuint)pointer._value - (nuint)offset); } - public static int Size + public static unsafe int Size { - [System.Runtime.Versioning.NonVersionable] + [Intrinsic] + [NonVersionable] get { -#if BIT64 - return 8; -#else // 32 - return 4; -#endif + return sizeof(nuint); } } - [CLSCompliant(false)] - [System.Runtime.Versioning.NonVersionable] + [Intrinsic] + [NonVersionable] public unsafe void* ToPointer() { return _value; } + + public unsafe override String ToString() + { + return ((nuint)_value).ToString(CultureInfo.InvariantCulture); + } } } - - diff --git a/src/mscorlib/src/System/AppDomain.cs b/src/mscorlib/src/System/AppDomain.cs index 813b2b5..f69e836 100644 --- a/src/mscorlib/src/System/AppDomain.cs +++ b/src/mscorlib/src/System/AppDomain.cs @@ -174,7 +174,7 @@ namespace System { // This should never happen under normal circumstances. However, there ar ways to create an // uninitialized object through remoting, etc. - if (_pDomain.IsNull()) + if (_pDomain == IntPtr.Zero) { throw new InvalidOperationException(SR.Argument_InvalidHandle); } diff --git a/src/mscorlib/src/System/Delegate.cs b/src/mscorlib/src/System/Delegate.cs index 7258614..ddbeb0c 100644 --- a/src/mscorlib/src/System/Delegate.cs +++ b/src/mscorlib/src/System/Delegate.cs @@ -130,9 +130,9 @@ namespace System // It may also happen that the method pointer was not jitted when creating one delegate and jitted in the other // if that's the case the delegates may still be equals but we need to make a more complicated check - if (_methodPtrAux.IsNull()) + if (_methodPtrAux == IntPtr.Zero) { - if (!d._methodPtrAux.IsNull()) + if (d._methodPtrAux != IntPtr.Zero) return false; // different delegate kind // they are both closed over the first arg if (_target != d._target) @@ -141,7 +141,7 @@ namespace System } else { - if (d._methodPtrAux.IsNull()) + if (d._methodPtrAux == IntPtr.Zero) return false; // different delegate kind // Ignore the target as it will be the delegate instance, though it may be a different one @@ -170,12 +170,12 @@ namespace System // in that case the delegate is the same and Equals will return true but GetHashCode returns a // different hashcode which is not true. /* - if (_methodPtrAux.IsNull()) + if (_methodPtrAux == IntPtr.Zero) return unchecked((int)((long)this._methodPtr)); else return unchecked((int)((long)this._methodPtrAux)); */ - if (_methodPtrAux.IsNull()) + if (_methodPtrAux == IntPtr.Zero) return ( _target != null ? RuntimeHelpers.GetHashCode(_target) * 33 : 0) + GetType().GetHashCode(); else return GetType().GetHashCode(); @@ -229,7 +229,7 @@ namespace System bool isStatic = (RuntimeMethodHandle.GetAttributes(method) & MethodAttributes.Static) != (MethodAttributes)0; if (!isStatic) { - if (_methodPtrAux == (IntPtr)0) + if (_methodPtrAux == IntPtr.Zero) { // The target may be of a derived type that doesn't have visibility onto the // target method. We don't want to call RuntimeType.GetMethodBase below with that @@ -679,7 +679,7 @@ namespace System internal virtual Object GetTarget() { - return (_methodPtrAux.IsNull()) ? _target : null; + return (_methodPtrAux == IntPtr.Zero) ? _target : null; } [MethodImplAttribute(MethodImplOptions.InternalCall)] diff --git a/src/mscorlib/src/System/Diagnostics/Stacktrace.cs b/src/mscorlib/src/System/Diagnostics/Stacktrace.cs index 1db7358..cc6f000 100644 --- a/src/mscorlib/src/System/Diagnostics/Stacktrace.cs +++ b/src/mscorlib/src/System/Diagnostics/Stacktrace.cs @@ -171,7 +171,7 @@ namespace System.Diagnostics // and then we fetch the proper MethodBase!! IntPtr mh = rgMethodHandle[i]; - if (mh.IsNull()) + if (mh == IntPtr.Zero) return null; IRuntimeMethodInfo mhReal = RuntimeMethodHandle.GetTypicalMethodDefinition(new RuntimeMethodInfoStub(mh, this)); diff --git a/src/mscorlib/src/System/Empty.cs b/src/mscorlib/src/System/Empty.cs deleted file mode 100644 index ac01fa6..0000000 --- a/src/mscorlib/src/System/Empty.cs +++ /dev/null @@ -1,33 +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. -//////////////////////////////////////////////////////////////////////////////// -// Empty -// This class represents an empty variant -//////////////////////////////////////////////////////////////////////////////// - - -using System; -using System.Runtime.Serialization; - -namespace System -{ - internal sealed class Empty : ISerializable - { - private Empty() - { - } - - public static readonly Empty Value = new Empty(); - - public override String ToString() - { - return String.Empty; - } - - public void GetObjectData(SerializationInfo info, StreamingContext context) - { - throw new PlatformNotSupportedException(); - } - } -} diff --git a/src/mscorlib/src/System/IntPtr.cs b/src/mscorlib/src/System/IntPtr.cs deleted file mode 100644 index 76a8ea9..0000000 --- a/src/mscorlib/src/System/IntPtr.cs +++ /dev/null @@ -1,268 +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. - -/*============================================================ -** -** -** -** Purpose: Platform independent integer -** -** -===========================================================*/ - -namespace System -{ - using System; - using System.Globalization; - using System.Runtime; - using System.Runtime.Serialization; - using System.Runtime.CompilerServices; - using System.Runtime.ConstrainedExecution; - using System.Security; - - [Serializable] - [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] - public struct IntPtr : IEquatable, ISerializable - { - unsafe private void* _value; // The compiler treats void* closest to uint hence explicit casts are required to preserve int behavior. Do not rename (binary serialization) - - public static readonly IntPtr Zero; - - // fast way to compare IntPtr to (IntPtr)0 while IntPtr.Zero doesn't work due to slow statics access - internal unsafe bool IsNull() - { - return (_value == null); - } - - [System.Runtime.Versioning.NonVersionable] - public unsafe IntPtr(int value) - { -#if BIT64 - _value = (void*)(long)value; -#else // !BIT64 (32) - _value = (void *)value; -#endif - } - - [System.Runtime.Versioning.NonVersionable] - public unsafe IntPtr(long value) - { -#if BIT64 - _value = (void*)value; -#else // !BIT64 (32) - _value = (void *)checked((int)value); -#endif - } - - [CLSCompliant(false)] - [System.Runtime.Versioning.NonVersionable] - public unsafe IntPtr(void* value) - { - _value = value; - } - - private unsafe IntPtr(SerializationInfo info, StreamingContext context) - { - long l = info.GetInt64("value"); - - if (Size == 4 && (l > Int32.MaxValue || l < Int32.MinValue)) - { - throw new ArgumentException(SR.Serialization_InvalidPtrValue); - } - - _value = (void*)l; - } - - unsafe void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) - { - if (info == null) - { - throw new ArgumentNullException(nameof(info)); - } -#if BIT64 - info.AddValue("value", (long)(_value)); -#else // !BIT64 (32) - info.AddValue("value", (long)((int)_value)); -#endif - } - - public unsafe override bool Equals(Object obj) - { - if (obj is IntPtr) - { - return (_value == ((IntPtr)obj)._value); - } - return false; - } - - unsafe bool IEquatable.Equals(IntPtr other) - { - return _value == other._value; - } - - public unsafe override int GetHashCode() - { -#if BIT64 - long l = (long)_value; - return (unchecked((int)l) ^ (int)(l >> 32)); -#else // !BIT64 (32) - return unchecked((int)_value); -#endif - } - - [System.Runtime.Versioning.NonVersionable] - public unsafe int ToInt32() - { -#if BIT64 - long l = (long)_value; - return checked((int)l); -#else // !BIT64 (32) - return (int)_value; -#endif - } - - [System.Runtime.Versioning.NonVersionable] - public unsafe long ToInt64() - { -#if BIT64 - return (long)_value; -#else // !BIT64 (32) - return (long)(int)_value; -#endif - } - - public unsafe override String ToString() - { -#if BIT64 - return ((long)_value).ToString(CultureInfo.InvariantCulture); -#else // !BIT64 (32) - return ((int)_value).ToString(CultureInfo.InvariantCulture); -#endif - } - - public unsafe String ToString(String format) - { -#if BIT64 - return ((long)_value).ToString(format, CultureInfo.InvariantCulture); -#else // !BIT64 (32) - return ((int)_value).ToString(format, CultureInfo.InvariantCulture); -#endif - } - - - [System.Runtime.Versioning.NonVersionable] - public static explicit operator IntPtr(int value) - { - return new IntPtr(value); - } - - [System.Runtime.Versioning.NonVersionable] - public static explicit operator IntPtr(long value) - { - return new IntPtr(value); - } - - [CLSCompliant(false), ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)] - [System.Runtime.Versioning.NonVersionable] - public static unsafe explicit operator IntPtr(void* value) - { - return new IntPtr(value); - } - - [CLSCompliant(false)] - [System.Runtime.Versioning.NonVersionable] - public static unsafe explicit operator void* (IntPtr value) - { - return value._value; - } - - [System.Runtime.Versioning.NonVersionable] - public unsafe static explicit operator int(IntPtr value) - { -#if BIT64 - long l = (long)value._value; - return checked((int)l); -#else // !BIT64 (32) - return (int)value._value; -#endif - } - - [System.Runtime.Versioning.NonVersionable] - public unsafe static explicit operator long(IntPtr value) - { -#if BIT64 - return (long)value._value; -#else // !BIT64 (32) - return (long)(int)value._value; -#endif - } - - [System.Runtime.Versioning.NonVersionable] - public unsafe static bool operator ==(IntPtr value1, IntPtr value2) - { - return value1._value == value2._value; - } - - [System.Runtime.Versioning.NonVersionable] - public unsafe static bool operator !=(IntPtr value1, IntPtr value2) - { - return value1._value != value2._value; - } - - [System.Runtime.Versioning.NonVersionable] - public static IntPtr Add(IntPtr pointer, int offset) - { - return pointer + offset; - } - - [System.Runtime.Versioning.NonVersionable] - public static IntPtr operator +(IntPtr pointer, int offset) - { -#if BIT64 - return new IntPtr(pointer.ToInt64() + offset); -#else // !BIT64 (32) - return new IntPtr(pointer.ToInt32() + offset); -#endif - } - - [System.Runtime.Versioning.NonVersionable] - public static IntPtr Subtract(IntPtr pointer, int offset) - { - return pointer - offset; - } - - [System.Runtime.Versioning.NonVersionable] - public static IntPtr operator -(IntPtr pointer, int offset) - { -#if BIT64 - return new IntPtr(pointer.ToInt64() - offset); -#else // !BIT64 (32) - return new IntPtr(pointer.ToInt32() - offset); -#endif - } - - public static int Size - { - [System.Runtime.Versioning.NonVersionable] - get - { -#if BIT64 - return 8; -#else // !BIT64 (32) - return 4; -#endif - } - } - - - [CLSCompliant(false)] - [System.Runtime.Versioning.NonVersionable] - public unsafe void* ToPointer() - { - return _value; - } - } -} - - diff --git a/src/mscorlib/src/System/Reflection/LoaderAllocator.cs b/src/mscorlib/src/System/Reflection/LoaderAllocator.cs index 7a34a15..5447773 100644 --- a/src/mscorlib/src/System/Reflection/LoaderAllocator.cs +++ b/src/mscorlib/src/System/Reflection/LoaderAllocator.cs @@ -38,7 +38,7 @@ namespace System.Reflection ~LoaderAllocatorScout() { - if (m_nativeLoaderAllocator.IsNull()) + if (m_nativeLoaderAllocator == IntPtr.Zero) return; // Assemblies and LoaderAllocators will be cleaned up during AppDomain shutdown in diff --git a/src/mscorlib/src/System/RtType.cs b/src/mscorlib/src/System/RtType.cs index eff9291..9e78e82 100644 --- a/src/mscorlib/src/System/RtType.cs +++ b/src/mscorlib/src/System/RtType.cs @@ -2453,13 +2453,13 @@ namespace System { get { - if (m_cache.IsNull()) + if (m_cache == IntPtr.Zero) { IntPtr newgcHandle = new RuntimeTypeHandle(this).GetGCHandle(GCHandleType.WeakTrackResurrection); - IntPtr gcHandle = Interlocked.CompareExchange(ref m_cache, newgcHandle, (IntPtr)0); + IntPtr gcHandle = Interlocked.CompareExchange(ref m_cache, newgcHandle, IntPtr.Zero); // Leak the handle if the type is collectible. It will be reclaimed when // the type goes away. - if (!gcHandle.IsNull() && !IsCollectible()) + if (gcHandle != IntPtr.Zero && !IsCollectible()) GCHandle.InternalFree(newgcHandle); } diff --git a/src/mscorlib/src/System/Runtime/InteropServices/GcHandle.cs b/src/mscorlib/src/System/Runtime/InteropServices/GcHandle.cs index 9b4670b..fe61af2 100644 --- a/src/mscorlib/src/System/Runtime/InteropServices/GcHandle.cs +++ b/src/mscorlib/src/System/Runtime/InteropServices/GcHandle.cs @@ -145,7 +145,7 @@ namespace System.Runtime.InteropServices } // Determine whether this handle has been allocated or not. - public bool IsAllocated => !m_handle.IsNull(); + public bool IsAllocated => m_handle != IntPtr.Zero; // Used to create a GCHandle from an int. This is intended to // be used with the reverse conversion. @@ -267,14 +267,14 @@ namespace System.Runtime.InteropServices private void ValidateHandle() { // Check if the handle was never initialized or was freed. - if (m_handle.IsNull()) + if (m_handle == IntPtr.Zero) ThrowInvalidOperationException_HandleIsNotInitialized(); } private static void ValidateHandle(IntPtr handle) { // Check if the handle was never initialized or was freed. - if (handle.IsNull()) + if (handle == IntPtr.Zero) ThrowInvalidOperationException_HandleIsNotInitialized(); } diff --git a/src/mscorlib/src/System/RuntimeHandles.cs b/src/mscorlib/src/System/RuntimeHandles.cs index eda28c6..69ee4c2 100644 --- a/src/mscorlib/src/System/RuntimeHandles.cs +++ b/src/mscorlib/src/System/RuntimeHandles.cs @@ -650,7 +650,7 @@ namespace System internal bool IsNullHandle() { - return m_handle.IsNull(); + return m_handle == IntPtr.Zero; } internal IntPtr Value @@ -1016,7 +1016,7 @@ namespace System { internal bool IsNullHandle() { - return m_handle.IsNull(); + return m_handle == IntPtr.Zero; } internal IntPtr Value diff --git a/src/mscorlib/src/System/StubHelpers.cs b/src/mscorlib/src/System/StubHelpers.cs index 888f25c..bf19c7f 100644 --- a/src/mscorlib/src/System/StubHelpers.cs +++ b/src/mscorlib/src/System/StubHelpers.cs @@ -681,9 +681,9 @@ namespace System.StubHelpers } finally { - if (!oldItemsIP.IsNull()) + if (oldItemsIP != IntPtr.Zero) Marshal.Release(oldItemsIP); - if (!newItemsIP.IsNull()) + if (newItemsIP != IntPtr.Zero) Marshal.Release(newItemsIP); } } diff --git a/src/mscorlib/src/System/Threading/Overlapped.cs b/src/mscorlib/src/System/Threading/Overlapped.cs index 2a9f1e2..44fe29c 100644 --- a/src/mscorlib/src/System/Threading/Overlapped.cs +++ b/src/mscorlib/src/System/Threading/Overlapped.cs @@ -150,20 +150,20 @@ namespace System.Threading m_iocbHelper = null; m_overlapped = null; m_userObject = null; - Debug.Assert(m_pinSelf.IsNull(), "OverlappedData has not been freed: m_pinSelf"); - m_pinSelf = (IntPtr)0; - m_userObjectInternal = (IntPtr)0; + Debug.Assert(m_pinSelf == IntPtr.Zero, "OverlappedData has not been freed: m_pinSelf"); + m_pinSelf = IntPtr.Zero; + m_userObjectInternal = IntPtr.Zero; Debug.Assert(m_AppDomainId == 0 || m_AppDomainId == AppDomain.CurrentDomain.Id, "OverlappedData is not in the current domain"); m_AppDomainId = 0; - m_nativeOverlapped.EventHandle = (IntPtr)0; + m_nativeOverlapped.EventHandle = IntPtr.Zero; m_isArray = 0; - m_nativeOverlapped.InternalLow = (IntPtr)0; - m_nativeOverlapped.InternalHigh = (IntPtr)0; + m_nativeOverlapped.InternalLow = IntPtr.Zero; + m_nativeOverlapped.InternalHigh = IntPtr.Zero; } unsafe internal NativeOverlapped* Pack(IOCompletionCallback iocb, Object userData) { - if (!m_pinSelf.IsNull()) + if (m_pinSelf != IntPtr.Zero) { throw new InvalidOperationException(SR.InvalidOperation_Overlapped_Pack); } @@ -195,7 +195,7 @@ namespace System.Threading unsafe internal NativeOverlapped* UnsafePack(IOCompletionCallback iocb, Object userData) { - if (!m_pinSelf.IsNull()) + if (m_pinSelf != IntPtr.Zero) { throw new InvalidOperationException(SR.InvalidOperation_Overlapped_Pack); } diff --git a/src/mscorlib/src/System/Threading/Thread.cs b/src/mscorlib/src/System/Threading/Thread.cs index a57b10f..c9ae3d8 100644 --- a/src/mscorlib/src/System/Threading/Thread.cs +++ b/src/mscorlib/src/System/Threading/Thread.cs @@ -217,7 +217,7 @@ namespace System.Threading // This should never happen under normal circumstances. m_assembly is always assigned before it is handed out to the user. // There are ways how to create an unitialized objects through remoting, etc. Avoid AVing in the EE by throwing a nice // exception here. - if (thread.IsNull()) + if (thread == IntPtr.Zero) throw new ArgumentException(null, SR.Argument_InvalidHandle); return new ThreadHandle(thread); diff --git a/src/mscorlib/src/System/TypedReference.cs b/src/mscorlib/src/System/TypedReference.cs index e29e880..f7c8779 100644 --- a/src/mscorlib/src/System/TypedReference.cs +++ b/src/mscorlib/src/System/TypedReference.cs @@ -97,7 +97,7 @@ namespace System { get { - return Value.IsNull() && Type.IsNull(); + return Value == IntPtr.Zero && Type == IntPtr.Zero; } }