Bug 711658. Move quirks triggering earlier. r=bgirard
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Mon, 19 Dec 2011 12:47:09 -0500
changeset 83818 2325e88b6026d5396df22e2f014daeb05e877fb9
parent 83817 bb91dfae700703d64870da6dd2ba7adc01963a9b
child 83819 ec3401e5a7b8c939b3a730718d85cabcee05a6c8
push id21798
push usermak77@bonardo.net
push dateThu, 05 Jan 2012 14:53:22 +0000
treeherdermozilla-central@595fba5b92d4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgirard
bugs711658, 696376
milestone12.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 711658. Move quirks triggering earlier. r=bgirard Bug 696376 caused our quirks to be triggered too late. This makes sure we're early enough. This also moves the copy of NS_CompareVersions into the header to make things work.
browser/app/nsBrowserApp.cpp
dom/plugins/ipc/interpose/plugin_child_quirks.mm
toolkit/xre/MacQuirks.h
toolkit/xre/nsAppRunner.cpp
toolkit/xre/nsEmbedFunctions.cpp
--- a/browser/app/nsBrowserApp.cpp
+++ b/browser/app/nsBrowserApp.cpp
@@ -41,16 +41,20 @@
 #if defined(XP_WIN)
 #include <windows.h>
 #include <stdlib.h>
 #elif defined(XP_UNIX)
 #include <sys/time.h>
 #include <sys/resource.h>
 #endif
 
+#ifdef XP_MACOSX
+#include "MacQuirks.h"
+#endif
+
 #include <stdio.h>
 #include <stdarg.h>
 #include <string.h>
 
 #include "plstr.h"
 #include "prprf.h"
 #include "prenv.h"
 
