⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 278404 in webkit


Ignore:
Timestamp:
Jun 3, 2021, 6:10:38 AM (5 years ago)
Author:
commit-queue@webkit.org
Message:

REGRESSION(r277744): Broke build on s390x mainframes
​https://bugs.webkit.org/show_bug.cgi?id=226497

Patch by Michael Catanzaro <Michael Catanzaro> on 2021-06-03
Reviewed by Darin Adler.

The problem is we have a template defined in a C++ source file, used by multiple source
files. This is not valid C++, so let's split the templates defined in StringBuilder.cpp out
into a new StringBuilderInternals.h that we can #include in both StringBuilder.cpp and
StringBuilderJSON.cpp.

Ideally we would move the template defined in StringBuilderJSON.cpp as well, and then
eliminate StringBuilderJSON.cpp since there would only be one function left. But that file
has an MPL license. It's easier to leave it be to keep the license situation simpler.

  • WTF.xcodeproj/project.pbxproj:
  • wtf/CMakeLists.txt:
  • wtf/text/StringBuilder.cpp:

(WTF::StringBuilder::expandedCapacity):
(WTF::expandedCapacity): Deleted.
(WTF::StringBuilder::allocateBuffer): Deleted.
(WTF::StringBuilder::extendBufferForAppending): Deleted.
(WTF::StringBuilder::extendBufferForAppendingSlowCase): Deleted.

  • wtf/text/StringBuilder.h:
  • wtf/text/StringBuilderInternals.h: Added.

(WTF::StringBuilder::allocateBuffer):
(WTF::StringBuilder::reallocateBuffer):
(WTF::StringBuilder::extendBufferForAppending):
(WTF::StringBuilder::extendBufferForAppendingSlowCase):

  • wtf/text/StringBuilderJSON.cpp:
Location:
trunk/Source/WTF
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r278384 r278404  
     12021-06-03  Michael Catanzaro  <mcatanzaro@gnome.org>
     2
     3        REGRESSION(r277744): Broke build on s390x mainframes
     4        https://bugs.webkit.org/show_bug.cgi?id=226497
     5
     6        Reviewed by Darin Adler.
     7
     8        The problem is we have a template defined in a C++ source file, used by multiple source
     9        files. This is not valid C++, so let's split the templates defined in StringBuilder.cpp out
     10        into a new StringBuilderInternals.h that we can #include in both StringBuilder.cpp and
     11        StringBuilderJSON.cpp.
     12
     13        Ideally we would move the template defined in StringBuilderJSON.cpp as well, and then
     14        eliminate StringBuilderJSON.cpp since there would only be one function left. But that file
     15        has an MPL license. It's easier to leave it be to keep the license situation simpler.
     16
     17        * WTF.xcodeproj/project.pbxproj:
     18        * wtf/CMakeLists.txt:
     19        * wtf/text/StringBuilder.cpp:
     20        (WTF::StringBuilder::expandedCapacity):
     21        (WTF::expandedCapacity): Deleted.
     22        (WTF::StringBuilder::allocateBuffer): Deleted.
     23        (WTF::StringBuilder::extendBufferForAppending): Deleted.
     24        (WTF::StringBuilder::extendBufferForAppendingSlowCase): Deleted.
     25        * wtf/text/StringBuilder.h:
     26        * wtf/text/StringBuilderInternals.h: Added.
     27        (WTF::StringBuilder::allocateBuffer):
     28        (WTF::StringBuilder::reallocateBuffer):
     29        (WTF::StringBuilder::extendBufferForAppending):
     30        (WTF::StringBuilder::extendBufferForAppendingSlowCase):
     31        * wtf/text/StringBuilderJSON.cpp:
     32
    1332021-06-02  Chris Dumez  <cdumez@apple.com>
    234
  • trunk/Source/WTF/WTF.xcodeproj/project.pbxproj

    r278344 r278404  
    655655                A8A47324151A825B004123FF /* StringBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringBuilder.cpp; sourceTree = "<group>"; };
    656656                A8A47325151A825B004123FF /* StringBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringBuilder.h; sourceTree = "<group>"; };
     657                A8A47325151A825B004123EE /* StringBuilderInternals.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringBuilderInternals.h; sourceTree = "<group>"; };
    657658                A8A47326151A825B004123FF /* StringConcatenate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringConcatenate.h; sourceTree = "<group>"; };
    658659                A8A47327151A825B004123FF /* StringHash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringHash.h; sourceTree = "<group>"; };
    … …  
    14251426                                A8A47324151A825B004123FF /* StringBuilder.cpp */,
    14261427                                A8A47325151A825B004123FF /* StringBuilder.h */,
     1428                                A8A47325151A825B004123EE /* StringBuilderInternals.h */,
    14271429                                E38D6E261F5522E300A75CC4 /* StringBuilderJSON.cpp */,
    14281430                                430B47871AAAAC1A001223DA /* StringCommon.h */,
  • trunk/Source/WTF/wtf/CMakeLists.txt

    r278355 r278404  
    347347    text/StringBuffer.h
    348348    text/StringBuilder.h
     349    text/StringBuilderInternals.h
    349350    text/StringCommon.h
    350351    text/StringConcatenate.h
  • trunk/Source/WTF/wtf/text/StringBuilder.cpp

    r277744 r278404  
    2929
    3030#include <wtf/dtoa.h>
     31#include <wtf/text/StringBuilderInternals.h>
    3132
    3233namespace WTF {
    … …  
    3435static constexpr unsigned maxCapacity = String::MaxLength;
    3536
    36 static unsigned expandedCapacity(unsigned capacity, unsigned requiredCapacity)
     37unsigned StringBuilder::expandedCapacity(unsigned capacity, unsigned requiredCapacity)
    3738{
    3839    static constexpr unsigned minimumCapacity = 16;
    … …  
    103104}
    104105
    105 // Allocate a new buffer, copying in currentCharacters (these may come from either m_string or m_buffer.
    106 template<typename AllocationCharacterType, typename CurrentCharacterType> void StringBuilder::allocateBuffer(const CurrentCharacterType* currentCharacters, unsigned requiredCapacity)
    107 {
    108     AllocationCharacterType* bufferCharacters;
    109     auto buffer = StringImpl::tryCreateUninitialized(requiredCapacity, bufferCharacters);
    110     if (UNLIKELY(!buffer)) {
    111         didOverflow();
    112         return;
    113     }
    114 
    115     ASSERT(!hasOverflowed());
    116     StringImpl::copyCharacters(bufferCharacters, currentCharacters, m_length);
    117 
    118     m_buffer = WTFMove(buffer);
    119     m_string = { };
    120 }
    121 
    122 template<typename CharacterType> void StringBuilder::reallocateBuffer(unsigned requiredCapacity)
    123 {
    124     // If the buffer has only one ref (by this StringBuilder), reallocate it.
    125     if (m_buffer) {
    126         m_string = { }; // Clear the string to remove the reference to m_buffer if any before checking the reference count of m_buffer.
    127         if (m_buffer->hasOneRef()) {
    128             CharacterType* bufferCharacters;
    129             auto buffer = StringImpl::tryReallocate(m_buffer.releaseNonNull(), requiredCapacity, bufferCharacters);
    130             if (UNLIKELY(!buffer)) {
    131                 didOverflow();
    132                 return;
    133             }
    134             m_buffer = WTFMove(*buffer);
    135             return;
    136         }
    137     }
    138 
    139     allocateBuffer<CharacterType>(characters<CharacterType>(), requiredCapacity);
    140 }
    141 
    142106void StringBuilder::reallocateBuffer(unsigned requiredCapacity)
    143107{
    … …  
    167131    }
    168132    ASSERT(hasOverflowed() || !newCapacity || m_buffer->length() >= newCapacity);
    169 }
    170 
    171 // Make 'additionalLength' additional capacity be available in m_buffer, update m_string & m_length to use,
    172 // that capacity and return a pointer to the newly allocated storage so the caller can write characters there.
    173 // Returns nullptr if allocation fails, length overflows, or if total capacity is 0 so no buffer is needed.
    174 // The caller has the responsibility for checking that CharacterType is the type of the existing buffer.
    175 template<typename CharacterType> CharacterType* StringBuilder::extendBufferForAppending(unsigned requiredLength)
    176 {
    177     if (m_buffer && requiredLength <= m_buffer->length()) {
    178         m_string = { };
    179         return const_cast<CharacterType*>(m_buffer->characters<CharacterType>()) + std::exchange(m_length, requiredLength);
    180     }
    181     return extendBufferForAppendingSlowCase<CharacterType>(requiredLength);
    182 }
    183 
    184 // Shared by the other extendBuffer functions.
    185 template<typename CharacterType> CharacterType* StringBuilder::extendBufferForAppendingSlowCase(unsigned requiredLength)
    186 {
    187     ASSERT(!hasOverflowed());
    188     if (!requiredLength)
    189         return nullptr;
    190     reallocateBuffer(expandedCapacity(capacity(), requiredLength));
    191     if (UNLIKELY(hasOverflowed()))
    192         return nullptr;
    193     return const_cast<CharacterType*>(m_buffer->characters<CharacterType>()) + std::exchange(m_length, requiredLength);
    194133}
    195134
  • trunk/Source/WTF/wtf/text/StringBuilder.h

    r277967 r278404  
    104104
    105105private:
     106    static unsigned expandedCapacity(unsigned capacity, unsigned requiredCapacity);
     107
    106108    template<typename AllocationCharacterType, typename CurrentCharacterType> void allocateBuffer(const CurrentCharacterType* currentCharacters, unsigned requiredCapacity);
    107109    template<typename CharacterType> void reallocateBuffer(unsigned requiredCapacity);
  • trunk/Source/WTF/wtf/text/StringBuilderJSON.cpp

    r278338 r278404  
    1313#include <wtf/text/StringBuilder.h>
    1414
     15#include <wtf/text/StringBuilderInternals.h>
    1516#include <wtf/text/WTFString.h>
    1617
Note: See TracChangeset for help on using the changeset viewer.