Imported Upstream version 6.0.0.172

Former-commit-id: f3cc9b82f3e5bd8f0fd3ebc098f789556b44e9cd
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2019-04-12 14:10:50 +00:00
parent 8016999e4d
commit 64ac736ec5
32155 changed files with 3981439 additions and 75368 deletions

View File

@@ -1138,7 +1138,7 @@ namespace System.Threading
private void EnterMyLockSpin()
{
int pc = Environment.ProcessorCount;
int pc = PlatformHelper.ProcessorCount;
for (int i = 0; ; i++)
{
if (i < LockSpinCount && pc > 1)
@@ -1172,7 +1172,7 @@ namespace System.Threading
private static void SpinWait(int SpinCount)
{
//Exponential backoff
if ((SpinCount < 5) && (Environment.ProcessorCount > 1))
if ((SpinCount < 5) && (PlatformHelper.ProcessorCount > 1))
{
Thread.SpinWait(LockSpinCycles * SpinCount);
}

View File

@@ -10,11 +10,15 @@ namespace System.Data.Common {
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Globalization;
using System.Xml;
using System.Linq;
using System.Reflection;
public static class DbProviderFactories {
@@ -23,8 +27,10 @@ namespace System.Data.Common {
private const string InvariantName = "InvariantName";
private const string Name = "Name";
private const string Description = "Description";
private const string InstanceFieldName = "Instance";
private static ConcurrentDictionary<string, ProviderRegistration> _registeredFactories = new ConcurrentDictionary<string, ProviderRegistration>();
private static ConnectionState _initState; // closed, connecting, open
private static DataTable _providerTable;
private static object _lockobj = new object();
@@ -250,5 +256,80 @@ namespace System.Data.Common {
}
}
}
#if MONO
public static IEnumerable<string> GetProviderInvariantNames()
{
return _registeredFactories.Keys.ToList();
}
public static void RegisterFactory(string providerInvariantName, string factoryTypeAssemblyQualifiedName)
{
ADP.CheckArgumentLength(providerInvariantName, nameof(providerInvariantName));
ADP.CheckArgumentLength(factoryTypeAssemblyQualifiedName, nameof(factoryTypeAssemblyQualifiedName));
// this method performs a deferred registration: the type name specified is checked when the factory is requested for the first time.
_registeredFactories[providerInvariantName] = new ProviderRegistration(factoryTypeAssemblyQualifiedName, null);
}
private static DbProviderFactory GetFactoryInstance(Type providerFactoryClass)
{
ADP.CheckArgumentNull(providerFactoryClass, nameof(providerFactoryClass));
if (!providerFactoryClass.IsSubclassOf(typeof(DbProviderFactory)))
{
throw ADP.Argument(SR.Format(SR.ADP_DbProviderFactories_NotAFactoryType, providerFactoryClass.FullName));
}
FieldInfo providerInstance = providerFactoryClass.GetField(InstanceFieldName, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Static);
if (null == providerInstance)
{
throw ADP.InvalidOperation(SR.ADP_DbProviderFactories_NoInstance);
}
if (!providerInstance.FieldType.IsSubclassOf(typeof(DbProviderFactory)))
{
throw ADP.InvalidOperation(SR.ADP_DbProviderFactories_NoInstance);
}
object factory = providerInstance.GetValue(null);
if (null == factory)
{
throw ADP.InvalidOperation(SR.ADP_DbProviderFactories_NoInstance);
}
return (DbProviderFactory)factory;
}
public static void RegisterFactory(string providerInvariantName, Type providerFactoryClass)
{
RegisterFactory(providerInvariantName, GetFactoryInstance(providerFactoryClass));
}
public static void RegisterFactory(string providerInvariantName, DbProviderFactory factory)
{
ADP.CheckArgumentLength(providerInvariantName, nameof(providerInvariantName));
ADP.CheckArgumentNull(factory, nameof(factory));
_registeredFactories[providerInvariantName] = new ProviderRegistration(factory.GetType().AssemblyQualifiedName, factory);
}
public static bool UnregisterFactory(string providerInvariantName)
{
return !string.IsNullOrWhiteSpace(providerInvariantName) && _registeredFactories.TryRemove(providerInvariantName, out _);
}
private struct ProviderRegistration
{
internal ProviderRegistration(string factoryTypeAssemblyQualifiedName, DbProviderFactory factoryInstance)
{
this.FactoryTypeAssemblyQualifiedName = factoryTypeAssemblyQualifiedName;
this.FactoryInstance = factoryInstance;
}
internal string FactoryTypeAssemblyQualifiedName { get; }
/// <summary>
/// The cached instance of the type in <see cref="FactoryTypeAssemblyQualifiedName"/>. If null, this registation is seen as a deferred registration
/// and <see cref="FactoryTypeAssemblyQualifiedName"/> is checked the first time when this registration is requested through GetFactory().
/// </summary>
internal DbProviderFactory FactoryInstance { get; }
}
#endif
}
}

View File

@@ -729,48 +729,9 @@ namespace System.Xml {
return s_enableLegacyXmlSettings.Value;
}
bool enableSettings = false; // default value
#if !MOBILE
if (!ReadSettingsFromRegistry(Registry.LocalMachine, ref enableSettings))
{
// still ok if this call return false too as we'll use the default value which is false
ReadSettingsFromRegistry(Registry.CurrentUser, ref enableSettings);
}
#endif
s_enableLegacyXmlSettings = enableSettings;
s_enableLegacyXmlSettings = false;
return s_enableLegacyXmlSettings.Value;
}
#if !MOBILE
[RegistryPermission(SecurityAction.Assert, Unrestricted = true)]
[SecuritySafeCritical]
private static bool ReadSettingsFromRegistry(RegistryKey hive, ref bool value)
{
const string regValueName = "EnableLegacyXmlSettings";
const string regValuePath = @"SOFTWARE\Microsoft\.NETFramework\XML";
try
{
using (RegistryKey xmlRegKey = hive.OpenSubKey(regValuePath, false))
{
if (xmlRegKey != null)
{
if (xmlRegKey.GetValueKind(regValueName) == RegistryValueKind.DWord)
{
value = ((int)xmlRegKey.GetValue(regValueName)) == 1;
return true;
}
}
}
}
catch { /* use the default if we couldn't read the key */ }
return false;
}
#endif // MOBILE
#endif // SILVERLIGHT
}
}

