Remove alignment code from IPC coders
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Nov 2014 17:40:50 +0000 (17:40 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Nov 2014 17:40:50 +0000 (17:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=138963

Reviewed by Anders Carlsson.

Alignment code achieves nothing except making the messages somewhat bigger.

* Platform/IPC/ArgumentCoders.cpp:
(IPC::ArgumentCoder<CString>::encode):
(IPC::ArgumentCoder<CString>::decode):
(IPC::ArgumentCoder<String>::encode):
(IPC::decodeStringText):
* Platform/IPC/ArgumentCoders.h:
(IPC::SimpleArgumentCoder::encode):
(IPC::SimpleArgumentCoder::decode):
* Platform/IPC/ArgumentDecoder.cpp:
(IPC::ArgumentDecoder::initialize):
(IPC::ArgumentDecoder::bufferIsLargeEnoughToContain):
(IPC::ArgumentDecoder::decodeFixedLengthData):
(IPC::ArgumentDecoder::decodeVariableLengthByteArray):
(IPC::ArgumentDecoder::decodeNumber):
(IPC::ArgumentDecoder::decode):
(IPC::roundUpToAlignment): Deleted.
(IPC::alignedBufferIsLargeEnoughToContain): Deleted.
(IPC::ArgumentDecoder::alignBufferPosition): Deleted.
(IPC::decodeValueFromBuffer): Deleted.
* Platform/IPC/ArgumentDecoder.h:
(IPC::ArgumentDecoder::isInvalid):
(IPC::ArgumentDecoder::markInvalid):
(IPC::ArgumentDecoder::bufferIsLargeEnoughToContain):
* Platform/IPC/ArgumentEncoder.cpp:
(IPC::ArgumentEncoder::ArgumentEncoder):
(IPC::ArgumentEncoder::grow):
(IPC::ArgumentEncoder::encodeFixedLengthData):
(IPC::ArgumentEncoder::encodeVariableLengthByteArray):
(IPC::ArgumentEncoder::encode):
* Platform/IPC/ArgumentEncoder.h:
(IPC::ArgumentEncoder::buffer):
(IPC::ArgumentEncoder::mutableBuffer):
* Platform/IPC/DataReference.cpp:
(IPC::SharedBufferDataReference::encode):
* Platform/IPC/MessageEncoder.cpp:
(IPC::MessageEncoder::setIsSyncMessage):
(IPC::MessageEncoder::setShouldDispatchMessageWhenWaitingForSyncReply):
* Platform/IPC/mac/ConnectionMac.mm:
(IPC::Connection::sendOutgoingMessage):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@176452 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/Platform/IPC/ArgumentCoders.cpp
Source/WebKit2/Platform/IPC/ArgumentCoders.h
Source/WebKit2/Platform/IPC/ArgumentDecoder.cpp
Source/WebKit2/Platform/IPC/ArgumentDecoder.h
Source/WebKit2/Platform/IPC/ArgumentEncoder.cpp
Source/WebKit2/Platform/IPC/ArgumentEncoder.h
Source/WebKit2/Platform/IPC/DataReference.cpp
Source/WebKit2/Platform/IPC/MessageEncoder.cpp
Source/WebKit2/Platform/IPC/mac/ConnectionMac.mm
Source/WebKit2/Platform/IPC/unix/ConnectionUnix.cpp

index 8591ad5..80159b1 100644 (file)
@@ -1,3 +1,52 @@
+2014-11-21  Antti Koivisto  <antti@apple.com>
+
+        Remove alignment code from IPC coders
+        https://bugs.webkit.org/show_bug.cgi?id=138963
+
+        Reviewed by Anders Carlsson.
+
+        Alignment code achieves nothing except making the messages somewhat bigger.
+
+        * Platform/IPC/ArgumentCoders.cpp:
+        (IPC::ArgumentCoder<CString>::encode):
+        (IPC::ArgumentCoder<CString>::decode):
+        (IPC::ArgumentCoder<String>::encode):
+        (IPC::decodeStringText):
+        * Platform/IPC/ArgumentCoders.h:
+        (IPC::SimpleArgumentCoder::encode):
+        (IPC::SimpleArgumentCoder::decode):
+        * Platform/IPC/ArgumentDecoder.cpp:
+        (IPC::ArgumentDecoder::initialize):
+        (IPC::ArgumentDecoder::bufferIsLargeEnoughToContain):
+        (IPC::ArgumentDecoder::decodeFixedLengthData):
+        (IPC::ArgumentDecoder::decodeVariableLengthByteArray):
+        (IPC::ArgumentDecoder::decodeNumber):
+        (IPC::ArgumentDecoder::decode):
+        (IPC::roundUpToAlignment): Deleted.
+        (IPC::alignedBufferIsLargeEnoughToContain): Deleted.
+        (IPC::ArgumentDecoder::alignBufferPosition): Deleted.
+        (IPC::decodeValueFromBuffer): Deleted.
+        * Platform/IPC/ArgumentDecoder.h:
+        (IPC::ArgumentDecoder::isInvalid):
+        (IPC::ArgumentDecoder::markInvalid):
+        (IPC::ArgumentDecoder::bufferIsLargeEnoughToContain):
+        * Platform/IPC/ArgumentEncoder.cpp:
+        (IPC::ArgumentEncoder::ArgumentEncoder):
+        (IPC::ArgumentEncoder::grow):
+        (IPC::ArgumentEncoder::encodeFixedLengthData):
+        (IPC::ArgumentEncoder::encodeVariableLengthByteArray):
+        (IPC::ArgumentEncoder::encode):
+        * Platform/IPC/ArgumentEncoder.h:
+        (IPC::ArgumentEncoder::buffer):
+        (IPC::ArgumentEncoder::mutableBuffer):
+        * Platform/IPC/DataReference.cpp:
+        (IPC::SharedBufferDataReference::encode):
+        * Platform/IPC/MessageEncoder.cpp:
+        (IPC::MessageEncoder::setIsSyncMessage):
+        (IPC::MessageEncoder::setShouldDispatchMessageWhenWaitingForSyncReply):
+        * Platform/IPC/mac/ConnectionMac.mm:
+        (IPC::Connection::sendOutgoingMessage):
+
 2014-11-21  Anders Carlsson  <andersca@apple.com>
 
         Make memoryCache() return a reference
index 5ca0641..cef0a91 100644 (file)
@@ -57,7 +57,7 @@ void ArgumentCoder<CString>::encode(ArgumentEncoder& encoder, const CString& str
 
     uint32_t length = string.length();
     encoder << length;
-    encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(string.data()), length, 1);
+    encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(string.data()), length);
 }
 
 bool ArgumentCoder<CString>::decode(ArgumentDecoder& decoder, CString& result)
