Title: [155121] trunk/Source
Revision
155121
Author
[email protected]
Date
2013-09-05 08:20:51 -0700 (Thu, 05 Sep 2013)

Log Message

Vector::releaseBuffer should return an OwnPtr
https://bugs.webkit.org/show_bug.cgi?id=120718

Reviewed by Andreas Kling.

Source/WebCore:

Change FormStreamFields::currentData to an OwnPtr.

* platform/network/cf/FormDataStreamCFNet.cpp:
(WebCore::closeCurrentStream):
(WebCore::advanceCurrentStream):
(WebCore::formCreate):

Source/WTF:

Change Vector::releaseBuffer() to return an OwnPtr. I intentionally chose
to use an OwnPtr over a PassOwnPtr since we're trying to move away from PassOwnPtr objects.

Fix fallout from this change by adopting OwnPtr/PassOwnPtr in StringBuffer and the two StringImpl
constructors that adopt the passed in pointer.

* wtf/Vector.h:
* wtf/text/StringBuffer.h:
* wtf/text/StringImpl.h:

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (155120 => 155121)


--- trunk/Source/WTF/ChangeLog	2013-09-05 15:17:33 UTC (rev 155120)
+++ trunk/Source/WTF/ChangeLog	2013-09-05 15:20:51 UTC (rev 155121)
@@ -1,3 +1,20 @@
+2013-09-04  Anders Carlsson  <[email protected]>
+
+        Vector::releaseBuffer should return an OwnPtr
+        https://bugs.webkit.org/show_bug.cgi?id=120718
+
+        Reviewed by Andreas Kling.
+
+        Change Vector::releaseBuffer() to return an OwnPtr. I intentionally chose
+        to use an OwnPtr over a PassOwnPtr since we're trying to move away from PassOwnPtr objects.
+        
+        Fix fallout from this change by adopting OwnPtr/PassOwnPtr in StringBuffer and the two StringImpl
+        constructors that adopt the passed in pointer.
+
+        * wtf/Vector.h:
+        * wtf/text/StringBuffer.h:
+        * wtf/text/StringImpl.h:
+
 2013-09-05  Mikhail Pozdnyakov  <[email protected]>
 
         Remove String(RefPtr<StringImpl>) constructor

Modified: trunk/Source/WTF/wtf/Vector.h (155120 => 155121)


--- trunk/Source/WTF/wtf/Vector.h	2013-09-05 15:17:33 UTC (rev 155120)
+++ trunk/Source/WTF/wtf/Vector.h	2013-09-05 15:20:51 UTC (rev 155121)
@@ -26,6 +26,7 @@
 #include <wtf/FastAllocBase.h>
 #include <wtf/Noncopyable.h>
 #include <wtf/NotFound.h>
+#include <wtf/OwnPtr.h>
 #include <wtf/StdLibExtras.h>
 #include <wtf/ValueCheck.h>
 #include <wtf/VectorTraits.h>
@@ -307,12 +308,12 @@
     const T* buffer() const { return m_buffer; }
     size_t capacity() const { return m_capacity; }
 
-    T* releaseBuffer()
+    OwnPtr<T> releaseBuffer()
     {
         T* buffer = m_buffer;
         m_buffer = 0;
         m_capacity = 0;
-        return buffer;
+        return adoptPtr(buffer);
     }
 
 protected:
@@ -487,10 +488,10 @@
     using Base::buffer;
     using Base::capacity;
 
-    T* releaseBuffer()
+    OwnPtr<T> releaseBuffer()
     {
         if (buffer() == inlineBuffer())
-            return 0;
+            return nullptr;
         return Base::releaseBuffer();
     }
 
@@ -541,6 +542,13 @@
             TypeOperations::initialize(begin(), end());
     }
 
+    Vector(size_t size, const T& val)
+        : Base(size, size)
+    {
+        if (begin())
+            TypeOperations::uninitializedFill(begin(), end(), val);
+    }
+
     ~Vector()
     {
         if (m_size)
@@ -653,19 +661,12 @@
         shrink(size() - 1); 
     }
 
-    Vector(size_t size, const T& val)
-        : Base(size, size)
-    {
-        if (begin())
-            TypeOperations::uninitializedFill(begin(), end(), val);
-    }
-
     void fill(const T&, size_t);
     void fill(const T& val) { fill(val, size()); }
 
     template<typename Iterator> void appendRange(Iterator start, Iterator end);
 
