Bug 1330529 - Part 4: Fold nsSetDllDirectory.h into nsWindowsMain.cpp. r?jimm draft
authorChris Peterson <cpeterson@mozilla.com>
Tue, 13 Feb 2018 00:52:44 -0800
changeset 755996 77291c35070a772cd960fad8e6ad7423cdfc490b
parent 755995 cedb99c58e7b22fea666a54849c4e2e2d973b514
child 755997 6c5bc88aa435fe5ab65cde2af85e17a791010634
push id99356
push usercpeterson@mozilla.com
push dateFri, 16 Feb 2018 08:57:25 +0000
reviewersjimm
bugs1330529, 699247
milestone60.0a1
Bug 1330529 - Part 4: Fold nsSetDllDirectory.h into nsWindowsMain.cpp. r?jimm nsSetDllDirectory.h consists of just one function definition, SanitizeEnvironmentVariables, which is now only called from nsWindowsMain.cpp. nsSetDllDirectory.h used to define its namesake NS_SetDllDirectory, but the function was removed in bug 699247. Also remove some #includes that are no longer necessary. MozReview-Commit-ID: E8OsXycdfO8
toolkit/xre/nsWindowsWMain.cpp
xpcom/base/nsSetDllDirectory.h
--- a/toolkit/xre/nsWindowsWMain.cpp
+++ b/toolkit/xre/nsWindowsWMain.cpp
@@ -6,21 +6,19 @@
 // similar bootstrap code. It converts wide-character windows wmain into UTF-8
 // narrow-character strings.
 
 #ifndef XP_WIN
 #error This file only makes sense on Windows.
 #endif
 
 #include "mozilla/Char16.h"
-#include "nsSetDllDirectory.h"
 #include "nsUTF8Utils.h"
 
-#include <intrin.h>
-#include <math.h>
+#include <windows.h>
 
 #ifdef __MINGW32__
 
 /* MingW currently does not implement a wide version of the
    startup routines.  Workaround is to implement something like
    it ourselves.  See bug 411826 */
 
 #include <shellapi.h>
@@ -44,16 +42,39 @@ int main(int argc, char **argv)
 #define main NS_internal_main
 
 #ifndef XRE_WANT_ENVIRON
 int main(int argc, char **argv);
 #else
 int main(int argc, char **argv, char **envp);
 #endif
 
+static void
+SanitizeEnvironmentVariables()
+{
+  DWORD bufferSize = GetEnvironmentVariableW(L"PATH", nullptr, 0);
+  if (bufferSize) {
+    wchar_t* originalPath = new wchar_t[bufferSize];
+    if (bufferSize - 1 == GetEnvironmentVariableW(L"PATH", originalPath,
+                                                  bufferSize)) {
+      bufferSize = ExpandEnvironmentStringsW(originalPath, nullptr, 0);
+      if (bufferSize) {
+        wchar_t* newPath = new wchar_t[bufferSize];
+        if (ExpandEnvironmentStringsW(originalPath,
+                                      newPath,
+                                      bufferSize)) {
+          SetEnvironmentVariableW(L"PATH", newPath);
+        }
+        delete[] newPath;
+      }
+    }
+    delete[] originalPath;
+  }
+}
+
 static char*
 AllocConvertUTF16toUTF8(char16ptr_t arg)
 {
   // be generous... UTF16 units can expand up to 3 UTF8 units
   int len = wcslen(arg);
   char *s = new char[len * 3 + 1];
   if (!s)
     return nullptr;
@@ -72,17 +93,17 @@ FreeAllocStrings(int argc, char **argv)
     delete [] argv[argc];
   }
 
   delete [] argv;
 }
 
 int wmain(int argc, WCHAR **argv)
 {
-  mozilla::SanitizeEnvironmentVariables();
+  SanitizeEnvironmentVariables();
   SetDllDirectoryW(L"");
 
   char **argvConverted = new char*[argc + 1];
   if (!argvConverted)
     return 127;
 
   for (int i = 0; i < argc; ++i) {
     argvConverted[i] = AllocConvertUTF16toUTF8(argv[i]);
deleted file mode 100644
--- a/xpcom/base/nsSetDllDirectory.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef nsSetDllDirectory_h
-#define nsSetDllDirectory_h
-
-#ifndef XP_WIN
-#error This file only makes sense on Windows.
-#endif
-
-#include <windows.h>
-#include <nscore.h>
-#include <stdlib.h>
-
-namespace mozilla {
-
-static void
-SanitizeEnvironmentVariables()
-{
-  DWORD bufferSize = GetEnvironmentVariableW(L"PATH", nullptr, 0);
-  if (bufferSize) {
-    wchar_t* originalPath = new wchar_t[bufferSize];
-    if (bufferSize - 1 == GetEnvironmentVariableW(L"PATH", originalPath,
-                                                  bufferSize)) {
-      bufferSize = ExpandEnvironmentStringsW(originalPath, nullptr, 0);
-      if (bufferSize) {
-        wchar_t* newPath = new wchar_t[bufferSize];
-        if (ExpandEnvironmentStringsW(originalPath,
-                                      newPath,
-                                      bufferSize)) {
-          SetEnvironmentVariableW(L"PATH", newPath);
-        }
-        delete[] newPath;
-      }
-    }
-    delete[] originalPath;
-  }
-}
-
-}
-
-#endif