View File

@@ -1473,7 +1473,8 @@ typedef struct _SCHANNEL_CRED
#endif // !FEATURE_PAL
[StructLayout(LayoutKind.Sequential)]
#if false
[StructLayout(LayoutKind.Sequential)]
internal unsafe struct SecurityBufferStruct {
public int count;
public BufferType type;
@@ -1547,6 +1548,7 @@ typedef struct _SCHANNEL_CRED
GlobalLog.Print(" securityBufferArray = 0x" + (new IntPtr(UnmanagedPointer)).ToString("x"));
}
} // SecurityBufferDescriptor
#endif
internal enum CertificateEncoding {
Zero = 0,

View File

@@ -394,16 +394,33 @@ namespace System.Threading
#endif
#if MONO
internal unsafe static IntPtr CreateSemaphore_internal (int initialCount, int maximumCount,
string name, out int errorCode)
{
// FIXME Check for embedded nuls in name.
fixed (char *fixed_name = name)
return CreateSemaphore_icall (initialCount, maximumCount,
fixed_name, name?.Length ?? 0, out errorCode);
}
private unsafe static IntPtr OpenSemaphore_internal (string name, SemaphoreRights rights, out int errorCode)
{
// FIXME Check for embedded nuls in name.
fixed (char *fixed_name = name)
return OpenSemaphore_icall (fixed_name, name?.Length ?? 0, rights, out errorCode);
}
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern IntPtr CreateSemaphore_internal (
int initialCount, int maximumCount, string name, out int errorCode);
private unsafe static extern IntPtr CreateSemaphore_icall (
int initialCount, int maximumCount, char *name, int name_length, out int errorCode);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private unsafe static extern IntPtr OpenSemaphore_icall (char *name, int name_length,
SemaphoreRights rights, out int errorCode);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern bool ReleaseSemaphore_internal (
IntPtr handle, int releaseCount, out int previousCount);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private static extern IntPtr OpenSemaphore_internal (string name, SemaphoreRights rights, out int errorCode);
#endif
}
}