@@ -80,7 +80,7 @@ bool ArgumentCoder<CString>::decode(ArgumentDecoder& decoder, CString& result)
 
     char* buffer;
     CString string = CString::newUninitialized(length, buffer);
-    if (!decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(buffer), length, 1))
+    if (!decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(buffer), length))
         return false;
 
     result = string;
@@ -102,9 +102,9 @@ void ArgumentCoder<String>::encode(ArgumentEncoder& encoder, const String& strin
     encoder << length << is8Bit;
 
     if (is8Bit)
-        encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(string.characters8()), length * sizeof(LChar), alignof(LChar));
+        encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(string.characters8()), length * sizeof(LChar));
     else
-        encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(string.characters16()), length * sizeof(UChar), alignof(UChar));
+        encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(string.characters16()), length * sizeof(UChar));
 }
 
 template <typename CharacterType>
@@ -118,7 +118,7 @@ static inline bool decodeStringText(ArgumentDecoder& decoder, uint32_t length, S
     
     CharacterType* buffer;
     String string = String::createUninitialized(length, buffer);
-    if (!decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(buffer), length * sizeof(CharacterType), alignof(CharacterType)))
+    if (!decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(buffer), length * sizeof(CharacterType)))
         return false;
     
     result = string;
