diff --git a/include/rapidjson/allocators.h b/include/rapidjson/allocators.h index ba1d73e..8a490a6 100644 --- a/include/rapidjson/allocators.h +++ b/include/rapidjson/allocators.h @@ -149,6 +149,7 @@ public: //! Allocates a memory block. (concept Allocator) void* Malloc(size_t size) { + size = RAPIDJSON_ALIGN(size); if (chunkHead_->size + size > chunkHead_->capacity) AddChunk(chunk_capacity_ > size ? chunk_capacity_ : size); @@ -169,6 +170,7 @@ public: // Simply expand it if it is the last allocation and there is sufficient space if (originalPtr == (char *)(chunkHead_ + 1) + chunkHead_->size - originalSize) { size_t increment = newSize - originalSize; + increment = RAPIDJSON_ALIGN(increment); if (chunkHead_->size + increment <= chunkHead_->capacity) { chunkHead_->size += increment; return originalPtr; diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 22d8311..54f4e28 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -98,11 +98,11 @@ public: //! Constructor for uint64_t value. GenericValue(uint64_t u64) : flags_(kNumberUint64Flag) { data_.n.u64 = u64; - if (!(u64 & 0x8000000000000000L)) + if (!(u64 & 0x8000000000000000ULL)) flags_ |= kInt64Flag; - if (!(u64 & 0xFFFFFFFF00000000L)) + if (!(u64 & 0xFFFFFFFF00000000ULL)) flags_ |= kUintFlag; - if (!(u64 & 0xFFFFFFFF80000000L)) + if (!(u64 & 0xFFFFFFFF80000000ULL)) flags_ |= kIntFlag; } @@ -270,18 +270,18 @@ public: return *this; } - GenericValue& AddMember(const char* name, Allocator& nameAllocator, GenericValue& value, Allocator& allocator) { + GenericValue& AddMember(const Ch* name, Allocator& nameAllocator, GenericValue& value, Allocator& allocator) { GenericValue n(name, internal::StrLen(name), nameAllocator); return AddMember(n, value, allocator); } - GenericValue& AddMember(const char* name, GenericValue& value, Allocator& allocator) { + GenericValue& AddMember(const Ch* name, GenericValue& value, Allocator& allocator) { GenericValue n(name, internal::StrLen(name)); return AddMember(n, value, allocator); } template - GenericValue& AddMember(const char* name, T value, Allocator& allocator) { + GenericValue& AddMember(const Ch* name, T value, Allocator& allocator) { GenericValue n(name, internal::StrLen(name)); GenericValue v(value); return AddMember(n, v, allocator); @@ -650,10 +650,10 @@ private: void SetStringRaw(const Ch* s, SizeType length, Allocator& allocator) { RAPIDJSON_ASSERT(s != NULL); flags_ = kCopyStringFlag; - data_.s.str = (char *)allocator.Malloc(length + 1); + data_.s.str = (Ch *)allocator.Malloc(length + 1); data_.s.length = length; memcpy((void*)data_.s.str, s, length); - ((char*)data_.s.str)[length] = '\0'; + ((Ch*)data_.s.str)[length] = '\0'; } //! Assignment without calling destructor @@ -703,7 +703,7 @@ public: GenericReader reader; if (reader.Parse(is, *this)) { RAPIDJSON_ASSERT(stack_.GetSize() == sizeof(ValueType)); // Got one and only one root object - RawAssign(*stack_.template Pop(1)); + this->RawAssign(*stack_.template Pop(1)); // Add this-> to prevent issue 13. parseError_ = 0; errorOffset_ = 0; } diff --git a/include/rapidjson/rapidjson.h b/include/rapidjson/rapidjson.h index 3ca1027..1160c7c 100644 --- a/include/rapidjson/rapidjson.h +++ b/include/rapidjson/rapidjson.h @@ -45,6 +45,19 @@ typedef unsigned __int64 uint64_t; #endif #endif // RAPIDJSON_ENDIAN + +/////////////////////////////////////////////////////////////////////////////// +// RAPIDJSON_ALIGNSIZE + +//! Data alignment of the machine. +/*! + Some machine requires strict data alignment. + Currently the default uses 4 bytes alignment. User can customize this. +*/ +#ifndef RAPIDJSON_ALIGN +#define RAPIDJSON_ALIGN(x) ((x + 3) & ~3) +#endif + /////////////////////////////////////////////////////////////////////////////// // RAPIDJSON_SSE2/RAPIDJSON_SSE42/RAPIDJSON_SIMD