Imported Upstream version 6.4.0.137

Former-commit-id: 943baa9f16a098c33e129777827f3a9d20da00d6
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2019-07-26 19:53:28 +00:00
parent e9207cf623
commit ef583813eb
2712 changed files with 74169 additions and 40587 deletions

View File

@@ -26,6 +26,10 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Disable unreachable code warnings in this entire file.
#pragma warning disable 162
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Mono.Globalization.Unicode;
@@ -33,16 +37,44 @@ using System.Threading;
namespace System.Globalization
{
interface ISimpleCollator
{
SortKey GetSortKey (string source, CompareOptions options);
int Compare (string s1, string s2);
int Compare (string s1, int idx1, int len1, string s2, int idx2, int len2, CompareOptions options);
bool IsPrefix (string src, string target, CompareOptions opt);
bool IsSuffix (string src, string target, CompareOptions opt);
int IndexOf (string s, string target, int start, int length, CompareOptions opt);
int IndexOf (string s, char target, int start, int length, CompareOptions opt);
int LastIndexOf (string s, string target, CompareOptions opt);
int LastIndexOf (string s, string target, int start, int length, CompareOptions opt);
int LastIndexOf (string s, char target, CompareOptions opt);
int LastIndexOf (string s, char target, int start, int length, CompareOptions opt);
}
partial class CompareInfo
{
[NonSerialized]
SimpleCollator collator;
ISimpleCollator collator;
// Maps culture IDs to SimpleCollator objects
static Dictionary<string, SimpleCollator> collators;
static Dictionary<string, ISimpleCollator> collators;
static bool managedCollation;
static bool managedCollationChecked;
#if WASM
const bool UseManagedCollation = false;
#else
static bool UseManagedCollation {
get {
if (!managedCollationChecked) {
@@ -53,14 +85,18 @@ namespace System.Globalization
return managedCollation;
}
}
#endif
SimpleCollator GetCollator ()
ISimpleCollator GetCollator ()
{
#if WASM
return null;
#else
if (collator != null)
return collator;
if (collators == null) {
Interlocked.CompareExchange (ref collators, new Dictionary<string, SimpleCollator> (StringComparer.Ordinal), null);
Interlocked.CompareExchange (ref collators, new Dictionary<string, ISimpleCollator> (StringComparer.Ordinal), null);
}
lock (collators) {
@@ -71,6 +107,7 @@ namespace System.Globalization
}
return collator;
#endif
}
SortKey CreateSortKeyCore (string source, CompareOptions options)

View File

@@ -624,7 +624,59 @@ namespace System.Globalization
return false;
}
internal void GetNFIValues (NumberFormatInfo nfi)
// mono/metadta/culture-info.h NumberFormatEntryManaged must match
// mcs/class/corlib/ReferenceSources/CultureData.cs NumberFormatEntryManaged.
// This is sorted alphabetically.
[StructLayout (LayoutKind.Sequential)]
internal struct NumberFormatEntryManaged
{
internal int currency_decimal_digits;
internal int currency_decimal_separator;
internal int currency_group_separator;
internal int currency_group_sizes0;
internal int currency_group_sizes1;
internal int currency_negative_pattern;
internal int currency_positive_pattern;
internal int currency_symbol;
internal int nan_symbol;
internal int negative_infinity_symbol;
internal int negative_sign;
internal int number_decimal_digits;
internal int number_decimal_separator;
internal int number_group_separator;
internal int number_group_sizes0;
internal int number_group_sizes1;
internal int number_negative_pattern;
internal int per_mille_symbol;
internal int percent_negative_pattern;
internal int percent_positive_pattern;
internal int percent_symbol;
internal int positive_infinity_symbol;
internal int positive_sign;
}
static private unsafe int strlen (byte* s)
{
int length = 0;
while (s [length] != 0)
++length;
return length;
}
static private unsafe string idx2string (byte* data, int idx)
{
return Encoding.UTF8.GetString (data + idx, strlen (data + idx));
}
private int [] create_group_sizes_array (int gs0, int gs1)
{
// group_sizes is an array of up to two integers, -1 terminated.
return (gs0 == -1) ? new int [ ] { }
: (gs1 == -1) ? new int [ ] {gs0}
: new int [ ] {gs0, gs1};
}
internal unsafe void GetNFIValues (NumberFormatInfo nfi)
{
if (this.IsInvariantCulture)
{
@@ -641,7 +693,29 @@ namespace System.Globalization
// PercentGroupSize
// PercentGroupSeparator
//
fill_number_data (nfi, numberIndex);
var nfe = new NumberFormatEntryManaged ();
byte* data = fill_number_data (numberIndex, ref nfe);
nfi.currencyGroupSizes = create_group_sizes_array (nfe.currency_group_sizes0, nfe.currency_group_sizes1);
nfi.numberGroupSizes = create_group_sizes_array (nfe.number_group_sizes0, nfe.number_group_sizes1);
nfi.NaNSymbol = idx2string (data, nfe.nan_symbol);
nfi.currencyDecimalDigits = nfe.currency_decimal_digits;
nfi.currencyDecimalSeparator = idx2string (data, nfe.currency_decimal_separator);
nfi.currencyGroupSeparator = idx2string (data, nfe.currency_group_separator);
nfi.currencyNegativePattern = nfe.currency_negative_pattern;
nfi.currencyPositivePattern = nfe.currency_positive_pattern;
nfi.currencySymbol = idx2string (data, nfe.currency_symbol);
nfi.negativeInfinitySymbol = idx2string (data, nfe.negative_infinity_symbol);
nfi.negativeSign = idx2string (data, nfe.negative_sign);
nfi.numberDecimalDigits = nfe.number_decimal_digits;
nfi.numberDecimalSeparator = idx2string (data, nfe.number_decimal_separator);
nfi.numberGroupSeparator = idx2string (data, nfe.number_group_separator);
nfi.numberNegativePattern = nfe.number_negative_pattern;
nfi.perMilleSymbol = idx2string (data, nfe.per_mille_symbol);
nfi.percentNegativePattern = nfe.percent_negative_pattern;
nfi.percentPositivePattern = nfe.percent_positive_pattern;
nfi.percentSymbol = idx2string (data, nfe.percent_symbol);
nfi.positiveInfinitySymbol = idx2string (data, nfe.positive_infinity_symbol);
nfi.positiveSign = idx2string (data, nfe.positive_sign);
}
//
@@ -654,6 +728,6 @@ namespace System.Globalization
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
extern static void fill_number_data (NumberFormatInfo nfi, int numberIndex);
extern unsafe static byte* fill_number_data (int index, ref NumberFormatEntryManaged nfe);
}
}

View File

@@ -17,5 +17,13 @@ namespace System.Runtime.CompilerServices {
{
return Array.UnsafeMov<T, long> (val);
}
#if NETCORE
[Intrinsic]
internal static bool EnumEquals<T>(T x, T y) where T : struct, Enum => throw new NotImplementedException ();
[Intrinsic]
internal static int EnumCompareTo<T>(T x, T y) where T : struct, Enum => throw new NotImplementedException ();
#endif
}
}

