Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use function pointers in more places #39752

Merged
merged 2 commits into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -701,14 +701,33 @@ public static TWrapper CreateWrapperOfType<T, TWrapper>([AllowNull] T o)
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern bool IsTypeVisibleFromCom(Type t);

[MethodImpl(MethodImplOptions.InternalCall)]
public static extern int /* HRESULT */ QueryInterface(IntPtr /* IUnknown */ pUnk, ref Guid iid, out IntPtr ppv);
public static unsafe int QueryInterface(IntPtr pUnk, ref Guid iid, out IntPtr ppv)
{
if (pUnk == IntPtr.Zero)
throw new ArgumentNullException(nameof(pUnk));

[MethodImpl(MethodImplOptions.InternalCall)]
public static extern int /* ULONG */ AddRef(IntPtr /* IUnknown */ pUnk);
fixed (Guid* pIID = &iid)
fixed (IntPtr* p = &ppv)
{
return ((delegate * stdcall <IntPtr, Guid*, IntPtr*, int>)(*(*(void***)pUnk + 0 /* IUnknown.QueryInterface slot */)))(pUnk, pIID, p);
AaronRobinsonMSFT marked this conversation as resolved.
Show resolved Hide resolved
}
}

[MethodImpl(MethodImplOptions.InternalCall)]
public static extern int /* ULONG */ Release(IntPtr /* IUnknown */ pUnk);
public static unsafe int AddRef(IntPtr pUnk)
{
if (pUnk == IntPtr.Zero)
throw new ArgumentNullException(nameof(pUnk));

return ((delegate * stdcall <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 * stdcall <IntPtr, int>)(*(*(void***)pUnk + 2 /* IUnknown.Release slot */)))(pUnk);
}

[MethodImpl(MethodImplOptions.InternalCall)]
public static extern void GetNativeVariantForObject(object? obj, /* VARIANT * */ IntPtr pDstNativeVariant);
Expand Down
3 changes: 0 additions & 3 deletions src/coreclr/src/vm/ecalllist.h
Original file line number Diff line number Diff line change
Expand Up @@ -776,12 +776,10 @@ FCFuncStart(gInteropMarshalFuncs)
FCFuncElement("IsComObject", MarshalNative::IsComObject)
FCFuncElement("GetObjectForIUnknownNative", MarshalNative::GetObjectForIUnknownNative)
FCFuncElement("GetUniqueObjectForIUnknownNative", MarshalNative::GetUniqueObjectForIUnknownNative)
FCFuncElement("AddRef", MarshalNative::AddRef)
FCFuncElement("GetNativeVariantForObject", MarshalNative::GetNativeVariantForObject)
FCFuncElement("GetObjectForNativeVariant", MarshalNative::GetObjectForNativeVariant)
FCFuncElement("InternalFinalReleaseComObject", MarshalNative::FinalReleaseComObject)
FCFuncElement("IsTypeVisibleFromCom", MarshalNative::IsTypeVisibleFromCom)
FCFuncElement("QueryInterface", MarshalNative::QueryInterface)
FCFuncElement("CreateAggregatedObject", MarshalNative::CreateAggregatedObject)
FCFuncElement("AreComObjectsAvailableForCleanup", MarshalNative::AreComObjectsAvailableForCleanup)
FCFuncElement("InternalCreateWrapperOfType", MarshalNative::InternalCreateWrapperOfType)
Expand All @@ -792,7 +790,6 @@ FCFuncStart(gInteropMarshalFuncs)
FCFuncElement("GetIDispatchForObjectNative", MarshalNative::GetIDispatchForObjectNative)
FCFuncElement("GetComInterfaceForObjectNative", MarshalNative::GetComInterfaceForObjectNative)
FCFuncElement("InternalReleaseComObject", MarshalNative::ReleaseComObject)
FCFuncElement("Release", MarshalNative::Release)
FCFuncElement("GetTypedObjectForIUnknown", MarshalNative::GetTypedObjectForIUnknown)
FCFuncElement("ChangeWrapperHandleStrength", MarshalNative::ChangeWrapperHandleStrength)
FCFuncElement("CleanupUnusedObjectsInCurrentContext", MarshalNative::CleanupUnusedObjectsInCurrentContext)
Expand Down
77 changes: 0 additions & 77 deletions src/coreclr/src/vm/marshalnative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1226,83 +1226,6 @@ FCIMPL1(FC_BOOL_RET, MarshalNative::IsTypeVisibleFromCom, ReflectClassBaseObject
}
FCIMPLEND


