From 9fe93bb9847b8cfb889d49eb7e20d94d0767350d Mon Sep 17 00:00:00 2001 From: Andrey Glebov Date: Wed, 21 Dec 2016 10:17:25 +0300 Subject: [PATCH 1/3] - replaced RAPIDJSON_NEW macro with variadic varient --- include/rapidjson/allocators.h | 2 +- include/rapidjson/document.h | 4 ++-- include/rapidjson/internal/regex.h | 2 +- include/rapidjson/internal/stack.h | 2 +- include/rapidjson/pointer.h | 4 ++-- include/rapidjson/rapidjson.h | 2 +- include/rapidjson/schema.h | 4 ++-- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/rapidjson/allocators.h b/include/rapidjson/allocators.h index 98affe03f..6405bc3a0 100644 --- a/include/rapidjson/allocators.h +++ b/include/rapidjson/allocators.h @@ -236,7 +236,7 @@ class MemoryPoolAllocator { */ bool AddChunk(size_t capacity) { if (!baseAllocator_) - ownBaseAllocator_ = baseAllocator_ = RAPIDJSON_NEW(BaseAllocator()); + ownBaseAllocator_ = baseAllocator_ = RAPIDJSON_NEW(BaseAllocator); if (ChunkHeader* chunk = reinterpret_cast(baseAllocator_->Malloc(RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + capacity))) { chunk->capacity = capacity; chunk->size = 0; diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 895af88e5..5822acce8 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -2088,7 +2088,7 @@ class GenericDocument : public GenericValue { GenericValue(type), allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_() { if (!allocator_) - ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator()); + ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator); } //! Constructor @@ -2101,7 +2101,7 @@ class GenericDocument : public GenericValue { allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_() { if (!allocator_) - ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator()); + ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator); } #if RAPIDJSON_HAS_CXX11_RVALUE_REFS diff --git a/include/rapidjson/internal/regex.h b/include/rapidjson/internal/regex.h index 8530cd771..500136404 100644 --- a/include/rapidjson/internal/regex.h +++ b/include/rapidjson/internal/regex.h @@ -606,7 +606,7 @@ class GenericRegexSearch { { RAPIDJSON_ASSERT(regex_.IsValid()); if (!allocator_) - ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator()); + ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator); stateSet_ = static_cast(allocator_->Malloc(GetStateSetSize())); state0_.template Reserve(regex_.stateCount_); state1_.template Reserve(regex_.stateCount_); diff --git a/include/rapidjson/internal/stack.h b/include/rapidjson/internal/stack.h index 022c9aab4..a1b456817 100644 --- a/include/rapidjson/internal/stack.h +++ b/include/rapidjson/internal/stack.h @@ -183,7 +183,7 @@ class Stack { size_t newCapacity; if (stack_ == 0) { if (!allocator_) - ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator()); + ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator); newCapacity = initialCapacity_; } else { newCapacity = GetCapacity(); diff --git a/include/rapidjson/pointer.h b/include/rapidjson/pointer.h index 0206ac1c8..eab66193c 100644 --- a/include/rapidjson/pointer.h +++ b/include/rapidjson/pointer.h @@ -758,7 +758,7 @@ class GenericPointer { */ Ch* CopyFromRaw(const GenericPointer& rhs, size_t extraToken = 0, size_t extraNameBufferSize = 0) { if (!allocator_) // allocator is independently owned. - ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator()); + ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator); size_t nameBufferSize = rhs.tokenCount_; // null terminators for tokens for (Token *t = rhs.tokens_; t != rhs.tokens_ + rhs.tokenCount_; ++t) @@ -806,7 +806,7 @@ class GenericPointer { // Create own allocator if user did not supply. if (!allocator_) - ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator()); + ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator); // Count number of '/' as tokenCount tokenCount_ = 0; diff --git a/include/rapidjson/rapidjson.h b/include/rapidjson/rapidjson.h index 053b2ce43..77611cec0 100644 --- a/include/rapidjson/rapidjson.h +++ b/include/rapidjson/rapidjson.h @@ -583,7 +583,7 @@ RAPIDJSON_NAMESPACE_END #ifndef RAPIDJSON_NEW ///! customization point for global \c new -#define RAPIDJSON_NEW(x) new x +#define RAPIDJSON_NEW(type, ...) new type(__VA_ARGS__) #endif #ifndef RAPIDJSON_DELETE ///! customization point for global \c delete diff --git a/include/rapidjson/schema.h b/include/rapidjson/schema.h index e7af3cf57..a99f1e835 100644 --- a/include/rapidjson/schema.h +++ b/include/rapidjson/schema.h @@ -1344,7 +1344,7 @@ class GenericSchemaDocument { schemaRef_(allocator, kInitialSchemaRefSize) { if (!allocator_) - ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator()); + ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator); typeless_ = static_cast(allocator_->Malloc(sizeof(SchemaType))); new (typeless_) SchemaType(this, PointerType(), ValueType(kObjectType).Move(), ValueType(kObjectType).Move(), 0); @@ -1823,7 +1823,7 @@ RAPIDJSON_MULTILINEMACRO_END StateAllocator& GetStateAllocator() { if (!stateAllocator_) - stateAllocator_ = ownStateAllocator_ = RAPIDJSON_NEW(StateAllocator()); + stateAllocator_ = ownStateAllocator_ = RAPIDJSON_NEW(StateAllocator); return *stateAllocator_; } From 3f120caeef7362ae0b4f219c5c6cafb5d074d698 Mon Sep 17 00:00:00 2001 From: Andrey Glebov Date: Wed, 21 Dec 2016 10:41:06 +0300 Subject: [PATCH 2/3] - replaced RAPIDJSON_NEW calls in fwdtest.cpp --- test/unittest/fwdtest.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/unittest/fwdtest.cpp b/test/unittest/fwdtest.cpp index 4f3268461..b9d18e8e1 100644 --- a/test/unittest/fwdtest.cpp +++ b/test/unittest/fwdtest.cpp @@ -118,23 +118,23 @@ Foo::Foo() : memorypoolallocator(RAPIDJSON_NEW(MemoryPoolAllocator<>)), // stream.h - stringstream(RAPIDJSON_NEW(StringStream(0))), - insitustringstream(RAPIDJSON_NEW(InsituStringStream(0))), + stringstream(RAPIDJSON_NEW(StringStream, NULL)), + insitustringstream(RAPIDJSON_NEW(InsituStringStream, NULL)), // stringbuffer.h stringbuffer(RAPIDJSON_NEW(StringBuffer)), // // filereadstream.h - // filereadstream(RAPIDJSON_NEW(FileReadStream(stdout, buffer, sizeof(buffer)))), + // filereadstream(RAPIDJSON_NEW(FileReadStream, stdout, buffer, sizeof(buffer))), // // filewritestream.h - // filewritestream(RAPIDJSON_NEW(FileWriteStream(stdout, buffer, sizeof(buffer)))), + // filewritestream(RAPIDJSON_NEW(FileWriteStream, stdout, buffer, sizeof(buffer))), // memorybuffer.h memorybuffer(RAPIDJSON_NEW(MemoryBuffer)), // memorystream.h - memorystream(RAPIDJSON_NEW(MemoryStream(0, 0))), + memorystream(RAPIDJSON_NEW(MemoryStream, NULL, 0)), // reader.h basereaderhandler(RAPIDJSON_NEW((BaseReaderHandler, void>))), @@ -154,8 +154,8 @@ Foo::Foo() : pointer(RAPIDJSON_NEW(Pointer)), // schema.h - schemadocument(RAPIDJSON_NEW(SchemaDocument(*document))), - schemavalidator(RAPIDJSON_NEW(SchemaValidator(*schemadocument))) + schemadocument(RAPIDJSON_NEW(SchemaDocument, *document)), + schemavalidator(RAPIDJSON_NEW(SchemaValidator, *schemadocument)) { } From 41ceb8624f2fb46fe5e62b7d2cce471c17db7a5f Mon Sep 17 00:00:00 2001 From: Andrey Glebov Date: Wed, 21 Dec 2016 14:03:53 +0300 Subject: [PATCH 3/3] - replaced RAPIDJSON_NEW with C++98 compatible version --- include/rapidjson/allocators.h | 2 +- include/rapidjson/document.h | 4 ++-- include/rapidjson/internal/regex.h | 2 +- include/rapidjson/internal/stack.h | 2 +- include/rapidjson/pointer.h | 4 ++-- include/rapidjson/rapidjson.h | 2 +- include/rapidjson/schema.h | 4 ++-- test/unittest/fwdtest.cpp | 25 ++++++++++++++----------- 8 files changed, 24 insertions(+), 21 deletions(-) diff --git a/include/rapidjson/allocators.h b/include/rapidjson/allocators.h index 6405bc3a0..655f4a385 100644 --- a/include/rapidjson/allocators.h +++ b/include/rapidjson/allocators.h @@ -236,7 +236,7 @@ class MemoryPoolAllocator { */ bool AddChunk(size_t capacity) { if (!baseAllocator_) - ownBaseAllocator_ = baseAllocator_ = RAPIDJSON_NEW(BaseAllocator); + ownBaseAllocator_ = baseAllocator_ = RAPIDJSON_NEW(BaseAllocator)(); if (ChunkHeader* chunk = reinterpret_cast(baseAllocator_->Malloc(RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + capacity))) { chunk->capacity = capacity; chunk->size = 0; diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 5822acce8..3873b99b4 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -2088,7 +2088,7 @@ class GenericDocument : public GenericValue { GenericValue(type), allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_() { if (!allocator_) - ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator); + ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)(); } //! Constructor @@ -2101,7 +2101,7 @@ class GenericDocument : public GenericValue { allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_() { if (!allocator_) - ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator); + ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)(); } #if RAPIDJSON_HAS_CXX11_RVALUE_REFS diff --git a/include/rapidjson/internal/regex.h b/include/rapidjson/internal/regex.h index 500136404..936b71448 100644 --- a/include/rapidjson/internal/regex.h +++ b/include/rapidjson/internal/regex.h @@ -606,7 +606,7 @@ class GenericRegexSearch { { RAPIDJSON_ASSERT(regex_.IsValid()); if (!allocator_) - ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator); + ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)(); stateSet_ = static_cast(allocator_->Malloc(GetStateSetSize())); state0_.template Reserve(regex_.stateCount_); state1_.template Reserve(regex_.stateCount_); diff --git a/include/rapidjson/internal/stack.h b/include/rapidjson/internal/stack.h index a1b456817..299e651ed 100644 --- a/include/rapidjson/internal/stack.h +++ b/include/rapidjson/internal/stack.h @@ -183,7 +183,7 @@ class Stack { size_t newCapacity; if (stack_ == 0) { if (!allocator_) - ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator); + ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)(); newCapacity = initialCapacity_; } else { newCapacity = GetCapacity(); diff --git a/include/rapidjson/pointer.h b/include/rapidjson/pointer.h index eab66193c..4d6391f90 100644 --- a/include/rapidjson/pointer.h +++ b/include/rapidjson/pointer.h @@ -758,7 +758,7 @@ class GenericPointer { */ Ch* CopyFromRaw(const GenericPointer& rhs, size_t extraToken = 0, size_t extraNameBufferSize = 0) { if (!allocator_) // allocator is independently owned. - ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator); + ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)(); size_t nameBufferSize = rhs.tokenCount_; // null terminators for tokens for (Token *t = rhs.tokens_; t != rhs.tokens_ + rhs.tokenCount_; ++t) @@ -806,7 +806,7 @@ class GenericPointer { // Create own allocator if user did not supply. if (!allocator_) - ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator); + ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)(); // Count number of '/' as tokenCount tokenCount_ = 0; diff --git a/include/rapidjson/rapidjson.h b/include/rapidjson/rapidjson.h index 77611cec0..a005257ee 100644 --- a/include/rapidjson/rapidjson.h +++ b/include/rapidjson/rapidjson.h @@ -583,7 +583,7 @@ RAPIDJSON_NAMESPACE_END #ifndef RAPIDJSON_NEW ///! customization point for global \c new -#define RAPIDJSON_NEW(type, ...) new type(__VA_ARGS__) +#define RAPIDJSON_NEW(TypeName) new TypeName #endif #ifndef RAPIDJSON_DELETE ///! customization point for global \c delete diff --git a/include/rapidjson/schema.h b/include/rapidjson/schema.h index a99f1e835..4760d1b43 100644 --- a/include/rapidjson/schema.h +++ b/include/rapidjson/schema.h @@ -1344,7 +1344,7 @@ class GenericSchemaDocument { schemaRef_(allocator, kInitialSchemaRefSize) { if (!allocator_) - ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator); + ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)(); typeless_ = static_cast(allocator_->Malloc(sizeof(SchemaType))); new (typeless_) SchemaType(this, PointerType(), ValueType(kObjectType).Move(), ValueType(kObjectType).Move(), 0); @@ -1823,7 +1823,7 @@ RAPIDJSON_MULTILINEMACRO_END StateAllocator& GetStateAllocator() { if (!stateAllocator_) - stateAllocator_ = ownStateAllocator_ = RAPIDJSON_NEW(StateAllocator); + stateAllocator_ = ownStateAllocator_ = RAPIDJSON_NEW(StateAllocator)(); return *stateAllocator_; } diff --git a/test/unittest/fwdtest.cpp b/test/unittest/fwdtest.cpp index b9d18e8e1..1936d9779 100644 --- a/test/unittest/fwdtest.cpp +++ b/test/unittest/fwdtest.cpp @@ -100,6 +100,9 @@ struct Foo { #include "rapidjson/prettywriter.h" #include "rapidjson/schema.h" // -> pointer.h +typedef Transcoder, UTF8<> > TranscoderUtf8ToUtf8; +typedef BaseReaderHandler, void> BaseReaderHandlerUtf8Void; + Foo::Foo() : // encodings.h utf8(RAPIDJSON_NEW(UTF8<>)), @@ -111,40 +114,40 @@ Foo::Foo() : utf32le(RAPIDJSON_NEW(UTF32LE<>)), ascii(RAPIDJSON_NEW(ASCII<>)), autoutf(RAPIDJSON_NEW(AutoUTF)), - transcoder(RAPIDJSON_NEW((Transcoder, UTF8<> >))), + transcoder(RAPIDJSON_NEW(TranscoderUtf8ToUtf8)), // allocators.h crtallocator(RAPIDJSON_NEW(CrtAllocator)), memorypoolallocator(RAPIDJSON_NEW(MemoryPoolAllocator<>)), // stream.h - stringstream(RAPIDJSON_NEW(StringStream, NULL)), - insitustringstream(RAPIDJSON_NEW(InsituStringStream, NULL)), + stringstream(RAPIDJSON_NEW(StringStream)(NULL)), + insitustringstream(RAPIDJSON_NEW(InsituStringStream)(NULL)), // stringbuffer.h stringbuffer(RAPIDJSON_NEW(StringBuffer)), // // filereadstream.h - // filereadstream(RAPIDJSON_NEW(FileReadStream, stdout, buffer, sizeof(buffer))), + // filereadstream(RAPIDJSON_NEW(FileReadStream)(stdout, buffer, sizeof(buffer))), // // filewritestream.h - // filewritestream(RAPIDJSON_NEW(FileWriteStream, stdout, buffer, sizeof(buffer))), + // filewritestream(RAPIDJSON_NEW(FileWriteStream)(stdout, buffer, sizeof(buffer))), // memorybuffer.h memorybuffer(RAPIDJSON_NEW(MemoryBuffer)), // memorystream.h - memorystream(RAPIDJSON_NEW(MemoryStream, NULL, 0)), + memorystream(RAPIDJSON_NEW(MemoryStream)(NULL, 0)), // reader.h - basereaderhandler(RAPIDJSON_NEW((BaseReaderHandler, void>))), + basereaderhandler(RAPIDJSON_NEW(BaseReaderHandlerUtf8Void)), reader(RAPIDJSON_NEW(Reader)), // writer.h - writer(RAPIDJSON_NEW((Writer))), + writer(RAPIDJSON_NEW(Writer)), // prettywriter.h - prettywriter(RAPIDJSON_NEW((PrettyWriter))), + prettywriter(RAPIDJSON_NEW(PrettyWriter)), // document.h value(RAPIDJSON_NEW(Value)), @@ -154,8 +157,8 @@ Foo::Foo() : pointer(RAPIDJSON_NEW(Pointer)), // schema.h - schemadocument(RAPIDJSON_NEW(SchemaDocument, *document)), - schemavalidator(RAPIDJSON_NEW(SchemaValidator, *schemadocument)) + schemadocument(RAPIDJSON_NEW(SchemaDocument)(*document)), + schemavalidator(RAPIDJSON_NEW(SchemaValidator)(*schemadocument)) { }