Changeset 155242 in webkit


Ignore:
Timestamp:
Sep 6, 2013 10:36:45 PM (11 years ago)
Author:
andersca@apple.com
Message:

Add a new smart pointer type for fastMalloc'ed memory
https://bugs.webkit.org/show_bug.cgi?id=120911

Reviewed by Andreas Kling.

Source/WebCore:

Update for WTF changes.

  • platform/network/cf/FormDataStreamCFNet.cpp:

(WebCore::advanceCurrentStream):

Source/WTF:

Due to an oversight on my part, Vector::releaseBuffer() currently returns an OwnPtr
which means that its data will be freed with operator delete instead of fastFree.

Fix this by introducing a new MllocPtr smart pointer class and change Vector::releaseBuffer() to return it instead.

  • WTF.pro:
  • WTF.vcxproj/WTF.vcxproj:
  • WTF.vcxproj/WTF.vcxproj.filters:
  • WTF.xcodeproj/project.pbxproj:
  • wtf/CMakeLists.txt:
  • wtf/FastAllocBase.h:
  • wtf/MallocPtr.h: Added.
  • wtf/Vector.h:
  • wtf/text/StringBuffer.h:
  • wtf/text/StringImpl.h:
Location:
trunk/Source
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r155232 r155242  
     12013-09-06  Anders Carlsson  <andersca@apple.com>
     2
     3        Add a new smart pointer type for fastMalloc'ed memory
     4        https://bugs.webkit.org/show_bug.cgi?id=120911
     5
     6        Reviewed by Andreas Kling.
     7
     8        Due to an oversight on my part, Vector::releaseBuffer() currently returns an OwnPtr
     9        which means that its data will be freed with operator delete instead of fastFree.
     10       
     11        Fix this by introducing a new MllocPtr smart pointer class and change Vector::releaseBuffer() to return it instead.
     12
     13        * WTF.pro:
     14        * WTF.vcxproj/WTF.vcxproj:
     15        * WTF.vcxproj/WTF.vcxproj.filters:
     16        * WTF.xcodeproj/project.pbxproj:
     17        * wtf/CMakeLists.txt:
     18        * wtf/FastAllocBase.h:
     19        * wtf/MallocPtr.h: Added.
     20        * wtf/Vector.h:
     21        * wtf/text/StringBuffer.h:
     22        * wtf/text/StringImpl.h:
     23
    1242013-09-06  Andreas Kling  <akling@apple.com>
    225
  • trunk/Source/WTF/WTF.pro

    r154962 r155242  
    8080    Locker.h \
    8181    MainThread.h \
     82    MallocPtr.h \
    8283    MathExtras.h \
    8384    MD5.h \
  • trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj

    r154498 r155242  
    185185    <ClInclude Include="..\wtf\Locker.h" />
    186186    <ClInclude Include="..\wtf\MainThread.h" />
     187    <ClInclude Include="..\wtf\MallocPtr.h" />
    187188    <ClInclude Include="..\wtf\MathExtras.h" />
    188189    <ClInclude Include="..\wtf\MD5.h" />
  • trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj.filters

    r154962 r155242  
    474474      <Filter>wtf</Filter>
    475475    </ClInclude>
     476    <ClInclude Include="..\wtf\MallocPtr.h">
     477      <Filter>wtf</Filter>
     478    </ClInclude>
    476479    <ClInclude Include="..\wtf\MathExtras.h">
    477480      <Filter>wtf</Filter>
  • trunk/Source/WTF/WTF.xcodeproj/project.pbxproj

    r155171 r155242  
    5151                1A1D8B9C173186CE00141DA4 /* FunctionDispatcher.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A1D8B9B173186CE00141DA4 /* FunctionDispatcher.h */; };
    5252                1A1D8B9E1731879800141DA4 /* FunctionDispatcher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A1D8B9D1731879800141DA4 /* FunctionDispatcher.cpp */; };
     53                1A233C7D17DAA6E300A93ACF /* MallocPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A233C7C17DAA6E300A93ACF /* MallocPtr.h */; };
    5354                1A6BB769162F300500DD16DB /* StreamBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A6BB768162F300500DD16DB /* StreamBuffer.h */; };
    5455                1FA47C8A152502DA00568D1B /* WebCoreThread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1FA47C88152502DA00568D1B /* WebCoreThread.cpp */; };
     
    316317                1A1D8B9B173186CE00141DA4 /* FunctionDispatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FunctionDispatcher.h; sourceTree = "<group>"; };
    317318                1A1D8B9D1731879800141DA4 /* FunctionDispatcher.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FunctionDispatcher.cpp; sourceTree = "<group>"; };
     319                1A233C7C17DAA6E300A93ACF /* MallocPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MallocPtr.h; sourceTree = "<group>"; };
    318320                1A3F6BE6174ADA2100B2EEA7 /* NeverDestroyed.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NeverDestroyed.h; sourceTree = "<group>"; };
    319321                1A6BB768162F300500DD16DB /* StreamBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StreamBuffer.h; sourceTree = "<group>"; };
     
    697699                                A736B3581799E11A00C6F05E /* LLVMHeaders.h */,
    698700                                A8A472C3151A825A004123FF /* Locker.h */,
     701                                A8A472CA151A825B004123FF /* MD5.cpp */,
     702                                A8A472CB151A825B004123FF /* MD5.h */,
    699703                                A8A472C6151A825A004123FF /* MainThread.cpp */,
    700704                                A8A472C7151A825B004123FF /* MainThread.h */,
     705                                1A233C7C17DAA6E300A93ACF /* MallocPtr.h */,
    701706                                A8A472C9151A825B004123FF /* MathExtras.h */,
    702                                 A8A472CA151A825B004123FF /* MD5.cpp */,
    703                                 A8A472CB151A825B004123FF /* MD5.h */,
    704707                                CD5497AA15857D0300B5BC30 /* MediaTime.cpp */,
    705708                                CD5497AB15857D0300B5BC30 /* MediaTime.h */,
     
    9971000                                A8A473D5151A825B004123FF /* HashIterators.h in Headers */,
    9981001                                A8A473D6151A825B004123FF /* HashMap.h in Headers */,
     1002                                1A233C7D17DAA6E300A93ACF /* MallocPtr.h in Headers */,
    9991003                                A8A473D7151A825B004123FF /* HashSet.h in Headers */,
    10001004                                A8A473D9151A825B004123FF /* HashTable.h in Headers */,
  • trunk/Source/WTF/wtf/CMakeLists.txt

    r154962 r155242  
    4949    MD5.h
    5050    MainThread.h
     51    MallocPtr.h
    5152    MathExtras.h
    5253    MediaTime.h
  • trunk/Source/WTF/wtf/Vector.h

    r155152 r155242  
    2525#include <wtf/CheckedArithmetic.h>
    2626#include <wtf/FastAllocBase.h>
     27#include <wtf/MallocPtr.h>
    2728#include <wtf/Noncopyable.h>
    2829#include <wtf/NotFound.h>
     
    309310    size_t capacity() const { return m_capacity; }
    310311
    311     OwnPtr<T> releaseBuffer()
     312    MallocPtr<T> releaseBuffer()
    312313    {
    313314        T* buffer = m_buffer;
    314315        m_buffer = 0;
    315316        m_capacity = 0;
    316         return adoptPtr(buffer);
     317        return adoptMallocPtr(buffer);
    317318    }
    318319
     
    489490    using Base::capacity;
    490491
    491     OwnPtr<T> releaseBuffer()
     492    MallocPtr<T> releaseBuffer()
    492493    {
    493494        if (buffer() == inlineBuffer())
     
    667668    template<typename Iterator> void appendRange(Iterator start, Iterator end);
    668669
    669     OwnPtr<T> releaseBuffer();
     670    MallocPtr<T> releaseBuffer();
    670671
    671672    void swap(Vector<T, inlineCapacity, OverflowHandler>& other)
     
    11541155
    11551156template<typename T, size_t inlineCapacity, typename OverflowHandler>
    1156 inline OwnPtr<T> Vector<T, inlineCapacity, OverflowHandler>::releaseBuffer()
    1157 {
    1158     OwnPtr<T> buffer = Base::releaseBuffer();
     1157inline MallocPtr<T> Vector<T, inlineCapacity, OverflowHandler>::releaseBuffer()
     1158{
     1159    auto buffer = Base::releaseBuffer();
    11591160    if (inlineCapacity && !buffer && m_size) {
    11601161        // If the vector had some data, but no buffer to release,
     
    11621163        // we create a brand new buffer so the caller always gets one.
    11631164        size_t bytes = m_size * sizeof(T);
    1164         buffer = adoptPtr(static_cast<T*>(fastMalloc(bytes)));
     1165        buffer = adoptMallocPtr(static_cast<T*>(fastMalloc(bytes)));
    11651166        memcpy(buffer.get(), data(), bytes);
    11661167    }
    11671168    m_size = 0;
    1168     return buffer.release();
     1169    return buffer;
    11691170}
    11701171
  • trunk/Source/WTF/wtf/text/StringBuffer.h

    r155126 r155242  
    7474    CharType& operator[](unsigned i) { ASSERT_WITH_SECURITY_IMPLICATION(i < m_length); return m_data[i]; }
    7575
    76     PassOwnPtr<CharType> release()
     76    MallocPtr<CharType> release()
    7777    {
    7878        CharType* data = m_data;
    7979        m_data = 0;
    80         return adoptPtr(data);
     80        return adoptMallocPtr(data);
    8181    }
    8282
  • trunk/Source/WTF/wtf/text/StringImpl.h

    r155121 r155242  
    2929#include <wtf/Forward.h>
    3030#include <wtf/MathExtras.h>
    31 #include <wtf/PassOwnPtr.h>
    3231#include <wtf/StdLibExtras.h>
    3332#include <wtf/StringHasher.h>
     
    234233
    235234    // Create a StringImpl adopting ownership of the provided buffer (BufferOwned)
    236     StringImpl(PassOwnPtr<LChar> characters, unsigned length)
     235    StringImpl(MallocPtr<LChar> characters, unsigned length)
    237236        : m_refCount(s_refCountIncrement)
    238237        , m_length(length)
     
    275274
    276275    // Create a StringImpl adopting ownership of the provided buffer (BufferOwned)
    277     StringImpl(PassOwnPtr<UChar> characters, unsigned length)
     276    StringImpl(MallocPtr<UChar> characters, unsigned length)
    278277        : m_refCount(s_refCountIncrement)
    279278        , m_length(length)
     
    474473            if (size > std::numeric_limits<unsigned>::max())
    475474                CRASH();
    476             return adoptRef(new StringImpl(vector.releaseBuffer().release(), size));
     475            return adoptRef(new StringImpl(vector.releaseBuffer(), size));
    477476        }
    478477        return empty();
  • trunk/Source/WebCore/ChangeLog

    r155240 r155242  
     12013-09-06  Anders Carlsson  <andersca@apple.com>
     2
     3        Add a new smart pointer type for fastMalloc'ed memory
     4        https://bugs.webkit.org/show_bug.cgi?id=120911
     5
     6        Reviewed by Andreas Kling.
     7
     8        Update for WTF changes.
     9
     10        * platform/network/cf/FormDataStreamCFNet.cpp:
     11        (WebCore::advanceCurrentStream):
     12
    1132013-09-06  Dirk Schulze  <krit@webkit.org>
    214
  • trunk/Source/WebCore/platform/network/cf/FormDataStreamCFNet.cpp

    r155121 r155242  
    108108    long long currentStreamRangeLength;
    109109#endif
    110     OwnPtr<char> currentData;
     110    MallocPtr<char> currentData;
    111111    CFReadStreamRef formStream;
    112112    unsigned long long streamLength;
     
    142142    if (nextInput.m_type == FormDataElement::data) {
    143143        size_t size = nextInput.m_data.size();
    144         OwnPtr<char> data = nextInput.m_data.releaseBuffer();
     144        MallocPtr<char> data = nextInput.m_data.releaseBuffer();
    145145        form->currentStream = CFReadStreamCreateWithBytesNoCopy(0, reinterpret_cast<const UInt8*>(data.get()), size, kCFAllocatorNull);
    146         form->currentData = data.release();
     146        form->currentData = std::move(data);
    147147    } else {
    148148#if ENABLE(BLOB)
Note: See TracChangeset for help on using the changeset viewer.