View File

@@ -95,19 +95,18 @@ namespace System
[MethodImplAttribute(MethodImplOptions.InternalCall)]
extern ConstructorInfo GetCorrespondingInflatedConstructor (ConstructorInfo generic);
#if !NETCORE
internal override MethodInfo GetMethod (MethodInfo fromNoninstanciated)
{
{
if (fromNoninstanciated == null)
throw new ArgumentNullException ("fromNoninstanciated");
return GetCorrespondingInflatedMethod (fromNoninstanciated);
}
return GetCorrespondingInflatedMethod (fromNoninstanciated);
}
internal override ConstructorInfo GetConstructor (ConstructorInfo fromNoninstanciated)
{
if (fromNoninstanciated == null)
throw new ArgumentNullException ("fromNoninstanciated");
return GetCorrespondingInflatedConstructor (fromNoninstanciated);
return GetCorrespondingInflatedConstructor (fromNoninstanciated);
}
internal override FieldInfo GetField (FieldInfo fromNoninstanciated)
@@ -117,7 +116,6 @@ namespace System
flags |= fromNoninstanciated.IsPublic ? BindingFlags.Public : BindingFlags.NonPublic;
return GetField (fromNoninstanciated.Name, flags);
}
#endif
string GetDefaultMemberName ()
{
@@ -142,7 +140,7 @@ namespace System
return m_serializationCtor;
}
internal Object CreateInstanceSlow(bool publicOnly, bool wrapExceptions, bool skipCheckThis, bool fillCache, ref StackCrawlMark stackMark)
internal Object CreateInstanceSlow(bool publicOnly, bool wrapExceptions, bool skipCheckThis, bool fillCache)
{
//bool bNeedSecurityCheck = true;
//bool bCanBeCached = false;
@@ -161,7 +159,11 @@ namespace System
{
var ctor = GetDefaultConstructor ();
if (!nonPublic && ctor != null && !ctor.IsPublic) {
#if NETCORE
throw new MissingMethodException(SR.Format(SR.Arg_NoDefCTor, FullName));
#else
ctor = null;
#endif
}
if (ctor == null) {
@@ -431,7 +433,7 @@ namespace System
public override StructLayoutAttribute StructLayoutAttribute {
get {
#if NETCORE
throw new NotImplementedException ();
return GetStructLayoutAttribute ();
#else
return StructLayoutAttribute.GetCustomAttribute (this);
#endif
@@ -697,11 +699,7 @@ namespace System
var a = new RuntimeFieldInfo[n];
for (int i = 0; i < n; i++) {
var fh = new RuntimeFieldHandle (h[i]);
#if NETCORE
throw new NotImplementedException ();
#else
a[i] = (RuntimeFieldInfo) FieldInfo.GetFieldFromHandle (fh, refh);
#endif
}
return a;
}
@@ -717,7 +715,7 @@ namespace System
for (int i = 0; i < n; i++) {
var eh = new Mono.RuntimeEventHandle (h[i]);
#if NETCORE
throw new NotImplementedException ();
a[i] = (RuntimeEventInfo) RuntimeEventInfo.GetEventFromHandle (eh, refh);
#else
a[i] = (RuntimeEventInfo) EventInfo.GetEventFromHandle (eh, refh);
#endif
@@ -736,7 +734,8 @@ namespace System
{
string internalName = null;
#if NETCORE
throw new NotImplementedException ();
if (displayName != null)
internalName = displayName;
#else
if (displayName != null)
internalName = TypeIdentifiers.FromDisplay (displayName).InternalName;
@@ -774,7 +773,19 @@ namespace System
get;
}
#if MOBILE
#if NETCORE
public override bool IsSecurityTransparent {
get { return false; }
}
public override bool IsSecurityCritical {
get { return true; }
}
public override bool IsSecuritySafeCritical {
get { return false; }
}
#elif MOBILE
static int get_core_clr_security_level ()
{
return 1;
@@ -797,6 +808,7 @@ namespace System
}
#endif
#if !NETCORE
public override int GetHashCode()
{
Type t = UnderlyingSystemType;
@@ -804,6 +816,7 @@ namespace System
return t.GetHashCode ();
return (int)_impl.Value;
}
#endif
public override string FullName {
get {
@@ -822,9 +835,7 @@ namespace System
}
}
#if !NETCORE
public sealed override bool HasSameMetadataDefinitionAs (MemberInfo other) => HasSameMetadataDefinitionAsCore<RuntimeType> (other);
#endif
public override bool IsSZArray {
get {
@@ -833,13 +844,11 @@ namespace System
}
}
#if !NETCORE
internal override bool IsUserType {
get {
return false;
}
}
#endif
[System.Runtime.InteropServices.ComVisible(true)]
[Pure]
@@ -862,5 +871,44 @@ namespace System
}
public override bool IsTypeDefinition => RuntimeTypeHandle.IsTypeDefinition (this);
#if NETCORE
private const int DEFAULT_PACKING_SIZE = 8;
internal StructLayoutAttribute GetStructLayoutAttribute ()
{
if (IsInterface || HasElementType || IsGenericParameter)
return null;
int pack = 0, size = 0;
LayoutKind layoutKind = LayoutKind.Auto;
switch (Attributes & TypeAttributes.LayoutMask)
{
case TypeAttributes.ExplicitLayout: layoutKind = LayoutKind.Explicit; break;
case TypeAttributes.AutoLayout: layoutKind = LayoutKind.Auto; break;
case TypeAttributes.SequentialLayout: layoutKind = LayoutKind.Sequential; break;
default: Contract.Assume(false); break;
}
CharSet charSet = CharSet.None;
switch (Attributes & TypeAttributes.StringFormatMask)
{
case TypeAttributes.AnsiClass: charSet = CharSet.Ansi; break;
case TypeAttributes.AutoClass: charSet = CharSet.Auto; break;
case TypeAttributes.UnicodeClass: charSet = CharSet.Unicode; break;
default: Contract.Assume(false); break;
}
GetPacking (out pack, out size);
// Metadata parameter checking should not have allowed 0 for packing size.
// The runtime later converts a packing size of 0 to 8 so do the same here
// because it's more useful from a user perspective.
if (pack == 0)
pack = DEFAULT_PACKING_SIZE;
return new StructLayoutAttribute (layoutKind) { Pack = pack, Size = size, CharSet = charSet };
}
#endif // NETCORE
}
}