未验证 提交 3cbbadee 编写于 作者: J John Tur 提交者: GitHub

Move some Marshal functions to shared partition (#51045)

上级 c5872ac0
......@@ -600,37 +600,6 @@ public static bool SetComObjectData(object obj, object key, object? data)
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern bool IsTypeVisibleFromCom(Type t);
[SupportedOSPlatform("windows")]
public static unsafe int QueryInterface(IntPtr pUnk, ref Guid iid, out IntPtr ppv)
{
if (pUnk == IntPtr.Zero)
throw new ArgumentNullException(nameof(pUnk));
fixed (Guid* pIID = &iid)
fixed (IntPtr* p = &ppv)
{
return ((delegate* unmanaged<IntPtr, Guid*, IntPtr*, int>)(*(*(void***)pUnk + 0 /* IUnknown.QueryInterface slot */)))(pUnk, pIID, p);
}
}
[SupportedOSPlatform("windows")]
public static unsafe int AddRef(IntPtr pUnk)
{
if (pUnk == IntPtr.Zero)
throw new ArgumentNullException(nameof(pUnk));
return ((delegate* unmanaged<IntPtr, int>)(*(*(void***)pUnk + 1 /* IUnknown.AddRef slot */)))(pUnk);
}
[SupportedOSPlatform("windows")]
public static unsafe int Release(IntPtr pUnk)
{
if (pUnk == IntPtr.Zero)
throw new ArgumentNullException(nameof(pUnk));
return ((delegate* unmanaged<IntPtr, int>)(*(*(void***)pUnk + 2 /* IUnknown.Release slot */)))(pUnk);
}
[SupportedOSPlatform("windows")]
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern void GetNativeVariantForObject(object? obj, /* VARIANT * */ IntPtr pDstNativeVariant);
......
......@@ -15,12 +15,6 @@ public static int GetHRForException(Exception? e)
return e?.HResult ?? 0;
}
[SupportedOSPlatform("windows")]
public static int AddRef(IntPtr pUnk)
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
}
public static bool AreComObjectsAvailableForCleanup() => false;
[SupportedOSPlatform("windows")]
......@@ -214,18 +208,6 @@ public static bool IsTypeVisibleFromCom(Type t)
return false;
}
[SupportedOSPlatform("windows")]
public static int QueryInterface(IntPtr pUnk, ref Guid iid, out IntPtr ppv)
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
}
[SupportedOSPlatform("windows")]
public static int Release(IntPtr pUnk)
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ComInterop);
}
[SupportedOSPlatform("windows")]
public static int ReleaseComObject(object o)
{
......
......@@ -144,6 +144,34 @@ public static int SizeOf(Type t)
public static int SizeOf<T>() => SizeOf(typeof(T));
public static unsafe int QueryInterface(IntPtr pUnk, ref Guid iid, out IntPtr ppv)
{
if (pUnk == IntPtr.Zero)
throw new ArgumentNullException(nameof(pUnk));
fixed (Guid* pIID = &iid)
fixed (IntPtr* p = &ppv)
{
return ((delegate* unmanaged<IntPtr, Guid*, IntPtr*, int>)(*(*(void***)pUnk + 0 /* IUnknown.QueryInterface slot */)))(pUnk, pIID, p);
}
}
public static unsafe int AddRef(IntPtr pUnk)
{
if (pUnk == IntPtr.Zero)
throw new ArgumentNullException(nameof(pUnk));
return ((delegate* unmanaged<IntPtr, int>)(*(*(void***)pUnk + 1 /* IUnknown.AddRef slot */)))(pUnk);
}
public static unsafe int Release(IntPtr pUnk)
{
if (pUnk == IntPtr.Zero)
throw new ArgumentNullException(nameof(pUnk));
return ((delegate* unmanaged<IntPtr, int>)(*(*(void***)pUnk + 2 /* IUnknown.Release slot */)))(pUnk);
}
/// <summary>
/// IMPORTANT NOTICE: This method does not do any verification on the array.
/// It must be used with EXTREME CAUTION since passing in invalid index or
......
......@@ -492,7 +492,6 @@ public static partial class Marshal
{
public static readonly int SystemDefaultCharSize;
public static readonly int SystemMaxDBCSCharSize;
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
public static int AddRef(System.IntPtr pUnk) { throw null; }
public static System.IntPtr AllocCoTaskMem(int cb) { throw null; }
public static System.IntPtr AllocHGlobal(int cb) { throw null; }
......@@ -625,7 +624,6 @@ public static partial class Marshal
public static object? PtrToStructure(System.IntPtr ptr, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] System.Type structureType) { throw null; }
public static T? PtrToStructure<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]T>(System.IntPtr ptr) { throw null; }
public static void PtrToStructure<T>(System.IntPtr ptr, [System.Diagnostics.CodeAnalysis.DisallowNullAttribute] T structure) { }
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
public static int QueryInterface(System.IntPtr pUnk, ref System.Guid iid, out System.IntPtr ppv) { throw null; }
public static byte ReadByte(System.IntPtr ptr) { throw null; }
public static byte ReadByte(System.IntPtr ptr, int ofs) { throw null; }
......@@ -654,7 +652,6 @@ public static partial class Marshal
public static System.IntPtr ReadIntPtr(object ptr, int ofs) { throw null; }
public static System.IntPtr ReAllocCoTaskMem(System.IntPtr pv, int cb) { throw null; }
public static System.IntPtr ReAllocHGlobal(System.IntPtr pv, System.IntPtr cb) { throw null; }
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
public static int Release(System.IntPtr pUnk) { throw null; }
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
public static int ReleaseComObject(object o) { throw null; }
......
......@@ -29,14 +29,6 @@ public void AddRef_ValidPointer_Success()
}
[Fact]
[PlatformSpecific(TestPlatforms.AnyUnix)]
public void AddRef_Unix_ThrowsPlatformNotSupportedException()
{
Assert.Throws<PlatformNotSupportedException>(() => Marshal.AddRef(IntPtr.Zero));
}
[Fact]
[PlatformSpecific(TestPlatforms.Windows)]
public void AddRef_ZeroPointer_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>("pUnk", () => Marshal.AddRef(IntPtr.Zero));
......
......@@ -124,15 +124,6 @@ public void QueryInterface_NoSuchInterface_Success(object o, string iidString)
}
[Fact]
[PlatformSpecific(TestPlatforms.AnyUnix)]
public void QueryInterface_Unix_ThrowsPlatformNotSupportedException()
{
Guid iid = Guid.Empty;
Assert.Throws<PlatformNotSupportedException>(() => Marshal.QueryInterface(IntPtr.Zero, ref iid, out IntPtr ppv));
}
[Fact]
[PlatformSpecific(TestPlatforms.Windows)]
public void QueryInterface_ZeroPointer_ThrowsArgumentNullException()
{
Guid iid = Guid.Empty;
......
......@@ -30,14 +30,6 @@ public void Release_ValidPointer_Success()
}
[Fact]
[PlatformSpecific(TestPlatforms.AnyUnix)]
public void Release_Unix_ThrowsPlatformNotSupportedException()
{
Assert.Throws<PlatformNotSupportedException>(() => Marshal.Release(IntPtr.Zero));
}
[Fact]
[PlatformSpecific(TestPlatforms.Windows)]
public void Release_ZeroPointer_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>("pUnk", () => Marshal.Release(IntPtr.Zero));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册