Changeset 53418 in webkit


Ignore:
Timestamp:
Jan 18, 2010 11:44:50 AM (14 years ago)
Author:
barraclough@apple.com
Message:

Eeeep! reverting r53416 & r53417, more to be done to fix windows.

Reviewed by NOBODY (build fix).

  • WebCore.base.exp:
  • platform/sql/SQLiteFileSystem.cpp:

(WebCore::SQLiteFileSystem::openDatabase):

  • platform/sql/SQLiteStatement.cpp:

(WebCore::SQLiteStatement::prepare):

  • platform/sql/SQLiteStatement.h:
  • platform/sql/chromium/SQLiteFileSystemChromium.cpp:

(WebCore::SQLiteFileSystem::openDatabase):

  • platform/text/PlatformString.h:
  • platform/text/String.cpp:

(WebCore::String::charactersWithNullTermination):

  • platform/text/StringImpl.cpp:

(WebCore::StringImpl::operator new):
(WebCore::StringImpl::operator delete):
(WebCore::StringImpl::StringImpl):
(WebCore::StringImpl::~StringImpl):
(WebCore::StringImpl::create):
(WebCore::StringImpl::createWithTerminatingNullCharacter):
(WebCore::StringImpl::crossThreadString):
(WebCore::StringImpl::sharedBuffer):

  • platform/text/StringImpl.h:

(WebCore::StringImpl::hasTerminatingNullCharacter):
(WebCore::StringImpl::inTable):
(WebCore::StringImpl::setInTable):
(WebCore::StringImpl::):

  • platform/win/ClipboardUtilitiesWin.cpp:

(WebCore::createGlobalData):

  • storage/OriginUsageRecord.cpp:

(WebCore::OriginUsageRecord::addDatabase):
(WebCore::OriginUsageRecord::markDatabase):

