[runtime] Add support for using COM types from corlib.
authorRodrigo Kumpera <kumpera@gmail.com>
Thu, 25 May 2017 22:19:52 +0000 (15:19 -0700)
committerRodrigo Kumpera <kumpera@gmail.com>
Fri, 26 May 2017 00:11:27 +0000 (17:11 -0700)
This can be reproduced by trying to load a type that implements a COM interface corlib ships.

mono/metadata/cominterop.c
mono/tests/cominterop.cs
mono/tests/libtest.c

index 86309ef20234d4dd559726f0c9fcfe1a32f08e32..d522657b62f0b97efa9792ba77734e29d2882e12 100644 (file)
@@ -1090,7 +1090,7 @@ mono_cominterop_get_invoke (MonoMethod *method)
        for (i = 1; i <= sig->param_count; i++)
                mono_mb_emit_ldarg (mb, i);
 
-       if (method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) {
+       if ((method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) || mono_class_is_interface (method->klass)) {
                MonoMethod * native_wrapper = mono_cominterop_get_native_wrapper(method);
                mono_mb_emit_managed_call (mb, native_wrapper, NULL);
        }
index cc86c7387d0b7728ac01e1d8733786d3b6f4c907..aecae40401d0b921845a313fde973fe7d126c7cc 100644 (file)
@@ -533,6 +533,9 @@ public class Tests
                        if (TestITestDelegate (itest) != 0)
                                return 174;
 
+                       if (TestIfaceNoIcall (itest as ITestPresSig) != 0)
+                               return 201;
+
                        itest = new TestClass ();
 
                        if (TestITest (itest) != 0)
@@ -543,6 +546,7 @@ public class Tests
                        if (TestITest (itest) != 0)
                                return 176;
 
+
 #endif
 
                        #endregion // Runtime Callable Wrapper Tests
@@ -775,6 +779,7 @@ public class Tests
                void ITestIn ([MarshalAs (UnmanagedType.Interface)]ITest val);
                [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
                void ITestOut ([MarshalAs (UnmanagedType.Interface)]out ITest val);
+               int Return22NoICall();
        }
 
        [ComImport ()]
@@ -826,6 +831,8 @@ public class Tests
                [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
                [PreserveSig ()]
                int ITestOut ([MarshalAs (UnmanagedType.Interface)]out ITestPresSig val);
+               [PreserveSig ()]
+               int Return22NoICall();
        }
 
        [System.Runtime.InteropServices.GuidAttribute ("00000000-0000-0000-0000-000000000002")]
@@ -865,6 +872,9 @@ public class Tests
                public virtual extern void ITestIn ([MarshalAs (UnmanagedType.Interface)]ITest val);
                [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
                public virtual extern void ITestOut ([MarshalAs (UnmanagedType.Interface)]out ITest val);
+
+               [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
+               public virtual extern int Return22NoICall();
        }
 
        [System.Runtime.InteropServices.GuidAttribute ("00000000-0000-0000-0000-000000000002")]
@@ -1004,6 +1014,11 @@ public class Tests
                        val = new ManagedTestPresSig ();
                        return 0;
                }
+
+               public int Return22NoICall()
+               {
+                       return 88;
+               }
        }
 
        public class ManagedTest : ITest
@@ -1093,6 +1108,11 @@ public class Tests
                                return new ManagedTest ();
                        }
                }
+
+               public int Return22NoICall()
+               {
+                       return 99;
+               }
        }
 
        public static int mono_test_marshal_variant_in_callback (VarEnum vt, object obj)
@@ -1306,6 +1326,10 @@ public class Tests
                }
                return 0;
        }
+
+       public static int TestIfaceNoIcall (ITestPresSig itest) {
+               return itest.Return22NoICall () == 22 ? 0 : 1;
+       }
 }
 
 public class TestVisible
index 4517eda2f74f64ddc41f8e2453372f4b17e5fd12..b94b29d52fd8eae95c11e0877adcc1269a91093d 100644 (file)
@@ -3337,6 +3337,7 @@ typedef struct
        int (STDCALL *DoubleIn)(MonoComObject* pUnk, double a);
        int (STDCALL *ITestIn)(MonoComObject* pUnk, MonoComObject* pUnk2);
        int (STDCALL *ITestOut)(MonoComObject* pUnk, MonoComObject* *ppUnk);
+       int (STDCALL *Return22NoICall)(MonoComObject* pUnk);
 } MonoIUnknown;
 
 struct MonoComObject
@@ -3453,6 +3454,13 @@ ITestOut(MonoComObject* pUnk, MonoComObject* *ppUnk)
        return S_OK;
 }
 
+LIBTEST_API int STDCALL
+Return22NoICall(MonoComObject* pUnk)
+{
+       return 22;
+}
+
+
 static void create_com_object (MonoComObject** pOut);
 
 LIBTEST_API int STDCALL 
@@ -3484,6 +3492,7 @@ static void create_com_object (MonoComObject** pOut)
        (*pOut)->vtbl->ITestIn = ITestIn;
        (*pOut)->vtbl->ITestOut = ITestOut;
        (*pOut)->vtbl->get_ITest = get_ITest;
+       (*pOut)->vtbl->Return22NoICall = Return22NoICall;
 }
 
 static MonoComObject* same_object = NULL;