Skip to content

Commit 8baff7d

Browse files
[release/7.0-rc1] [mono] Implement missing functionality for cctor invocation (#74043)
* [mono] Implement missing functionality for cctor invocation * [mono] Re-enable test Co-authored-by: Vlad Brezae <[email protected]>
1 parent d8866dc commit 8baff7d

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

src/libraries/System.Reflection/tests/ConstructorInfoTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ public void Invoke_StaticConstructor_NullObject_NullParameters()
6969
}
7070

7171
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsInvokingStaticConstructorsSupported))]
72-
[ActiveIssue("https://github.com/dotnet/runtime/issues/40351", TestRuntimes.Mono)]
7372
public void Invoke_StaticConstructorMultipleTimes()
7473
{
7574
ConstructorInfo[] constructors = GetConstructors(typeof(ClassWithStaticConstructorThatIsCalledMultipleTimesViaReflection));

src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.Mono.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -802,10 +802,13 @@ internal RuntimeType[] ArgumentTypes
802802
}
803803
}
804804

805-
private static void InvokeClassConstructor()
805+
[MethodImplAttribute(MethodImplOptions.InternalCall)]
806+
internal static extern void InvokeClassConstructor(QCallTypeHandle type);
807+
808+
private void InvokeClassConstructor()
806809
{
807-
// [TODO] Mechanism for invoking class constructor
808-
// See https://github.com/dotnet/runtime/issues/40351
810+
RuntimeType type = (RuntimeType)DeclaringType;
811+
InvokeClassConstructor(new QCallTypeHandle(ref type));
809812
}
810813

811814
/*

src/mono/mono/metadata/icall-def.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ HANDLES(RASSEM_7, "InternalGetReferencedAssemblies", ves_icall_System_Reflection
357357
ICALL_TYPE(MCMETH, "System.Reflection.RuntimeConstructorInfo", MCMETH_1)
358358
HANDLES(MCMETH_1, "GetGenericMethodDefinition_impl", ves_icall_RuntimeMethodInfo_GetGenericMethodDefinition, MonoReflectionMethod, 1, (MonoReflectionMethod))
359359
HANDLES(MCMETH_2, "InternalInvoke", ves_icall_InternalInvoke, MonoObject, 4, (MonoReflectionMethod, MonoObject, MonoSpanOfObjects_ref, MonoExceptionOut))
360+
HANDLES(MCMETH_5, "InvokeClassConstructor", ves_icall_InvokeClassConstructor, void, 1, (MonoQCallTypeHandle))
360361
HANDLES_REUSE_WRAPPER(MCMETH_4, "get_metadata_token", ves_icall_reflection_get_token)
361362

362363
ICALL_TYPE(CATTR_DATA, "System.Reflection.RuntimeCustomAttributeData", CATTR_DATA_1)

src/mono/mono/metadata/icall.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2809,6 +2809,18 @@ ves_icall_RuntimeTypeHandle_IsComObject (MonoQCallTypeHandle type_handle, MonoEr
28092809
return mono_class_is_com_object (klass);
28102810
}
28112811

2812+
void
2813+
ves_icall_InvokeClassConstructor (MonoQCallTypeHandle type_handle, MonoError *error)
2814+
{
2815+
MonoType *type = type_handle.type;
2816+
MonoClass *klass = mono_class_from_mono_type_internal (type);
2817+
2818+
MonoVTable *vtable = mono_class_vtable_checked (klass, error);
2819+
return_if_nok (error);
2820+
2821+
mono_runtime_class_init_full (vtable, error);
2822+
}
2823+
28122824
guint32
28132825
ves_icall_reflection_get_token (MonoObjectHandle obj, MonoError *error)
28142826
{

0 commit comments

Comments
 (0)