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

darin darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:31:22 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 55bbbfe7071c8d297e5c5bfb5e3751d369d11b1e
Author: darin <darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Mar 30 18:33:33 2004 +0000

            Reviewed by Ken.
    
            - fixed garbage characters seen while I was rigging up the Mozilla JavaScript tests
    
            * kwq/KWQString.h: Add a "move constructor" for KWQStringData that extracts the data
            from an existing KWQStringData.
            * kwq/KWQString.mm:
            (KWQStringData::KWQStringData): Implement the move constructor.
            (QString::detachInternal): Use the move constructor rather than making a copy of the
            data. Should be both more efficient and preserves both the Unicode and the ASCII. The
            bug here is that TokenizerSubstring relies on the Unicode staying around. We still
            have a problem in the case where the Unicode is inside the KWQStringData. To deal with
            that we'll have to add a new QString call that TokenizerSubstring can use. The new call
            will force QString to keep the Unicode outside the internal KWQStringData.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@6277 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index b31a983..6ba4bd4 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -2,6 +2,23 @@
 
         Reviewed by Ken.
 
+        - fixed garbage characters seen while I was rigging up the Mozilla JavaScript tests
+
+        * kwq/KWQString.h: Add a "move constructor" for KWQStringData that extracts the data
+        from an existing KWQStringData.
+        * kwq/KWQString.mm:
+        (KWQStringData::KWQStringData): Implement the move constructor.
+        (QString::detachInternal): Use the move constructor rather than making a copy of the
+        data. Should be both more efficient and preserves both the Unicode and the ASCII. The
+        bug here is that TokenizerSubstring relies on the Unicode staying around. We still
+        have a problem in the case where the Unicode is inside the KWQStringData. To deal with
+        that we'll have to add a new QString call that TokenizerSubstring can use. The new call
+        will force QString to keep the Unicode outside the internal KWQStringData.
+
+2004-03-30  Darin Adler  <darin at apple.com>
+
+        Reviewed by Ken.
+
         - fixed <rdar://problem/3606146>: repro nil-deref in QWidget::move (www.stoltoffshore.com)
 
         * khtml/khtml_part.cpp:
diff --git a/WebCore/kwq/KWQString.h b/WebCore/kwq/KWQString.h
index 76b1d59..37805b5 100644
--- a/WebCore/kwq/KWQString.h
+++ b/WebCore/kwq/KWQString.h
@@ -331,14 +331,17 @@ struct KWQStringData {
     KWQStringData(QChar *u, uint l, uint m);
     void initialize(QChar *u, uint l, uint m);
     
-    // Copy bytes;
+    // Copy bytes.
     KWQStringData(const QChar *u, uint l);
     void initialize(const QChar *u, uint l);
 
-    // Copy bytes;
+    // Copy bytes.
     KWQStringData(const char *u, uint l);
     void initialize(const char *u, uint l);
 
+    // Move from destination to source.
+    KWQStringData(KWQStringData &);
+
     ~KWQStringData();
 
 #ifdef QSTRING_DEBUG_ALLOCATIONS
@@ -371,6 +374,10 @@ struct KWQStringData {
     uint _isAsciiValid:1;
     
     char _internalBuffer[QS_INTERNAL_BUFFER_SIZE]; // Pad out to a (((size + 1) & ~15) + 14) size
+
+private:
+    KWQStringData(const KWQStringData &);
+    KWQStringData &operator=(const KWQStringData &);
 };
 
 #define QSTRING_NULL QString()
diff --git a/WebCore/kwq/KWQString.mm b/WebCore/kwq/KWQString.mm
index 36eec39..fbbcc3c 100644
--- a/WebCore/kwq/KWQString.mm
+++ b/WebCore/kwq/KWQString.mm
@@ -464,6 +464,49 @@ void KWQStringData::initialize(const char *a, uint l)
     }
 }
 
+KWQStringData::KWQStringData(KWQStringData &o)
+    : refCount(1)
+    , _length(o._length)
+    , _unicode(o._unicode)
+    , _ascii(o._ascii)
+    , _maxUnicode(o._maxUnicode)
+    , _isUnicodeValid(o._isUnicodeValid)
+    , _isHeapAllocated(0)
+    , _maxAscii(o._maxAscii)
+    , _isAsciiValid(o._isAsciiValid)
+{
+    // Handle the case where either the Unicode or 8-bit pointer was
+    // pointing to the internal buffer. We need to point at the
+    // internal buffer in the new object, and copy the characters.
+    if (_unicode == reinterpret_cast<QChar *>(o._internalBuffer)) {
+        if (_isUnicodeValid) {
+            ASSERT(!_isAsciiValid || _ascii != o._internalBuffer);
+            ASSERT(_length <= QS_INTERNAL_BUFFER_UCHARS);
+            memcpy(_internalBuffer, o._internalBuffer, _length * sizeof(QChar));
+            _unicode = reinterpret_cast<QChar *>(_internalBuffer);
+        } else {
+            _unicode = 0;
+        }
+    }
+    if (_ascii == o._internalBuffer) {
+        if (_isAsciiValid) {
+            ASSERT(_length <= QS_INTERNAL_BUFFER_CHARS);
+            memcpy(_internalBuffer, o._internalBuffer, _length);
+            _internalBuffer[_length] = 0;
+            _ascii = _internalBuffer;
+        } else {
+            _ascii = 0;
+        }
+    }
+
+    // Clean up the other KWQStringData just enough so that it can be destroyed
+    // cleanly. It's not in a good enough state to use, but that's OK. It just
+    // needs to be in a state where ~KWQStringData won't do anything harmful,
+    // and setting these to 0 will do that (preventing any double-free problems).
+    o._unicode = 0;
+    o._ascii = 0;
+}
+
 KWQStringData *QString::makeSharedNull()
 {
     if (!shared_null) {
@@ -742,25 +785,11 @@ NSString *QString::getNSString() const
 inline void QString::detachInternal()
 {
     KWQStringData *oldData = *dataHandle;
-    KWQStringData *newData;
-    if (oldData->_isAsciiValid)
-        newData = new KWQStringData(oldData->ascii(), oldData->_length);
-    else {
-        ASSERT(oldData->_isUnicodeValid);
-        // No need to copy the allocated unicode bytes.
-        if (oldData->isUnicodeInternal())
-            newData = new KWQStringData(oldData->unicode(), oldData->_length);
-        else {
-            newData = new KWQStringData(oldData->unicode(), oldData->_length, oldData->_maxUnicode);
-            oldData->_unicode = 0;
-            oldData->_isUnicodeValid = 0;
-        }
-    }
+    KWQStringData *newData = new KWQStringData(*oldData);
     newData->_isHeapAllocated = 1;
     newData->refCount = oldData->refCount - 1;
-    *dataHandle = newData;
-    
     oldData->refCount = 1;
+    *dataHandle = newData;    
 }
 
 inline void QString::detachIfInternal()

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list