tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Fixing firefox for non x86 cpus



Hi folks,

I'll leave out a long story and censor my thoughts on some of this as well,
the end result is short and easy:

Firefox 2 is currently broken on all CPUs that require strict alignment
due to some bogus "unicode" conversion code. There is a fix in their
bugzilla, but it can only be downloaded via https, so making it a vendor
patch sounds complicated (besides I dare not touch the pkg makefile).

Is it ok to just put the attached as patches/patch-ee and regen distinfo?
I tried that and it makes the pkg work on sparc64.

Martin
$NetBSD$

This is align.patch from https://bugzilla.mozilla.org/show_bug.cgi?id=161826
(https://bugzilla.mozilla.org/attachment.cgi?id=294965)

It is needed to make firefox work on CPUs requiring strict alignment.

Index: intl/unicharutil/util/nsUnicharUtils.cpp
===================================================================
RCS file: /cvsroot/mozilla/intl/unicharutil/util/nsUnicharUtils.cpp,v
retrieving revision 1.27.8.1
diff -u -b -B -u -8 -p -r1.27.8.1 nsUnicharUtils.cpp
--- intl/unicharutil/util/nsUnicharUtils.cpp    22 Jun 2006 19:13:00 -0000      
1.27.8.1
+++ intl/unicharutil/util/nsUnicharUtils.cpp    31 Dec 2007 16:07:40 -0000
@@ -343,8 +343,20 @@ ToUpperCase(PRUnichar aChar)
         if (aChar < 256)
             result = toupper(char(aChar));
         else
             result = aChar;
     }
     return result;
 }
 
+void
+SetUnichar(void *ptr, PRUnichar aChar)
+{
+#if NEED_STRICT_ALIGNMENT
+    *((char *) ptr) = *((char *) &aChar);
+    *((char *) ptr + 1) = *((char *) &aChar + 1);
+#else
+    *((PRUnichar *) ptr) = aChar;
+#endif
+}
+
+
Index: intl/unicharutil/util/nsUnicharUtils.h
===================================================================
RCS file: /cvsroot/mozilla/intl/unicharutil/util/nsUnicharUtils.h,v
retrieving revision 1.19
diff -u -b -B -u -8 -p -r1.19 nsUnicharUtils.h
--- intl/unicharutil/util/nsUnicharUtils.h      24 Feb 2005 15:50:57 -0000      
1.19
+++ intl/unicharutil/util/nsUnicharUtils.h      31 Dec 2007 16:07:40 -0000
@@ -77,16 +77,20 @@ inline PRBool CaseInsensitiveFindInReada
                         aHay.BeginReading(searchBegin),
                         aHay.EndReading(searchEnd),
                         nsCaseInsensitiveStringComparator());
 }
 
 PRUnichar ToUpperCase(PRUnichar);
 PRUnichar ToLowerCase(PRUnichar);
 
+#define NEED_STRICT_ALIGNMENT defined(__sparc__) || defined(__alpha__) || 
defined(__mips__)
+
+void SetUnichar(void *, PRUnichar);
+
 inline PRBool IsUpperCase(PRUnichar c) {
     return ToLowerCase(c) != c;
 }
 
 inline PRBool IsLowerCase(PRUnichar c) {
     return ToUpperCase(c) != c;
 }
 
Index: layout/generic/nsTextFrame.cpp
===================================================================
RCS file: /cvsroot/mozilla/layout/generic/Attic/nsTextFrame.cpp,v
retrieving revision 1.513.4.17
diff -u -b -B -u -8 -p -r1.513.4.17 nsTextFrame.cpp
--- layout/generic/nsTextFrame.cpp      19 Sep 2007 01:45:40 -0000      
1.513.4.17
+++ layout/generic/nsTextFrame.cpp      31 Dec 2007 16:07:41 -0000
@@ -5118,28 +5118,37 @@ struct TextRun {
     mSegments[mNumSegments].mIsWhitespace = aIsWhitespace;
     mTotalContentLen += aContentLen;
     mSegments[mNumSegments].mContentLen = PRUint32(mTotalContentLen);
     mNumSegments++;
   }
 };
 
 // Transforms characters in place from ascii to Unicode
-static void
+static PRUnichar *
 TransformTextToUnicode(char* aText, PRInt32 aNumChars)
 {
   // Go backwards over the characters and convert them.
   unsigned char*  cp1 = (unsigned char*)aText + aNumChars - 1;
-  PRUnichar*      cp2 = (PRUnichar*)aText + (aNumChars - 1);
+  PRUnichar*      cp2;
+  PRUnichar*      ret;
   
-  while (aNumChars-- > 0) {
-    // XXX: If you crash here then you may see the issue described
-    // in http://bugzilla.mozilla.org/show_bug.cgi?id=36146#c44
-    *cp2-- = PRUnichar(*cp1--);
-  }
+  if ((unsigned long) aText & 0x1)
+    cp2 = ((PRUnichar*)(aText + 1));
+  else
+    cp2 = (PRUnichar*)aText;
+  
+  ret = cp2;
+
+  cp2 += (aNumChars - 1);
+
+  while (aNumChars-- > 0)
+    SetUnichar(cp2--, PRUnichar(*cp1--));
+
+  return ret;
 }
  
 PRUint32
 nsTextFrame::EstimateNumChars(PRUint32 aAvailableWidth,
                               PRUint32 aAverageCharWidth)
 {
   // Estimate the number of characters that will fit. Use 105% of the available
   // width divided by the average character width.
@@ -5697,17 +5706,17 @@ nsTextFrame::MeasureText(nsPresContext* 
           PRUnichar* pWordBuf = lastWordPtr;
           PRUint32   wordBufLen = aTx.GetWordBufferLength() -
                                   (lastWordPtr - aTx.GetWordBuffer());
 
           if (aTx.TransformedTextIsAscii()) {
             // The text transform buffer contains ascii characters, so
             // transform it to Unicode
             NS_ASSERTION(wordBufLen >= PRUint32(lastWordLen), "no room to 
transform in place");
-            TransformTextToUnicode((char*)lastWordPtr, lastWordLen);
+            pWordBuf = TransformTextToUnicode((char*)lastWordPtr, lastWordLen);
           }
 
           // Look ahead in the text-run and compute the final word
           // width, taking into account any style changes and stopping
           // at the first breakable point.
           if (!aTextData.mMeasureText || (lastWordDimensions.width == -1)) {
             // We either didn't measure any text or we measured multiple words
             // at once so either way we don't know lastWordDimensions. We'll 
have to
@@ -6227,17 +6236,17 @@ nsTextFrame::TrimTrailingWhiteSpace(nsPr
 
 static void
 RevertSpacesToNBSP(PRUnichar* aBuffer, PRInt32 aWordLen)
 {
   PRUnichar* end = aBuffer + aWordLen;
   for (; aBuffer < end; aBuffer++) {
     PRUnichar ch = *aBuffer;
     if (ch == ' ') {
-      *aBuffer = CH_NBSP;
+      SetUnichar(aBuffer, CH_NBSP);
     }
   }
 }
 
 nsTextDimensions
 nsTextFrame::ComputeTotalWordDimensions(nsPresContext* aPresContext,
                                    nsILineBreaker* aLineBreaker,
                                    nsLineLayout& aLineLayout,


Home | Main Index | Thread Index | Old Index