Merge pull request #484 from miloyip/Issue483_PointerValue
Fix #483 by using the correct value type
This commit is contained in:
commit
28f2ed00d9
@ -390,7 +390,7 @@ public:
|
||||
bool exist = true;
|
||||
for (const Token *t = tokens_; t != tokens_ + tokenCount_; ++t) {
|
||||
if (v->IsArray() && t->name[0] == '-' && t->length == 1) {
|
||||
v->PushBack(Value().Move(), allocator);
|
||||
v->PushBack(ValueType().Move(), allocator);
|
||||
v = &((*v)[v->Size() - 1]);
|
||||
exist = false;
|
||||
}
|
||||
@ -408,7 +408,7 @@ public:
|
||||
if (t->index >= v->Size()) {
|
||||
v->Reserve(t->index + 1, allocator);
|
||||
while (t->index >= v->Size())
|
||||
v->PushBack(Value().Move(), allocator);
|
||||
v->PushBack(ValueType().Move(), allocator);
|
||||
exist = false;
|
||||
}
|
||||
v = &((*v)[t->index]);
|
||||
@ -416,7 +416,7 @@ public:
|
||||
else {
|
||||
typename ValueType::MemberIterator m = v->FindMember(GenericStringRef<Ch>(t->name, t->length));
|
||||
if (m == v->MemberEnd()) {
|
||||
v->AddMember(Value(t->name, t->length, allocator).Move(), Value().Move(), allocator);
|
||||
v->AddMember(ValueType(t->name, t->length, allocator).Move(), ValueType().Move(), allocator);
|
||||
v = &(--v->MemberEnd())->value; // Assumes AddMember() appends at the end
|
||||
exist = false;
|
||||
}
|
||||
|
@ -1456,3 +1456,38 @@ TEST(Pointer, Ambiguity) {
|
||||
EXPECT_EQ(456, Pointer("/0/1").Get(d)->GetInt());
|
||||
}
|
||||
}
|
||||
|
||||
// https://github.com/miloyip/rapidjson/issues/483
|
||||
namespace myjson {
|
||||
|
||||
class MyAllocator
|
||||
{
|
||||
public:
|
||||
static const bool kNeedFree = true;
|
||||
void * Malloc(size_t _size) { return malloc(_size); }
|
||||
void * Realloc(void *_org_p, size_t _org_size, size_t _new_size) { (void)_org_size; return realloc(_org_p, _new_size); }
|
||||
static void Free(void *_p) { return free(_p); }
|
||||
};
|
||||
|
||||
typedef rapidjson::GenericDocument<
|
||||
rapidjson::UTF8<>,
|
||||
rapidjson::MemoryPoolAllocator< MyAllocator >,
|
||||
MyAllocator
|
||||
> Document;
|
||||
|
||||
typedef rapidjson::GenericPointer<
|
||||
::myjson::Document::ValueType,
|
||||
MyAllocator
|
||||
> Pointer;
|
||||
|
||||
typedef ::myjson::Document::ValueType Value;
|
||||
|
||||
}
|
||||
|
||||
TEST(Pointer, Issue483) {
|
||||
std::string mystr, path;
|
||||
myjson::Document document;
|
||||
myjson::Value value(rapidjson::kStringType);
|
||||
value.SetString(mystr.c_str(), mystr.length(), document.GetAllocator());
|
||||
myjson::Pointer(path.c_str()).Set(document, value, document.GetAllocator());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user