View File

@@ -15,7 +15,9 @@
using System;
using System.Security;
#if !MONO
using System.Security.Permissions;
#endif
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
@@ -36,8 +38,10 @@ namespace Microsoft.Win32.SafeHandles {
}
[System.Security.SecurityCritical]
#if !MONO
[ResourceExposure(ResourceScope.Machine)]
[ResourceConsumption(ResourceScope.Machine)]
#endif
override protected bool ReleaseHandle()
{
#if MONO

View File

@@ -15,6 +15,9 @@ namespace System
public static readonly bool ThrowExceptionIfDisposedCancellationTokenSource = false;
public static readonly bool SetActorAsReferenceWhenCopyingClaimsIdentity = false;
public static readonly bool NoAsyncCurrentCulture = false;
public static readonly bool EnforceJapaneseEraYearRanges = false;
public static readonly bool FormatJapaneseFirstYearAsANumber = false;
public static readonly bool EnforceLegacyJapaneseDateParsing = false;
#else
private static int _noAsyncCurrentCulture;
public static bool NoAsyncCurrentCulture
@@ -26,6 +29,36 @@ namespace System
}
}
// from https://github.com/dotnet/coreclr/pull/18209
private static int _enforceJapaneseEraYearRanges;
public static bool EnforceJapaneseEraYearRanges
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return GetCachedSwitchValue(AppContextDefaultValues.SwitchEnforceJapaneseEraYearRanges, ref _enforceJapaneseEraYearRanges);
}
}
private static int _formatJapaneseFirstYearAsANumber;
public static bool FormatJapaneseFirstYearAsANumber
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return GetCachedSwitchValue(AppContextDefaultValues.SwitchFormatJapaneseFirstYearAsANumber, ref _formatJapaneseFirstYearAsANumber);
}
}
private static int _enforceLegacyJapaneseDateParsing;
public static bool EnforceLegacyJapaneseDateParsing
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return GetCachedSwitchValue(AppContextDefaultValues.SwitchEnforceLegacyJapaneseDateParsing, ref _enforceLegacyJapaneseDateParsing);
}
}
private static int _throwExceptionIfDisposedCancellationTokenSource;
public static bool ThrowExceptionIfDisposedCancellationTokenSource
{

View File

@@ -13,17 +13,19 @@ namespace System {
using System.Globalization;
using System.Diagnostics.Contracts;
using System.Security;
#if !MONO
using System.Security.Permissions;
#endif
[Serializable]
[AttributeUsageAttribute(AttributeTargets.All, Inherited = true, AllowMultiple=false)]
#if !MOBILE
#if !MOBILE && !NETCORE
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(_Attribute))]
[System.Runtime.InteropServices.ComVisible(true)]
#endif
public abstract partial class Attribute
#if !MOBILE
#if !MOBILE && !NETCORE
: _Attribute
#endif
{
@@ -68,7 +70,7 @@ namespace System {
custom_attributes.Add (param_attribute);
}
var base_method = method.GetBaseMethod ();
var base_method = ((RuntimeMethodInfo)method).GetBaseMethod ();
if (base_method == method)
break;
@@ -103,7 +105,7 @@ namespace System {
if (member.MemberType != MemberTypes.Method)
return false;
var method = ((MethodInfo) member).GetBaseMethod ();
var method = ((RuntimeMethodInfo)(MethodInfo) member).GetBaseMethod ();
while (true) {
var parameters = method.GetParametersInternal ();
@@ -113,7 +115,7 @@ namespace System {
if (param.IsDefined (attributeType, false))
return true;
var base_method = method.GetBaseMethod ();
var base_method = ((RuntimeMethodInfo)method).GetBaseMethod ();
if (base_method == method)
break;
@@ -1048,7 +1050,7 @@ namespace System {
public virtual bool IsDefaultAttribute() { return false; }
#endregion
#if !FEATURE_CORECLR && !MOBILE
#if !FEATURE_CORECLR && !MOBILE && !NETCORE
void _Attribute.GetTypeInfoCount(out uint pcTInfo)
{
throw new NotImplementedException();

View File

@@ -34,8 +34,10 @@ namespace System {
// parameter validation has already been done. The count and offset
// parameters here are in bytes. If you want to use traditional
// array element indices and counts, use Array.Copy.
#if !MONO
[System.Security.SecuritySafeCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
#endif
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern bool InternalBlockCopy(Array src, int srcOffsetBytes,
Array dst, int dstOffsetBytes, int byteCount);
@@ -131,8 +133,10 @@ namespace System {
// This essentially does the following:
// return ((byte*)array) + index.
//
#if !MONO
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
#endif
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern byte _GetByte(Array array, int index);
#if !MONO
@@ -160,8 +164,10 @@ namespace System {
// This essentially does the following:
// *(((byte*)array) + index) = value.
//
#if !MONO
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
#endif
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern void _SetByte(Array array, int index, byte value);
#if !MONO
@@ -191,8 +197,10 @@ namespace System {
// This essentially does the following:
// return array.length * sizeof(array.UnderlyingElementType).
//
#if !MONO
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
#endif
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern int _ByteLength(Array array);
#if !MONO

View File

@@ -511,7 +511,8 @@ namespace System {
throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException"));
return candidates[currentMin];
}
#if !MONO
// Given a set of methods that match the base criteria, select a method based
// upon an array of types. This method should return null if no method matchs
// the criteria.
@@ -588,6 +589,7 @@ namespace System {
throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException"));
return candidates[currentMin];
}
#endif
// Given a set of properties that match the base criteria, select one.
[System.Security.SecuritySafeCritical] // auto-generated

View File

@@ -28,7 +28,9 @@
#elif BARTOK_RUNTIME
#else // CLR
#if !MONO
#define FEATURE_UNTRUSTED_CALLERS
#endif
#define FEATURE_RELIABILITY_CONTRACTS
#define FEATURE_SERIALIZATION
#endif

View File

@@ -38,8 +38,10 @@ using System.Runtime.ConstrainedExecution;
#endif
#if FEATURE_UNTRUSTED_CALLERS
using System.Security;
#if !MONO
using System.Security.Permissions;
#endif
#endif
namespace System.Diagnostics.Contracts {
@@ -57,8 +59,10 @@ namespace System.Diagnostics.Contracts {
[SecuritySafeCritical]
static partial void AssertMustUseRewriter(ContractFailureKind kind, String contractKind)
{
#if !NETCORE
if (_assertingMustUseRewriter)
System.Diagnostics.Assert.Fail("Asserting that we must use the rewriter went reentrant.", "Didn't rewrite this mscorlib?");
#endif
_assertingMustUseRewriter = true;
// For better diagnostics, report which assembly is at fault. Walk up stack and

View File

@@ -243,13 +243,17 @@ namespace System
return result;
}
#if !MONO
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
#endif
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern int InternalCompareTo(Object o1, Object o2);
#if !MONO
[System.Security.SecuritySafeCritical]
[ResourceExposure(ResourceScope.None)]
#endif
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern RuntimeType InternalGetUnderlyingType(RuntimeType enumType);
@@ -264,8 +268,10 @@ namespace System
private static extern void GetEnumValuesAndNames(RuntimeTypeHandle enumType, ObjectHandleOnStack values, ObjectHandleOnStack names, bool getNames);
#endif
#if !MONO
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
#endif
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern Object InternalBoxEnum(RuntimeType enumType, long value);
#endregion
@@ -554,13 +560,14 @@ namespace System
// Delegate rest of error checking to the other functions
TypeCode typeCode = Convert.GetTypeCode(value);
#if !MONO
// NetCF doesn't support char and boolean conversion
if (CompatibilitySwitches.IsAppEarlierThanWindowsPhone8 &&
((typeCode == TypeCode.Boolean) || (typeCode == TypeCode.Char)))
{
throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnumBaseTypeOrEnum"), "value");
}
#endif
switch (typeCode)
{
@@ -747,17 +754,19 @@ namespace System
#endif
}
#if !MONO
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
#endif
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern bool InternalHasFlag(Enum flags);
[System.Security.SecuritySafeCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
#if MONO
private extern int get_hashcode ();
#else
[System.Security.SecuritySafeCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
private extern CorElementType InternalGetCorElementType();
#endif
#endregion
@@ -1223,5 +1232,37 @@ namespace System
return InternalBoxEnum(rtType, value ? 1 : 0);
}
#endregion
#if MONO
public static TEnum Parse<TEnum>(string value) where TEnum : struct
{
return Parse<TEnum>(value, false);
}
public static TEnum Parse<TEnum>(string value, bool ignoreCase) where TEnum : struct
{
EnumResult parseResult = new EnumResult() { canThrow = true };
if (TryParseEnum(typeof(TEnum), value, ignoreCase, ref parseResult))
return (TEnum)parseResult.parsedEnum;
else
throw parseResult.GetEnumParseException();
}
public static bool TryParse(Type enumType, String value, bool ignoreCase, out object result)
{
result = null;
EnumResult parseResult = new EnumResult();
bool retValue;
if (retValue = TryParseEnum(enumType, value, ignoreCase, ref parseResult))
result = parseResult.parsedEnum;
return retValue;
}
public static bool TryParse(Type enumType, String value, out object result)
{
return TryParse(enumType, value, false, out result);
}
#endif
}
}

View File

@@ -23,7 +23,9 @@ namespace System {
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Diagnostics;
#if !MONO
using System.Security.Permissions;
#endif
using System.Security;
using System.IO;
using System.Text;
@@ -31,16 +33,21 @@ namespace System {
using System.Collections;
using System.Globalization;
using System.Diagnostics.Contracts;
#if NETCORE
using __HResults = System.HResults;
#endif
#if !MONO
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(_Exception))]
#endif
[Serializable]
[ComVisible(true)]
#if MONO
[StructLayout (LayoutKind.Sequential)]
#endif
public class Exception : ISerializable
#if !(MONO && MOBILE)
public partial class Exception : ISerializable
#if !MOBILE && !NETCORE
, _Exception
#endif
{
@@ -162,12 +169,15 @@ namespace System {
public virtual IDictionary Data {
[System.Security.SecuritySafeCritical] // auto-generated
get {
if (_data == null)
if (_data == null) {
#if !MONO
if (IsImmutableAgileException(this))
_data = new EmptyReadOnlyDictionaryInternal();
else
#endif
_data = new ListDictionaryInternal();
}
return _data;
}
}
@@ -210,7 +220,9 @@ namespace System {
}
}
#if !MONO
[FriendAccessAllowed]
#endif
internal void AddExceptionDataForRestrictedErrorInfo(
string restrictedError,
string restrictedErrorReference,
@@ -390,8 +402,10 @@ namespace System {
String tempStackTraceString = Environment.GetStackTrace(this, needFileInfo);
return remoteStackTraceString + tempStackTraceString;
}
#if !MONO
[FriendAccessAllowed]
#endif
internal void SetErrorCode(int hr)
{
HResult = hr;
@@ -643,7 +657,7 @@ namespace System {
// this assert to ensure that it fails when that exception's _safeSerializationManager is NULL
Contract.Assert(((_safeSerializationManager != null) || (this.GetType().Assembly == typeof(object).Assembly)),
"User defined exceptions must have a valid _safeSerializationManager");
// Handle serializing any transparent or partial trust subclass data
_safeSerializationManager.CompleteSerialization(this, info, context);
}
@@ -748,7 +762,14 @@ namespace System {
_stackTrace = null;
_stackTraceString = null;
}
#if MONO
// This is only needed for Watson support
private string StripFileInfo(string stackTrace, bool isRemoteStackTrace) {
return stackTrace;
}
#endif
#if FEATURE_EXCEPTIONDISPATCHINFO
// This is the object against which a lock will be taken
@@ -785,12 +806,7 @@ namespace System {
}
}
#if MONO
// This is only needed for Watson support
private string StripFileInfo(string stackTrace, bool isRemoteStackTrace) {
return stackTrace;
}
#else
#if !MONO
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
@@ -949,7 +965,10 @@ namespace System {
{
return _HResult;
}
protected set
#if !NETCORE
protected
#endif
set
{
_HResult = value;
}
@@ -978,6 +997,8 @@ namespace System {
// Mono addition: Used on iPhone
IntPtr[] native_trace_ips;
int caught_in_unmanaged;
#endif
// See clr\src\vm\excep.h's EXCEPTION_COMPLUS definition:
@@ -1107,8 +1128,8 @@ namespace System {
internal Exception FixRemotingException ()
{
string message = (0 == _remoteStackIndex) ?
Locale.GetText ("{0}{0}Server stack trace: {0}{1}{0}{0}Exception rethrown at [{2}]: {0}") :
Locale.GetText ("{1}{0}{0}Exception rethrown at [{2}]: {0}");
"{0}{0}Server stack trace: {0}{1}{0}{0}Exception rethrown at [{2}]: {0}" :
"{1}{0}{0}Exception rethrown at [{2}]: {0}";
string tmp = String.Format (message, Environment.NewLine, StackTrace, _remoteStackIndex);
_remoteStackTraceString = tmp;

View File

@@ -18,7 +18,9 @@ namespace System {
//This class only static members and doesn't require the serializable keyword.
using System;
#if !MONO
using System.Security.Permissions;
#endif
using System.Reflection;
using System.Security;
using System.Threading;
@@ -63,7 +65,7 @@ namespace System {
NotApplicable = 4
}
public static class GC
public static partial class GC
{
#if MONO
[MethodImplAttribute (MethodImplOptions.InternalCall)]
@@ -101,6 +103,9 @@ namespace System {
lastRecordedHeapSize = UIntPtr.Zero;
lastRecordedFragmentation = UIntPtr.Zero;
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public static extern long GetAllocatedBytesForCurrentThread ();
#else
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
@@ -226,7 +231,9 @@ namespace System {
#else
[System.Security.SecuritySafeCritical] // auto-generated
#endif
#if !MONO
[ResourceExposure(ResourceScope.None)]
#endif
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern int GetGeneration(Object obj);
@@ -418,8 +425,10 @@ namespace System {
// Indicates that the system should not call the Finalize() method on
// an object that would normally require this call.
#if !MONO
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
#endif
[MethodImplAttribute(MethodImplOptions.InternalCall)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
private static extern void _SuppressFinalize(Object o);
@@ -437,8 +446,10 @@ namespace System {
// for which SuppressFinalize has already been called. The other situation
// where calling ReRegisterForFinalize is useful is inside a finalizer that
// needs to resurrect itself or an object that it references.
#if !MONO
[System.Security.SecurityCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
#endif
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern void _ReRegisterForFinalize(Object o);

View File

@@ -44,6 +44,9 @@ namespace System.Globalization {
// is derived from DateTime class.
//
internal const int MaxYear = 9999;
#if MONO
internal const int MinYear = 1; // needed for ISOWeek
#endif
internal GregorianCalendarTypes m_type;

View File

@@ -141,7 +141,86 @@ namespace System.Globalization {
m_maxYear = m_EraInfo[0].maxEraYear;
m_minYear = m_EraInfo[0].minEraYear;;
}
#if MONO // see https://github.com/dotnet/coreclr/pull/18209
// EraInfo.yearOffset: The offset to Gregorian year when the era starts. Gregorian Year = Era Year + yearOffset
// Era Year = Gregorian Year - yearOffset
// EraInfo.minEraYear: Min year value in this era. Generally, this value is 1, but this may be affected by the DateTime.MinValue;
// EraInfo.maxEraYear: Max year value in this era. (== the year length of the era + 1)
private int GetYearOffset(int year, int era, bool throwOnError)
{
if (year < 0)
{
if (throwOnError)
{
throw new ArgumentOutOfRangeException(nameof(year), SR.ArgumentOutOfRange_NeedNonNegNum);
}
return -1;
}
if (era == Calendar.CurrentEra)
{
era = m_Cal.CurrentEraValue;
}
for (int i = 0; i < m_EraInfo.Length; i++)
{
if (era == m_EraInfo[i].era)
{
if (year >= m_EraInfo[i].minEraYear)
{
if (year <= m_EraInfo[i].maxEraYear)
{
return m_EraInfo[i].yearOffset;
}
else if (!AppContextSwitches.EnforceJapaneseEraYearRanges)
{
// If we got the year number exceeding the era max year number, this still possible be valid as the date can be created before
// introducing new eras after the era we are checking. we'll loop on the eras after the era we have and ensure the year
// can exist in one of these eras. otherwise, we'll throw.
// Note, we always return the offset associated with the requested era.
//
// Here is some example:
// if we are getting the era number 4 (Heisei) and getting the year number 32. if the era 4 has year range from 1 to 31
// then year 32 exceeded the range of era 4 and we'll try to find out if the years difference (32 - 31 = 1) would lay in
// the subsequent eras (e.g era 5 and up)
int remainingYears = year - m_EraInfo[i].maxEraYear;
for (int j = i - 1; j >= 0; j--)
{
if (remainingYears <= m_EraInfo[j].maxEraYear)
{
return m_EraInfo[i].yearOffset;
}
remainingYears -= m_EraInfo[j].maxEraYear;
}
}
}
if (throwOnError)
{
throw new ArgumentOutOfRangeException(
nameof(year),
string.Format(
CultureInfo.CurrentCulture,
SR.ArgumentOutOfRange_Range,
m_EraInfo[i].minEraYear,
m_EraInfo[i].maxEraYear));
}
break; // no need to iterate more on eras.
}
}
if (throwOnError)
{
throw new ArgumentOutOfRangeException(nameof(era), SR.ArgumentOutOfRange_InvalidEraValue);
}
return -1;
}
#endif
/*=================================GetGregorianYear==========================
**Action: Get the Gregorian year value for the specified year in an era.
**Returns: The Gregorian year value.
@@ -153,6 +232,9 @@ namespace System.Globalization {
============================================================================*/
internal int GetGregorianYear(int year, int era) {
#if MONO
return GetYearOffset(year, era, throwOnError: true) + year;
#else
if (year < 0) {
throw new ArgumentOutOfRangeException("year",
Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
@@ -178,9 +260,13 @@ namespace System.Globalization {
}
}
throw new ArgumentOutOfRangeException("era", Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue"));
#endif
}
internal bool IsValidYear(int year, int era) {
#if MONO
return GetYearOffset(year, era, throwOnError: false) >= 0;
#else
if (year < 0) {
return false;
}
@@ -198,8 +284,8 @@ namespace System.Globalization {
}
}
return false;
}
#endif
}
// Returns a given date part of this DateTime. This method is used
// to compute the year, day-of-year, month, or day part.

View File

@@ -159,7 +159,7 @@ namespace System.IO {
case Win32Native.ERROR_ALREADY_EXISTS:
if (str.Length == 0)
goto default;
throw new IOException(Environment.GetResourceString("IO.IO_AlreadyExists_Name", str), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath);
throw new IOException(Environment.GetResourceString("IO.IO_AlreadyExists_Name", str), Win32Native.MakeHRFromErrorCode(errorCode));
case Win32Native.ERROR_FILENAME_EXCED_RANGE:
throw new PathTooLongException(Environment.GetResourceString("IO.PathTooLong"));
@@ -168,24 +168,24 @@ namespace System.IO {
throw new DriveNotFoundException(Environment.GetResourceString("IO.DriveNotFound_Drive", str));
case Win32Native.ERROR_INVALID_PARAMETER:
throw new IOException(Win32Native.GetMessage(errorCode), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath);
throw new IOException(Win32Native.GetMessage(errorCode), Win32Native.MakeHRFromErrorCode(errorCode));
case Win32Native.ERROR_SHARING_VIOLATION:
if (str.Length == 0)
throw new IOException(Environment.GetResourceString("IO.IO_SharingViolation_NoFileName"), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath);
throw new IOException(Environment.GetResourceString("IO.IO_SharingViolation_NoFileName"), Win32Native.MakeHRFromErrorCode(errorCode));
else
throw new IOException(Environment.GetResourceString("IO.IO_SharingViolation_File", str), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath);
throw new IOException(Environment.GetResourceString("IO.IO_SharingViolation_File", str), Win32Native.MakeHRFromErrorCode(errorCode));
case Win32Native.ERROR_FILE_EXISTS:
if (str.Length == 0)
goto default;
throw new IOException(Environment.GetResourceString("IO.IO_FileExists_Name", str), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath);
throw new IOException(Environment.GetResourceString("IO.IO_FileExists_Name", str), Win32Native.MakeHRFromErrorCode(errorCode));
case Win32Native.ERROR_OPERATION_ABORTED:
throw new OperationCanceledException();
default:
throw new IOException(Win32Native.GetMessage(errorCode), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath);
throw new IOException(Win32Native.GetMessage(errorCode), Win32Native.MakeHRFromErrorCode(errorCode));
}
}
#if !MONO

View File

@@ -254,7 +254,7 @@ namespace System.IO {
[ResourceConsumption(ResourceScope.Machine)]
public StreamReader OpenText()
{
return new StreamReader(FullPath, Encoding.UTF8, true, StreamReader.DefaultBufferSize, false);
return new StreamReader(FullPath, Encoding.UTF8, detectEncodingFromByteOrderMarks: true);
}
[ResourceExposure(ResourceScope.Machine)]

View File

@@ -794,7 +794,7 @@ namespace System.IO
FileIOPermission.QuickDemand(FileIOPermissionAccess.Read, permissionName, false, false);
#endif
#endif
DirectoryInfo di = new DirectoryInfo(name, false);
DirectoryInfo di = new DirectoryInfo(Path.GetFileName(name), fullPath: name, isNormalized: true);
di.InitializeFrom(result.FindData);
return di;
}
@@ -833,7 +833,7 @@ namespace System.IO
FileIOPermission.QuickDemand(FileIOPermissionAccess.Read, permissionName, false, false);
#endif
#endif
DirectoryInfo di = new DirectoryInfo(name, false);
DirectoryInfo di = new DirectoryInfo(Path.GetFileName(name), fullPath: name, isNormalized: true);
di.InitializeFrom(result.FindData);
return di;
}

Some files were not shown because too many files have changed in this diff Show More