Skip to content

Commit 53e8c7c

Browse files
Reflection Invoke share more coreclr/mono (#60270)
* Remove ActiveIssues from some mono tests. * Convert INVOCATION_FLAGS enum to repo style casing. * Rename various files to match partial class style.
1 parent 972891f commit 53e8c7c

File tree

21 files changed

+937
-877
lines changed

21 files changed

+937
-877
lines changed

src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@
176176
<Compile Include="$(BclSourcesRoot)\System\Reflection\Emit\TypeBuilderInstantiation.cs" />
177177
<Compile Include="$(BclSourcesRoot)\System\Reflection\Emit\XXXOnTypeBuilderInstantiation.cs" />
178178
<Compile Include="$(BclSourcesRoot)\System\Reflection\FieldInfo.CoreCLR.cs" />
179-
<Compile Include="$(BclSourcesRoot)\System\Reflection\INVOCATION_FLAGS.cs" />
180179
<Compile Include="$(BclSourcesRoot)\System\Reflection\LoaderAllocator.cs" />
181180
<Compile Include="$(BclSourcesRoot)\System\Reflection\MdConstant.cs" />
182181
<Compile Include="$(BclSourcesRoot)\System\Reflection\MdFieldInfo.cs" />
@@ -187,14 +186,14 @@
187186
<Compile Include="$(BclSourcesRoot)\System\Reflection\MethodBase.CoreCLR.cs" />
188187
<Compile Include="$(BclSourcesRoot)\System\Reflection\RtFieldInfo.cs" />
189188
<Compile Include="$(BclSourcesRoot)\System\Reflection\RuntimeAssembly.cs" />
190-
<Compile Include="$(BclSourcesRoot)\System\Reflection\RuntimeConstructorInfo.cs" />
189+
<Compile Include="$(BclSourcesRoot)\System\Reflection\RuntimeConstructorInfo.CoreCLR.cs" />
191190
<Compile Include="$(BclSourcesRoot)\System\Reflection\RuntimeCustomAttributeData.cs" />
192191
<Compile Include="$(BclSourcesRoot)\System\Reflection\RuntimeEventInfo.cs" />
193192
<Compile Include="$(BclSourcesRoot)\System\Reflection\RuntimeExceptionHandlingClause.cs" />
194193
<Compile Include="$(BclSourcesRoot)\System\Reflection\RuntimeFieldInfo.cs" />
195194
<Compile Include="$(BclSourcesRoot)\System\Reflection\RuntimeLocalVariableInfo.cs" />
196195
<Compile Include="$(BclSourcesRoot)\System\Reflection\RuntimeMethodBody.cs" />
197-
<Compile Include="$(BclSourcesRoot)\System\Reflection\RuntimeMethodInfo.cs" />
196+
<Compile Include="$(BclSourcesRoot)\System\Reflection\RuntimeMethodInfo.CoreCLR.cs" />
198197
<Compile Include="$(BclSourcesRoot)\System\Reflection\RuntimeModule.cs" />
199198
<Compile Include="$(BclSourcesRoot)\System\Reflection\RuntimeParameterInfo.cs" />
200199
<Compile Include="$(BclSourcesRoot)\System\Reflection\RuntimePropertyInfo.cs" />

src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ internal RuntimeMethodHandle GetMethodDescriptor()
463463
Span<object?> arguments = default;
464464
if (actualCount != 0)
465465
{
466-
arguments = CheckArguments(ref stackArgs, parameters, binder, invokeAttr, culture, sig);
466+
arguments = CheckArguments(ref stackArgs, parameters, binder, invokeAttr, culture, sig.Arguments);
467467
}
468468

469469
object? retValue = RuntimeMethodHandle.InvokeMethod(null, arguments, sig, false, wrapExceptions);

src/coreclr/System.Private.CoreLib/src/System/Reflection/MethodBase.CoreCLR.cs

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -66,58 +66,6 @@ internal virtual Type[] GetParameterTypes()
6666

6767
return parameterTypes;
6868
}
69-
70-
private protected Span<object?> CheckArguments(ref StackAllocedArguments stackArgs, ReadOnlySpan<object?> parameters, Binder? binder,
71-
BindingFlags invokeAttr, CultureInfo? culture, Signature sig)
72-
{
73-
Debug.Assert(Unsafe.SizeOf<StackAllocedArguments>() == StackAllocedArguments.MaxStackAllocArgCount * Unsafe.SizeOf<object>(),
74-
"MaxStackAllocArgCount not properly defined.");
75-
Debug.Assert(!parameters.IsEmpty);
76-
77-
// We need to perform type safety validation against the incoming arguments, but we also need
78-
// to be resilient against the possibility that some other thread (or even the binder itself!)
79-
// may mutate the array after we've validated the arguments but before we've properly invoked
80-
// the method. The solution is to copy the arguments to a different, not-user-visible buffer
81-
// as we validate them. n.b. This disallows use of ArrayPool, as ArrayPool-rented arrays are
82-
// considered user-visible to threads which may still be holding on to returned instances.
83-
84-
Span<object?> copyOfParameters = (parameters.Length <= StackAllocedArguments.MaxStackAllocArgCount)
85-
? MemoryMarshal.CreateSpan(ref stackArgs._arg0, parameters.Length)
86-
: new Span<object?>(new object?[parameters.Length]);
87-
88-
ParameterInfo[]? p = null;
89-
for (int i = 0; i < parameters.Length; i++)
90-
{
91-
object? arg = parameters[i];
92-
RuntimeType argRT = sig.Arguments[i];
93-
94-
if (arg == Type.Missing)
95-
{
96-
p ??= GetParametersNoCopy();
97-
if (p[i].DefaultValue == System.DBNull.Value)
98-
throw new ArgumentException(SR.Arg_VarMissNull, nameof(parameters));
99-
arg = p[i].DefaultValue!;
100-
}
101-
copyOfParameters[i] = argRT.CheckValue(arg, binder, culture, invokeAttr);
102-
}
103-
104-
return copyOfParameters;
105-
}
106-
107-
// Helper struct to avoid intermediate object[] allocation in calls to the native reflection stack.
108-
// Typical usage is to define a local of type default(StackAllocedArguments), then pass 'ref theLocal'
109-
// as the first parameter to CheckArguments. CheckArguments will try to utilize storage within this
110-
// struct instance if there's sufficient space; otherwise CheckArguments will allocate a temp array.
111-
private protected struct StackAllocedArguments
112-
{
113-
internal const int MaxStackAllocArgCount = 4;
114-
internal object? _arg0;
115-
#pragma warning disable CA1823, CS0169, IDE0051 // accessed via 'CheckArguments' ref arithmetic
116-
private object? _arg1;
117-
private object? _arg2;
118-
private object? _arg3;
119-
#pragma warning restore CA1823, CS0169, IDE0051
120-
}
12169
#endregion
12270
}
12371
}