//====================================================================
// IUnknown Helpers
//====================================================================
// IUnknown::QueryInterface
FCIMPL3(HRESULT, MarshalNative::QueryInterface, IUnknown* pUnk, REFGUID iid, void** ppv)
{
CONTRACTL
{
FCALL_CHECK;
PRECONDITION(CheckPointer(pUnk, NULL_OK));
PRECONDITION(CheckPointer(ppv));
}
CONTRACTL_END;

HRESULT hr = S_OK;
HELPER_METHOD_FRAME_BEGIN_RET_0();

if (!pUnk)
COMPlusThrowArgumentNull(W("pUnk"));

hr = SafeQueryInterface(pUnk,iid,(IUnknown**)ppv);
LogInteropQI(pUnk, iid, hr, "PInvoke::QI");

HELPER_METHOD_FRAME_END();
return hr;
}
FCIMPLEND

// IUnknown::AddRef
FCIMPL1(ULONG, MarshalNative::AddRef, IUnknown* pUnk)
{
CONTRACTL
{
FCALL_CHECK;
PRECONDITION(CheckPointer(pUnk, NULL_OK));
}
CONTRACTL_END;

ULONG cbRef = 0;
HELPER_METHOD_FRAME_BEGIN_RET_0();

if (!pUnk)
COMPlusThrowArgumentNull(W("pUnk"));

cbRef = SafeAddRef(pUnk);
LogInteropAddRef(pUnk, cbRef, "PInvoke.AddRef");

HELPER_METHOD_FRAME_END();
return cbRef;
}
FCIMPLEND

//IUnknown::Release
FCIMPL1(ULONG, MarshalNative::Release, IUnknown* pUnk)
{
CONTRACTL
{
FCALL_CHECK;
PRECONDITION(CheckPointer(pUnk, NULL_OK));
}
CONTRACTL_END;

ULONG cbRef = 0;
HELPER_METHOD_FRAME_BEGIN_RET_0();

if (!pUnk)
COMPlusThrowArgumentNull(W("pUnk"));

cbRef = SafeRelease(pUnk);
LogInteropRelease(pUnk, cbRef, "PInvoke.Release");

HELPER_METHOD_FRAME_END();
return cbRef;
}
FCIMPLEND

FCIMPL2(void, MarshalNative::GetNativeVariantForObject, Object* ObjUNSAFE, LPVOID pDestNativeVariant)
{
CONTRACTL
Expand Down
7 changes: 0 additions & 7 deletions src/coreclr/src/vm/marshalnative.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,6 @@ class MarshalNative
//====================================================================
static FCDECL1(FC_BOOL_RET, IsTypeVisibleFromCom, ReflectClassBaseObject* refClassUNSAFE);

//====================================================================
// IUnknown Helpers
//====================================================================
static FCDECL3(HRESULT, QueryInterface, IUnknown* pUnk, REFGUID iid, void** ppv);
static FCDECL1(ULONG, AddRef, IUnknown* pUnk);
static FCDECL1(ULONG, Release, IUnknown* pUnk);

//====================================================================
// These methods convert OLE variants to and from objects.
//====================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,6 @@ int TryInvoke(
IntPtr puArgErr);
}

/// <summary>
/// Layout of the IDispatch vtable
/// </summary>
internal enum IDispatchMethodIndices
{
IUnknown_QueryInterface,
IUnknown_AddRef,
IUnknown_Release,

IDispatch_GetTypeInfoCount,
IDispatch_GetTypeInfo,
IDispatch_GetIDsOfNames,
IDispatch_Invoke
}

[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("B196B283-BAB4-101A-B69C-00AA00341D07")]
Expand Down
Loading