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

Remove dead code in MarshalNative #44506

Merged
merged 3 commits into from
Nov 11, 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 @@ -300,18 +300,11 @@ public static string GetTypeInfoName(ITypeInfo typeInfo)
throw new ArgumentNullException(nameof(o));
}

return GetIUnknownForObjectNative(o, false);
return GetIUnknownForObjectNative(o);
}

[MethodImpl(MethodImplOptions.InternalCall)]
private static extern IntPtr /* IUnknown* */ GetIUnknownForObjectNative(object o, bool onlyInContext);

/// <summary>
/// Return the raw IUnknown* for a COM Object not related to current.
/// Does not call AddRef.
/// </summary>
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern IntPtr /* IUnknown* */ GetRawIUnknownForComObjectNoAddRef(object o);
private static extern IntPtr /* IUnknown* */ GetIUnknownForObjectNative(object o);

/// <summary>
/// Return the IDispatch* for an Object.
Expand All @@ -324,11 +317,11 @@ public static string GetTypeInfoName(ITypeInfo typeInfo)
throw new ArgumentNullException(nameof(o));
}

return GetIDispatchForObjectNative(o, false);
return GetIDispatchForObjectNative(o);
}

[MethodImpl(MethodImplOptions.InternalCall)]
private static extern IntPtr /* IDispatch* */ GetIDispatchForObjectNative(object o, bool onlyInContext);
private static extern IntPtr /* IDispatch* */ GetIDispatchForObjectNative(object o);

/// <summary>
/// Return the IUnknown* representing the interface for the Object.
Expand All @@ -347,7 +340,7 @@ public static string GetTypeInfoName(ITypeInfo typeInfo)
throw new ArgumentNullException(nameof(T));
}

return GetComInterfaceForObjectNative(o, T, false, true);
return GetComInterfaceForObjectNative(o, T, true);
}

[SupportedOSPlatform("windows")]
Expand All @@ -372,11 +365,11 @@ public static string GetTypeInfoName(ITypeInfo typeInfo)
}

bool bEnableCustomizedQueryInterface = ((mode == CustomQueryInterfaceMode.Allow) ? true : false);
return GetComInterfaceForObjectNative(o, T, false, bEnableCustomizedQueryInterface);
return GetComInterfaceForObjectNative(o, T, bEnableCustomizedQueryInterface);
}

[MethodImpl(MethodImplOptions.InternalCall)]
private static extern IntPtr /* IUnknown* */ GetComInterfaceForObjectNative(object o, Type t, bool onlyInContext, bool fEnableCustomizedQueryInterface);
private static extern IntPtr /* IUnknown* */ GetComInterfaceForObjectNative(object o, Type t, bool fEnableCustomizedQueryInterface);

/// <summary>
/// Return the managed object representing the IUnknown*
Expand Down
29 changes: 0 additions & 29 deletions src/coreclr/src/vm/cominterfacemarshaler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,35 +456,6 @@ VOID COMInterfaceMarshaler::InitializeExistingComObject(OBJECTREF *pComObj, IUnk
CreateObjectRef(NeedUniqueObject(), pComObj, ppIncomingIP, /* pIncomingItfMT = */ NULL, /* bIncomingIPAddRefed = */ true);
}

//--------------------------------------------------------------------------------
// Helper to wrap an IUnknown with COM object
//--------------------------------------------------------------------------------
OBJECTREF COMInterfaceMarshaler::WrapWithComObject()
{
CONTRACTL
{
THROWS;
GC_TRIGGERS;
MODE_COOPERATIVE;
}
CONTRACTL_END;

OBJECTREF oref = NULL;
GCPROTECT_BEGIN(oref)
{
CreateObjectRef(
TRUE, // fDuplicate
&oref, // pComObj
NULL, // ppIncomingIP
NULL, // pIncomingItfMT
false // bIncomingIPAddRefed
);
}
GCPROTECT_END();

return oref;
}

//--------------------------------------------------------------------------------
// VOID EnsureCOMInterfacesSupported(OBJECTREF oref, MethodTable* pClassMT)
// Make sure the oref supports all the COM interfaces in the class
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/src/vm/cominterfacemarshaler.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ class COMInterfaceMarshaler
OBJECTREF FindOrCreateObjectRef(IUnknown **ppIncomingIP, MethodTable *pIncomingItfMT = NULL);
OBJECTREF FindOrCreateObjectRef(IUnknown *pIncomingIP, MethodTable *pIncomingItfMT = NULL);

OBJECTREF WrapWithComObject();

VOID InitializeExistingComObject(OBJECTREF *pComObj, IUnknown **ppIncomingIP);

private:
Expand Down
26 changes: 10 additions & 16 deletions src/coreclr/src/vm/dllimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2537,7 +2537,7 @@ void PInvokeStaticSigInfo::PreInit(MethodDesc* pMD)
}