index ffe632c..653e3e1 100644 (file)
@@ -41,12 +41,12 @@ namespace IPC {
 template<typename T> struct SimpleArgumentCoder {
     static void encode(ArgumentEncoder& encoder, const T& t)
     {
-        encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(&t), sizeof(T), alignof(T));
+        encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(&t), sizeof(T));
     }
 
     static bool decode(ArgumentDecoder& decoder, T& t)
     {
-        return decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(&t), sizeof(T), alignof(T));
+        return decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(&t), sizeof(T));
     }
 };
 
@@ -178,7 +178,7 @@ template<typename T, unsigned inlineCapacity> struct VectorArgumentCoder<true, T
     static void encode(ArgumentEncoder& encoder, const Vector<T, inlineCapacity>& vector)
     {
         encoder << static_cast<uint64_t>(vector.size());
-        encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(vector.data()), vector.size() * sizeof(T), alignof(T));
+        encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(vector.data()), vector.size() * sizeof(T));
     }
     
     static bool decode(ArgumentDecoder& decoder, Vector<T, inlineCapacity>& vector)
@@ -198,7 +198,7 @@ template<typename T, unsigned inlineCapacity> struct VectorArgumentCoder<true, T
         Vector<T, inlineCapacity> temp;
         temp.resize(size);
 
-        decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(temp.data()), size * sizeof(T), alignof(T));
+        decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(temp.data()), size * sizeof(T));
 
         vector.swap(temp);
         return true;
index 4105a70..0fa0959 100644 (file)
@@ -56,56 +56,29 @@ ArgumentDecoder::~ArgumentDecoder()
 #endif
 }
 
-static inline uint8_t* roundUpToAlignment(uint8_t* ptr, unsigned alignment)
-{
-    // Assert that the alignment is a power of 2.
-    ASSERT(alignment && !(alignment & (alignment - 1)));
-
-    uintptr_t alignmentMask = alignment - 1;
-    return reinterpret_cast<uint8_t*>((reinterpret_cast<uintptr_t>(ptr) + alignmentMask) & ~alignmentMask);
-}
-
 void ArgumentDecoder::initialize(const uint8_t* buffer, size_t bufferSize)
 {
     m_buffer = static_cast<uint8_t*>(malloc(bufferSize));
 
     ASSERT(!(reinterpret_cast<uintptr_t>(m_buffer) % alignof(uint64_t)));
 
-    m_bufferPos = m_buffer;
+    m_bufferPosition = m_buffer;
     m_bufferEnd = m_buffer + bufferSize;
     memcpy(m_buffer, buffer, bufferSize);
 }
 
-static inline bool alignedBufferIsLargeEnoughToContain(const uint8_t* alignedPosition, const uint8_t* bufferEnd, size_t size)
-{
-    return bufferEnd >= alignedPosition && static_cast<size_t>(bufferEnd - alignedPosition) >= size;
-}
-
-bool ArgumentDecoder::alignBufferPosition(unsigned alignment, size_t size)
-{
-    uint8_t* alignedPosition = roundUpToAlignment(m_bufferPos, alignment);
-    if (!alignedBufferIsLargeEnoughToContain(alignedPosition, m_bufferEnd, size)) {
-        // We've walked off the end of this buffer.
-        markInvalid();
-        return false;
-    }
-    
-    m_bufferPos = alignedPosition;
-    return true;
-}
-
-bool ArgumentDecoder::bufferIsLargeEnoughToContain(unsigned alignment, size_t size) const
+bool ArgumentDecoder::bufferIsLargeEnoughToContain(size_t size) const
 {
-    return alignedBufferIsLargeEnoughToContain(roundUpToAlignment(m_bufferPos, alignment), m_bufferEnd, size);
+    return m_buffer + size <= m_bufferEnd;
 }
 