src/coreclr/System.Private.CoreLib/src/System/Reflection/RtFieldInfo.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,46 @@ internal sealed unsafe class RtFieldInfo : RuntimeFieldInfo, IRuntimeFieldInfo
1717
// lazy caching
1818
private string? m_name;
1919
private RuntimeType? m_fieldType;
20-
private INVOCATION_FLAGS m_invocationFlags;
20+
private InvocationFlags m_invocationFlags;
2121

22-
internal INVOCATION_FLAGS InvocationFlags
22+
internal InvocationFlags InvocationFlags
2323
{
2424
[MethodImpl(MethodImplOptions.AggressiveInlining)]
25-
get => (m_invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_INITIALIZED) != 0 ?
25+
get => (m_invocationFlags & InvocationFlags.Initialized) != 0 ?
2626
m_invocationFlags : InitializeInvocationFlags();
2727
}
2828

2929
[MethodImpl(MethodImplOptions.NoInlining)]
30-
private INVOCATION_FLAGS InitializeInvocationFlags()
30+
private InvocationFlags InitializeInvocationFlags()
3131
{
3232
Type? declaringType = DeclaringType;
3333

34-
INVOCATION_FLAGS invocationFlags = 0;
34+
InvocationFlags invocationFlags = 0;
3535

3636
// first take care of all the NO_INVOKE cases
3737
if (declaringType != null && declaringType.ContainsGenericParameters)
3838
{
39-
invocationFlags |= INVOCATION_FLAGS.INVOCATION_FLAGS_NO_INVOKE;
39+
invocationFlags |= InvocationFlags.NoInvoke;
4040
}
4141

4242
// If the invocationFlags are still 0, then
4343
// this should be an usable field, determine the other flags
4444
if (invocationFlags == 0)
4545
{
4646
if ((m_fieldAttributes & FieldAttributes.InitOnly) != (FieldAttributes)0)
47-
invocationFlags |= INVOCATION_FLAGS.INVOCATION_FLAGS_SPECIAL_FIELD;
47+
invocationFlags |= InvocationFlags.SpecialField;
4848

4949
if ((m_fieldAttributes & FieldAttributes.HasFieldRVA) != (FieldAttributes)0)
50-
invocationFlags |= INVOCATION_FLAGS.INVOCATION_FLAGS_SPECIAL_FIELD;
50+
invocationFlags |= InvocationFlags.SpecialField;
5151

5252
// find out if the field type is one of the following: Primitive, Enum or Pointer
5353
Type fieldType = FieldType;
5454
if (fieldType.IsPointer || fieldType.IsEnum || fieldType.IsPrimitive)
55-
invocationFlags |= INVOCATION_FLAGS.INVOCATION_FLAGS_FIELD_SPECIAL_CAST;
55+
invocationFlags |= InvocationFlags.FieldSpecialCast;
5656
}
5757

5858
// must be last to avoid threading problems
59-
return m_invocationFlags = invocationFlags | INVOCATION_FLAGS.INVOCATION_FLAGS_INITIALIZED;
59+
return m_invocationFlags = invocationFlags | InvocationFlags.Initialized;
6060
}
6161
#endregion
6262

