mirror of
https://github.com/Tencent/rapidjson.git
synced 2025-03-09 11:09:32 +01:00
Merge pull request #148 from pah/fixes/solaris
Alternative compilation fix for Solaris
This commit is contained in:
commit
ca9b2d188f
@ -68,9 +68,9 @@ concept Allocator {
|
||||
class CrtAllocator {
|
||||
public:
|
||||
static const bool kNeedFree = true;
|
||||
void* Malloc(size_t size) { return malloc(size); }
|
||||
void* Realloc(void* originalPtr, size_t originalSize, size_t newSize) { (void)originalSize; return realloc(originalPtr, newSize); }
|
||||
static void Free(void *ptr) { free(ptr); }
|
||||
void* Malloc(size_t size) { return std::malloc(size); }
|
||||
void* Realloc(void* originalPtr, size_t originalSize, size_t newSize) { (void)originalSize; return std::realloc(originalPtr, newSize); }
|
||||
static void Free(void *ptr) { std::free(ptr); }
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -200,7 +200,7 @@ public:
|
||||
// Realloc process: allocate and copy memory, do not free original buffer.
|
||||
void* newBuffer = Malloc(newSize);
|
||||
RAPIDJSON_ASSERT(newBuffer != 0); // Do not handle out-of-memory explicitly.
|
||||
return memcpy(newBuffer, originalPtr, originalSize);
|
||||
return std::memcpy(newBuffer, originalPtr, originalSize);
|
||||
}
|
||||
|
||||
//! Frees a memory block (concept Allocator)
|
||||
|
@ -413,7 +413,6 @@ template <typename T> struct IsGenericValue : IsGenericValueImpl<T>::Type {};
|
||||
\tparam Encoding Encoding of the value. (Even non-string values need to have the same encoding in a document)
|
||||
\tparam Allocator Allocator type for allocating memory of object, array and string.
|
||||
*/
|
||||
#pragma pack (push, 4)
|
||||
template <typename Encoding, typename Allocator = MemoryPoolAllocator<> >
|
||||
class GenericValue {
|
||||
public:
|
||||
@ -1098,7 +1097,7 @@ public:
|
||||
MemberIterator pos = MemberBegin() + (first - MemberBegin());
|
||||
for (MemberIterator itr = pos; itr != last; ++itr)
|
||||
itr->~Member();
|
||||
memmove(&*pos, &*last, (MemberEnd() - last) * sizeof(Member));
|
||||
std::memmove(&*pos, &*last, (MemberEnd() - last) * sizeof(Member));
|
||||
data_.o.size -= (last - first);
|
||||
return pos;
|
||||
}
|
||||
@ -1278,7 +1277,7 @@ int z = a[0u].GetInt(); // This works too.
|
||||
ValueIterator pos = Begin() + (first - Begin());
|
||||
for (ValueIterator itr = pos; itr != last; ++itr)
|
||||
itr->~GenericValue();
|
||||
memmove(pos, last, (End() - last) * sizeof(GenericValue));
|
||||
std::memmove(pos, last, (End() - last) * sizeof(GenericValue));
|
||||
data_.a.size -= (last - first);
|
||||
return pos;
|
||||
}
|
||||
@ -1528,7 +1527,7 @@ private:
|
||||
void SetArrayRaw(GenericValue* values, SizeType count, Allocator& allocator) {
|
||||
flags_ = kArrayFlag;
|
||||
data_.a.elements = (GenericValue*)allocator.Malloc(count * sizeof(GenericValue));
|
||||
memcpy(data_.a.elements, values, count * sizeof(GenericValue));
|
||||
std::memcpy(data_.a.elements, values, count * sizeof(GenericValue));
|
||||
data_.a.size = data_.a.capacity = count;
|
||||
}
|
||||
|
||||
@ -1536,7 +1535,7 @@ private:
|
||||
void SetObjectRaw(Member* members, SizeType count, Allocator& allocator) {
|
||||
flags_ = kObjectFlag;
|
||||
data_.o.members = (Member*)allocator.Malloc(count * sizeof(Member));
|
||||
memcpy(data_.o.members, members, count * sizeof(Member));
|
||||
std::memcpy(data_.o.members, members, count * sizeof(Member));
|
||||
data_.o.size = data_.o.capacity = count;
|
||||
}
|
||||
|
||||
@ -1560,7 +1559,7 @@ private:
|
||||
str = (Ch *)allocator.Malloc((s.length + 1) * sizeof(Ch));
|
||||
data_.s.str = str;
|
||||
}
|
||||
memcpy(str, s, s.length * sizeof(Ch));
|
||||
std::memcpy(str, s, s.length * sizeof(Ch));
|
||||
str[s.length] = '\0';
|
||||
}
|
||||
|
||||
@ -1584,13 +1583,12 @@ private:
|
||||
const Ch* const str2 = rhs.GetString();
|
||||
if(str1 == str2) { return true; } // fast path for constant string
|
||||
|
||||
return (memcmp(str1, str2, sizeof(Ch) * len1) == 0);
|
||||
return (std::memcmp(str1, str2, sizeof(Ch) * len1) == 0);
|
||||
}
|
||||
|
||||
Data data_;
|
||||
unsigned flags_;
|
||||
};
|
||||
#pragma pack (pop)
|
||||
|
||||
//! GenericValue with UTF8 encoding
|
||||
typedef GenericValue<UTF8<> > Value;
|
||||
|
@ -48,7 +48,7 @@ public:
|
||||
void PutN(char c, size_t n) {
|
||||
size_t avail = static_cast<size_t>(bufferEnd_ - current_);
|
||||
while (n > avail) {
|
||||
memset(current_, c, avail);
|
||||
std::memset(current_, c, avail);
|
||||
current_ += avail;
|
||||
Flush();
|
||||
n -= avail;
|
||||
@ -56,7 +56,7 @@ public:
|
||||
}
|
||||
|
||||
if (n > 0) {
|
||||
memset(current_, c, n);
|
||||
std::memset(current_, c, n);
|
||||
current_ += n;
|
||||
}
|
||||
}
|
||||
|
@ -362,14 +362,14 @@ inline char* Prettify(char* buffer, int length, int k) {
|
||||
}
|
||||
else if (0 < kk && kk <= 21) {
|
||||
// 1234e-2 -> 12.34
|
||||
memmove(&buffer[kk + 1], &buffer[kk], length - kk);
|
||||
std::memmove(&buffer[kk + 1], &buffer[kk], length - kk);
|
||||
buffer[kk] = '.';
|
||||
return &buffer[length + 1];
|
||||
}
|
||||
else if (-6 < kk && kk <= 0) {
|
||||
// 1234e-6 -> 0.001234
|
||||
const int offset = 2 - kk;
|
||||
memmove(&buffer[offset], &buffer[0], length);
|
||||
std::memmove(&buffer[offset], &buffer[0], length);
|
||||
buffer[0] = '0';
|
||||
buffer[1] = '.';
|
||||
for (int i = 2; i < offset; i++)
|
||||
@ -383,7 +383,7 @@ inline char* Prettify(char* buffer, int length, int k) {
|
||||
}
|
||||
else {
|
||||
// 1234e30 -> 1.234e33
|
||||
memmove(&buffer[2], &buffer[1], length - 1);
|
||||
std::memmove(&buffer[2], &buffer[1], length - 1);
|
||||
buffer[1] = '.';
|
||||
buffer[length + 1] = 'e';
|
||||
return WriteExponent(kk - 1, &buffer[0 + length + 2]);
|
||||
|
@ -68,7 +68,7 @@ typedef GenericMemoryBuffer<> MemoryBuffer;
|
||||
//! Implement specialized version of PutN() with memset() for better performance.
|
||||
template<>
|
||||
inline void PutN(MemoryBuffer& memoryBuffer, char c, size_t n) {
|
||||
memset(memoryBuffer.stack_.Push<char>(n), c, n * sizeof(c));
|
||||
std::memset(memoryBuffer.stack_.Push<char>(n), c, n * sizeof(c));
|
||||
}
|
||||
|
||||
} // namespace rapidjson
|
||||
|
@ -45,8 +45,8 @@
|
||||
different translation units of a single application.
|
||||
*/
|
||||
|
||||
#include <cstdlib> // malloc(), realloc(), free()
|
||||
#include <cstring> // memcpy()
|
||||
#include <cstdlib> // malloc(), realloc(), free(), size_t
|
||||
#include <cstring> // memset(), memcpy(), memmove(), memcmp()
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// RAPIDJSON_NO_INT64DEFINE
|
||||
@ -248,6 +248,11 @@ typedef unsigned SizeType;
|
||||
} // namespace rapidjson
|
||||
#endif
|
||||
|
||||
// always import std::size_t to rapidjson namespace
|
||||
namespace rapidjson {
|
||||
using std::size_t;
|
||||
} // namespace rapidjson
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// RAPIDJSON_ASSERT
|
||||
|
||||
|
@ -71,7 +71,7 @@ typedef GenericStringBuffer<UTF8<> > StringBuffer;
|
||||
//! Implement specialized version of PutN() with memset() for better performance.
|
||||
template<>
|
||||
inline void PutN(GenericStringBuffer<UTF8<> >& stream, char c, size_t n) {
|
||||
memset(stream.stack_.Push<char>(n), c, n * sizeof(c));
|
||||
std::memset(stream.stack_.Push<char>(n), c, n * sizeof(c));
|
||||
}
|
||||
|
||||
} // namespace rapidjson
|
||||
|
Loading…
x
Reference in New Issue
Block a user