Location:
trunk/WebCore
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r53417 r53418  
     12010-01-18  Gavin Barraclough  <barraclough@apple.com>
     2
     3        Reviewed by NOBODY (build fix).
     4
     5        Eeeep! reverting r53416 & r53417, more to be done to fix windows.
     6
     7        * WebCore.base.exp:
     8        * platform/sql/SQLiteFileSystem.cpp:
     9        (WebCore::SQLiteFileSystem::openDatabase):
     10        * platform/sql/SQLiteStatement.cpp:
     11        (WebCore::SQLiteStatement::prepare):
     12        * platform/sql/SQLiteStatement.h:
     13        * platform/sql/chromium/SQLiteFileSystemChromium.cpp:
     14        (WebCore::SQLiteFileSystem::openDatabase):
     15        * platform/text/PlatformString.h:
     16        * platform/text/String.cpp:
     17        (WebCore::String::charactersWithNullTermination):
     18        * platform/text/StringImpl.cpp:
     19        (WebCore::StringImpl::operator new):
     20        (WebCore::StringImpl::operator delete):
     21        (WebCore::StringImpl::StringImpl):
     22        (WebCore::StringImpl::~StringImpl):
     23        (WebCore::StringImpl::create):
     24        (WebCore::StringImpl::createWithTerminatingNullCharacter):
     25        (WebCore::StringImpl::crossThreadString):
     26        (WebCore::StringImpl::sharedBuffer):
     27        * platform/text/StringImpl.h:
     28        (WebCore::StringImpl::hasTerminatingNullCharacter):
     29        (WebCore::StringImpl::inTable):
     30        (WebCore::StringImpl::setInTable):
     31        (WebCore::StringImpl::):
     32        * platform/win/ClipboardUtilitiesWin.cpp:
     33        (WebCore::createGlobalData):
     34        * storage/OriginUsageRecord.cpp:
     35        (WebCore::OriginUsageRecord::addDatabase):
     36        (WebCore::OriginUsageRecord::markDatabase):
     37
    1382010-01-18  Gavin Barraclough  <barraclough@apple.com>
    239
  • trunk/WebCore/WebCore.base.exp

    r53416 r53418  
    143143__ZN7WebCore10StringImplD1Ev
    144144__ZN7WebCore10StringImplcvP8NSStringEv
     145__ZN7WebCore10StringImpldlEPv
    145146__ZN7WebCore10handCursorEv
    146147__ZN7WebCore10setCookiesEPNS_8DocumentERKNS_4KURLERKNS_6StringE
  • trunk/WebCore/platform/sql/SQLiteFileSystem.cpp

    r53416 r53418  
    5050{
    5151    // SQLite expects a null terminator on its UTF-16 strings.
    52     OwnArrayPtr<const UChar> path;
    53     fileName.copyWithNullTermination(path);
    54     return sqlite3_open16(path.get(), database);
     52    String path = fileName;
     53    return sqlite3_open16(path.charactersWithNullTermination(), database);
    5554}
    5655
  • trunk/WebCore/platform/sql/SQLiteStatement.cpp

    r53416 r53418  
    6464    const void* tail;
    6565    LOG(SQLDatabase, "SQL - prepare - %s", m_query.ascii().data());
    66     if (!m_queryWithNullTermination)
    67         m_query.copyWithNullTermination(m_queryWithNullTermination);
    68     int error = sqlite3_prepare16_v2(m_database.sqlite3Handle(), m_queryWithNullTermination.get(), -1, &m_statement, &tail);
     66    int error = sqlite3_prepare16_v2(m_database.sqlite3Handle(), m_query.charactersWithNullTermination(), -1, &m_statement, &tail);
    6967    if (error != SQLITE_OK)
    7068        LOG(SQLDatabase, "sqlite3_prepare16 failed (%i)\n%s\n%s", error, m_query.ascii().data(), sqlite3_errmsg(m_database.sqlite3Handle()));
  • trunk/WebCore/platform/sql/SQLiteStatement.h

    r53416 r53418  
    9292    SQLiteDatabase& m_database;
    9393    String m_query;
    94     OwnArrayPtr<const UChar> m_queryWithNullTermination;
    9594    sqlite3_stmt* m_statement;
    9695#ifndef NDEBUG
  • trunk/WebCore/platform/sql/chromium/SQLiteFileSystemChromium.cpp

    r53416 r53418  
    5252{
    5353    if (!ChromiumBridge::sandboxEnabled()) {
    54         OwnArrayPtr<const UChar> path;
    55         fileName.copyWithNullTermination(path);
    56         return sqlite3_open16(path.get(), database);
     54        String path = fileName;
     55        return sqlite3_open16(path.charactersWithNullTermination(), database);
    5756    }
    5857
  • trunk/WebCore/platform/text/PlatformString.h

    r53416 r53418  
    2727
    2828#include "StringImpl.h"
    29 #include <wtf/OwnArrayPtr.h>
    3029
    3130#ifdef __OBJC__
     
    9594    unsigned length() const;
    9695    const UChar* characters() const;
    97     void copyWithNullTermination(OwnArrayPtr<const UChar>&) const;
     96    const UChar* charactersWithNullTermination();
    9897   
    9998    UChar operator[](unsigned i) const; // if i >= length(), returns 0   
  • trunk/WebCore/platform/text/String.cpp

    r53416 r53418  
    330330}
    331331
    332 void String::copyWithNullTermination(OwnArrayPtr<const UChar>& result) const
    333 {
    334     if (!m_impl)
    335         CRASH();
    336     unsigned length = m_impl->length();
    337     UChar* buffer = new UChar[length + 1];
    338     memcpy(buffer, m_impl->characters(), length * sizeof(UChar));
    339     buffer[length] = 0;
    340     result.set(buffer);
     332const UChar* String::charactersWithNullTermination()
     333{
     334    if (!m_impl)
     335        return 0;
     336    if (m_impl->hasTerminatingNullCharacter())
     337        return m_impl->characters();
     338    m_impl = StringImpl::createWithTerminatingNullCharacter(*m_impl);
     339    return m_impl->characters();
    341340}
    342341
  • trunk/WebCore/platform/text/StringImpl.cpp

    r53416 r53418  
    5858}
    5959
     60// Some of the factory methods create buffers using fastMalloc.
     61// We must ensure that all allocations of StringImpl are allocated using
     62// fastMalloc so that we don't have mis-matched frees. We accomplish
     63// this by overriding the new and delete operators.
     64void* StringImpl::operator new(size_t size, void* address)
     65{
     66    if (address)
     67        return address;  // Allocating using an internal buffer
     68    return fastMalloc(size);
     69}
     70
     71void* StringImpl::operator new(size_t size)
     72{
     73    return fastMalloc(size);
     74}
     75
     76void StringImpl::operator delete(void* address)
     77{
     78    fastFree(address);
     79}
     80
    6081// This constructor is used only to create the empty string.
    6182StringImpl::StringImpl()
    6283    : m_data(0)
    63     , m_sharedBuffer(0)
    6484    , m_length(0)
    65     , m_refCountAndFlags(s_refCountIncrement)
    6685    , m_hash(0)
    6786{
     
    7493inline StringImpl::StringImpl(const UChar* characters, unsigned length)
    7594    : m_data(characters)
    76     , m_sharedBuffer(0)
    7795    , m_length(length)
    78     , m_refCountAndFlags(s_refCountIncrement)
    7996    , m_hash(0)
    8097{
     
    88105        AtomicString::remove(this);
    89106    if (!bufferIsInternal()) {
    90         SharedUChar* sharedBuffer = m_sharedBuffer;
     107        SharedUChar* sharedBuffer = m_sharedBufferAndFlags.get();
    91108        if (sharedBuffer)
    92109            sharedBuffer->deref();
     
    954971        PassRefPtr<StringImpl> impl = adoptRef(new StringImpl(str.data(), str.size()));
    955972        sharedBuffer->ref();
    956         impl->m_sharedBuffer = sharedBuffer;
     973        impl->m_sharedBufferAndFlags.set(sharedBuffer);
    957974        return impl;
    958975    }
     
    969986}
    970987#endif
     988
     989PassRefPtr<StringImpl> StringImpl::createWithTerminatingNullCharacter(const StringImpl& string)
     990{
     991    // Use createUninitialized instead of 'new StringImpl' so that the string and its buffer
     992    // get allocated in a single malloc block.
     993    UChar* data;
     994    int length = string.m_length;
     995    RefPtr<StringImpl> terminatedString = createUninitialized(length + 1, data);
     996    memcpy(data, string.m_data, length * sizeof(UChar));
     997    data[length] = 0;
     998    terminatedString->m_length--;
     999    terminatedString->m_hash = string.m_hash;
     1000    terminatedString->m_sharedBufferAndFlags.setFlag(HasTerminatingNullCharacter);
     1001    return terminatedString.release();
     1002}
    9711003
    9721004PassRefPtr<StringImpl> StringImpl::threadsafeCopy() const
     
    9831015    if (shared) {
    9841016        RefPtr<StringImpl> impl = adoptRef(new StringImpl(m_data, m_length));
    985         impl->m_sharedBuffer = shared->crossThreadCopy().releaseRef();
     1017        impl->m_sharedBufferAndFlags.set(shared->crossThreadCopy().releaseRef());
    9861018        return impl.release();
    9871019    }
     
    9961028        return 0;
    9971029
    998     if (!m_sharedBuffer)
    999         m_sharedBuffer = SharedUChar::create(new OwnFastMallocPtr<UChar>(const_cast<UChar*>(m_data))).releaseRef();
    1000     return m_sharedBuffer;
     1030    if (!m_sharedBufferAndFlags.get())
     1031        m_sharedBufferAndFlags.set(SharedUChar::create(new OwnFastMallocPtr<UChar>(const_cast<UChar*>(m_data))).releaseRef());
     1032    return m_sharedBufferAndFlags.get();
    10011033}
    10021034
  • trunk/WebCore/platform/text/StringImpl.h

    r53416 r53418  
    2727#include <wtf/ASCIICType.h>
    2828#include <wtf/CrossThreadRefCounted.h>
    29 #include <wtf/Noncopyable.h>
    3029#include <wtf/OwnFastMallocPtr.h>
     30#include <wtf/PtrAndFlags.h>
    3131#include <wtf/RefCounted.h>
    3232#include <wtf/StringHashFunctions.h>
     
    5959typedef bool (*CharacterMatchFunctionPtr)(UChar);
    6060
    61 class StringImpl : public Noncopyable {
     61class StringImpl : public RefCounted<StringImpl> {
    6262    friend struct CStringTranslator;
    6363    friend struct HashAndCharactersTranslator;
     
    8383    static PassRefPtr<StringImpl> createUninitialized(unsigned length, UChar*& data);
    8484
     85    static PassRefPtr<StringImpl> createWithTerminatingNullCharacter(const StringImpl&);
     86
    8587    static PassRefPtr<StringImpl> createStrippingNullCharacters(const UChar*, unsigned length);
    8688    static PassRefPtr<StringImpl> adopt(StringBuffer&);
     
    9597    unsigned length() { return m_length; }
    9698
    97     bool inTable() const { return m_refCountAndFlags & s_refCountFlagInTable; }
    98     void setInTable() { m_refCountAndFlags |= s_refCountFlagInTable; }
     99    bool hasTerminatingNullCharacter() const { return m_sharedBufferAndFlags.isFlagSet(HasTerminatingNullCharacter); }
     100
     101    bool inTable() const { return m_sharedBufferAndFlags.isFlagSet(InTable); }
     102    void setInTable() { return m_sharedBufferAndFlags.setFlag(InTable); }
    99103
    100104    unsigned hash() { if (m_hash == 0) m_hash = computeHash(m_data, m_length); return m_hash; }
     
    103107    inline static unsigned computeHash(const char* data) { return WTF::stringHash(data); }
    104108   
    105     StringImpl* ref() { m_refCountAndFlags += s_refCountIncrement; return this; }
    106     ALWAYS_INLINE void deref() { m_refCountAndFlags -= s_refCountIncrement; if (!(m_refCountAndFlags & s_refCountMask)) delete this; }
    107     ALWAYS_INLINE bool hasOneRef() const { return (m_refCountAndFlags & s_refCountMask) == s_refCountIncrement; }
    108 
    109109    // Returns a StringImpl suitable for use on another thread.
    110110    PassRefPtr<StringImpl> crossThreadString();
     
    176176#endif
    177177
     178    void operator delete(void*);
     179
    178180private:
    179     using Noncopyable::operator new;
    180     void* operator new(size_t, void* inPlace) { ASSERT(inPlace); return inPlace; }
     181    // Allocation from a custom buffer is only allowed internally to avoid
     182    // mismatched allocators. Callers should use create().
     183    void* operator new(size_t size);
     184    void* operator new(size_t size, void* address);
    181185
    182186    static PassRefPtr<StringImpl> createStrippingNullCharactersSlowCase(const UChar*, unsigned length);
     
    186190    bool bufferIsInternal() { return m_data == reinterpret_cast<const UChar*>(this + 1); }
    187191
    188     static const unsigned s_refCountMask = 0xFFFFFFFE;
    189     static const unsigned s_refCountIncrement = 0x2;
    190     static const unsigned s_refCountFlagInTable = 0x1;
     192    enum StringImplFlags {
     193        HasTerminatingNullCharacter,
     194        InTable,
     195    };
    191196
    192197    const UChar* m_data;
    193     SharedUChar* m_sharedBuffer;
    194198    unsigned m_length;
    195     unsigned m_refCountAndFlags;
    196199    mutable unsigned m_hash;
     200    PtrAndFlags<SharedUChar, StringImplFlags> m_sharedBufferAndFlags;
    197201    // There is a fictitious variable-length UChar array at the end, which is used
    198202    // as the internal buffer by the createUninitialized and create methods.
  • trunk/WebCore/platform/win/ClipboardUtilitiesWin.cpp

    r53417 r53418  
    115115    if (cbData) {
    116116        PWSTR buffer = (PWSTR)::GlobalLock(cbData);
    117         OwnArrayPtr<const UChar> nullTerminatedURL;
    118         mutableURL.copyWithNullTermination(nullTerminatedURL);
    119         OwnArrayPtr<const UChar> nullTerminatedTitle;
    120         mutableTitle.copyWithNullTermination(nullTerminatedTitle);
    121         swprintf_s(buffer, size, L"%s\n%s", nullTerminatedURL.get(), nullTerminatedTitle.get());
     117        swprintf_s(buffer, size, L"%s\n%s", mutableURL.charactersWithNullTermination(), mutableTitle.charactersWithNullTermination());
    122118        ::GlobalUnlock(cbData);
    123119    }
  • trunk/WebCore/storage/OriginUsageRecord.cpp

    r53416 r53418  
    4343{
    4444    ASSERT(!m_databaseMap.contains(identifier));
    45     ASSERT_ARG(identifier, identifier.impl()->hasOneRef());
    46     ASSERT_ARG(fullPath, fullPath.impl()->hasOneRef());
     45    ASSERT_ARG(identifier, identifier.impl()->refCount() == 1);
     46    ASSERT_ARG(fullPath, fullPath.impl()->refCount() == 1);
    4747
    4848    m_databaseMap.set(identifier, DatabaseEntry(fullPath));
     
    6464{
    6565    ASSERT(m_databaseMap.contains(identifier));
    66     ASSERT_ARG(identifier, identifier.impl()->hasOneRef());
     66    ASSERT_ARG(identifier, identifier.impl()->refCount() == 1);
    6767
    6868    m_unknownSet.add(identifier);
Note: See TracChangeset for help on using the changeset viewer.