Skip to content

Commit fa0b55d

Browse files
author
Mike McLaughlin
committed
Code review feedback. Making the new MetadataUpdater.GetCapabilities() internal.
Fixed the argument checking in coreclr's MetadataUpdater.ApplyUpdate().
1 parent b4cd895 commit fa0b55d

File tree

8 files changed

+28
-19
lines changed

8 files changed

+28
-19
lines changed

src/coreclr/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,5 @@
66
<type fullname="Internal.Runtime.InteropServices.ComponentActivator" feature="System.Runtime.InteropServices.EnableConsumingManagedCodeFromNativeHosting" featurevalue="false">
77
<method signature="System.Boolean get_IsSupported()" body="stub" value="false" />
88
</type>
9-
<type fullname="System.Reflection.Metadata.MetadataUpdater" feature="System.Reflection.Metadata.MetadataUpdater.IsSupported" featurevalue="false">
10-
<method signature="System.Boolean get_IsSupported()" body="stub" value="false" />
11-
</type>
129
</assembly>
1310
</linker>

src/coreclr/System.Private.CoreLib/src/System/Reflection/Metadata/MetadataUpdater.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,15 @@ public static class MetadataUpdater
2828
/// <param name="metadataDelta">The metadata changes to be applied.</param>
2929
/// <param name="ilDelta">The IL changes to be applied.</param>
3030
/// <param name="pdbDelta">The PDB changes to be applied.</param>
31+
/// <exception cref="ArgumentException">The assembly argument is not a runtime assembly.</exception>
3132
/// <exception cref="ArgumentNullException">The assembly argument is null.</exception>
33+
/// <exception cref="InvalidOperationException">The assembly is not editable.</exception>
3234
/// <exception cref="NotSupportedException">The update could not be applied.</exception>
3335
public static void ApplyUpdate(Assembly assembly, ReadOnlySpan<byte> metadataDelta, ReadOnlySpan<byte> ilDelta, ReadOnlySpan<byte> pdbDelta)
3436
{
35-
if (assembly == null)
36-
{
37-
throw new ArgumentNullException(nameof(assembly));
38-
}
39-
40-
RuntimeAssembly? runtimeAssembly = assembly as RuntimeAssembly;
41-
if (runtimeAssembly == null)
37+
if (assembly is not RuntimeAssembly runtimeAssembly)
4238
{
39+
if (assembly is null) throw new ArgumentNullException(nameof(assembly));
4340
throw new ArgumentException(SR.Argument_MustBeRuntimeAssembly);
4441
}
4542

@@ -56,7 +53,7 @@ public static void ApplyUpdate(Assembly assembly, ReadOnlySpan<byte> metadataDel
5653
/// <summary>
5754
/// Returns the metadata update capabilities.
5855
/// </summary>
59-
public static string GetCapabilities() => "Baseline AddMethodToExistingType AddStaticFieldToExistingType AddInstanceFieldToExistingType NewTypeDefinition ChangeCustomAttributes";
56+
internal static string GetCapabilities() => "Baseline AddMethodToExistingType AddStaticFieldToExistingType AddInstanceFieldToExistingType NewTypeDefinition ChangeCustomAttributes";
6057

6158
/// <summary>
6259
/// Returns true if the apply assembly update is enabled and available.

src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.Shared.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,8 @@
2727
<type fullname="System.Resources.ResourceReader" feature="System.Resources.ResourceManager.AllowCustomResourceTypes" featurevalue="false">
2828
<method signature="System.Boolean get_AllowCustomResourceTypes()" body="stub" value="false" />
2929
</type>
30+
<type fullname="System.Reflection.Metadata.MetadataUpdater" feature="System.Reflection.Metadata.MetadataUpdater.IsSupported" featurevalue="false">
31+
<method signature="System.Boolean get_IsSupported()" body="stub" value="false" />
32+
</type>
3033
</assembly>
3134
</linker>

src/libraries/System.Runtime.Loader/ref/System.Runtime.Loader.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public static partial class AssemblyExtensions
1515
public static partial class MetadataUpdater
1616
{
1717
public static void ApplyUpdate(Assembly assembly, ReadOnlySpan<byte> metadataDelta, ReadOnlySpan<byte> ilDelta, ReadOnlySpan<byte> pdbDelta) { throw null; }
18-
public static string GetCapabilities() { throw null; }
1918
public static bool IsSupported { get { throw null; } }
2019
}
2120
[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = true)]

src/libraries/System.Runtime.Loader/tests/ApplyUpdateTest.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,19 @@ public static void ApplyUpdateInvalidParameters()
111111
[Fact]
112112
public static void GetCapabilities()
113113
{
114-
string result = MetadataUpdater.GetCapabilities();
114+
var ty = typeof(System.Reflection.Metadata.MetadataUpdater);
115+
var mi = ty.GetMethod("GetCapabilities", BindingFlags.NonPublic | BindingFlags.Static, Array.Empty<Type>());
116+
117+
Assert.NotNull(mi);
118+
119+
var result = mi.Invoke(null, null);
120+
115121
Assert.NotNull(result);
122+
Assert.Equal(typeof(string), result.GetType());
116123
}
117124

118125
[Fact]
126+
[ActiveIssue("Returns true on mono", TestRuntimes.Mono)]
119127
public static void IsSupported()
120128
{
121129
bool result = MetadataUpdater.IsSupported;

src/libraries/System.Runtime.Loader/tests/ApplyUpdateUtil.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,16 @@ internal static bool CheckSupportedMonoConfiguration()
4848

4949
internal static bool HasApplyUpdateCapabilities()
5050
{
51-
string caps = MetadataUpdater.GetCapabilities();
51+
var ty = typeof(MetadataUpdater);
52+
var mi = ty.GetMethod("GetCapabilities", BindingFlags.NonPublic | BindingFlags.Static, Array.Empty<Type>());
53+
54+
if (mi == null)
55+
return false;
56+
57+
var caps = mi.Invoke(null, null);
5258

5359
// any non-empty string, assumed to be at least "baseline"
54-
return caps.Length > 0;
60+
return caps is string {Length: > 0};
5561
}
5662

5763
private static System.Collections.Generic.Dictionary<Assembly, int> assembly_count = new();
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
<linker>
2-
<type fullname="System.Reflection.Metadata.MetadataUpdater" feature="System.Reflection.Metadata.MetadataUpdater.IsSupported" featurevalue="false">
3-
<method signature="System.Boolean get_IsSupported()" body="stub" value="false" />
4-
</type>
52
</linker>

src/mono/System.Private.CoreLib/src/System/Reflection/Metadata/MetadataUpdater.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ public static class MetadataUpdater
2121
/// <param name="metadataDelta">The metadata changes to be applied.</param>
2222
/// <param name="ilDelta">The IL changes to be applied.</param>
2323
/// <param name="pdbDelta">The PDB changes to be applied.</param>
24+
/// <exception cref="ArgumentException">The assembly argument is not a runtime assembly.</exception>
2425
/// <exception cref="ArgumentNullException">The assembly argument is null.</exception>
26+
/// <exception cref="InvalidOperationException">The assembly is not editable.</exception>
2527
/// <exception cref="NotSupportedException">The update could not be applied.</exception>
2628
public static void ApplyUpdate(Assembly assembly, ReadOnlySpan<byte> metadataDelta, ReadOnlySpan<byte> ilDelta, ReadOnlySpan<byte> pdbDelta)
2729
{
@@ -45,7 +47,7 @@ public static void ApplyUpdate(Assembly assembly, ReadOnlySpan<byte> metadataDel
4547
}
4648
}
4749

48-
public static string GetCapabilities() => s_ApplyUpdateCapabilities.Value;
50+
internal static string GetCapabilities() => s_ApplyUpdateCapabilities.Value;
4951

5052
public static bool IsSupported { get; } = ApplyUpdateEnabled() != 0;
5153

0 commit comments

Comments
 (0)