Commit c008d517 authored by miloyip@gmail.com's avatar miloyip@gmail.com

Fixed several issues (10, 11, 13, 14) from 0.1x branch

git-svn-id: https://rapidjson.googlecode.com/svn/trunk@57 c5894555-1306-4e8d-425f-1f6f381ee07c
parent bedeb0d8
......@@ -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;
......
......@@ -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 <typename T>
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<SourceEncoding, Encoding> reader;
if (reader.Parse<parseFlags>(is, *this)) {
RAPIDJSON_ASSERT(stack_.GetSize() == sizeof(ValueType)); // Got one and only one root object
RawAssign(*stack_.template Pop<ValueType>(1));
this->RawAssign(*stack_.template Pop<ValueType>(1)); // Add this-> to prevent issue 13.
parseError_ = 0;
errorOffset_ = 0;
}
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment