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.

--HG--
extra : rebase_source : cf2179f0127a5e2c150c5fd54a0a6e8904c52301
This commit is contained in:
Jeff Muizelaar 2011-12-19 12:47:09 -05:00
parent 30f1dc7f1a
commit 43465f2503
5 changed files with 199 additions and 203 deletions

View File

@ -46,6 +46,10 @@
#include <sys/resource.h>
#endif
#ifdef XP_MACOSX
#include "MacQuirks.h"
#endif
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
@ -208,6 +212,10 @@ 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");

View File

@ -37,10 +37,6 @@
*
* ***** 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"
@ -49,9 +45,6 @@
#define PRInt32 int32_t
#define PRUint32 uint32_t
PRInt32
NS_CompareVersions(const char *A, const char *B);
#include "MacQuirks.h"
int static_init() {
@ -59,189 +52,3 @@ int static_init() {
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;
}

View File

@ -47,6 +47,197 @@
#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()
{

View File

@ -69,7 +69,6 @@
#ifdef XP_MACOSX
#include "nsVersionComparator.h"
#include "MacQuirks.h"
#include "MacLaunchHelper.h"
#include "MacApplicationDelegate.h"
#include "MacAutoreleasePool.h"
@ -2594,10 +2593,6 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData)
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.

View File

@ -79,7 +79,6 @@
#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"
@ -314,10 +313,6 @@ XRE_InitChildProcess(int aArgc,
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