Load WebKit and its dependencies manually so they come from DllDirectory
authoraroben <aroben@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Sep 2007 07:07:41 +0000 (07:07 +0000)
committeraroben <aroben@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Sep 2007 07:07:41 +0000 (07:07 +0000)
         I had to change WebKitInitializer to use malloc/free instead of
         new/delete to avoid pulling in WebKit (and its dependencies) early
         through use of fastMalloc.

         Reviewed by Oliver.

         * WebKitInitializer/WebKitInitializer.cpp:
         (getStringValue): Changed to use malloc/free.
         (getInstalledWebKitDirectory): Ditto.
         (initializeWebKit): Call SetDllDirectory first, then load all of
         WebKit's dependencies manually, finally followed by WebKit itself.
         * WebKitInitializer/WebKitInitializer.vcproj: Added a new
         configuration to match our other projects.
         * WebKitInitializer/debug_internal.vsprops: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@25760 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKitTools/ChangeLog
WebKitTools/WebKitInitializer/WebKitInitializer.cpp
WebKitTools/WebKitInitializer/WebKitInitializer.vcproj
WebKitTools/WebKitInitializer/debug_internal.vsprops [new file with mode: 0644]

index 5c66ea2..b5602bf 100644 (file)
@@ -1,3 +1,22 @@
+2007-09-26  Adam Roben  <aroben@apple.com>
+
+        Load WebKit and its dependencies manually so they come from DllDirectory
+
+        I had to change WebKitInitializer to use malloc/free instead of
+        new/delete to avoid pulling in WebKit (and its dependencies) early
+        through use of fastMalloc.
+
+        Reviewed by Oliver.
+
+        * WebKitInitializer/WebKitInitializer.cpp:
+        (getStringValue): Changed to use malloc/free.
+        (getInstalledWebKitDirectory): Ditto.
+        (initializeWebKit): Call SetDllDirectory first, then load all of
+        WebKit's dependencies manually, finally followed by WebKit itself.
+        * WebKitInitializer/WebKitInitializer.vcproj: Added a new
+        configuration to match our other projects.
+        * WebKitInitializer/debug_internal.vsprops: Added.
+
 2007-09-25  Adam Roben  <aroben@apple.com>
 
         Actually define DEBUG/NDEBUG so that we load WebKit correctly
index 03590b0..ebd7179 100644 (file)
 #include <tchar.h>
 #include <windows.h>
 
+#define DEBUGDLLSUFFIX TEXT("_debug")
+#define RELEASEDLLSUFFIX
+
+#define EITHERDLL(name, suffix) (TEXT( #name ) suffix TEXT(".dll"))
+#define RELEASEDLL(name) EITHERDLL(name, RELEASEDLLSUFFIX)
+#define DEBUGDLL(name) EITHERDLL(name, DEBUGDLLSUFFIX)
+
+#ifdef USE_DEBUG_SUPPORT_LIBS
+#define DLL(name) DEBUGDLL(name)
+#else
+#define DLL(name) RELEASEDLL(name)
+#endif
+
 static TCHAR* getStringValue(HKEY key, LPCTSTR valueName)
 {
     DWORD type = 0;
@@ -42,9 +55,9 @@ static TCHAR* getStringValue(HKEY key, LPCTSTR valueName)
     if (RegQueryValueEx(key, valueName, 0, &type, 0, &bufferSize) != ERROR_SUCCESS || type != REG_SZ)
         return 0;
 
-    TCHAR* buffer = new TCHAR[bufferSize / sizeof(TCHAR)];
+    TCHAR* buffer = (TCHAR*)malloc(bufferSize);
     if (RegQueryValueEx(key, 0, 0, &type, reinterpret_cast<LPBYTE>(buffer), &bufferSize) != ERROR_SUCCESS) {
-        delete [] buffer;
+        free(buffer);
         return 0;
     }
 
@@ -83,7 +96,7 @@ static TCHAR* getInstalledWebKitDirectory()
         return 0;
 
     size_t keyBufferLength = _tcslen(keyPrefix) + _tcslen(clsid) + _tcslen(keySuffix) + 1;
-    TCHAR* keyString = new TCHAR[keyBufferLength];
+    TCHAR* keyString = (TCHAR*)malloc(keyBufferLength * sizeof(TCHAR));
 
     int ret = _sntprintf_s(keyString, keyBufferLength, keyBufferLength - 1, TEXT("%s%s%s"), keyPrefix, clsid, keySuffix);
     CoTaskMemFree(clsid);
@@ -94,7 +107,7 @@ static TCHAR* getInstalledWebKitDirectory()
 
     HKEY serverKey = 0;
     LONG error = RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyString, 0, KEY_READ, &serverKey);