@@ -124,10 +124,10 @@ internal override RuntimeModule GetRuntimeModule()
124124
[Diagnostics.DebuggerHidden]
125125
public override object? GetValue(object? obj)
126126
{
127-
INVOCATION_FLAGS invocationFlags = InvocationFlags;
127+
InvocationFlags invocationFlags = InvocationFlags;
128128
RuntimeType? declaringType = DeclaringType as RuntimeType;
129129

130-
if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NO_INVOKE) != 0)
130+
if ((invocationFlags & InvocationFlags.NoInvoke) != 0)
131131
{
132132
if (declaringType != null && DeclaringType!.ContainsGenericParameters)
133133
throw new InvalidOperationException(SR.Arg_UnboundGenField);
@@ -170,10 +170,10 @@ internal override RuntimeModule GetRuntimeModule()
170170
[Diagnostics.DebuggerHidden]
171171
public override void SetValue(object? obj, object? value, BindingFlags invokeAttr, Binder? binder, CultureInfo? culture)
172172
{
173-
INVOCATION_FLAGS invocationFlags = InvocationFlags;
173+
InvocationFlags invocationFlags = InvocationFlags;
174174
RuntimeType? declaringType = DeclaringType as RuntimeType;
175175

176-
if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NO_INVOKE) != 0)
176+
if ((invocationFlags & InvocationFlags.NoInvoke) != 0)
177177
{
178178
if (declaringType != null && declaringType.ContainsGenericParameters)
179179
throw new InvalidOperationException(SR.Arg_UnboundGenField);

0 commit comments

Comments
 (0)