[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

mjs mjs at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:51:34 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 415c7f0e4f19df3818cc3f5f0e82474f66e4c14c
Author: mjs <mjs at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Jul 20 08:12:08 2004 +0000

            Reviewed by Trey.
    
    	<rdar://problem/3721428> REGRESSION (125.8-146): external javascript statements produce extra garbage character (sina.com)
    
    	* khtml/misc/stringit.h:
            (khtml::TokenizerSubstring::TokenizerSubstring): For the apple branch, use the new
    	stableUnicode() method to get the unicode pointer.
            * kwq/KWQString.h:
            * kwq/KWQString.mm:
            (QString::detachIfInternal): Reorganize this to be a bit less wacky about refcounts.
    	It does not leave around a zombie internal data handle but rather destroys it right away,
    	and leaves the object pointing to the new handle (which it can then deref). This makes
    	the code more clear.
            (QString::~QString): Simplify.
            (QString::stableUnicode): New method that detaches a copy of the KWQStringData if it
    	is internal to a string besides this one. This guarantees that if you get the unicode()
    	pointer, it won't go bad so long as this string is still alive.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@7060 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index d9d1a55..344e602 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,23 @@
+2004-07-19  Maciej Stachowiak  <mjs at apple.com>
+
+        Reviewed by Trey.
+
+	<rdar://problem/3721428> REGRESSION (125.8-146): external javascript statements produce extra garbage character (sina.com)
+        
+	* khtml/misc/stringit.h:
+        (khtml::TokenizerSubstring::TokenizerSubstring): For the apple branch, use the new
+	stableUnicode() method to get the unicode pointer.
+        * kwq/KWQString.h:
+        * kwq/KWQString.mm:
+        (QString::detachIfInternal): Reorganize this to be a bit less wacky about refcounts.
+	It does not leave around a zombie internal data handle but rather destroys it right away,
+	and leaves the object pointing to the new handle (which it can then deref). This makes
+	the code more clear.
+        (QString::~QString): Simplify.
+        (QString::stableUnicode): New method that detaches a copy of the KWQStringData if it
+	is internal to a string besides this one. This guarantees that if you get the unicode()
+	pointer, it won't go bad so long as this string is still alive.
+
 2004-07-19  David Hyatt  <hyatt at apple.com>
 
 	Fix for 3715117, crash from a bug in removeChildren.  Clean up node removal and fix an n-squared removal
diff --git a/WebCore/khtml/misc/stringit.h b/WebCore/khtml/misc/stringit.h
index f06253c..d652d70 100644
--- a/WebCore/khtml/misc/stringit.h
+++ b/WebCore/khtml/misc/stringit.h
@@ -43,7 +43,16 @@ private:
     friend class TokenizerString;
     
     TokenizerSubstring() : m_length(0), m_current(0) {}
-    TokenizerSubstring(const QString &str) : m_string(str), m_length(str.length()), m_current(m_length == 0 ? 0 : str.unicode()) {}
+    TokenizerSubstring(const QString &str) : m_string(str), m_length(str.length()) {
+#if APPLE_CHANGES
+	m_current = m_length == 0 ? 0 : m_string.stableUnicode();
+#else
+	m_current = m_length == 0 ? 0 : m_string.unicode();
+#endif
+
+
+    }
+
     TokenizerSubstring(const QChar *str, int length) : m_length(length), m_current(length == 0 ? 0 : str) {}
 
     void clear() { m_length = 0; m_current = 0; }
diff --git a/WebCore/kwq/KWQString.h b/WebCore/kwq/KWQString.h
index 73bd275..b7d958d 100644
--- a/WebCore/kwq/KWQString.h
+++ b/WebCore/kwq/KWQString.h
@@ -362,7 +362,7 @@ struct KWQStringData {
     
     bool isUnicodeInternal() const { return (char *)_unicode == _internalBuffer; }
     bool isAsciiInternal() const { return _ascii == _internalBuffer; }
-    
+
     uint refCount;
     uint _length;
     mutable QChar *_unicode;
@@ -413,6 +413,7 @@ public:
     uint length() const;
 
     const QChar *unicode() const;
+    const QChar *stableUnicode();
     const char *latin1() const;
     const char *ascii() const;
     bool isAllASCII() const;
@@ -543,7 +544,7 @@ public:
     NSString *getNSString() const;
 
     void setBufferFromCFString(CFStringRef);
-    
+
 private:
     // Used by QConstString.
     QString(KWQStringData *constData, bool /*dummy*/);
diff --git a/WebCore/kwq/KWQString.mm b/WebCore/kwq/KWQString.mm
index 799a7c2..6aacfb4 100644
--- a/WebCore/kwq/KWQString.mm
+++ b/WebCore/kwq/KWQString.mm
@@ -809,48 +809,51 @@ NSString *QString::getNSString() const
     return nil;
 }
 
-inline void QString::detachInternal()
+inline void QString::detachIfInternal()
 {
     KWQStringData *oldData = *dataHandle;
-    KWQStringData *newData = new KWQStringData(*oldData);
-    newData->_isHeapAllocated = 1;
-    newData->refCount = oldData->refCount - 1;
-    oldData->refCount = 1;
-    *dataHandle = newData;    
+    if (oldData->refCount > 1 && oldData == &internalData) {
+	KWQStringData *newData = new KWQStringData(*oldData);
+	newData->_isHeapAllocated = 1;
+	newData->refCount = oldData->refCount;
+	oldData->refCount = 1;
+	oldData->deref();
+	*dataHandle = newData;    
+    }
 }
 
-inline void QString::detachIfInternal()
+const QChar *QString::stableUnicode()
 {
-    KWQStringData *oldData = *dataHandle;
-    if (oldData->refCount > 1 && oldData == &internalData) {
-        detachInternal();
+    // if we're using the internal data of another string, detach now
+    if (!dataHandle[0]->_isHeapAllocated && *dataHandle != &internalData) {
+	detach();
     }
+    return unicode();
 }
 
+
 QString::~QString()
 {
-    KWQStringData **oldHandle = dataHandle;
-    KWQStringData *oldData = *oldHandle;
-    
-    ASSERT(oldHandle);
-    ASSERT(oldData->refCount != 0);
+    ASSERT(dataHandle);
+    ASSERT(dataHandle[0]->refCount != 0);
 
     // Only free the handle if no other string has a reference to the
     // data.  The handle will be freed by the string that has the
     // last reference to data.
-    bool needToFreeHandle = oldData->refCount == 1 && oldData != shared_null;
+    bool needToFreeHandle = dataHandle[0]->refCount == 1 && *dataHandle != shared_null;
 
     // Copy our internal data if necessary, other strings still need it.
     detachIfInternal();
     
     // Remove our reference. This should always be the last reference
-    // if *dataHandle points to our internal KWQStringData.
-    oldData->deref();
+    // if *dataHandle points to our internal KWQStringData. If we just detached,
+    // this will remove the extra ref from the new handle.
+    dataHandle[0]->deref();
 
-    ASSERT(oldData != &internalData || oldData->refCount == 0);
+    ASSERT(*dataHandle != &internalData || dataHandle[0]->refCount == 0);
     
     if (needToFreeHandle)
-        freeHandle(oldHandle);
+        freeHandle(dataHandle);
 
     dataHandle = 0;
 }

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list