-    delete [] keyString;
+    free(keyString);
     if (error != ERROR_SUCCESS) {
         _ftprintf(stderr, TEXT("Failed to open registry key %s\n"), keyString);
         return 0;
@@ -110,7 +123,7 @@ static TCHAR* getInstalledWebKitDirectory()
     TCHAR* startOfFileName = PathFindFileName(webKitPath);
     if (startOfFileName == webKitPath) {
         _ftprintf(stderr, TEXT("Couldn't find filename from path %s\n"), webKitPath);
-        delete [] webKitPath;
+        free(webKitPath);
         return 0;
     }
 
@@ -127,15 +140,39 @@ bool initializeWebKit()
 
     haveInitialized = true;
 
-#ifdef NDEBUG
-    LPCTSTR webKitDLL = TEXT("WebKit.dll");
-#else
-    LPCTSTR webKitDLL = TEXT("WebKit_debug.dll");
-#endif
+    TCHAR* directory = getInstalledWebKitDirectory();
+    if (!directory) {
+        _ftprintf(stderr, TEXT("Couldn't determine installed WebKit directory\n"));
+        return false;
+    }
 
-    HMODULE webKitModule = LoadLibrary(webKitDLL);
+    SetDllDirectory(directory);
+    free(directory);
+
+    LPCTSTR webKitDependencies[] = {
+        DLL(CFNetwork),
+        DLL(CoreFoundation),
+        DLL(CoreGraphics),
+        DLL(SQLite3),
+        DLL(SafariTheme),
+        RELEASEDLL(icudt36),
+        DLL(icuin36),
+        DLL(icuuc36),
+        DLL(libxml2),
+        DLL(libxslt),
+        DLL(pthreadVC2),
+        DLL(zlib1),
+    };
+
+    for (int i = 0; i < ARRAYSIZE(webKitDependencies); ++i)
+        if (!LoadLibrary(webKitDependencies[i])) {
+            _ftprintf(stderr, TEXT("LoadLibrary(%s) failed\n"), webKitDependencies[i]);
+            return false;
+        }
+
+    HMODULE webKitModule = LoadLibrary(DLL(WebKit));
     if (!webKitModule) {
-        _ftprintf(stderr, TEXT("LoadLibrary(%s) failed\n"), webKitDLL);
+        _ftprintf(stderr, TEXT("LoadLibrary(%s) failed\n"), DLL(WebKit));
         return false;
     }
 
@@ -147,15 +184,6 @@ bool initializeWebKit()
 
     dllRegisterServer();
 
-    TCHAR* directory = getInstalledWebKitDirectory();
-    if (!directory) {
-        _ftprintf(stderr, TEXT("Couldn't determine installed WebKit directory\n"));
-        return false;
-    }
-
-    SetDllDirectory(directory);
-    delete [] directory;
-
     success = true;
     return success;
 }
index 6dd5686..93ffe14 100644 (file)
                                CommandLine="mkdir 2&gt;NUL &quot;$(WebKitOutputDir)\include\WebKitInitializer&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(InputDir)*.h&quot; &quot;$(WebKitOutputDir)\include\WebKitInitializer&quot;&#x0D;&#x0A;"
                        />
                </Configuration>
+               <Configuration
+                       Name="Debug_Internal|Win32"
+                       OutputDirectory="$(WebKitOutputDir)\lib"
+                       IntermediateDirectory="$(WebKitOutputDir)\obj\$(ProjectName)\$(ConfigurationName)"
+                       ConfigurationType="4"
+                       InheritedPropertySheets=".\debug_internal.vsprops"
+                       CharacterSet="1"
+                       >
+                       <Tool
+                               Name="VCPreBuildEventTool"
+                       />
+                       <Tool
+                               Name="VCCustomBuildTool"
+                       />
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCMIDLTool"
+                       />
+                       <Tool
+                               Name="VCCLCompilerTool"
+                               Optimization="0"
+                               PreprocessorDefinitions="DEBUG"
+                               MinimalRebuild="true"
+                               BasicRuntimeChecks="3"
+                               RuntimeLibrary="3"
+                               WarningLevel="4"
+                               WarnAsError="true"
+                               Detect64BitPortabilityProblems="true"
+                               DebugInformationFormat="4"
+                       />
+                       <Tool
+                               Name="VCManagedResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCPreLinkEventTool"
+                       />
+                       <Tool
+                               Name="VCLibrarianTool"
+                               AdditionalDependencies="shlwapi.lib advapi32.lib ole32.lib"
+                               OutputFile="$(OutDir)\$(ProjectName)$(WebKitConfigSuffix).lib"
+                       />
+                       <Tool
+                               Name="VCALinkTool"
+                       />
+                       <Tool
+                               Name="VCXDCMakeTool"
+                       />
+                       <Tool
+                               Name="VCBscMakeTool"
+                       />
+                       <Tool
+                               Name="VCFxCopTool"
+                       />
+                       <Tool
+                               Name="VCPostBuildEventTool"
+                               CommandLine="mkdir 2&gt;NUL &quot;$(WebKitOutputDir)\include\WebKitInitializer&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(InputDir)*.h&quot; &quot;$(WebKitOutputDir)\include\WebKitInitializer&quot;&#x0D;&#x0A;"
+                       />
+               </Configuration>
        </Configurations>
        <References>
        </References>
diff --git a/WebKitTools/WebKitInitializer/debug_internal.vsprops b/WebKitTools/WebKitInitializer/debug_internal.vsprops
new file mode 100644 (file)
index 0000000..3dfd6eb
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0"?>
+<VisualStudioPropertySheet 
+       ProjectType="Visual C++" 
+       Version="8.00" 
+       Name="debug_internal"
+       >
+</VisualStudioPropertySheet>