-    T* releaseBuffer();
+    OwnPtr<T> releaseBuffer();
 
     void swap(Vector<T, inlineCapacity, OverflowHandler>& other)
     {
@@ -1152,19 +1153,19 @@
 }
 
 template<typename T, size_t inlineCapacity, typename OverflowHandler>
-inline T* Vector<T, inlineCapacity, OverflowHandler>::releaseBuffer()
+inline OwnPtr<T> Vector<T, inlineCapacity, OverflowHandler>::releaseBuffer()
 {
-    T* buffer = Base::releaseBuffer();
+    OwnPtr<T> buffer = Base::releaseBuffer();
     if (inlineCapacity && !buffer && m_size) {
         // If the vector had some data, but no buffer to release,
         // that means it was using the inline buffer. In that case,
         // we create a brand new buffer so the caller always gets one.
         size_t bytes = m_size * sizeof(T);
-        buffer = static_cast<T*>(fastMalloc(bytes));
-        memcpy(buffer, data(), bytes);
+        buffer = adoptPtr(static_cast<T*>(fastMalloc(bytes)));
+        memcpy(buffer.get(), data(), bytes);
     }
     m_size = 0;
-    return buffer;
+    return buffer.release();
 }
 
 template<typename T, size_t inlineCapacity, typename OverflowHandler>

Modified: trunk/Source/WTF/wtf/text/StringBuffer.h (155120 => 155121)


--- trunk/Source/WTF/wtf/text/StringBuffer.h	2013-09-05 15:17:33 UTC (rev 155120)
+++ trunk/Source/WTF/wtf/text/StringBuffer.h	2013-09-05 15:20:51 UTC (rev 155121)
@@ -44,12 +44,11 @@
     {
         if (m_length > std::numeric_limits<unsigned>::max() / sizeof(CharType))
             CRASH();
-        m_data = static_cast<CharType*>(fastMalloc(m_length * sizeof(CharType)));
+        m_data = adoptPtr(static_cast<CharType*>(fastMalloc(m_length * sizeof(CharType))));
     }
 
     ~StringBuffer()
     {
-        fastFree(m_data);
     }
 
     void shrink(unsigned newLength)
@@ -63,21 +62,29 @@
         if (newLength > m_length) {
             if (newLength > std::numeric_limits<unsigned>::max() / sizeof(UChar))
                 CRASH();
-            m_data = static_cast<UChar*>(fastRealloc(m_data, newLength * sizeof(UChar)));
+            m_data = adoptPtr(static_cast<UChar*>(fastRealloc(m_data.release().leakPtr(), newLength * sizeof(UChar))));
         }
         m_length = newLength;
     }
 
     unsigned length() const { return m_length; }
-    CharType* characters() { return m_data; }
+    CharType* characters() { return m_data.get(); }
 
-    CharType& operator[](unsigned i) { ASSERT_WITH_SECURITY_IMPLICATION(i < m_length); return m_data[i]; }
+    CharType& operator[](unsigned i)
+    {
+        ASSERT_WITH_SECURITY_IMPLICATION(i < m_length);
+        return m_data.get()[i];
+    }
 
-    CharType* release() { CharType* data = "" m_data = 0; return data; }
+    PassOwnPtr<CharType> release()
+    {
+        OwnPtr<CharType> data = ""
+        return data.release();
+    }
 
 private:
     unsigned m_length;
-    CharType* m_data;
+    OwnPtr<CharType> m_data;
 };
 
 } // namespace WTF

Modified: trunk/Source/WTF/wtf/text/StringImpl.h (155120 => 155121)


--- trunk/Source/WTF/wtf/text/StringImpl.h	2013-09-05 15:17:33 UTC (rev 155120)
+++ trunk/Source/WTF/wtf/text/StringImpl.h	2013-09-05 15:20:51 UTC (rev 155121)
@@ -28,6 +28,7 @@
 #include <wtf/CompilationThread.h>
 #include <wtf/Forward.h>
 #include <wtf/MathExtras.h>
+#include <wtf/PassOwnPtr.h>
 #include <wtf/StdLibExtras.h>
 #include <wtf/StringHasher.h>
 #include <wtf/Vector.h>
@@ -232,10 +233,10 @@
     }
 
     // Create a StringImpl adopting ownership of the provided buffer (BufferOwned)