-bool ArgumentDecoder::decodeFixedLengthData(uint8_t* data, size_t size, unsigned alignment)
+bool ArgumentDecoder::decodeFixedLengthData(uint8_t* data, size_t size)
 {
-    if (!alignBufferPosition(alignment, size))
+    if (!bufferIsLargeEnoughToContain(size))
         return false;
 
-    memcpy(data, m_bufferPos, size);
-    m_bufferPos += size;
+    memcpy(data, m_bufferPosition, size);
+    m_bufferPosition += size;
 
     return true;
 }
@@ -116,102 +89,71 @@ bool ArgumentDecoder::decodeVariableLengthByteArray(DataReference& dataReference
     if (!decode(size))
         return false;
     
-    if (!alignBufferPosition(1, size))
+    if (!bufferIsLargeEnoughToContain(size))
         return false;
 
-    uint8_t* data = m_bufferPos;
-    m_bufferPos += size;
+    uint8_t* data = m_bufferPosition;
+    m_bufferPosition += size;
 
     dataReference = DataReference(data, size);
     return true;
 }
 
 template<typename Type>
-static void decodeValueFromBuffer(Type& value, uint8_t*& bufferPosition)
+bool ArgumentDecoder::decodeNumber(Type& value)
 {
-    memcpy(&value, bufferPosition, sizeof(value));
-    bufferPosition += sizeof(Type);
+    if (!bufferIsLargeEnoughToContain(sizeof(Type)))
+        return false;
+
+    memcpy(&value, m_bufferPosition, sizeof(Type));
+    m_bufferPosition += sizeof(Type);
+
+    return true;
 }
 
 bool ArgumentDecoder::decode(bool& result)
 {
-    if (!alignBufferPosition(sizeof(result), sizeof(result)))
-        return false;
-    
-    decodeValueFromBuffer(result, m_bufferPos);
-    return true;
+    return decodeNumber(result);
 }
 
 bool ArgumentDecoder::decode(uint8_t& result)
 {
-    if (!alignBufferPosition(sizeof(result), sizeof(result)))
-        return false;
-
-    decodeValueFromBuffer(result, m_bufferPos);
-    return true;
+    return decodeNumber(result);
 }
 
 bool ArgumentDecoder::decode(uint16_t& result)
 {
-    if (!alignBufferPosition(sizeof(result), sizeof(result)))
-        return false;
-
-    decodeValueFromBuffer(result, m_bufferPos);
-    return true;
+    return decodeNumber(result);
 }
 
 bool ArgumentDecoder::decode(uint32_t& result)
 {
-    if (!alignBufferPosition(sizeof(result), sizeof(result)))
-        return false;
-
-    decodeValueFromBuffer(result, m_bufferPos);
-    return true;
+    return decodeNumber(result);
 }
 
 bool ArgumentDecoder::decode(uint64_t& result)
 {
-    if (!alignBufferPosition(sizeof(result), sizeof(result)))
-        return false;
-    
-    decodeValueFromBuffer(result, m_bufferPos);
-    return true;
+    return decodeNumber(result);
 }
 
 bool ArgumentDecoder::decode(int32_t& result)
 {
-    if (!alignBufferPosition(sizeof(result), sizeof(result)))
-        return false;
-    
-    decodeValueFromBuffer(result, m_bufferPos);
-    return true;
+    return decodeNumber(result);
 }
 
 bool ArgumentDecoder::decode(int64_t& result)
 {
-    if (!alignBufferPosition(sizeof(result), sizeof(result)))
-        return false;
-
-    decodeValueFromBuffer(result, m_bufferPos);
-    return true;
+    return decodeNumber(result);
 }
 
 bool ArgumentDecoder::decode(float& result)
 {
-    if (!alignBufferPosition(sizeof(result), sizeof(result)))
-        return false;
-
-    decodeValueFromBuffer(result, m_bufferPos);
-    return true;
+    return decodeNumber(result);
 }
 
 bool ArgumentDecoder::decode(double& result)
 {
-    if (!alignBufferPosition(sizeof(result), sizeof(result)))
-        return false;
-    
-    decodeValueFromBuffer(result, m_bufferPos);
-    return true;
+    return decodeNumber(result);
 }
 
 bool ArgumentDecoder::removeAttachment(Attachment& attachment)