@@ -203,16 +207,20 @@ static int do_main(const char *exePath, 
 
   return result;
 }
 
 int main(int argc, char* argv[])
 {
   char exePath[MAXPATHLEN];
 
+#ifdef XP_MACOSX
+  TriggerQuirks();
+#endif
+
   nsresult rv = mozilla::BinaryPath::Get(argv[0], exePath);
   if (NS_FAILED(rv)) {
     Output("Couldn't calculate the application directory.\n");
     return 255;
   }
 
   char *lastSlash = strrchr(exePath, XPCOM_FILE_PATH_SEPARATOR[0]);
   if (!lastSlash || (lastSlash - exePath > MAXPATHLEN - sizeof(XPCOM_DLL) - 1))
--- a/dom/plugins/ipc/interpose/plugin_child_quirks.mm
+++ b/dom/plugins/ipc/interpose/plugin_child_quirks.mm
@@ -32,216 +32,23 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-// This file is a copy and paste from existing methods from
-// libxul. This is intentional because this interpose
-// library does not link with libxul.
-
 #include <sys/types.h>
 #include <sys/sysctl.h>
 #import "CoreFoundation/CoreFoundation.h"
 #import "CoreServices/CoreServices.h"
 #import "Carbon/Carbon.h"
 #define PRInt32 int32_t
 #define PRUint32 uint32_t
 
-PRInt32
-NS_CompareVersions(const char *A, const char *B);
-
 #include "MacQuirks.h"
 
 int static_init() {
   TriggerQuirks();
   return 0;
 }
 int run = static_init();
-
-struct VersionPart {
-  PRInt32     numA;
-
-  const char *strB;    // NOT null-terminated, can be a null pointer
-  PRUint32    strBlen;
-
-  PRInt32     numC;
-
-  char       *extraD;  // null-terminated
-};
-
-/**
- * Parse a version part into a number and "extra text".
- *
- * @returns A pointer to the next versionpart, or null if none.
- */
-static char*
-ParseVP(char *part, VersionPart &result)
-{
-  char *dot;
-
-  result.numA = 0;
-  result.strB = NULL;
-  result.strBlen = 0;
-  result.numC = 0;
-  result.extraD = NULL;
-
-  if (!part)
-    return part;
-
-  dot = strchr(part, '.');
-  if (dot)
-    *dot = '\0';
-
-  if (part[0] == '*' && part[1] == '\0') {
-    result.numA = INT32_MAX;
-    result.strB = "";
-  }
-  else {
-    result.numA = strtol(part, const_cast<char**>(&result.strB), 10);
-  }
-
-  if (!*result.strB) {
-    result.strB = NULL;
-    result.strBlen = 0;
-  }
-  else {
-    if (result.strB[0] == '+') {
-      static const char kPre[] = "pre";
-
-      ++result.numA;
-      result.strB = kPre;
-      result.strBlen = sizeof(kPre) - 1;
-    }
-    else {
-      const char *numstart = strpbrk(result.strB, "0123456789+-");
-      if (!numstart) {
-  result.strBlen = strlen(result.strB);
-      }
-      else {
-  result.strBlen = numstart - result.strB;
-
-  result.numC = strtol(numstart, &result.extraD, 10);
-  if (!*result.extraD)
-    result.extraD = NULL;
-      }
-    }
-  }
-
-  if (dot) {
-    ++dot;
-
-    if (!*dot)
-      dot = NULL;
-  }
-
-  return dot;
-}
-
-
-// compare two null-terminated strings, which may be null pointers
-static PRInt32
-ns_strcmp(const char *str1, const char *str2)
-{
-  // any string is *before* no string
-  if (!str1)
-    return str2 != 0;
-
-  if (!str2)
-    return -1;
-
-  return strcmp(str1, str2);
-}
-
-// compare two length-specified string, which may be null pointers
-static PRInt32
-ns_strnncmp(const char *str1, PRUint32 len1, const char *str2, PRUint32 len2)
-{
-  // any string is *before* no string
-  if (!str1)
-    return str2 != 0;
-
-  if (!str2)
-    return -1;
-
-  for (; len1 && len2; --len1, --len2, ++str1, ++str2) {
-    if (*str1 < *str2)
-      return -1;
-
-    if (*str1 > *str2)
-      return 1;
-  }
-
-  if (len1 == 0)
-    return len2 == 0 ? 0 : -1;
-
-  return 1;
-}
-
-// compare two PRInt32
-static PRInt32
-ns_cmp(PRInt32 n1, PRInt32 n2)
-{
-  if (n1 < n2)
-    return -1;
-
-  return n1 != n2;
-}
-
-/**
- * Compares two VersionParts
- */
-static PRInt32
-CompareVP(VersionPart &v1, VersionPart &v2)
-{
-  PRInt32 r = ns_cmp(v1.numA, v2.numA);
-  if (r)
-    return r;
-
-  r = ns_strnncmp(v1.strB, v1.strBlen, v2.strB, v2.strBlen);
-  if (r)
-    return r;
-
-  r = ns_cmp(v1.numC, v2.numC);
-  if (r)
-    return r;
-
-  return ns_strcmp(v1.extraD, v2.extraD);
-}
-
-PRInt32
-NS_CompareVersions(const char *A, const char *B)
-{
-  char *A2 = strdup(A);
-  if (!A2)
-    return 1;
-
-  char *B2 = strdup(B);
-  if (!B2) {
-    free(A2);
-    return 1;
-  }
-
-  PRInt32 result;
-  char *a = A2, *b = B2;
-
-  do {
-    VersionPart va, vb;
-
-    a = ParseVP(a, va);
-    b = ParseVP(b, vb);
-
-    result = CompareVP(va, vb);
-    if (result)
-      break;
-
-  } while (a || b);
-
-  free(A2);
-  free(B2);
-
-  return result;
-}
-
-
--- a/toolkit/xre/MacQuirks.h
+++ b/toolkit/xre/MacQuirks.h
@@ -42,16 +42,207 @@
 #define MacQuirks_h__
 
 #include <sys/types.h>
 #include <sys/sysctl.h>
 #include "CoreFoundation/CoreFoundation.h"
 #include "CoreServices/CoreServices.h"
 #include "Carbon/Carbon.h"
 
+// This file is a copy and paste from existing methods from
+// libxul. This is intentional because this interpose
+// library does not link with libxul.
+
+struct VersionPart {
+  PRInt32     numA;
+
+  const char *strB;    // NOT null-terminated, can be a null pointer
+  PRUint32    strBlen;
+
+  PRInt32     numC;
+
+  char       *extraD;  // null-terminated
+};
+
+/**
+ * Parse a version part into a number and "extra text".
+ *
+ * @returns A pointer to the next versionpart, or null if none.
+ */
+static char*
+ParseVP(char *part, VersionPart &result)
+{
+  char *dot;
+
+  result.numA = 0;
+  result.strB = NULL;
+  result.strBlen = 0;
+  result.numC = 0;
+  result.extraD = NULL;
+
+  if (!part)
+    return part;
+
+  dot = strchr(part, '.');
+  if (dot)
+    *dot = '\0';
+
+  if (part[0] == '*' && part[1] == '\0') {
+    result.numA = INT32_MAX;
+    result.strB = "";
+  }
+  else {
+    result.numA = strtol(part, const_cast<char**>(&result.strB), 10);
+  }
+
+  if (!*result.strB) {
+    result.strB = NULL;
+    result.strBlen = 0;
+  }
+  else {
+    if (result.strB[0] == '+') {
+      static const char kPre[] = "pre";
+
+      ++result.numA;
+      result.strB = kPre;
+      result.strBlen = sizeof(kPre) - 1;
+    }
+    else {
+      const char *numstart = strpbrk(result.strB, "0123456789+-");
+      if (!numstart) {
+  result.strBlen = strlen(result.strB);
+      }
+      else {
+  result.strBlen = numstart - result.strB;
+
+  result.numC = strtol(numstart, &result.extraD, 10);
+  if (!*result.extraD)
+    result.extraD = NULL;
+      }
+    }
+  }
+
+  if (dot) {
+    ++dot;
+
+    if (!*dot)
+      dot = NULL;
+  }
+
+  return dot;
+}
+
+
+// compare two null-terminated strings, which may be null pointers
+static PRInt32
+ns_strcmp(const char *str1, const char *str2)
+{
+  // any string is *before* no string
+  if (!str1)
+    return str2 != 0;
+
+  if (!str2)
+    return -1;
+
+  return strcmp(str1, str2);
+}
+
+// compare two length-specified string, which may be null pointers
+static PRInt32
+ns_strnncmp(const char *str1, PRUint32 len1, const char *str2, PRUint32 len2)
+{
+  // any string is *before* no string
+  if (!str1)
+    return str2 != 0;
+
+  if (!str2)
+    return -1;
+
+  for (; len1 && len2; --len1, --len2, ++str1, ++str2) {
+    if (*str1 < *str2)
+      return -1;
+
+    if (*str1 > *str2)
+      return 1;
+  }
+
+  if (len1 == 0)
+    return len2 == 0 ? 0 : -1;
+
+  return 1;
+}
+
+// compare two PRInt32
+static PRInt32
+ns_cmp(PRInt32 n1, PRInt32 n2)
+{
+  if (n1 < n2)
+    return -1;
+
+  return n1 != n2;
+}
+
+/**
+ * Compares two VersionParts
+ */
+static PRInt32
+CompareVP(VersionPart &v1, VersionPart &v2)
+{
+  PRInt32 r = ns_cmp(v1.numA, v2.numA);
+  if (r)
+    return r;
+
+  r = ns_strnncmp(v1.strB, v1.strBlen, v2.strB, v2.strBlen);
+  if (r)
+    return r;
+
+  r = ns_cmp(v1.numC, v2.numC);
+  if (r)
+    return r;
+
+  return ns_strcmp(v1.extraD, v2.extraD);
+}
+
+/* this is intentionally not static so that we don't end up making copies
+ * anywhere */
+PRInt32
+NS_CompareVersions(const char *A, const char *B)
+{
+  char *A2 = strdup(A);
+  if (!A2)
+    return 1;
+
+  char *B2 = strdup(B);
+  if (!B2) {
+    free(A2);
+    return 1;
+  }
+
+  PRInt32 result;
+  char *a = A2, *b = B2;
+
+  do {
+    VersionPart va, vb;
+
+    a = ParseVP(a, va);
+    b = ParseVP(b, vb);
+
+    result = CompareVP(va, vb);
+    if (result)
+      break;
+
+  } while (a || b);
+
+  free(A2);
+  free(B2);
+
+  return result;
+}
+
+
 static void
 TriggerQuirks()
 {
   int mib[2];
 
   mib[0] = CTL_KERN;
   mib[1] = KERN_OSRELEASE;
   // we won't support versions greater than 10.7.99
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -64,17 +64,16 @@
 #include "nsUpdateDriver.h"
 
 #ifdef MOZ_INSTRUMENT_EVENT_LOOP
 #include "EventTracer.h"
 #endif
 
 #ifdef XP_MACOSX
 #include "nsVersionComparator.h"
-#include "MacQuirks.h"
 #include "MacLaunchHelper.h"
 #include "MacApplicationDelegate.h"
 #include "MacAutoreleasePool.h"
 // these are needed for sysctl
 #include <sys/types.h>
 #include <sys/sysctl.h>
 #endif
 
@@ -2589,20 +2588,16 @@ XRE_main(int argc, char* argv[], const n
   nsresult rv;
   ArgResult ar;
 
 #ifdef DEBUG
   if (PR_GetEnv("XRE_MAIN_BREAK"))
     NS_BREAK();
 #endif
 
-#ifdef XP_MACOSX
-  TriggerQuirks();
-#endif
-
   // see bug 639842
   // it's very important to fire this process BEFORE we set up error handling.
   // indeed, this process is expected to be crashy, and we don't want the user to see its crashes.
   // That's the whole reason for doing this in a separate process.
 #ifdef MOZ_X11
 #ifndef MOZ_PLATFORM_MAEMO
   if (fire_glxtest_process())
     return 0;
--- a/toolkit/xre/nsEmbedFunctions.cpp
+++ b/toolkit/xre/nsEmbedFunctions.cpp
@@ -74,17 +74,16 @@
 #include "nsThreadUtils.h"
 #include "nsJSUtils.h"
 #include "nsWidgetsCID.h"
 #include "nsXREDirProvider.h"
 
 #include "mozilla/Omnijar.h"
 #if defined(XP_MACOSX)
 #include "nsVersionComparator.h"
-#include "MacQuirks.h"
 #include "chrome/common/mach_ipc_mac.h"
 #endif
 #include "nsX11ErrorHandler.h"
 #include "base/at_exit.h"
 #include "base/command_line.h"
 #include "base/message_loop.h"
 #include "base/process_util.h"
 #include "chrome/common/child_process.h"
@@ -309,20 +308,16 @@ nsresult
 XRE_InitChildProcess(int aArgc,
                      char* aArgv[],
                      GeckoProcessType aProcess)
 {
   NS_ENSURE_ARG_MIN(aArgc, 2);
   NS_ENSURE_ARG_POINTER(aArgv);
   NS_ENSURE_ARG_POINTER(aArgv[0]);
 
-#ifdef XP_MACOSX
-  TriggerQuirks();
-#endif
-
   sChildProcessType = aProcess;
 
   // Complete 'task_t' exchange for Mac OS X. This structure has the same size
   // regardless of architecture so we don't have any cross-arch issues here.
 #ifdef XP_MACOSX
   if (aArgc < 1)
     return 1;
   const char* const mach_port_name = aArgv[--aArgc];