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
This commit is contained in:
parent
bedeb0d8ea
commit
c008d5176b
@ -149,6 +149,7 @@ public:
|
|||||||
|
|
||||||
//! Allocates a memory block. (concept Allocator)
|
//! Allocates a memory block. (concept Allocator)
|
||||||
void* Malloc(size_t size) {
|
void* Malloc(size_t size) {
|
||||||
|
size = RAPIDJSON_ALIGN(size);
|
||||||
if (chunkHead_->size + size > chunkHead_->capacity)
|
if (chunkHead_->size + size > chunkHead_->capacity)
|
||||||
AddChunk(chunk_capacity_ > size ? chunk_capacity_ : size);
|
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
|
// Simply expand it if it is the last allocation and there is sufficient space
|
||||||
if (originalPtr == (char *)(chunkHead_ + 1) + chunkHead_->size - originalSize) {
|
if (originalPtr == (char *)(chunkHead_ + 1) + chunkHead_->size - originalSize) {
|
||||||
size_t increment = newSize - originalSize;
|
size_t increment = newSize - originalSize;
|
||||||
|
increment = RAPIDJSON_ALIGN(increment);
|
||||||
if (chunkHead_->size + increment <= chunkHead_->capacity) {
|
if (chunkHead_->size + increment <= chunkHead_->capacity) {
|
||||||
chunkHead_->size += increment;
|
chunkHead_->size += increment;
|
||||||
return originalPtr;
|
return originalPtr;
|
||||||
|
@ -98,11 +98,11 @@ public:
|
|||||||
//! Constructor for uint64_t value.
|
//! Constructor for uint64_t value.
|
||||||
GenericValue(uint64_t u64) : flags_(kNumberUint64Flag) {
|
GenericValue(uint64_t u64) : flags_(kNumberUint64Flag) {
|
||||||
data_.n.u64 = u64;
|
data_.n.u64 = u64;
|
||||||
if (!(u64 & 0x8000000000000000L))
|
if (!(u64 & 0x8000000000000000ULL))
|
||||||
flags_ |= kInt64Flag;
|
flags_ |= kInt64Flag;
|
||||||
if (!(u64 & 0xFFFFFFFF00000000L))
|
if (!(u64 & 0xFFFFFFFF00000000ULL))
|
||||||
flags_ |= kUintFlag;
|
flags_ |= kUintFlag;
|
||||||
if (!(u64 & 0xFFFFFFFF80000000L))
|
if (!(u64 & 0xFFFFFFFF80000000ULL))
|
||||||
flags_ |= kIntFlag;
|
flags_ |= kIntFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,18 +270,18 @@ public:
|
|||||||
return *this;
|
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);
|
GenericValue n(name, internal::StrLen(name), nameAllocator);
|
||||||
return AddMember(n, value, allocator);
|
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));
|
GenericValue n(name, internal::StrLen(name));
|
||||||
return AddMember(n, value, allocator);
|
return AddMember(n, value, allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
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 n(name, internal::StrLen(name));
|
||||||
GenericValue v(value);
|
GenericValue v(value);
|
||||||
return AddMember(n, v, allocator);
|
return AddMember(n, v, allocator);
|
||||||
@ -650,10 +650,10 @@ private:
|
|||||||
void SetStringRaw(const Ch* s, SizeType length, Allocator& allocator) {
|
void SetStringRaw(const Ch* s, SizeType length, Allocator& allocator) {
|
||||||
RAPIDJSON_ASSERT(s != NULL);
|
RAPIDJSON_ASSERT(s != NULL);
|
||||||
flags_ = kCopyStringFlag;
|
flags_ = kCopyStringFlag;
|
||||||
data_.s.str = (char *)allocator.Malloc(length + 1);
|
data_.s.str = (Ch *)allocator.Malloc(length + 1);
|
||||||
data_.s.length = length;
|
data_.s.length = length;
|
||||||
memcpy((void*)data_.s.str, s, length);
|
memcpy((void*)data_.s.str, s, length);
|
||||||
((char*)data_.s.str)[length] = '\0';
|
((Ch*)data_.s.str)[length] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Assignment without calling destructor
|
//! Assignment without calling destructor
|
||||||
@ -703,7 +703,7 @@ public:
|
|||||||
GenericReader<SourceEncoding, Encoding> reader;
|
GenericReader<SourceEncoding, Encoding> reader;
|
||||||
if (reader.Parse<parseFlags>(is, *this)) {
|
if (reader.Parse<parseFlags>(is, *this)) {
|
||||||
RAPIDJSON_ASSERT(stack_.GetSize() == sizeof(ValueType)); // Got one and only one root object
|
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;
|
parseError_ = 0;
|
||||||
errorOffset_ = 0;
|
errorOffset_ = 0;
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,19 @@ typedef unsigned __int64 uint64_t;
|
|||||||
#endif
|
#endif
|
||||||
#endif // RAPIDJSON_ENDIAN
|
#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
|
// RAPIDJSON_SSE2/RAPIDJSON_SSE42/RAPIDJSON_SIMD
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user