index 0ca0c19..569bdb5 100644 (file)
@@ -42,10 +42,10 @@ public:
 
     size_t length() const { return m_bufferEnd - m_buffer; }
 
-    bool isInvalid() const { return m_bufferPos > m_bufferEnd; }
-    void markInvalid() { m_bufferPos = m_bufferEnd + 1; }
+    bool isInvalid() const { return m_bufferPosition > m_bufferEnd; }
+    void markInvalid() { m_bufferPosition = m_bufferEnd + 1; }
 
-    bool decodeFixedLengthData(uint8_t*, size_t, unsigned alignment);
+    bool decodeFixedLengthData(uint8_t*, size_t);
 
     // The data in the data reference here will only be valid for the lifetime of the ArgumentDecoder object.
     bool decodeVariableLengthByteArray(DataReference&);
@@ -80,7 +80,7 @@ public:
         if (numElements > std::numeric_limits<size_t>::max() / sizeof(T))
             return false;
 
-        return bufferIsLargeEnoughToContain(alignof(T), numElements * sizeof(T));
+        return bufferIsLargeEnoughToContain(numElements * sizeof(T));
     }
 
     // Generic type decode function.
@@ -96,12 +96,12 @@ protected:
 
     void initialize(const uint8_t* buffer, size_t bufferSize);
 
-    bool alignBufferPosition(unsigned alignment, size_t size);
-    bool bufferIsLargeEnoughToContain(unsigned alignment, size_t size) const;
+    bool bufferIsLargeEnoughToContain(size_t) const;
+    template <typename Type> bool decodeNumber(Type& value);
 
 private:
     uint8_t* m_buffer;
-    uint8_t* m_bufferPos;
+    uint8_t* m_bufferPosition;
     uint8_t* m_bufferEnd;
 
     Vector<Attachment> m_attachments;
index c71e1a1..da3df96 100644 (file)
@@ -57,7 +57,6 @@ static inline void freeBuffer(void* addr, size_t size)
 
 ArgumentEncoder::ArgumentEncoder()
     : m_buffer(m_inlineBuffer)
-    , m_bufferPointer(m_inlineBuffer)
     , m_bufferSize(0)
     , m_bufferCapacity(sizeof(m_inlineBuffer))
 {
@@ -103,89 +102,78 @@ void ArgumentEncoder::reserve(size_t size)
     m_bufferCapacity = newCapacity;
 }
 
-uint8_t* ArgumentEncoder::grow(unsigned alignment, size_t size)
+uint8_t* ArgumentEncoder::grow(size_t size)
 {
-    size_t alignedSize = roundUpToAlignment(m_bufferSize, alignment);
-    reserve(alignedSize + size);
+    size_t position = m_bufferSize;
+    reserve(m_bufferSize + size);
 
-    m_bufferSize = alignedSize + size;
-    m_bufferPointer = m_buffer + alignedSize + size;
-    
-    return m_buffer + alignedSize;
+    m_bufferSize += size;
+
+    return m_buffer + position;
 }
 
-void ArgumentEncoder::encodeFixedLengthData(const uint8_t* data, size_t size, unsigned alignment)
+void ArgumentEncoder::encodeFixedLengthData(const uint8_t* data, size_t size)
 {
-    ASSERT(!(reinterpret_cast<uintptr_t>(data) % alignment));
-
-    uint8_t* buffer = grow(alignment, size);
+    uint8_t* buffer = grow(size);
     memcpy(buffer, data, size);
 }
 
 void ArgumentEncoder::encodeVariableLengthByteArray(const DataReference& dataReference)
 {
     encode(static_cast<uint64_t>(dataReference.size()));
-    encodeFixedLengthData(dataReference.data(), dataReference.size(), 1);
+    encodeFixedLengthData(dataReference.data(), dataReference.size());
 }
 
 template<typename Type>
-static void copyValueToBuffer(Type value, uint8_t* bufferPosition)
+void ArgumentEncoder::encodeNumber(Type value)
 {
+    uint8_t* bufferPosition = grow(sizeof(Type));
     memcpy(bufferPosition, &value, sizeof(Type));
 }
 
-void ArgumentEncoder::encode(bool n)
+void ArgumentEncoder::encode(bool value)
 {
-    uint8_t* buffer = grow(sizeof(n), sizeof(n));
-    copyValueToBuffer(n, buffer);
+    encodeNumber(value);
 }
 
-void ArgumentEncoder::encode(uint8_t n)
+void ArgumentEncoder::encode(uint8_t value)
 {
-    uint8_t* buffer = grow(sizeof(n), sizeof(n));
-    copyValueToBuffer(n, buffer);
+    encodeNumber(value);
 }
 
-void ArgumentEncoder::encode(uint16_t n)
+void ArgumentEncoder::encode(uint16_t value)
 {
-    uint8_t* buffer = grow(sizeof(n), sizeof(n));
-    copyValueToBuffer(n, buffer);
+    encodeNumber(value);
 }
 
-void ArgumentEncoder::encode(uint32_t n)
+void ArgumentEncoder::encode(uint32_t value)
 {
-    uint8_t* buffer = grow(sizeof(n), sizeof(n));
-    copyValueToBuffer(n, buffer);
+    encodeNumber(value);
 }
 
-void ArgumentEncoder::encode(uint64_t n)
+void ArgumentEncoder::encode(uint64_t value)
 {
-    uint8_t* buffer = grow(sizeof(n), sizeof(n));
-    copyValueToBuffer(n, buffer);
+    encodeNumber(value);
 }
 
-void ArgumentEncoder::encode(int32_t n)
+void ArgumentEncoder::encode(int32_t value)
 {
-    uint8_t* buffer = grow(sizeof(n), sizeof(n));
-    copyValueToBuffer(n, buffer);
+    encodeNumber(value);
 }
 
-void ArgumentEncoder::encode(int64_t n)
+void ArgumentEncoder::encode(int64_t value)
 {
-    uint8_t* buffer = grow(sizeof(n), sizeof(n));
-    copyValueToBuffer(n, buffer);
+    encodeNumber(value);
 }
 
-void ArgumentEncoder::encode(float n)
+void ArgumentEncoder::encode(float value)
 {
-    uint8_t* buffer = grow(sizeof(n), sizeof(n));
-    copyValueToBuffer(n, buffer);
+    encodeNumber(value);
 }
 
-void ArgumentEncoder::encode(double n)
+void ArgumentEncoder::encode(double value)
 {
-    uint8_t* buffer = grow(sizeof(n), sizeof(n));
-    copyValueToBuffer(n, buffer);
+    encodeNumber(value);
 }
 
 void ArgumentEncoder::addAttachment(const Attachment& attachment)
index 75d0bfb..8e1d51b 100644 (file)
@@ -41,7 +41,7 @@ public:
     ArgumentEncoder();
     virtual ~ArgumentEncoder();
 
-    void encodeFixedLengthData(const uint8_t*, size_t, unsigned alignment);
+    void encodeFixedLengthData(const uint8_t*, size_t);
     void encodeVariableLengthByteArray(const DataReference&);
 
     template<typename T> void encodeEnum(T t)
@@ -62,13 +62,16 @@ public:
         return *this;
     }
 
-    uint8_t* buffer() const { return m_buffer; }
+    const uint8_t* buffer() const { return m_buffer; }
     size_t bufferSize() const { return m_bufferSize; }
 
     void addAttachment(const Attachment&);
     Vector<Attachment> releaseAttachments();
     void reserve(size_t);
 
+protected:
+    uint8_t* mutableBuffer() { return m_buffer; }
+
 private:
     void encode(bool);
     void encode(uint8_t);
@@ -79,14 +82,13 @@ private:
     void encode(int64_t);
     void encode(float);
     void encode(double);
+    template<typename Type> void encodeNumber(Type);
 
-    uint8_t* grow(unsigned alignment, size_t size);
+    uint8_t* grow(size_t);
 
     uint8_t m_inlineBuffer[512];
-
     uint8_t* m_buffer;
-    uint8_t* m_bufferPointer;
-    
+
     size_t m_bufferSize;
     size_t m_bufferCapacity;
 
index ca61fa6..33f7194 100644 (file)
@@ -51,7 +51,7 @@ void SharedBufferDataReference::encode(ArgumentEncoder& encoder) const
     unsigned position = 0;
     while (position < bufferSize) {
         unsigned bytesToWrite = m_buffer->getSomeData(partialData, position);
-        encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(partialData), bytesToWrite, 1);
+        encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(partialData), bytesToWrite);
         position += bytesToWrite;
     }
 }
index d2e4efe..c681921 100644 (file)
@@ -51,17 +51,17 @@ MessageEncoder::~MessageEncoder()
 void MessageEncoder::setIsSyncMessage(bool isSyncMessage)
 {
     if (isSyncMessage)
-        *buffer() |= SyncMessage;
+        *mutableBuffer() |= SyncMessage;
     else
-        *buffer() &= ~SyncMessage;
+        *mutableBuffer() &= ~SyncMessage;
 }
 
 void MessageEncoder::setShouldDispatchMessageWhenWaitingForSyncReply(bool shouldDispatchMessageWhenWaitingForSyncReply)
 {
     if (shouldDispatchMessageWhenWaitingForSyncReply)
-        *buffer() |= DispatchMessageWhenWaitingForSyncReply;
+        *mutableBuffer() |= DispatchMessageWhenWaitingForSyncReply;
     else
-        *buffer() &= ~DispatchMessageWhenWaitingForSyncReply;
+        *mutableBuffer() &= ~DispatchMessageWhenWaitingForSyncReply;
 }
 
 } // namespace IPC
index c0845ec..0fed3dd 100644 (file)
@@ -327,7 +327,7 @@ bool Connection::sendOutgoingMessage(std::unique_ptr<MessageEncoder> encoder)
         if (messageBodyIsOOL) {
             mach_msg_descriptor_t* descriptor = reinterpret_cast<mach_msg_descriptor_t*>(descriptorData);
 
-            descriptor->out_of_line.address = encoder->buffer();
+            descriptor->out_of_line.address = const_cast<uint8_t*>(encoder->buffer());
             descriptor->out_of_line.size = encoder->bufferSize();
             descriptor->out_of_line.copy = MACH_MSG_VIRTUAL_COPY;
             descriptor->out_of_line.deallocate = false;
index 16be014..f9ff8b5 100644 (file)
@@ -514,7 +514,7 @@ bool Connection::sendOutgoingMessage(std::unique_ptr<MessageEncoder> encoder)
     }
 
     if (!messageInfo.isMessageBodyIsOutOfLine() && encoder->bufferSize()) {
-        iov[iovLength].iov_base = reinterpret_cast<void*>(encoder->buffer());
+        iov[iovLength].iov_base = reinterpret_cast<void*>(const_cast<uint8_t*>(encoder->buffer()));
         iov[iovLength].iov_len = encoder->bufferSize();
         ++iovLength;
     }