Skip to content

Commit

Permalink
Fix String.IsInterned regression (#99389)
Browse files Browse the repository at this point in the history
Introduced by FCall to QCall conversion

Fixes #99386
  • Loading branch information
jkotas authored Mar 7, 2024
1 parent ea2532e commit 4e86b1c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ public static string Intern(string str)
}

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "String_IsInterned")]
[return: MarshalAs(UnmanagedType.Bool)]
private static partial void IsInterned(StringHandleOnStack src);

public static string? IsInterned(string str)
{
ArgumentNullException.ThrowIfNull(str);
Intern(new StringHandleOnStack(ref str!));
IsInterned(new StringHandleOnStack(ref str!));
return str;
}

Expand Down
13 changes: 12 additions & 1 deletion src/libraries/Common/tests/Tests/System/StringTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7612,7 +7612,7 @@ public static unsafe void InternTest()
}

[Fact]
public static void InternalTestAotSubset()
public static void InternTestAotSubset()
{
#pragma warning disable 0618 // suppress obsolete warning for String.Copy
string emptyFromField = string.Empty;
Expand All @@ -7629,6 +7629,17 @@ public static void InternalTestAotSubset()
#pragma warning restore 0618 // restore warning when accessing obsolete members
}

[Fact]
public static void InternTestCanReturnNull()
{
for (int i = 0; i < 20; i++)
{
if (string.IsInterned(Guid.NewGuid().ToString()) == null)
return;
}
Assert.Fail("string.IsInterned never returns null");
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotInvariantGlobalization))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/34577", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)]
public static unsafe void NormalizationTest() // basic test; more tests in globalization tests
Expand Down

0 comments on commit 4e86b1c

Please sign in to comment.