Remove unused functions in MarshalInfo (#51907)
authorElinor Fung <elfung@microsoft.com>
Tue, 27 Apr 2021 17:09:58 +0000 (10:09 -0700)
committerGitHub <noreply@github.com>
Tue, 27 Apr 2021 17:09:58 +0000 (10:09 -0700)
src/coreclr/vm/mlinfo.cpp
src/coreclr/vm/mlinfo.h

index cc4bcdc..57ee8a4 100644 (file)
 #define INITIAL_NUM_CMINFO_HASHTABLE_BUCKETS 32
 #define DEBUG_CONTEXT_STR_LEN 2000
 
-
-//-------------------------------------------------------------------------------------
-// Return the copy ctor for a VC class (if any exists)
-//-------------------------------------------------------------------------------------
-void FindCopyCtor(Module *pModule, MethodTable *pMT, MethodDesc **pMDOut)
+namespace
 {
-    CONTRACTL
+    //-------------------------------------------------------------------------------------
+    // Return the copy ctor for a VC class (if any exists)
+    //-------------------------------------------------------------------------------------
+    void FindCopyCtor(Module *pModule, MethodTable *pMT, MethodDesc **pMDOut)
     {
-        THROWS;
-        GC_TRIGGERS;    // CompareTypeTokens may trigger GC
-        MODE_ANY;
-    }
-    CONTRACTL_END;
-
-    *pMDOut = NULL;
+        CONTRACTL
+        {
+            THROWS;
+            GC_TRIGGERS;    // CompareTypeTokens may trigger GC
+            MODE_ANY;
+        }
+        CONTRACTL_END;
 
-    HRESULT     hr;
-    mdMethodDef tk;
-    mdTypeDef cl = pMT->GetCl();
-    TypeHandle th = TypeHandle(pMT);
-    SigTypeContext typeContext(th);
+        *pMDOut = NULL;
 
-    IMDInternalImport *pInternalImport = pModule->GetMDImport();
-    MDEnumHolder      hEnumMethod(pInternalImport);
+        HRESULT     hr;
+        mdMethodDef tk;
+        mdTypeDef cl = pMT->GetCl();
+        TypeHandle th = TypeHandle(pMT);
+        SigTypeContext typeContext(th);
 
-    //
-    // First try for the new syntax: <MarshalCopy>
-    //
-    IfFailThrow(pInternalImport->EnumInit(mdtMethodDef, cl, &hEnumMethod));
+        IMDInternalImport *pInternalImport = pModule->GetMDImport();
+        MDEnumHolder      hEnumMethod(pInternalImport);
 
-    while (pInternalImport->EnumNext(&hEnumMethod, &tk))
-    {
-        _ASSERTE(TypeFromToken(tk) == mdtMethodDef);
-        DWORD dwMemberAttrs;
-        IfFailThrow(pInternalImport->GetMethodDefProps(tk, &dwMemberAttrs));
+        //
+        // First try for the new syntax: <MarshalCopy>
+        //
+        IfFailThrow(pInternalImport->EnumInit(mdtMethodDef, cl, &hEnumMethod));
 
-        if (IsMdSpecialName(dwMemberAttrs))
+        while (pInternalImport->EnumNext(&hEnumMethod, &tk))
         {
-            ULONG cSig;
-            PCCOR_SIGNATURE pSig;
-            LPCSTR pName;
-            IfFailThrow(pInternalImport->GetNameAndSigOfMethodDef(tk, &pSig, &cSig, &pName));
+            _ASSERTE(TypeFromToken(tk) == mdtMethodDef);
+            DWORD dwMemberAttrs;
+            IfFailThrow(pInternalImport->GetMethodDefProps(tk, &dwMemberAttrs));
 
-            const char *pBaseName = "<MarshalCopy>";
-            int ncBaseName = (int)strlen(pBaseName);
-            int nc = (int)strlen(pName);
-            if (nc >= ncBaseName && 0 == strcmp(pName + nc - ncBaseName, pBaseName))
+            if (IsMdSpecialName(dwMemberAttrs))
             {
-                MetaSig msig(pSig, cSig, pModule, &typeContext);
+                ULONG cSig;
+                PCCOR_SIGNATURE pSig;
+                LPCSTR pName;
+                IfFailThrow(pInternalImport->GetNameAndSigOfMethodDef(tk, &pSig, &cSig, &pName));
 
-                // Looking for the prototype   void <MarshalCopy>(Ptr VC, Ptr VC);
-                if (msig.NumFixedArgs() == 2)
+                const char *pBaseName = "<MarshalCopy>";
+                int ncBaseName = (int)strlen(pBaseName);
+                int nc = (int)strlen(pName);
+                if (nc >= ncBaseName && 0 == strcmp(pName + nc - ncBaseName, pBaseName))
                 {
-                    if (msig.GetReturnType() == ELEMENT_TYPE_VOID)
+                    MetaSig msig(pSig, cSig, pModule, &typeContext);
+
+                    // Looking for the prototype   void <MarshalCopy>(Ptr VC, Ptr VC);
+                    if (msig.NumFixedArgs() == 2)
                     {
-                        if (msig.NextArg() == ELEMENT_TYPE_PTR)
+                        if (msig.GetReturnType() == ELEMENT_TYPE_VOID)
                         {
-                            SigPointer sp1 = msig.GetArgProps();
-                            IfFailThrow(sp1.GetElemType(NULL));
-                            CorElementType eType;
-                            IfFailThrow(sp1.GetElemType(&eType));
-                            if (eType == ELEMENT_TYPE_VALUETYPE)
+                            if (msig.NextArg() == ELEMENT_TYPE_PTR)
                             {
-                                mdToken tk1;
-                                IfFailThrow(sp1.GetToken(&tk1));
-                                hr = CompareTypeTokensNT(tk1, cl, pModule, pModule);
-                                if (FAILED(hr))
+                                SigPointer sp1 = msig.GetArgProps();
+                                IfFailThrow(sp1.GetElemType(NULL));
+                                CorElementType eType;
+                                IfFailThrow(sp1.GetElemType(&eType));
+                                if (eType == ELEMENT_TYPE_VALUETYPE)
                                 {
-                                    pInternalImport->EnumClose(&hEnumMethod);
-                                    ThrowHR(hr);
-                                }
+                                    mdToken tk1;
+                                    IfFailThrow(sp1.GetToken(&tk1));
+                                    hr = CompareTypeTokensNT(tk1, cl, pModule, pModule);
+                                    if (FAILED(hr))
+                                    {
+                                        pInternalImport->EnumClose(&hEnumMethod);
+                                        ThrowHR(hr);
+                                    }
 
-                                if (hr == S_OK)
-                                {
-                                    if (msig.NextArg() == ELEMENT_TYPE_PTR)
+                                    if (hr == S_OK)
                                     {
-                                        SigPointer sp2 = msig.GetArgProps();
-                                        IfFailThrow(sp2.GetElemType(NULL));
-                                        IfFailThrow(sp2.GetElemType(&eType));
-                                        if (eType == ELEMENT_TYPE_VALUETYPE)
+                                        if (msig.NextArg() == ELEMENT_TYPE_PTR)
                                         {
-                                            mdToken tk2;
-                                            IfFailThrow(sp2.GetToken(&tk2));
-
-                                            hr = (tk2 == tk1) ? S_OK : CompareTypeTokensNT(tk2, cl, pModule, pModule);
-                                            if (hr == S_OK)
+                                            SigPointer sp2 = msig.GetArgProps();
+                                            IfFailThrow(sp2.GetElemType(NULL));
+                                            IfFailThrow(sp2.GetElemType(&eType));
+                                            if (eType == ELEMENT_TYPE_VALUETYPE)
                                             {
-                                                *pMDOut = pModule->LookupMethodDef(tk);
-                                                return;
+                                                mdToken tk2;
+                                                IfFailThrow(sp2.GetToken(&tk2));
+
+                                                hr = (tk2 == tk1) ? S_OK : CompareTypeTokensNT(tk2, cl, pModule, pModule);
+                                                if (hr == S_OK)
+                                                {
+                                                    *pMDOut = pModule->LookupMethodDef(tk);
+                                                    return;
+                                                }
                                             }
                                         }
                                     }
@@ -155,90 +157,90 @@ void FindCopyCtor(Module *pModule, MethodTable *pMT, MethodDesc **pMDOut)
                 }
             }
         }
-    }
 
-    //
-    // Next try the old syntax: global .__ctor
-    //
-    IfFailThrow(pInternalImport->EnumGlobalFunctionsInit(&hEnumMethod));
-
-    while (pInternalImport->EnumNext(&hEnumMethod, &tk))
-    {
-        _ASSERTE(TypeFromToken(tk) == mdtMethodDef);
-        DWORD dwMemberAttrs;
-        IfFailThrow(pInternalImport->GetMethodDefProps(tk, &dwMemberAttrs));
+        //
+        // Next try the old syntax: global .__ctor
+        //
+        IfFailThrow(pInternalImport->EnumGlobalFunctionsInit(&hEnumMethod));
 
-        if (IsMdSpecialName(dwMemberAttrs))
+        while (pInternalImport->EnumNext(&hEnumMethod, &tk))
         {
-            ULONG cSig;
-            PCCOR_SIGNATURE pSig;
-            LPCSTR pName;
-            IfFailThrow(pInternalImport->GetNameAndSigOfMethodDef(tk, &pSig, &cSig, &pName));
+            _ASSERTE(TypeFromToken(tk) == mdtMethodDef);
+            DWORD dwMemberAttrs;
+            IfFailThrow(pInternalImport->GetMethodDefProps(tk, &dwMemberAttrs));
 
-            const char *pBaseName = ".__ctor";
-            int ncBaseName = (int)strlen(pBaseName);
-            int nc = (int)strlen(pName);
-            if (nc >= ncBaseName && 0 == strcmp(pName + nc - ncBaseName, pBaseName))
+            if (IsMdSpecialName(dwMemberAttrs))
             {
+                ULONG cSig;
+                PCCOR_SIGNATURE pSig;
+                LPCSTR pName;
+                IfFailThrow(pInternalImport->GetNameAndSigOfMethodDef(tk, &pSig, &cSig, &pName));
 
-                MetaSig msig(pSig, cSig, pModule, &typeContext);
-
-                // Looking for the prototype   Ptr VC __ctor(Ptr VC, ByRef VC);
-                if (msig.NumFixedArgs() == 2)
+                const char *pBaseName = ".__ctor";
+                int ncBaseName = (int)strlen(pBaseName);
+                int nc = (int)strlen(pName);
+                if (nc >= ncBaseName && 0 == strcmp(pName + nc - ncBaseName, pBaseName))
                 {
-                    if (msig.GetReturnType() == ELEMENT_TYPE_PTR)
+
+                    MetaSig msig(pSig, cSig, pModule, &typeContext);
+
+                    // Looking for the prototype   Ptr VC __ctor(Ptr VC, ByRef VC);
+                    if (msig.NumFixedArgs() == 2)
                     {
-                        SigPointer spret = msig.GetReturnProps();
-                        IfFailThrow(spret.GetElemType(NULL));
-                        CorElementType eType;
-                        IfFailThrow(spret.GetElemType(&eType));
-                        if (eType == ELEMENT_TYPE_VALUETYPE)
+                        if (msig.GetReturnType() == ELEMENT_TYPE_PTR)
                         {
-                            mdToken tk0;
-                            IfFailThrow(spret.GetToken(&tk0));
-                            hr = CompareTypeTokensNT(tk0, cl, pModule, pModule);
-                            if (FAILED(hr))
+                            SigPointer spret = msig.GetReturnProps();
+                            IfFailThrow(spret.GetElemType(NULL));
+                            CorElementType eType;
+                            IfFailThrow(spret.GetElemType(&eType));
+                            if (eType == ELEMENT_TYPE_VALUETYPE)
                             {
-                                pInternalImport->EnumClose(&hEnumMethod);
-                                ThrowHR(hr);
-                            }
+                                mdToken tk0;
+                                IfFailThrow(spret.GetToken(&tk0));
+                                hr = CompareTypeTokensNT(tk0, cl, pModule, pModule);
+                                if (FAILED(hr))
+                                {
+                                    pInternalImport->EnumClose(&hEnumMethod);
+                                    ThrowHR(hr);
+                                }
 
-                            if (hr == S_OK)
-                            {
-                                if (msig.NextArg() == ELEMENT_TYPE_PTR)
+                                if (hr == S_OK)
                                 {
-                                    SigPointer sp1 = msig.GetArgProps();
-                                    IfFailThrow(sp1.GetElemType(NULL));
-                                    IfFailThrow(sp1.GetElemType(&eType));
-                                    if (eType == ELEMENT_TYPE_VALUETYPE)
+                                    if (msig.NextArg() == ELEMENT_TYPE_PTR)
                                     {
-                                        mdToken tk1;
-                                        IfFailThrow(sp1.GetToken(&tk1));
-                                        hr = (tk1 == tk0) ? S_OK : CompareTypeTokensNT(tk1, cl, pModule, pModule);
-                                        if (FAILED(hr))
+                                        SigPointer sp1 = msig.GetArgProps();
+                                        IfFailThrow(sp1.GetElemType(NULL));
+                                        IfFailThrow(sp1.GetElemType(&eType));
+                                        if (eType == ELEMENT_TYPE_VALUETYPE)
                                         {
-                                            pInternalImport->EnumClose(&hEnumMethod);
-                                            ThrowHR(hr);
-                                        }
+                                            mdToken tk1;
+                                            IfFailThrow(sp1.GetToken(&tk1));
+                                            hr = (tk1 == tk0) ? S_OK : CompareTypeTokensNT(tk1, cl, pModule, pModule);
+                                            if (FAILED(hr))
+                                            {
+                                                pInternalImport->EnumClose(&hEnumMethod);
+                                                ThrowHR(hr);
+                                            }
 
-                                        if (hr == S_OK)
-                                        {
-                                            if (msig.NextArg() == ELEMENT_TYPE_PTR &&
-                                                msig.GetArgProps().HasCustomModifier(pModule, "Microsoft.VisualC.IsCXXReferenceModifier", ELEMENT_TYPE_CMOD_OPT))
+                                            if (hr == S_OK)
                                             {
-                                                SigPointer sp2 = msig.GetArgProps();
-                                                IfFailThrow(sp2.GetElemType(NULL));
-                                                IfFailThrow(sp2.GetElemType(&eType));
-                                                if (eType == ELEMENT_TYPE_VALUETYPE)
+                                                if (msig.NextArg() == ELEMENT_TYPE_PTR &&
+                                                    msig.GetArgProps().HasCustomModifier(pModule, "Microsoft.VisualC.IsCXXReferenceModifier", ELEMENT_TYPE_CMOD_OPT))
                                                 {
-                                                    mdToken tk2;
-                                                    IfFailThrow(sp2.GetToken(&tk2));
-
-                                                    hr = (tk2 == tk0) ? S_OK : CompareTypeTokensNT(tk2, cl, pModule, pModule);
-                                                    if (hr == S_OK)
+                                                    SigPointer sp2 = msig.GetArgProps();
+                                                    IfFailThrow(sp2.GetElemType(NULL));
+                                                    IfFailThrow(sp2.GetElemType(&eType));
+                                                    if (eType == ELEMENT_TYPE_VALUETYPE)
                                                     {
-                                                        *pMDOut = pModule->LookupMethodDef(tk);
-                                                        return;
+                                                        mdToken tk2;
+                                                        IfFailThrow(sp2.GetToken(&tk2));
+
+                                                        hr = (tk2 == tk0) ? S_OK : CompareTypeTokensNT(tk2, cl, pModule, pModule);
+                                                        if (hr == S_OK)
+                                                        {
+                                                            *pMDOut = pModule->LookupMethodDef(tk);
+                                                            return;
+                                                        }
                                                     }
                                                 }
                                             }
@@ -252,59 +254,111 @@ void FindCopyCtor(Module *pModule, MethodTable *pMT, MethodDesc **pMDOut)
             }
         }
     }
-}
 
 
-//-------------------------------------------------------------------------------------
-// Return the destructor for a VC class (if any exists)
-//-------------------------------------------------------------------------------------
-void FindDtor(Module *pModule, MethodTable *pMT, MethodDesc **pMDOut)
-{
-    CONTRACTL
+    //-------------------------------------------------------------------------------------
+    // Return the destructor for a VC class (if any exists)
+    //-------------------------------------------------------------------------------------
+    void FindDtor(Module *pModule, MethodTable *pMT, MethodDesc **pMDOut)
     {
-        THROWS;
-        GC_TRIGGERS;    // CompareTypeTokens may trigger GC
-        MODE_ANY;
-    }
-    CONTRACTL_END;
+        CONTRACTL
+        {
+            THROWS;
+            GC_TRIGGERS;    // CompareTypeTokens may trigger GC
+            MODE_ANY;
+        }
+        CONTRACTL_END;
 
-    *pMDOut = NULL;
+        *pMDOut = NULL;
 
-    HRESULT     hr;
-    mdMethodDef tk;
-    mdTypeDef cl = pMT->GetCl();
-    TypeHandle th = TypeHandle(pMT);
-    SigTypeContext typeContext(th);
+        HRESULT     hr;
+        mdMethodDef tk;
+        mdTypeDef cl = pMT->GetCl();
+        TypeHandle th = TypeHandle(pMT);
+        SigTypeContext typeContext(th);
 
-    IMDInternalImport *pInternalImport = pModule->GetMDImport();
-    MDEnumHolder       hEnumMethod(pInternalImport);
+        IMDInternalImport *pInternalImport = pModule->GetMDImport();
+        MDEnumHolder       hEnumMethod(pInternalImport);
 
-    //
-    // First try for the new syntax: <MarshalDestroy>
-    //
-    IfFailThrow(pInternalImport->EnumInit(mdtMethodDef, cl, &hEnumMethod));
+        //
+        // First try for the new syntax: <MarshalDestroy>
+        //
+        IfFailThrow(pInternalImport->EnumInit(mdtMethodDef, cl, &hEnumMethod));
 
-    while (pInternalImport->EnumNext(&hEnumMethod, &tk))
-    {
-        _ASSERTE(TypeFromToken(tk) == mdtMethodDef);
-        DWORD dwMemberAttrs;
-        IfFailThrow(pInternalImport->GetMethodDefProps(tk, &dwMemberAttrs));
+        while (pInternalImport->EnumNext(&hEnumMethod, &tk))
+        {
+            _ASSERTE(TypeFromToken(tk) == mdtMethodDef);
+            DWORD dwMemberAttrs;
+            IfFailThrow(pInternalImport->GetMethodDefProps(tk, &dwMemberAttrs));
+
+            if (IsMdSpecialName(dwMemberAttrs))
+            {
+                ULONG cSig;
+                PCCOR_SIGNATURE pSig;
+                LPCSTR pName;
+                IfFailThrow(pInternalImport->GetNameAndSigOfMethodDef(tk, &pSig, &cSig, &pName));
+
+                const char *pBaseName = "<MarshalDestroy>";
+                int ncBaseName = (int)strlen(pBaseName);
+                int nc = (int)strlen(pName);
+                if (nc >= ncBaseName && 0 == strcmp(pName + nc - ncBaseName, pBaseName))
+                {
+                    MetaSig msig(pSig, cSig, pModule, &typeContext);
+
+                    // Looking for the prototype   void <MarshalDestroy>(Ptr VC);
+                    if (msig.NumFixedArgs() == 1)
+                    {
+                        if (msig.GetReturnType() == ELEMENT_TYPE_VOID)
+                        {
+                            if (msig.NextArg() == ELEMENT_TYPE_PTR)
+                            {
+                                SigPointer sp1 = msig.GetArgProps();
+                                IfFailThrow(sp1.GetElemType(NULL));
+                                CorElementType eType;
+                                IfFailThrow(sp1.GetElemType(&eType));
+                                if (eType == ELEMENT_TYPE_VALUETYPE)
+                                {
+                                    mdToken tk1;
+                                    IfFailThrow(sp1.GetToken(&tk1));
+
+                                    hr = CompareTypeTokensNT(tk1, cl, pModule, pModule);
+                                    IfFailThrow(hr);
+
+                                    if (hr == S_OK)
+                                    {
+                                        *pMDOut = pModule->LookupMethodDef(tk);
+                                        return;
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+
+        //
+        // Next try the old syntax: global .__dtor
+        //
+        IfFailThrow(pInternalImport->EnumGlobalFunctionsInit(&hEnumMethod));
 
-        if (IsMdSpecialName(dwMemberAttrs))
+        while (pInternalImport->EnumNext(&hEnumMethod, &tk))
         {
+            _ASSERTE(TypeFromToken(tk) == mdtMethodDef);
             ULONG cSig;
             PCCOR_SIGNATURE pSig;
             LPCSTR pName;
             IfFailThrow(pInternalImport->GetNameAndSigOfMethodDef(tk, &pSig, &cSig, &pName));
 
-            const char *pBaseName = "<MarshalDestroy>";
+            const char *pBaseName = ".__dtor";
             int ncBaseName = (int)strlen(pBaseName);
             int nc = (int)strlen(pName);
             if (nc >= ncBaseName && 0 == strcmp(pName + nc - ncBaseName, pBaseName))
             {
                 MetaSig msig(pSig, cSig, pModule, &typeContext);
 
-                // Looking for the prototype   void <MarshalDestroy>(Ptr VC);
+                // Looking for the prototype   void __dtor(Ptr VC);
                 if (msig.NumFixedArgs() == 1)
                 {
                     if (msig.GetReturnType() == ELEMENT_TYPE_VOID)
@@ -319,9 +373,12 @@ void FindDtor(Module *pModule, MethodTable *pMT, MethodDesc **pMDOut)
                             {
                                 mdToken tk1;
                                 IfFailThrow(sp1.GetToken(&tk1));
-
                                 hr = CompareTypeTokensNT(tk1, cl, pModule, pModule);
-                                IfFailThrow(hr);
+                                if (FAILED(hr))
+                                {
+                                    pInternalImport->EnumClose(&hEnumMethod);
+                                    ThrowHR(hr);
+                                }
 
                                 if (hr == S_OK)
                                 {
@@ -335,61 +392,6 @@ void FindDtor(Module *pModule, MethodTable *pMT, MethodDesc **pMDOut)
             }
         }
     }
-
-
-    //
-    // Next try the old syntax: global .__dtor
-    //
-    IfFailThrow(pInternalImport->EnumGlobalFunctionsInit(&hEnumMethod));
-
-    while (pInternalImport->EnumNext(&hEnumMethod, &tk))
-    {
-        _ASSERTE(TypeFromToken(tk) == mdtMethodDef);
-        ULONG cSig;
-        PCCOR_SIGNATURE pSig;
-        LPCSTR pName;
-        IfFailThrow(pInternalImport->GetNameAndSigOfMethodDef(tk, &pSig, &cSig, &pName));
-
-        const char *pBaseName = ".__dtor";
-        int ncBaseName = (int)strlen(pBaseName);
-        int nc = (int)strlen(pName);
-        if (nc >= ncBaseName && 0 == strcmp(pName + nc - ncBaseName, pBaseName))
-        {
-            MetaSig msig(pSig, cSig, pModule, &typeContext);
-
-            // Looking for the prototype   void __dtor(Ptr VC);
-            if (msig.NumFixedArgs() == 1)
-            {
-                if (msig.GetReturnType() == ELEMENT_TYPE_VOID)
-                {
-                    if (msig.NextArg() == ELEMENT_TYPE_PTR)
-                    {
-                        SigPointer sp1 = msig.GetArgProps();
-                        IfFailThrow(sp1.GetElemType(NULL));
-                        CorElementType eType;
-                        IfFailThrow(sp1.GetElemType(&eType));
-                        if (eType == ELEMENT_TYPE_VALUETYPE)
-                        {
-                            mdToken tk1;
-                            IfFailThrow(sp1.GetToken(&tk1));
-                            hr = CompareTypeTokensNT(tk1, cl, pModule, pModule);
-                            if (FAILED(hr))
-                            {
-                                pInternalImport->EnumClose(&hEnumMethod);
-                                ThrowHR(hr);
-                            }
-
-                            if (hr == S_OK)
-                            {
-                                *pMDOut = pModule->LookupMethodDef(tk);
-                                return;
-                            }
-                        }
-                    }
-                }
-            }
-        }
-    }
 }
 
 //==========================================================================
@@ -421,32 +423,35 @@ CustomMarshalerHelper *SetupCustomMarshalerHelper(LPCUTF8 strMarshalerTypeName,
 #endif
 }
 
-//==========================================================================
-// Return: S_OK if there is valid data to compress
-//         S_FALSE if at end of data block
-//         E_FAIL if corrupt data found
-//==========================================================================
-HRESULT CheckForCompressedData(PCCOR_SIGNATURE pvNativeTypeStart, PCCOR_SIGNATURE pvNativeType, ULONG cbNativeType)
+namespace
 {
-    CONTRACTL
+    //==========================================================================
+    // Return: S_OK if there is valid data to compress
+    //         S_FALSE if at end of data block
+    //         E_FAIL if corrupt data found
+    //==========================================================================
+    HRESULT CheckForCompressedData(PCCOR_SIGNATURE pvNativeTypeStart, PCCOR_SIGNATURE pvNativeType, ULONG cbNativeType)
     {
-        NOTHROW;
-        GC_NOTRIGGER;
-        MODE_ANY;
-    }
-    CONTRACTL_END;
+        CONTRACTL
+        {
+            NOTHROW;
+            GC_NOTRIGGER;
+            MODE_ANY;
+        }
+        CONTRACTL_END;
 
-    if (pvNativeTypeStart + cbNativeType == pvNativeType)
-    {   // end of data block
-        return S_FALSE;
-    }
+        if (pvNativeTypeStart + cbNativeType == pvNativeType)
+        {   // end of data block
+            return S_FALSE;
+        }
 
-    ULONG ulDummy;
-    BYTE const *pbDummy;
-    return CPackedLen::SafeGetLength((BYTE const *)pvNativeType,
-                                     (BYTE const *)pvNativeTypeStart + cbNativeType,
-                                     &ulDummy,
-                                     &pbDummy);
+        ULONG ulDummy;
+        BYTE const *pbDummy;
+        return CPackedLen::SafeGetLength((BYTE const *)pvNativeType,
+                                        (BYTE const *)pvNativeTypeStart + cbNativeType,
+                                        &ulDummy,
+                                        &pbDummy);
+    }
 }
 
 //==========================================================================
@@ -2608,52 +2613,53 @@ ILMarshaler* CreateILMarshaler(MarshalInfo::MarshalType mtype, NDirectStubLinker
     return pMarshaler;
 }
 
+namespace
+{
+    DWORD CalculateArgumentMarshalFlags(BOOL byref, BOOL in, BOOL out, BOOL fMngToNative)
+    {
+        LIMITED_METHOD_CONTRACT;
+        DWORD dwMarshalFlags = 0;
 
+        if (byref)
+        {
+            dwMarshalFlags |= MARSHAL_FLAG_BYREF;
+        }
 
-DWORD CalculateArgumentMarshalFlags(BOOL byref, BOOL in, BOOL out, BOOL fMngToNative)
-{
-    LIMITED_METHOD_CONTRACT;
-    DWORD dwMarshalFlags = 0;
+        if (in)
+        {
+            dwMarshalFlags |= MARSHAL_FLAG_IN;
+        }
 
-    if (byref)
-    {
-        dwMarshalFlags |= MARSHAL_FLAG_BYREF;
-    }
+        if (out)
+        {
+            dwMarshalFlags |= MARSHAL_FLAG_OUT;
+        }
 
-    if (in)
-    {
-        dwMarshalFlags |= MARSHAL_FLAG_IN;
-    }
+        if (fMngToNative)
+        {
+            dwMarshalFlags |= MARSHAL_FLAG_CLR_TO_NATIVE;
+        }
 
-    if (out)
-    {
-        dwMarshalFlags |= MARSHAL_FLAG_OUT;
+        return dwMarshalFlags;
     }
 
-    if (fMngToNative)
+    DWORD CalculateReturnMarshalFlags(BOOL hrSwap, BOOL fMngToNative)
     {
-        dwMarshalFlags |= MARSHAL_FLAG_CLR_TO_NATIVE;
-    }
-
-    return dwMarshalFlags;
-}
+        LIMITED_METHOD_CONTRACT;
+        DWORD dwMarshalFlags = MARSHAL_FLAG_RETVAL;
 
-DWORD CalculateReturnMarshalFlags(BOOL hrSwap, BOOL fMngToNative)
-{
-    LIMITED_METHOD_CONTRACT;
-    DWORD dwMarshalFlags = MARSHAL_FLAG_RETVAL;
+        if (hrSwap)
+        {
+            dwMarshalFlags |= MARSHAL_FLAG_HRESULT_SWAP;
+        }
 
-    if (hrSwap)
-    {
-        dwMarshalFlags |= MARSHAL_FLAG_HRESULT_SWAP;
-    }
+        if (fMngToNative)
+        {
+            dwMarshalFlags |= MARSHAL_FLAG_CLR_TO_NATIVE;
+        }
 
-    if (fMngToNative)
-    {
-        dwMarshalFlags |= MARSHAL_FLAG_CLR_TO_NATIVE;
+        return dwMarshalFlags;
     }
-
-    return dwMarshalFlags;
 }
 
 void MarshalInfo::GenerateArgumentIL(NDirectStubLinker* psl,
@@ -3140,38 +3146,6 @@ void MarshalInfo::GetItfMarshalInfo(TypeHandle th, BOOL fDispItf, MarshalScenari
 #endif // FEATURE_COMINTEROP
 }
 
-HRESULT MarshalInfo::TryGetItfMarshalInfo(TypeHandle th, BOOL fDispItf, ItfMarshalInfo *pInfo)
-{
-    CONTRACTL
-    {
-        STANDARD_VM_CHECK;
-        INJECT_FAULT(COMPlusThrowOM());
-        PRECONDITION(!th.IsNull());
-        PRECONDITION(CheckPointer(pInfo));
-    }
-    CONTRACTL_END;
-
-    HRESULT hr = S_OK;
-
-    EX_TRY
-    {
-        GetItfMarshalInfo(th, fDispItf,
-#ifdef FEATURE_COMINTEROP
-            MARSHAL_SCENARIO_COMINTEROP,
-#else // FEATURE_COMINTEROP
-            MARSHAL_SCENARIO_NDIRECT,
-#endif // FEATURE_COMINTEROP
-            pInfo);
-    }
-    EX_CATCH
-    {
-        hr = GET_EXCEPTION()->GetHR();
-    }
-    EX_END_CATCH(RethrowTerminalExceptions);
-
-    return hr;
-}
-
 #ifdef _DEBUG
 VOID MarshalInfo::DumpMarshalInfo(Module* pModule, SigPointer sig, const SigTypeContext *pTypeContext, mdToken token,
                                   MarshalScenario ms, CorNativeLinkType nlType, CorNativeLinkFlags nlFlags)
@@ -3431,8 +3405,7 @@ VOID MarshalInfo::DumpMarshalInfo(Module* pModule, SigPointer sig, const SigType
 } // MarshalInfo::DumpMarshalInfo
 #endif //_DEBUG
 
-#ifndef CROSSGEN_COMPILE
-#ifdef FEATURE_COMINTEROP
+#if defined(FEATURE_COMINTEROP) && !defined(CROSSGEN_COMPILE)
 DispParamMarshaler *MarshalInfo::GenerateDispParamMarshaler()
 {
     CONTRACT (DispParamMarshaler*)
@@ -3482,11 +3455,9 @@ DispParamMarshaler *MarshalInfo::GenerateDispParamMarshaler()
             pDispParamMarshaler = new DispParamRecordMarshaler(m_pMT);
             break;
 
-#ifdef FEATURE_COMINTEROP
         case MARSHAL_TYPE_SAFEARRAY:
             pDispParamMarshaler = new DispParamArrayMarshaler(m_arrayElementType, m_hndArrayElemType.GetMethodTable());
             break;
-#endif
 
         case MARSHAL_TYPE_DELEGATE:
             pDispParamMarshaler = new DispParamDelegateMarshaler(m_pMT);
@@ -3501,7 +3472,6 @@ DispParamMarshaler *MarshalInfo::GenerateDispParamMarshaler()
     RETURN pDispParamMarshaler;
 }
 
-
 DispatchWrapperType MarshalInfo::GetDispWrapperType()
 {
     STANDARD_VM_CONTRACT;
@@ -3556,373 +3526,7 @@ DispatchWrapperType MarshalInfo::GetDispWrapperType()
     return WrapperType;
 }
 
-#endif // FEATURE_COMINTEROP
-
-
-VOID MarshalInfo::MarshalTypeToString(SString& strMarshalType, BOOL fSizeIsSpecified)
-{
-    CONTRACTL
-    {
-        THROWS;
-        GC_TRIGGERS;
-        MODE_ANY;
-    }
-    CONTRACTL_END;
-
-    LPCWSTR strRetVal;
-
-    if (m_type == MARSHAL_TYPE_NATIVEARRAY)
-    {
-        SString strVarType;
-        VarTypeToString(m_arrayElementType, strVarType);
-
-        if (!fSizeIsSpecified)
-        {
-            strMarshalType.Printf(W("native array of %s (size not specified by a parameter)"),
-                                  strVarType.GetUnicode());
-        }
-        else
-        {
-            strMarshalType.Printf(W("native array of %s (size specified by parameter %i)"),
-                                  strVarType.GetUnicode(), m_countParamIdx);
-        }
-
-        return;
-    }
-#ifdef FEATURE_COMINTEROP
-    // Some MarshalTypes have extra information and require special handling
-    else if (m_type == MARSHAL_TYPE_INTERFACE)
-    {
-        ItfMarshalInfo itfInfo;
-        GetItfMarshalInfo(TypeHandle(m_pMT), m_fDispItf, m_ms, &itfInfo);
-
-        if (!itfInfo.thItf.IsNull())
-        {
-            StackSString ssClassName;
-            itfInfo.thItf.GetMethodTable()->_GetFullyQualifiedNameForClass(ssClassName);
-
-            if (!!(itfInfo.dwFlags & ItfMarshalInfo::ITF_MARSHAL_DISP_ITF))
-            {
-                strMarshalType.SetLiteral(W("IDispatch "));
-            }
-            else
-            {
-                strMarshalType.SetLiteral(W("IUnknown "));
-            }
-
-            if (itfInfo.dwFlags & ItfMarshalInfo::ITF_MARSHAL_USE_BASIC_ITF)
-            {
-                strMarshalType.Append(W("(basic) "));
-            }
-
-            strMarshalType.Append(ssClassName);
-            return;
-        }
-        else
-        {
-            if (!!(itfInfo.dwFlags & ItfMarshalInfo::ITF_MARSHAL_DISP_ITF))
-                strRetVal = W("IDispatch");
-            else
-                strRetVal = W("IUnknown");
-        }
-    }
-    else if (m_type == MARSHAL_TYPE_SAFEARRAY)
-    {
-        StackSString strVarType;
-        VarTypeToString(m_arrayElementType, strVarType);
-
-        strMarshalType = SL(W("SafeArray of "));
-        strMarshalType.Append(strVarType);
-
-        return;
-    }
-#endif // FEATURE_COMINTEROP
-    else if (m_type == MARSHAL_TYPE_REFERENCECUSTOMMARSHALER)
-    {
-        GCX_COOP();
-
-        OBJECTREF pObjRef = m_pCMHelper->GetCustomMarshalerInfo()->GetCustomMarshaler();
-        {
-            DefineFullyQualifiedNameForClassW();
-
-            strMarshalType.Printf(W("custom marshaler (%s)"),
-                                  GetFullyQualifiedNameForClassW(pObjRef->GetMethodTable()));
-        }
-
-        return;
-    }
-    else
-    {
-        // All other MarshalTypes with no special handling
-        switch (m_type)
-        {
-            case MARSHAL_TYPE_GENERIC_1:
-                strRetVal = W("BYTE");
-                break;
-            case MARSHAL_TYPE_GENERIC_U1:
-                strRetVal = W("unsigned BYTE");
-                break;
-            case MARSHAL_TYPE_GENERIC_2:
-                strRetVal = W("WORD");
-                break;
-            case MARSHAL_TYPE_GENERIC_U2:
-                strRetVal = W("unsigned WORD");
-                break;
-            case MARSHAL_TYPE_GENERIC_4:
-                strRetVal = W("DWORD");
-                break;
-            case MARSHAL_TYPE_GENERIC_8:
-                strRetVal = W("QUADWORD");
-                break;
-            case MARSHAL_TYPE_WINBOOL:
-                strRetVal = W("Windows Bool");
-                break;
-#ifdef FEATURE_COMINTEROP
-            case MARSHAL_TYPE_VTBOOL:
-                strRetVal = W("VARIANT Bool");
-                break;
-#endif // FEATURE_COMINTEROP
-            case MARSHAL_TYPE_ANSICHAR:
-                strRetVal = W("Ansi character");
-                break;
-            case MARSHAL_TYPE_CBOOL:
-                strRetVal = W("CBool");
-                break;
-            case MARSHAL_TYPE_FLOAT:
-                strRetVal = W("float");
-                break;
-            case MARSHAL_TYPE_DOUBLE:
-                strRetVal = W("double");
-                break;
-            case MARSHAL_TYPE_CURRENCY:
-                strRetVal = W("CURRENCY");
-                break;
-            case MARSHAL_TYPE_DECIMAL:
-                strRetVal = W("DECIMAL");
-                break;
-            case MARSHAL_TYPE_DECIMAL_PTR:
-                strRetVal = W("DECIMAL pointer");
-                break;
-            case MARSHAL_TYPE_GUID:
-                strRetVal = W("GUID");
-                break;
-            case MARSHAL_TYPE_GUID_PTR:
-                strRetVal = W("GUID pointer");
-                break;
-            case MARSHAL_TYPE_DATE:
-                strRetVal = W("DATE");
-                break;
-             case MARSHAL_TYPE_BSTR:
-                strRetVal = W("BSTR");
-                break;
-            case MARSHAL_TYPE_LPWSTR:
-                strRetVal = W("LPWSTR");
-                break;
-            case MARSHAL_TYPE_LPSTR:
-                strRetVal = W("LPSTR");
-                break;
-            case MARSHAL_TYPE_LPUTF8STR:
-                strRetVal = W("LPUTF8STR");
-                break;
-#ifdef FEATURE_COMINTEROP
-            case MARSHAL_TYPE_ANSIBSTR:
-                strRetVal = W("AnsiBStr");
-                break;
-#endif // FEATURE_COMINTEROP
-            case MARSHAL_TYPE_LPWSTR_BUFFER:
-                strRetVal = W("LPWSTR buffer");
-                break;
-            case MARSHAL_TYPE_LPSTR_BUFFER:
-                strRetVal = W("LPSTR buffer");
-                break;
-            case MARSHAL_TYPE_UTF8_BUFFER:
-                strRetVal = W("UTF8 buffer");
-                break;
-            case MARSHAL_TYPE_ASANYA:
-                strRetVal = W("AsAnyA");
-                break;
-            case MARSHAL_TYPE_ASANYW:
-                strRetVal = W("AsAnyW");
-                break;
-            case MARSHAL_TYPE_DELEGATE:
-                strRetVal = W("Delegate");
-                break;
-            case MARSHAL_TYPE_BLITTABLEPTR:
-                strRetVal = W("blittable pointer");
-                break;
-#ifdef FEATURE_COMINTEROP
-            case MARSHAL_TYPE_VBBYVALSTR:
-                strRetVal = W("VBByValStr");
-                break;
-            case MARSHAL_TYPE_VBBYVALSTRW:
-                strRetVal = W("VBByRefStr");
-                break;
-#endif // FEATURE_COMINTEROP
-            case MARSHAL_TYPE_LAYOUTCLASSPTR:
-                strRetVal = W("Layout class pointer");
-                break;
-            case MARSHAL_TYPE_ARRAYWITHOFFSET:
-                strRetVal = W("ArrayWithOffset");
-                break;
-            case MARSHAL_TYPE_BLITTABLEVALUECLASS:
-                strRetVal = W("blittable value class");
-                break;
-            case MARSHAL_TYPE_VALUECLASS:
-                strRetVal = W("value class");
-                break;
-            case MARSHAL_TYPE_ARGITERATOR:
-                strRetVal = W("ArgIterator");
-                break;
-            case MARSHAL_TYPE_BLITTABLEVALUECLASSWITHCOPYCTOR:
-                strRetVal = W("blittable value class with copy constructor");
-                break;
-#ifdef FEATURE_COMINTEROP
-            case MARSHAL_TYPE_OBJECT:
-                strRetVal = W("VARIANT");
-                break;
-#endif // FEATURE_COMINTEROP
-            case MARSHAL_TYPE_HANDLEREF:
-                strRetVal = W("HandleRef");
-                break;
-#ifdef FEATURE_COMINTEROP
-            case MARSHAL_TYPE_OLECOLOR:
-                strRetVal = W("OLE_COLOR");
-                break;
-#endif // FEATURE_COMINTEROP
-            case MARSHAL_TYPE_RUNTIMETYPEHANDLE:
-                strRetVal = W("RuntimeTypeHandle");
-                break;
-            case MARSHAL_TYPE_RUNTIMEFIELDHANDLE:
-                strRetVal = W("RuntimeFieldHandle");
-                break;
-            case MARSHAL_TYPE_RUNTIMEMETHODHANDLE:
-                strRetVal = W("RuntimeMethodHandle");
-                break;
-            default:
-                strRetVal = W("<UNKNOWN>");
-                break;
-        }
-    }
-
-    strMarshalType.Set(strRetVal);
-    return;
-}
-
-VOID MarshalInfo::VarTypeToString(VARTYPE vt, SString& strVarType)
-{
-    CONTRACTL
-    {
-        THROWS;
-        GC_NOTRIGGER;
-        MODE_ANY;
-    }
-    CONTRACTL_END;
-
-
-    LPCWSTR strRetVal;
-
-    switch(vt)
-    {
-        case VT_I2:
-            strRetVal = W("2-byte signed int");
-            break;
-        case VT_I4:
-            strRetVal = W("4-byte signed int");
-            break;
-        case VT_R4:
-            strRetVal = W("4-byte real");
-            break;
-        case VT_R8:
-            strRetVal = W("8-byte real");
-            break;
-        case VT_CY:
-            strRetVal = W("currency");
-            break;
-        case VT_DATE:
-            strRetVal = W("date");
-            break;
-        case VT_BSTR:
-            strRetVal = W("binary string");
-            break;
-        case VT_DISPATCH:
-            strRetVal = W("IDispatch *");
-            break;
-        case VT_ERROR:
-            strRetVal = W("Scode");
-            break;
-        case VT_BOOL:
-            strRetVal = W("boolean");
-            break;
-        case VT_VARIANT:
-            strRetVal = W("VARIANT *");
-            break;
-        case VT_UNKNOWN:
-            strRetVal = W("IUnknown *");
-            break;
-        case VT_DECIMAL:
-            strRetVal = W("16-byte fixed point");
-            break;
-        case VT_RECORD:
-            strRetVal = W("user defined structure");
-            break;
-        case VT_I1:
-            strRetVal = W("signed char");
-            break;
-        case VT_UI1:
-            strRetVal = W("unsigned char");
-            break;
-        case VT_UI2:
-            strRetVal = W("unsigned short");
-            break;
-        case VT_UI4:
-            strRetVal = W("unsigned short");
-            break;
-        case VT_INT:
-            strRetVal = W("signed int");
-            break;
-        case VT_UINT:
-            strRetVal = W("unsigned int");
-            break;
-        case VT_LPSTR:
-            strRetVal = W("LPSTR");
-            break;
-        case VT_LPWSTR:
-            strRetVal = W("LPWSTR");
-            break;
-        case VT_HRESULT:
-            strRetVal = W("HResult");
-            break;
-        case VT_I8:
-            strRetVal = W("8-byte signed int");
-            break;
-        case VT_NULL:
-            strRetVal = W("null");
-            break;
-        case VT_UI8:
-            strRetVal = W("8-byte unsigned int");
-            break;
-        case VT_VOID:
-            strRetVal = W("void");
-            break;
-        case VTHACK_WINBOOL:
-            strRetVal = W("boolean");
-            break;
-        case VTHACK_ANSICHAR:
-            strRetVal = W("char");
-            break;
-        case VTHACK_CBOOL:
-            strRetVal = W("1-byte C bool");
-            break;
-        default:
-            strRetVal = W("unknown");
-            break;
-    }
-
-    strVarType.Set(strRetVal);
-    return;
-}
-
-#endif // CROSSGEN_COMPILE
+#endif // defined(FEATURE_COMINTEROP) && !defined(CROSSGEN_COMPILE)
 
 // Returns true if the marshaler represented by this instance requires COM to have been started.
 bool MarshalInfo::MarshalerRequiresCOM()
index 3124c8c..68546b1 100644 (file)
@@ -182,8 +182,6 @@ struct NativeTypeParamInfo
 #endif // FEATURE_COMINTEROP
 };
 
-HRESULT CheckForCompressedData(PCCOR_SIGNATURE pvNativeTypeStart, PCCOR_SIGNATURE pvNativeType, ULONG cbNativeType);
-
 BOOL ParseNativeTypeInfo(mdToken                    token,
                          IMDInternalImport*         pScope,
                          NativeTypeParamInfo*       pParamInfo);
@@ -460,10 +458,6 @@ public:
 
     // Helper functions used to map the specified type to its interface marshalling info.
     static void GetItfMarshalInfo(TypeHandle th, BOOL fDispItf, MarshalScenario ms, ItfMarshalInfo *pInfo);
-    static HRESULT TryGetItfMarshalInfo(TypeHandle th, BOOL fDispItf, ItfMarshalInfo *pInfo);
-
-    VOID MarshalTypeToString(SString& strMarshalType, BOOL fSizeIsSpecified);
-    static VOID VarTypeToString(VARTYPE vt, SString& strVarType);
 
     // Returns true if the specified marshaler requires COM to have been started.
     bool MarshalerRequiresCOM();
@@ -701,9 +695,6 @@ VOID ThrowInteropParamException(UINT resID, UINT paramIdx);
 VOID CollateParamTokens(IMDInternalImport *pInternalImport, mdMethodDef md, ULONG numargs, mdParamDef *aParams);
 bool IsUnsupportedTypedrefReturn(MetaSig& msig);
 
-void FindCopyCtor(Module *pModule, MethodTable *pMT, MethodDesc **pMDOut);
-void FindDtor(Module *pModule, MethodTable *pMT, MethodDesc **pMDOut);
-
 // We'll cap the total native size at a (somewhat) arbitrary limit to ensure
 // that we don't expose some overflow bug later on.
 #define MAX_SIZE_FOR_INTEROP    0x7ffffff0