diff options
author | Luqun Lou <luqunl@microsoft.com> | 2017-10-17 07:03:54 +0300 |
---|---|---|
committer | Luqun Lou <luqunl@microsoft.com> | 2017-10-17 07:03:54 +0300 |
commit | 990f55966aa7daef1e312c12e73c624ed02c789e (patch) | |
tree | 87d2b591085747ddb7dc7b4f1da8bb97ceef47d4 /src/System.Private.Interop | |
parent | ce1d3e31090e2ace1bd2ac7e9fddaca0b1f70738 (diff) |
Fix For Bug#507240 Marshal.IsComObject fails for __ComObject in x-plat MCG
Yi/Alan/Tyler found out this bug and the root cause--- IsComObject(Type t) only check whether t is subclass of __ComObject or not --- IsSubclassOf fails if type is exactly __ComObject: https://msdn.microsoft.com/en-us/library/system.type.issubclassof%28v=vs.110%29.aspx
the fix is to add a check to see whether type itself is __ComObject or not.
Changes:
1. Unify IsCOMObject and IsComObject into IsComObject. don't confuse ourselves
2. Move McgComHelpers.IsComObject into McgMarshal.IsComObject
TODO:
1. Consider to split McgMarshal.cs into McgMarshal.Pinvoke.cs/McgMarshal.Com.cs/McgMarshal.WinRT.cs/McgMarshal.Common.cs
[tfs-changeset: 1678276]
Diffstat (limited to 'src/System.Private.Interop')
4 files changed, 21 insertions, 20 deletions
diff --git a/src/System.Private.Interop/src/Shared/McgComHelpers.cs b/src/System.Private.Interop/src/Shared/McgComHelpers.cs index 781232011..603543449 100644 --- a/src/System.Private.Interop/src/Shared/McgComHelpers.cs +++ b/src/System.Private.Interop/src/Shared/McgComHelpers.cs @@ -231,14 +231,6 @@ namespace System.Runtime.InteropServices } /// <summary> - /// Return true if the object is a RCW. False otherwise - /// </summary> - internal static bool IsComObject(object obj) - { - return (obj is __ComObject); - } - - /// <summary> /// Unwrap if this is a managed wrapper /// Typically used in data binding /// For example, you don't want to data bind against a KeyValuePairImpl<K, V> - you want the real diff --git a/src/System.Private.Interop/src/Shared/McgMarshal.cs b/src/System.Private.Interop/src/Shared/McgMarshal.cs index 2c3b9e5a4..b9db11146 100644 --- a/src/System.Private.Interop/src/Shared/McgMarshal.cs +++ b/src/System.Private.Interop/src/Shared/McgMarshal.cs @@ -78,15 +78,26 @@ namespace System.Runtime.InteropServices #endif } - public static bool IsCOMObject(Type type) + /// <summary> + /// Return true if the type is __COM or derived from __COM. False otherwise + /// </summary> + public static bool IsComObject(Type type) { #if RHTESTCL return false; #else - return type.GetTypeInfo().IsSubclassOf(typeof(__ComObject)); + return type == typeof(__ComObject) || type.GetTypeInfo().IsSubclassOf(typeof(__ComObject)); #endif } + /// <summary> + /// Return true if the object is a RCW. False otherwise + /// </summary> + internal static bool IsComObject(object obj) + { + return (obj is __ComObject); + } + public static T FastCast<T>(object value) where T : class { // We have an assert here, to verify that a "real" cast would have succeeded. @@ -401,7 +412,7 @@ namespace System.Runtime.InteropServices #endregion -#region COM marshalling + #region COM marshalling /// <summary> /// Explicit AddRef for RCWs @@ -921,10 +932,9 @@ namespace System.Runtime.InteropServices { return CoCreateInstanceEx(clsid, string.Empty); } + #endregion -#endregion - -#region Testing + #region Testing /// <summary> /// Internal-only method to allow testing of apartment teardown code @@ -1063,7 +1073,7 @@ namespace System.Runtime.InteropServices IntPtr pResult = default(IntPtr); - int hr = CalliIntrinsics.StdCall<int>( + int hr = CalliIntrinsics.StdCall__int( pIActivationFactoryInternal->pVtable->pfnActivateInstance, pIActivationFactoryInternal, &pResult diff --git a/src/System.Private.Interop/src/System/Runtime/InteropServices/Marshal.cs b/src/System.Private.Interop/src/System/Runtime/InteropServices/Marshal.cs index 28a956b6d..20b088a7a 100644 --- a/src/System.Private.Interop/src/System/Runtime/InteropServices/Marshal.cs +++ b/src/System.Private.Interop/src/System/Runtime/InteropServices/Marshal.cs @@ -802,7 +802,7 @@ namespace System.Runtime.InteropServices if (o == null) throw new ArgumentNullException(nameof(o), SR.Arg_InvalidHandle); - return McgComHelpers.IsComObject(o); + return McgMarshal.IsComObject(o); } public static unsafe IntPtr StringToCoTaskMemUni(String s) diff --git a/src/System.Private.Interop/src/System/Runtime/InteropServices/MarshalImpl.cs b/src/System.Private.Interop/src/System/Runtime/InteropServices/MarshalImpl.cs index 973b305a7..20f08a919 100644 --- a/src/System.Private.Interop/src/System/Runtime/InteropServices/MarshalImpl.cs +++ b/src/System.Private.Interop/src/System/Runtime/InteropServices/MarshalImpl.cs @@ -38,18 +38,18 @@ namespace System.Runtime.InteropServices { if (o == null) throw new ArgumentNullException(nameof(o)); - return McgMarshal.IsCOMObject(o.GetType()); + return McgMarshal.IsComObject(o); } public static int ReleaseComObject(object o) { if (o == null) throw new ArgumentNullException(nameof(o)); - return McgMarshal.Release(o as __ComObject); + return McgMarshal.Release(o as __ComObject); } public static int FinalReleaseComObject(object o) { - return McgMarshal.FinalReleaseComObject(o); + return McgMarshal.FinalReleaseComObject(o); } public static int QueryInterface(IntPtr pUnk, ref Guid iid, out IntPtr ppv) @@ -72,6 +72,5 @@ namespace System.Runtime.InteropServices { return McgMarshal.ComRelease(pUnk); } - } } |