PInvokeStaticSigInfo::PInvokeStaticSigInfo(
MethodDesc* pMD, LPCUTF8 *pLibName, LPCUTF8 *pEntryPointName, ThrowOnError throwOnError)
MethodDesc* pMD, LPCUTF8 *pLibName, LPCUTF8 *pEntryPointName)
{
CONTRACTL
{
Expand All @@ -2549,8 +2549,7 @@ PInvokeStaticSigInfo::PInvokeStaticSigInfo(

DllImportInit(pMD, pLibName, pEntryPointName);

if (throwOnError)
ReportErrors();
ReportErrors();
}

PInvokeStaticSigInfo::PInvokeStaticSigInfo(MethodDesc* pMD, ThrowOnError throwOnError)
Expand Down Expand Up @@ -2654,7 +2653,7 @@ PInvokeStaticSigInfo::PInvokeStaticSigInfo(MethodDesc* pMD, ThrowOnError throwOn
}

PInvokeStaticSigInfo::PInvokeStaticSigInfo(
Signature sig, Module* pModule, ThrowOnError throwOnError)
Signature sig, Module* pModule)
{
CONTRACTL
{
Expand All @@ -2671,8 +2670,7 @@ PInvokeStaticSigInfo::PInvokeStaticSigInfo(
SetIsStatic (!(MetaSig::GetCallingConvention(pModule, sig) & IMAGE_CEE_CS_CALLCONV_HASTHIS));
InitCallConv((CorPinvokeMap)0, FALSE);

if (throwOnError)
ReportErrors();
ReportErrors();
}

void PInvokeStaticSigInfo::DllImportInit(MethodDesc* pMD, LPCUTF8 *ppLibName, LPCUTF8 *ppEntryPointName)
Expand Down Expand Up @@ -4293,18 +4291,17 @@ static void CreateNDirectStubAccessMetadata(
}
}

void NDirect::PopulateNDirectMethodDesc(NDirectMethodDesc* pNMD, PInvokeStaticSigInfo* pSigInfo, BOOL throwOnError /*= TRUE*/)
void NDirect::PopulateNDirectMethodDesc(NDirectMethodDesc* pNMD, PInvokeStaticSigInfo* pSigInfo)
{
if (pNMD->IsSynchronized() && throwOnError)
if (pNMD->IsSynchronized())
COMPlusThrow(kTypeLoadException, IDS_EE_NOSYNCHRONIZED);

WORD ndirectflags = 0;
if (pNMD->MethodDesc::IsVarArg())
ndirectflags |= NDirectMethodDesc::kVarArgs;

LPCUTF8 szLibName = NULL, szEntryPointName = NULL;
new (pSigInfo) PInvokeStaticSigInfo(pNMD, &szLibName, &szEntryPointName,
(throwOnError ? PInvokeStaticSigInfo::THROW_ON_ERROR : PInvokeStaticSigInfo::NO_THROW_ON_ERROR));
new (pSigInfo) PInvokeStaticSigInfo(pNMD, &szLibName, &szEntryPointName);

if (pSigInfo->GetCharSet() == nltAnsi)
ndirectflags |= NDirectMethodDesc::kNativeAnsi;
Expand Down Expand Up @@ -5249,7 +5246,7 @@ MethodDesc* NDirect::GetILStubMethodDesc(NDirectMethodDesc* pNMD, PInvokeStaticS

MethodDesc* pStubMD = NULL;

if (!pNMD->IsVarArgs() || SF_IsForNumParamBytes(dwStubFlags))
if (!pNMD->IsVarArgs())
{
if (pNMD->IsClassConstructorTriggeredByILStub())
{
Expand All @@ -5258,7 +5255,7 @@ MethodDesc* NDirect::GetILStubMethodDesc(NDirectMethodDesc* pNMD, PInvokeStaticS

pStubMD = CreateCLRToNativeILStub(
pSigInfo,
dwStubFlags & ~NDIRECTSTUB_FL_FOR_NUMPARAMBYTES,
dwStubFlags,
pNMD);
}

Expand Down Expand Up @@ -5354,14 +5351,11 @@ PCODE NDirect::GetStubForILStub(NDirectMethodDesc* pNMD, MethodDesc** ppStubMD,
if (NULL == *ppStubMD)
{
PInvokeStaticSigInfo sigInfo;
NDirect::PopulateNDirectMethodDesc(pNMD, &sigInfo, /* throwOnError = */ !SF_IsForNumParamBytes(dwStubFlags));
NDirect::PopulateNDirectMethodDesc(pNMD, &sigInfo);

*ppStubMD = NDirect::GetILStubMethodDesc(pNMD, &sigInfo, dwStubFlags);
}

if (SF_IsForNumParamBytes(dwStubFlags))
return NULL;

if (*ppStubMD)
{
pStub = JitILStub(*ppStubMD);
Expand Down
10 changes: 4 additions & 6 deletions src/coreclr/src/vm/dllimport.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class NDirect
_In_opt_ PCCOR_SIGNATURE pSig = NULL,
_In_opt_ Module* pModule = NULL,
_In_ bool unmanagedCallersOnlyRequiresMarshalling = true);
static void PopulateNDirectMethodDesc(NDirectMethodDesc* pNMD, PInvokeStaticSigInfo* pSigInfo, BOOL throwOnError = TRUE);
static void PopulateNDirectMethodDesc(NDirectMethodDesc* pNMD, PInvokeStaticSigInfo* pSigInfo);

static MethodDesc* CreateCLRToNativeILStub(
StubSigDesc* pSigDesc,
Expand Down Expand Up @@ -161,7 +161,7 @@ enum NDirectStubFlags
#endif // FEATURE_COMINTEROP

// internal flags -- these won't ever show up in an NDirectStubHashBlob
NDIRECTSTUB_FL_FOR_NUMPARAMBYTES = 0x10000000, // do just enough to return the right value from Marshal.NumParamBytes
// unused = 0x10000000,

#ifdef FEATURE_COMINTEROP
NDIRECTSTUB_FL_COMLATEBOUND = 0x20000000, // we use a generic stub for late bound calls
Expand Down Expand Up @@ -210,7 +210,6 @@ inline bool SF_IsNGENedStubForProfiling(DWORD dwStubFlags) { LIMITED_METHOD_CONT
inline bool SF_IsDebuggableStub (DWORD dwStubFlags) { LIMITED_METHOD_CONTRACT; return (dwStubFlags < NDIRECTSTUB_FL_INVALID && 0 != (dwStubFlags & NDIRECTSTUB_FL_GENERATEDEBUGGABLEIL)); }
inline bool SF_IsCALLIStub (DWORD dwStubFlags) { LIMITED_METHOD_CONTRACT; return (dwStubFlags < NDIRECTSTUB_FL_INVALID && 0 != (dwStubFlags & NDIRECTSTUB_FL_UNMANAGED_CALLI)); }
inline bool SF_IsStubWithCctorTrigger (DWORD dwStubFlags) { LIMITED_METHOD_CONTRACT; return (dwStubFlags < NDIRECTSTUB_FL_INVALID && 0 != (dwStubFlags & NDIRECTSTUB_FL_TRIGGERCCTOR)); }
inline bool SF_IsForNumParamBytes (DWORD dwStubFlags) { LIMITED_METHOD_CONTRACT; return (dwStubFlags < NDIRECTSTUB_FL_INVALID && 0 != (dwStubFlags & NDIRECTSTUB_FL_FOR_NUMPARAMBYTES)); }
inline bool SF_IsStructMarshalStub (DWORD dwStubFlags) { LIMITED_METHOD_CONTRACT; return (dwStubFlags < NDIRECTSTUB_FL_INVALID && 0 != (dwStubFlags & NDIRECTSTUB_FL_STRUCT_MARSHAL)); }

#ifdef FEATURE_ARRAYSTUB_AS_IL
Expand Down Expand Up @@ -320,11 +319,11 @@ struct PInvokeStaticSigInfo
public:
PInvokeStaticSigInfo() { LIMITED_METHOD_CONTRACT; }

PInvokeStaticSigInfo(Signature sig, Module* pModule, ThrowOnError throwOnError = THROW_ON_ERROR);
PInvokeStaticSigInfo(Signature sig, Module* pModule);

PInvokeStaticSigInfo(MethodDesc* pMdDelegate, ThrowOnError throwOnError = THROW_ON_ERROR);

PInvokeStaticSigInfo(MethodDesc* pMD, LPCUTF8 *pLibName, LPCUTF8 *pEntryPointName, ThrowOnError throwOnError = THROW_ON_ERROR);
PInvokeStaticSigInfo(MethodDesc* pMD, LPCUTF8 *pLibName, LPCUTF8 *pEntryPointName);

public:
void ReportErrors();
Expand Down Expand Up @@ -563,7 +562,6 @@ class NDirectStubLinker : public ILStubLinker
#endif // DACCESS_COMPILE

// This attempts to guess whether a target is an API call that uses SetLastError to communicate errors.
BOOL HeuristicDoesThisLooksLikeAnApiCall(LPBYTE pTarget);
BOOL HeuristicDoesThisLookLikeAGetLastErrorCall(LPBYTE pTarget);
DWORD STDMETHODCALLTYPE FalseGetLastError();

Expand Down
1 change: 0 additions & 1 deletion src/coreclr/src/vm/ecalllist.h
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,6 @@ FCFuncStart(gInteropMarshalFuncs)

#ifdef FEATURE_COMINTEROP
FCFuncElement("GetHRForException", MarshalNative::GetHRForException)
FCFuncElement("GetRawIUnknownForComObjectNoAddRef", MarshalNative::GetRawIUnknownForComObjectNoAddRef)
FCFuncElement("IsComObject", MarshalNative::IsComObject)
FCFuncElement("GetObjectForIUnknownNative", MarshalNative::GetObjectForIUnknownNative)
FCFuncElement("GetUniqueObjectForIUnknownNative", MarshalNative::GetUniqueObjectForIUnknownNative)
Expand Down
Loading