-    StringImpl(const LChar* characters, unsigned length)
+    StringImpl(PassOwnPtr<LChar> characters, unsigned length)
         : m_refCount(s_refCountIncrement)
         , m_length(length)
-        , m_data8(characters)
+        , m_data8(characters.leakPtr())
         , m_buffer(0)
         , m_hashAndFlags(s_hashFlag8BitBuffer | BufferOwned)
     {
@@ -273,10 +274,10 @@
     }
 
     // Create a StringImpl adopting ownership of the provided buffer (BufferOwned)
-    StringImpl(const UChar* characters, unsigned length)
+    StringImpl(PassOwnPtr<UChar> characters, unsigned length)
         : m_refCount(s_refCountIncrement)
         , m_length(length)
-        , m_data16(characters)
+        , m_data16(characters.leakPtr())
         , m_buffer(0)
         , m_hashAndFlags(BufferOwned)
     {
@@ -472,7 +473,7 @@
             ASSERT(vector.data());
             if (size > std::numeric_limits<unsigned>::max())
                 CRASH();
-            return adoptRef(new StringImpl(vector.releaseBuffer(), size));
+            return adoptRef(new StringImpl(vector.releaseBuffer().release(), size));
         }
         return empty();
     }

Modified: trunk/Source/WebCore/ChangeLog (155120 => 155121)


--- trunk/Source/WebCore/ChangeLog	2013-09-05 15:17:33 UTC (rev 155120)
+++ trunk/Source/WebCore/ChangeLog	2013-09-05 15:20:51 UTC (rev 155121)
@@ -1,3 +1,17 @@
+2013-09-04  Anders Carlsson  <[email protected]>
+
+        Vector::releaseBuffer should return an OwnPtr
+        https://bugs.webkit.org/show_bug.cgi?id=120718
+
+        Reviewed by Andreas Kling.
+
+        Change FormStreamFields::currentData to an OwnPtr.
+
+        * platform/network/cf/FormDataStreamCFNet.cpp:
+        (WebCore::closeCurrentStream):
+        (WebCore::advanceCurrentStream):
+        (WebCore::formCreate):
+
 2013-09-05  Andreas Kling  <[email protected]>
 
         Reverting "Cached Page and Frame don't need to be ref-counted.

Modified: trunk/Source/WebCore/platform/network/cf/FormDataStreamCFNet.cpp (155120 => 155121)


--- trunk/Source/WebCore/platform/network/cf/FormDataStreamCFNet.cpp	2013-09-05 15:17:33 UTC (rev 155120)
+++ trunk/Source/WebCore/platform/network/cf/FormDataStreamCFNet.cpp	2013-09-05 15:20:51 UTC (rev 155121)
@@ -107,7 +107,7 @@
 #if ENABLE(BLOB)
     long long currentStreamRangeLength;
 #endif
-    char* currentData;
+    OwnPtr<char> currentData;
     CFReadStreamRef formStream;
     unsigned long long streamLength;
     unsigned long long bytesSent;
@@ -124,10 +124,8 @@
         form->currentStreamRangeLength = BlobDataItem::toEndOfFile;
 #endif
     }
-    if (form->currentData) {
-        fastFree(form->currentData);
-        form->currentData = 0;
-    }
+
+    form->currentData = nullptr;
 }
 
 // Return false if we cannot advance the stream. Currently the only possible failure is that the underlying file has been removed or changed since File.slice.
@@ -143,9 +141,9 @@
 
     if (nextInput.m_type == FormDataElement::data) {
         size_t size = nextInput.m_data.size();
-        char* data = ""
-        form->currentStream = CFReadStreamCreateWithBytesNoCopy(0, reinterpret_cast<const UInt8*>(data), size, kCFAllocatorNull);
-        form->currentData = data;
+        OwnPtr<char> data = ""
+        form->currentStream = CFReadStreamCreateWithBytesNoCopy(0, reinterpret_cast<const UInt8*>(data.get()), size, kCFAllocatorNull);
+        form->currentData = data.release();
     } else {
 #if ENABLE(BLOB)
         // Check if the file has been changed or not if required.
@@ -206,7 +204,6 @@
 #if ENABLE(BLOB)
     newInfo->currentStreamRangeLength = BlobDataItem::toEndOfFile;
 #endif
-    newInfo->currentData = 0;
     newInfo->formStream = stream; // Don't retain. That would create a reference cycle.
     newInfo->streamLength = formContext->streamLength;
     newInfo->bytesSent = 0;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to