Skip to content

Commit

Permalink
Remove the BinaryCompatibility class as it is not useful on .NET Core… (
Browse files Browse the repository at this point in the history
dotnet/coreclr#8396)

* Remove the BinaryCompatibility class as it is not useful on .NET Core and creates issues on Debug builds when the TFM on the AppDomain is not recognized.
* Update the code for DateTimeFormatInfo to not use BinaryCompatibility
* Remove initialization of preferExistingTokens now that we removed its usage

Commit migrated from dotnet/coreclr@eca37b4
  • Loading branch information
AlexGhiondea authored and jkotas committed Dec 1, 2016
1 parent 39b61e9 commit e62d02a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 627 deletions.
1 change: 0 additions & 1 deletion src/coreclr/src/mscorlib/mscorlib.shared.sources.props
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,6 @@
<SerializationSources Include="$(BclSourcesRoot)\System\Runtime\Serialization\SafeSerializationManager.cs" />
</ItemGroup>
<ItemGroup>
<VersioningSources Include="$(BclSourcesRoot)\System\Runtime\Versioning\BinaryCompatibility.cs" />
<VersioningSources Include="$(BclSourcesRoot)\System\Runtime\Versioning\TargetFrameworkAttribute.cs" />
<VersioningSources Include="$(BclSourcesRoot)\System\Runtime\Versioning\TargetFrameworkId.cs" />
<VersioningSources Include="$(BclSourcesRoot)\System\Runtime\Versioning\CompatibilitySwitch.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,7 @@ internal static int FloorLog2(int n)
}

internal static void ThrowOrIgnoreBadComparer(Object comparer) {
// This is hit when an invarant of QuickSort is violated due to a bad IComparer implementation (for
// example, imagine an IComparer that returns 0 when items are equal but -1 all other times).
//
// We could have thrown this exception on v4, but due to changes in v4.5 around how we partition arrays
// there are different sets of input where we would throw this exception. In order to reduce overall risk from
// an app compat persective, we're changing to never throw on v4. Instead, we'll return with a partially
// sorted array.
if(BinaryCompatibility.TargetsAtLeast_Desktop_V4_5) {
throw new ArgumentException(Environment.GetResourceString("Arg_BogusIComparer", comparer));
}
throw new ArgumentException(Environment.GetResourceString("Arg_BogusIComparer", comparer));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,13 +545,13 @@ public void ForEach(Action<T> action) {
int version = _version;

for(int i = 0 ; i < _size; i++) {
if (version != _version && BinaryCompatibility.TargetsAtLeast_Desktop_V4_5) {
if (version != _version) {
break;
}
action(_items[i]);
}

if (version != _version && BinaryCompatibility.TargetsAtLeast_Desktop_V4_5)
if (version != _version)
ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,6 @@ public sealed class DateTimeFormatInfo : ICloneable, IFormatProvider
// genitive form or leap year month names.
[OptionalField(VersionAdded = 2)]
internal DateTimeFormatFlags formatFlags = DateTimeFormatFlags.NotInitialized;
internal static bool preferExistingTokens = InitPreferExistingTokens();


[System.Security.SecuritySafeCritical]
static bool InitPreferExistingTokens()
{
bool ret = false;
#if !FEATURE_CORECLR
ret = DateTime.LegacyParseMode();
#endif
return ret;
}

private String CultureName
{
Expand Down Expand Up @@ -2877,35 +2865,13 @@ void InsertHash(TokenHashValue[] hashTable, String str, TokenType tokenType, int
int nTokenType = (int)tokenType;
int nCurrentTokenTypeInHash = (int)value.tokenType;

// The idea behind this check is:
// - if the app is targetting 4.5.1 or above OR the compat flag is set, use the correct behavior by default.
// - if the app is targetting 4.5 or below AND the compat switch is set, use the correct behavior
// - if the app is targetting 4.5 or below AND the compat switch is NOT set, use the incorrect behavior
if (preferExistingTokens || BinaryCompatibility.TargetsAtLeast_Desktop_V4_5_1)
{
if (((nCurrentTokenTypeInHash & (int)TokenType.RegularTokenMask) == 0) && ((nTokenType & (int)TokenType.RegularTokenMask) != 0) ||
((nCurrentTokenTypeInHash & (int)TokenType.SeparatorTokenMask) == 0) && ((nTokenType & (int)TokenType.SeparatorTokenMask) != 0))
{
value.tokenType |= tokenType;
if (tokenValue != 0)
{
value.tokenValue = tokenValue;
}
}
}
else
if (((nCurrentTokenTypeInHash & (int)TokenType.RegularTokenMask) == 0) && ((nTokenType & (int)TokenType.RegularTokenMask) != 0) ||
((nCurrentTokenTypeInHash & (int)TokenType.SeparatorTokenMask) == 0) && ((nTokenType & (int)TokenType.SeparatorTokenMask) != 0))
{
// The following logic is incorrect and causes updates to happen depending on the bitwise relationship between the existing token type and the
// the stored token type. It was this way in .NET 4 RTM. The behavior above is correct and will be adopted going forward.

if ((((nTokenType | nCurrentTokenTypeInHash) & (int)TokenType.RegularTokenMask) == nTokenType) ||
(((nTokenType | nCurrentTokenTypeInHash) & (int)TokenType.SeparatorTokenMask) == nTokenType))
value.tokenType |= tokenType;
if (tokenValue != 0)
{
value.tokenType |= tokenType;
if (tokenValue != 0)
{
value.tokenValue = tokenValue;
}
value.tokenValue = tokenValue;
}
}
// The token to be inserted is already in the table. Skip it.
Expand Down
Loading

0 comments on commit e62d02a

Please sign in to comment.