Skip to content

Commit

Permalink
[release/7.0-rc1] [mono] Implement missing functionality for cctor in…
Browse files Browse the repository at this point in the history
…vocation (#74043)

* [mono] Implement missing functionality for cctor invocation

* [mono] Re-enable test

Co-authored-by: Vlad Brezae <[email protected]>
  • Loading branch information
github-actions[bot] and BrzVlad authored Aug 17, 2022
1 parent d8866dc commit 8baff7d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public void Invoke_StaticConstructor_NullObject_NullParameters()
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsInvokingStaticConstructorsSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/40351", TestRuntimes.Mono)]
public void Invoke_StaticConstructorMultipleTimes()
{
ConstructorInfo[] constructors = GetConstructors(typeof(ClassWithStaticConstructorThatIsCalledMultipleTimesViaReflection));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -802,10 +802,13 @@ internal RuntimeType[] ArgumentTypes
}
}

private static void InvokeClassConstructor()
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern void InvokeClassConstructor(QCallTypeHandle type);

private void InvokeClassConstructor()
{
// [TODO] Mechanism for invoking class constructor
// See https://github.com/dotnet/runtime/issues/40351
RuntimeType type = (RuntimeType)DeclaringType;
InvokeClassConstructor(new QCallTypeHandle(ref type));
}

/*
Expand Down
1 change: 1 addition & 0 deletions src/mono/mono/metadata/icall-def.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ HANDLES(RASSEM_7, "InternalGetReferencedAssemblies", ves_icall_System_Reflection
ICALL_TYPE(MCMETH, "System.Reflection.RuntimeConstructorInfo", MCMETH_1)
HANDLES(MCMETH_1, "GetGenericMethodDefinition_impl", ves_icall_RuntimeMethodInfo_GetGenericMethodDefinition, MonoReflectionMethod, 1, (MonoReflectionMethod))
HANDLES(MCMETH_2, "InternalInvoke", ves_icall_InternalInvoke, MonoObject, 4, (MonoReflectionMethod, MonoObject, MonoSpanOfObjects_ref, MonoExceptionOut))
HANDLES(MCMETH_5, "InvokeClassConstructor", ves_icall_InvokeClassConstructor, void, 1, (MonoQCallTypeHandle))
HANDLES_REUSE_WRAPPER(MCMETH_4, "get_metadata_token", ves_icall_reflection_get_token)

ICALL_TYPE(CATTR_DATA, "System.Reflection.RuntimeCustomAttributeData", CATTR_DATA_1)
Expand Down
12 changes: 12 additions & 0 deletions src/mono/mono/metadata/icall.c
Original file line number Diff line number Diff line change
Expand Up @@ -2809,6 +2809,18 @@ ves_icall_RuntimeTypeHandle_IsComObject (MonoQCallTypeHandle type_handle, MonoEr
return mono_class_is_com_object (klass);
}

void
ves_icall_InvokeClassConstructor (MonoQCallTypeHandle type_handle, MonoError *error)
{
MonoType *type = type_handle.type;
MonoClass *klass = mono_class_from_mono_type_internal (type);

MonoVTable *vtable = mono_class_vtable_checked (klass, error);
return_if_nok (error);

mono_runtime_class_init_full (vtable, error);
}

guint32
ves_icall_reflection_get_token (MonoObjectHandle obj, MonoError *error)
{
Expand Down

0 comments on commit 8baff7d

Please sign in to comment.