diff options
author | Faizur Rahman <shrah@microsoft.com> | 2017-10-18 04:41:04 +0300 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2017-10-18 04:41:04 +0300 |
commit | c6995b38cbb76212861b4f665c8b9525eaec69ec (patch) | |
tree | b90834fb320647390fb7d511d47e4c6d040ab366 /src/ILCompiler.Compiler | |
parent | 53f2da1da47159b7b4dd39de53e0887ab9a013e8 (diff) |
Add support for marshalling struct with delegates (#4737)
Diffstat (limited to 'src/ILCompiler.Compiler')
-rw-r--r-- | src/ILCompiler.Compiler/src/Compiler/CompilerGeneratedInteropStubManager.cs | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/src/ILCompiler.Compiler/src/Compiler/CompilerGeneratedInteropStubManager.cs b/src/ILCompiler.Compiler/src/Compiler/CompilerGeneratedInteropStubManager.cs index b018f7a5e..d63f1b92a 100644 --- a/src/ILCompiler.Compiler/src/Compiler/CompilerGeneratedInteropStubManager.cs +++ b/src/ILCompiler.Compiler/src/Compiler/CompilerGeneratedInteropStubManager.cs @@ -136,6 +136,36 @@ namespace ILCompiler }; } } + + private void AddDependenciesDueToPInvokeStructDelegateField(ref DependencyList dependencies, NodeFactory factory, TypeDesc typeDesc) + { + if (typeDesc is ByRefType) + { + typeDesc = typeDesc.GetParameterType(); + } + + MetadataType metadataType = typeDesc as MetadataType; + if (metadataType != null) + { + foreach (FieldDesc field in metadataType.GetFields()) + { + if (field.IsStatic) + { + continue; + } + TypeDesc fieldType = field.FieldType; + + if (fieldType.IsDelegate) + { + AddDependenciesDueToPInvokeDelegate(ref dependencies, factory, fieldType); + } + else if (MarshalHelpers.IsStructMarshallingRequired(fieldType)) + { + AddDependenciesDueToPInvokeStructDelegateField(ref dependencies, factory, fieldType); + } + } + } + } public override void AddDependeciesDueToPInvoke(ref DependencyList dependencies, NodeFactory factory, MethodDesc method) { @@ -146,9 +176,19 @@ namespace ILCompiler MethodSignature methodSig = method.Signature; AddDependenciesDueToPInvokeDelegate(ref dependencies, factory, methodSig.ReturnType); + // struct may contain delegate fields, hence we need to add dependencies for it + if (MarshalHelpers.IsStructMarshallingRequired(methodSig.ReturnType)) + { + AddDependenciesDueToPInvokeStructDelegateField(ref dependencies, factory, methodSig.ReturnType); + } + for (int i = 0; i < methodSig.Length; i++) { AddDependenciesDueToPInvokeDelegate(ref dependencies, factory, methodSig[i]); + if (MarshalHelpers.IsStructMarshallingRequired(methodSig[i])) + { + AddDependenciesDueToPInvokeStructDelegateField(ref dependencies, factory, methodSig[i]); + } } } @@ -226,13 +266,7 @@ namespace ILCompiler dependencies.Add(factory.MethodEntrypoint(GetStructMarshallingNativeToManagedStub(type)), "Struct Marshalling stub"); dependencies.Add(factory.MethodEntrypoint(GetStructMarshallingCleanupStub(type)), "Struct Marshalling stub"); - foreach (var inlineArrayCandidate in stub.GetInlineArrayCandidates()) - { - foreach (var method in inlineArrayCandidate.ElementType.GetMethods()) - { - dependencies.Add(factory.MethodEntrypoint(method), "inline array marshalling stub"); - } - } + AddDependenciesDueToPInvokeStructDelegateField(ref dependencies, factory, type); } } |