Binder utils cleanup (dotnet/coreclr#27475)
authorVitek Karas <vitek.karas@microsoft.com>
Sun, 27 Oct 2019 06:46:40 +0000 (23:46 -0700)
committerJan Kotas <jkotas@microsoft.com>
Sun, 27 Oct 2019 06:46:40 +0000 (23:46 -0700)
* Binder utils cleanup

* Binder startup cleanup

Commit migrated from https://github.com/dotnet/coreclr/commit/e4c043dff38e38f15b1f8e4aa32f8919a18166bd

src/coreclr/src/binder/assemblybinder.cpp
src/coreclr/src/binder/coreclrbindercommon.cpp
src/coreclr/src/binder/inc/utils.hpp
src/coreclr/src/binder/utils.cpp
src/coreclr/src/vm/ceemain.cpp

index d96a2af..bd4aebd 100644 (file)
@@ -55,8 +55,6 @@ namespace BINDER_SPACE
 {
     namespace
     {
-        BOOL fAssemblyBinderInitialized = FALSE;
-
         //
         // This defines the assembly equivalence relation
         //
@@ -362,19 +360,17 @@ namespace BINDER_SPACE
     /* static */
     HRESULT AssemblyBinder::Startup()
     {
+        STATIC_CONTRACT_NOTHROW;
+
         HRESULT hr = S_OK;
  
-       if (!BINDER_SPACE::fAssemblyBinderInitialized)
-        {
-            g_BinderVariables = new Variables();
-            IF_FAIL_GO(g_BinderVariables->Init());
+        // This should only be called once
+        _ASSERTE(g_BinderVariables == NULL);
+        g_BinderVariables = new Variables();
+        IF_FAIL_GO(g_BinderVariables->Init());
 
-            // Setup Debug log
-            BINDER_LOG_STARTUP();
-
-            // We're done
-            BINDER_SPACE::fAssemblyBinderInitialized = TRUE;
-        }
+        // Setup Debug log
+        BINDER_LOG_STARTUP();
 
     Exit:
         return hr;
@@ -576,7 +572,8 @@ namespace BINDER_SPACE
                                          Assembly **ppSystemAssembly,
                                          bool       fBindToNativeImage)
     {
-        _ASSERTE(BINDER_SPACE::fAssemblyBinderInitialized == TRUE);
+        // Indirect check that binder was initialized.
+        _ASSERTE(g_BinderVariables != NULL);
 
         HRESULT hr = S_OK;
         BINDER_LOG_ENTER(W("AssemblyBinder:BindToSystem"));
@@ -596,10 +593,9 @@ namespace BINDER_SPACE
         // At run-time, System.Private.CoreLib.dll is expected to be the NI image.
         sCoreLib = sCoreLibDir;
         sCoreLib.Append(CoreLibName_IL_W);
-        BOOL fExplicitBindToNativeImage = (fBindToNativeImage == true)? TRUE:FALSE;
         IF_FAIL_GO(AssemblyBinder::GetAssembly(sCoreLib,
                                                TRUE /* fIsInGAC */,
-                                               fExplicitBindToNativeImage,
+                                               fBindToNativeImage,
                                                &pSystemAssembly));
         
         *ppSystemAssembly = pSystemAssembly.Extract();
@@ -616,7 +612,8 @@ namespace BINDER_SPACE
                                                   SString   &cultureName,
                                                   Assembly **ppSystemAssembly)
     {
-        _ASSERTE(BINDER_SPACE::fAssemblyBinderInitialized == TRUE);
+        // Indirect check that binder was initialized.
+        _ASSERTE(g_BinderVariables != NULL);
 
         HRESULT hr = S_OK;
         BINDER_LOG_ENTER(W("AssemblyBinder:BindToSystemSatellite"));
@@ -1530,7 +1527,8 @@ HRESULT AssemblyBinder::BindUsingPEImage(/* in */  ApplicationContext *pApplicat
     HRESULT hr = E_FAIL;
     BINDER_LOG_ENTER(W("AssemblyBinder::BindUsingPEImage"));
     
-    _ASSERTE(BINDER_SPACE::fAssemblyBinderInitialized == TRUE);
+    // Indirect check that binder was initialized.
+    _ASSERTE(g_BinderVariables != NULL);
 
     LONG kContextVersion = 0;
     BindResult bindResult;
index d396854..670acb0 100644 (file)
@@ -16,15 +16,9 @@ using namespace BINDER_SPACE;
 /* static */
 HRESULT CCoreCLRBinderHelper::Init()
 {
-    STANDARD_VM_CONTRACT;
-    HRESULT hr = S_OK;
-    EX_TRY
-    {
-        hr = AssemblyBinder::Startup();
-    }
-    EX_CATCH_HRESULT(hr);
+    STATIC_CONTRACT_NOTHROW;
 
-    return hr;
+    return AssemblyBinder::Startup();
 }
 
 HRESULT CCoreCLRBinderHelper::DefaultBinderSetupContext(DWORD dwAppDomainId,CLRPrivBinderCoreCLR **ppTPABinder)
index d6903da..e6e72cf 100644 (file)
@@ -29,15 +29,8 @@ namespace BINDER_SPACE
         return string.HashCaseInsensitive();
     }
 
-    HRESULT FileOrDirectoryExists(PathString &path);
-    HRESULT FileOrDirectoryExistsLog(PathString &path);
-
     void MutateUrlToPath(SString &urlOrPath);
 
-    // Mutates path
-    void PlatformPath(SString &path);
-    void CanonicalizePath(SString &path, BOOL fAppendPathSeparator = FALSE);
-
     // It is safe to use either A or B as CombinedPath.
     void CombinePath(SString &pathA,
                      SString &pathB,
index e9686d2..bd710bd 100644 (file)
@@ -16,8 +16,6 @@
 
 #include "utils.hpp"
 
-#include <shlwapi.h>
-
 #include "strongname.h"
 #include "corpriv.h"
 
@@ -25,127 +23,16 @@ namespace BINDER_SPACE
 {
     namespace
     {
-        inline BOOL IsPathSeparator(WCHAR wcChar)
-        {
-            // Invariant: Valid only for MutateUrlToPath treated pathes
-            return (wcChar == W('\\'));
-        }
-
         inline const WCHAR *GetPlatformPathSeparator()
         {
 #ifdef PLATFORM_UNIX
             return W("/");
 #else
             return W("\\");
-#endif // PLATFORM_UNIX            
-        }
-
-        inline WCHAR ToPlatformPathSepator(WCHAR wcChar)
-        {
-#ifdef PLATFORM_UNIX
-            if (IsPathSeparator(wcChar))
-            {
-                wcChar = W('/');
-            }
 #endif // PLATFORM_UNIX
-
-            return wcChar;
-        }
-
-        inline BOOL IsDoublePathSeparator(SString::CIterator &cur)
-        {
-            return (IsPathSeparator(cur[0]) && IsPathSeparator(cur[1]));
-        }
-
-        bool NeedToRemoveDoubleAndNormalizePathSeparators(SString const &path)
-        {
-#ifdef PLATFORM_UNIX
-            return true;
-#else
-            SString::CIterator begin = path.Begin();
-            SString::CIterator end = path.End();
-            SString::CIterator cur = path.Begin();
-
-            while (cur < end)
-            {
-                if ((cur != begin) && ((cur + 2) < end) && IsDoublePathSeparator(cur))
-                {
-                    return true;
-                }
-
-                cur++;
-            }
-
-            return false;
-#endif
-        }
-
-        void RemoveDoubleAndNormalizePathSeparators(SString &path)
-        {
-            BINDER_LOG_ENTER(W("Utils::RemoveDoubleAndNormalizePathSeparators"));
-
-            SString::Iterator begin = path.Begin();
-            SString::Iterator end = path.End();
-            SString::Iterator cur = path.Begin();
-            PathString resultPath;
-
-            BINDER_LOG_STRING(W("path"), path);
-
-            while (cur < end)
-            {
-                if ((cur != begin) && ((cur + 2) < end) && IsDoublePathSeparator(cur))
-                {
-                    // Skip the doublette
-                    cur++;
-                }
-
-                resultPath.Append(ToPlatformPathSepator(cur[0]));
-                cur++;
-            }
-            
-            BINDER_LOG_STRING(W("resultPath"), resultPath);
-
-            path.Set(resultPath);
-
-            BINDER_LOG_LEAVE(W("Utils::RemoveDoubleAndNormalizePathSeparators"));
         }
     }
 
-    HRESULT FileOrDirectoryExists(PathString &path)
-    {
-        HRESULT hr = S_FALSE;
-
-        DWORD dwFileAttributes = WszGetFileAttributes(path.GetUnicode());
-        if (dwFileAttributes == INVALID_FILE_ATTRIBUTES)
-        {
-            hr = HRESULT_FROM_GetLastError();
-
-            if ((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) ||
-                (hr == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)))
-            {
-                hr = S_FALSE;
-            }
-        }
-        else
-        {
-            hr = S_TRUE;
-        }
-
-        return hr;
-    }
-
-    HRESULT FileOrDirectoryExistsLog(PathString &path)
-    {
-        HRESULT hr = S_FALSE;
-        BINDER_LOG_ENTER(W("Utils::FileOrDirectoryExistsLog"));
-        BINDER_LOG_STRING(W("path"), path);
-        
-        hr = FileOrDirectoryExists(path);
-        
-        BINDER_LOG_LEAVE_HR(W("Utils::FileOrDirectoryExistsLog"), hr);
-        return hr;
-    }
-
     void MutateUrlToPath(SString &urlOrPath)
     {
         BINDER_LOG_ENTER(W("Utils::MutateUrlToPath"));
@@ -194,21 +81,6 @@ namespace BINDER_SPACE
         BINDER_LOG_LEAVE(W("Utils::MutateUrlToPath"));
     }
 
-    void PlatformPath(SString &path)
-    {
-        BINDER_LOG_ENTER(W("Utils::PlatformPath"));
-        BINDER_LOG_STRING(W("input path"), path);
-
-        // Create platform representation
-        MutateUrlToPath(path);
-        if (NeedToRemoveDoubleAndNormalizePathSeparators(path))
-            RemoveDoubleAndNormalizePathSeparators(path);
-
-        BINDER_LOG_STRING(W("platform path"), path);
-
-        BINDER_LOG_LEAVE(W("Utils::PlatformPath"));
-    }
-
     void CombinePath(SString &pathA,
                      SString &pathB,
                      SString &combinedPath)
index 1a19f8a..b967d5e 100644 (file)
@@ -750,8 +750,7 @@ void EEStartupHelper(COINITIEE fFlags)
         InitEventStore();
 #endif
 
-        // Fusion
-        // Initialize the general Assembly Binder infrastructure
+        // Initialize the default Assembly Binder and the binder infrastructure
         IfFailGoLog(CCoreCLRBinderHelper::Init());
 
         if (g_pConfig != NULL)