From 33b7a4bae03a8b46a7fedcbae5be1a7fc0c86c6b Mon Sep 17 00:00:00 2001 From: Justin Scheiber Date: Tue, 5 May 2015 09:26:22 -0600 Subject: [PATCH 01/45] don't try to use google's servers --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 8e9d1f3..b54b211 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "thirdparty/gtest"] path = thirdparty/gtest - url = https://chromium.googlesource.com/external/googletest.git + url = ssh://git@git.eyesopen.com/common/rapidjson.git From 5be9b6e584656bbc94d894887ded663442a024fb Mon Sep 17 00:00:00 2001 From: Justin Scheiber Date: Tue, 5 May 2015 22:41:35 -0600 Subject: [PATCH 02/45] update the submodule fore google test --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index b54b211..25460de 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "thirdparty/gtest"] path = thirdparty/gtest - url = ssh://git@git.eyesopen.com/common/rapidjson.git + url = ssh://git@git.eyesopen.com/common/googletest.git From 013b71b92fdc835b53a61c739d6d57bd6c5627be Mon Sep 17 00:00:00 2001 From: Kal Conley Date: Sun, 31 May 2015 20:35:55 +0200 Subject: [PATCH 03/45] Fix warnings when compiling with clang and -Wimplicit-fallthrough --- include/rapidjson/reader.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/rapidjson/reader.h b/include/rapidjson/reader.h index 8989e38..43b2d9c 100644 --- a/include/rapidjson/reader.h +++ b/include/rapidjson/reader.h @@ -109,7 +109,7 @@ RAPIDJSON_DIAG_OFF(effc++) #define RAPIDJSON_PARSE_ERROR(parseErrorCode, offset) \ RAPIDJSON_MULTILINEMACRO_BEGIN \ RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode, offset); \ - RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; \ + return RAPIDJSON_NOTHING; \ RAPIDJSON_MULTILINEMACRO_END #endif From ce0184e73bd8eb14c3c5c8a894d7b4ee7ea75e37 Mon Sep 17 00:00:00 2001 From: miloyip Date: Wed, 3 Jun 2015 23:53:14 +0800 Subject: [PATCH 04/45] Add and fix -Wimplicit-fallthrough for clang, revert #350 --- include/rapidjson/reader.h | 14 +++++++------- test/unittest/CMakeLists.txt | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/rapidjson/reader.h b/include/rapidjson/reader.h index 43b2d9c..18c4ca5 100644 --- a/include/rapidjson/reader.h +++ b/include/rapidjson/reader.h @@ -109,7 +109,7 @@ RAPIDJSON_DIAG_OFF(effc++) #define RAPIDJSON_PARSE_ERROR(parseErrorCode, offset) \ RAPIDJSON_MULTILINEMACRO_BEGIN \ RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode, offset); \ - return RAPIDJSON_NOTHING; \ + RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; \ RAPIDJSON_MULTILINEMACRO_END #endif @@ -1387,13 +1387,13 @@ private: } switch (src) { - case IterativeParsingStartState: RAPIDJSON_PARSE_ERROR(kParseErrorDocumentEmpty, is.Tell()); - case IterativeParsingFinishState: RAPIDJSON_PARSE_ERROR(kParseErrorDocumentRootNotSingular, is.Tell()); + case IterativeParsingStartState: RAPIDJSON_PARSE_ERROR(kParseErrorDocumentEmpty, is.Tell()); return; + case IterativeParsingFinishState: RAPIDJSON_PARSE_ERROR(kParseErrorDocumentRootNotSingular, is.Tell()); return; case IterativeParsingObjectInitialState: - case IterativeParsingMemberDelimiterState: RAPIDJSON_PARSE_ERROR(kParseErrorObjectMissName, is.Tell()); - case IterativeParsingMemberKeyState: RAPIDJSON_PARSE_ERROR(kParseErrorObjectMissColon, is.Tell()); - case IterativeParsingMemberValueState: RAPIDJSON_PARSE_ERROR(kParseErrorObjectMissCommaOrCurlyBracket, is.Tell()); - case IterativeParsingElementState: RAPIDJSON_PARSE_ERROR(kParseErrorArrayMissCommaOrSquareBracket, is.Tell()); + case IterativeParsingMemberDelimiterState: RAPIDJSON_PARSE_ERROR(kParseErrorObjectMissName, is.Tell()); return; + case IterativeParsingMemberKeyState: RAPIDJSON_PARSE_ERROR(kParseErrorObjectMissColon, is.Tell()); return; + case IterativeParsingMemberValueState: RAPIDJSON_PARSE_ERROR(kParseErrorObjectMissCommaOrCurlyBracket, is.Tell()); return; + case IterativeParsingElementState: RAPIDJSON_PARSE_ERROR(kParseErrorArrayMissCommaOrSquareBracket, is.Tell()); return; default: RAPIDJSON_PARSE_ERROR(kParseErrorUnspecificSyntaxError, is.Tell()); } } diff --git a/test/unittest/CMakeLists.txt b/test/unittest/CMakeLists.txt index fb95b8e..fd2eb4d 100644 --- a/test/unittest/CMakeLists.txt +++ b/test/unittest/CMakeLists.txt @@ -21,7 +21,7 @@ set(UNITTEST_SOURCES if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wextra -Weffc++ -Wswitch-default -Wfloat-equal") elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wextra -Weffc++ -Wswitch-default -Wfloat-equal") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wextra -Weffc++ -Wswitch-default -Wfloat-equal -Wimplicit-fallthrough") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") add_definitions(-D_CRT_SECURE_NO_WARNINGS=1) endif() From 81678272a234c599e51d08b95caa2c4252958b71 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Thu, 4 Jun 2015 16:07:43 +0800 Subject: [PATCH 05/45] Fix #349 emscripten alignment issue --- emscripten/a.cpp | 24 ++++++++++++++++++++++++ include/rapidjson/allocators.h | 6 +++--- include/rapidjson/rapidjson.h | 2 +- 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 emscripten/a.cpp diff --git a/emscripten/a.cpp b/emscripten/a.cpp new file mode 100644 index 0000000..9114857 --- /dev/null +++ b/emscripten/a.cpp @@ -0,0 +1,24 @@ +#include +#include +#include +#include + +#define private public +#include "rapidjson/document.h" + +int main() { + // std::ifstream in_file("config.json", std::ios::in); + rapidjson::Document json_config_; + // std::string json_string( + // (std::istreambuf_iterator(in_file)), + // std::istreambuf_iterator()); + std::string json_string("{\"float_test\": 75.0}"); + // if (!json_string.empty()) { + json_config_.Parse(json_string.c_str()); + // } + + printf("%p\n", &json_config_); + printf("%p\n", &json_config_.data_.o.members[0].value.data_.n.d); + + std::cout << json_config_["float_test"].GetDouble() << std::endl; +} \ No newline at end of file diff --git a/include/rapidjson/allocators.h b/include/rapidjson/allocators.h index f615ffd..6be2776 100644 --- a/include/rapidjson/allocators.h +++ b/include/rapidjson/allocators.h @@ -181,7 +181,7 @@ public: if (chunkHead_ == 0 || chunkHead_->size + size > chunkHead_->capacity) AddChunk(chunk_capacity_ > size ? chunk_capacity_ : size); - void *buffer = reinterpret_cast(chunkHead_ + 1) + chunkHead_->size; + void *buffer = reinterpret_cast(chunkHead_) + RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + chunkHead_->size; chunkHead_->size += size; return buffer; } @@ -199,7 +199,7 @@ public: return originalPtr; // 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_) + RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + chunkHead_->size - originalSize) { size_t increment = static_cast(newSize - originalSize); increment = RAPIDJSON_ALIGN(increment); if (chunkHead_->size + increment <= chunkHead_->capacity) { @@ -231,7 +231,7 @@ private: void AddChunk(size_t capacity) { if (!baseAllocator_) ownBaseAllocator_ = baseAllocator_ = RAPIDJSON_NEW(BaseAllocator()); - ChunkHeader* chunk = reinterpret_cast(baseAllocator_->Malloc(sizeof(ChunkHeader) + capacity)); + ChunkHeader* chunk = reinterpret_cast(baseAllocator_->Malloc(RAPIDJSON_ALIGN(sizeof(ChunkHeader)) + capacity)); chunk->capacity = capacity; chunk->size = 0; chunk->next = chunkHead_; diff --git a/include/rapidjson/rapidjson.h b/include/rapidjson/rapidjson.h index f5d5630..b0dabc7 100644 --- a/include/rapidjson/rapidjson.h +++ b/include/rapidjson/rapidjson.h @@ -223,7 +223,7 @@ //! Whether using 64-bit architecture #ifndef RAPIDJSON_64BIT -#if defined(__LP64__) || defined(_WIN64) +#if defined(__LP64__) || defined(_WIN64) || defined(__EMSCRIPTEN__) #define RAPIDJSON_64BIT 1 #else #define RAPIDJSON_64BIT 0 From 935d0a39445d0f571421a94d92b431795b7142e5 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Fri, 5 Jun 2015 09:56:25 +0800 Subject: [PATCH 06/45] Remove emscripten test --- emscripten/a.cpp | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 emscripten/a.cpp diff --git a/emscripten/a.cpp b/emscripten/a.cpp deleted file mode 100644 index 9114857..0000000 --- a/emscripten/a.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include -#include -#include - -#define private public -#include "rapidjson/document.h" - -int main() { - // std::ifstream in_file("config.json", std::ios::in); - rapidjson::Document json_config_; - // std::string json_string( - // (std::istreambuf_iterator(in_file)), - // std::istreambuf_iterator()); - std::string json_string("{\"float_test\": 75.0}"); - // if (!json_string.empty()) { - json_config_.Parse(json_string.c_str()); - // } - - printf("%p\n", &json_config_); - printf("%p\n", &json_config_.data_.o.members[0].value.data_.n.d); - - std::cout << json_config_["float_test"].GetDouble() << std::endl; -} \ No newline at end of file From 3bc945fdce5badebaf64f383a2aab00dc76806a1 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Fri, 5 Jun 2015 09:57:11 +0800 Subject: [PATCH 07/45] Change documentation URL to http://www.rapidjson.org --- readme.md | 4 ++-- readme.zh-cn.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index 19da386..584e33b 100644 --- a/readme.md +++ b/readme.md @@ -10,8 +10,8 @@ Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights * [RapidJSON GitHub](https://github.com/miloyip/rapidjson/) * RapidJSON Documentation - * [English](http://miloyip.github.io/rapidjson/) - * [简体中文](http://miloyip.github.io/rapidjson/zh-cn/) + * [English](http://www.rapidjson.org/) + * [简体中文](http://www.rapidjson.org/zh-cn/) * [GitBook](https://www.gitbook.com/book/miloyip/rapidjson/) with downloadable PDF/EPUB/MOBI, without API reference. ## Build status diff --git a/readme.zh-cn.md b/readme.zh-cn.md index ec6bd90..ce9456f 100644 --- a/readme.zh-cn.md +++ b/readme.zh-cn.md @@ -10,8 +10,8 @@ Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights * [RapidJSON GitHub](https://github.com/miloyip/rapidjson/) * RapidJSON 文档 - * [English](http://miloyip.github.io/rapidjson/) - * [简体中文](http://miloyip.github.io/rapidjson/zh-cn/) + * [English](http://www.rapidjson.org/) + * [简体中文](http://www.rapidjson.org/zh-cn/) * [GitBook](https://www.gitbook.com/book/miloyip/rapidjson/)可下载PDF/EPUB/MOBI,但不含API参考手册。 ## Build 状态 From 93bf4ceb32da38a8f3c1d80333b063ee79de6a47 Mon Sep 17 00:00:00 2001 From: miloyip Date: Fri, 5 Jun 2015 14:08:15 +0800 Subject: [PATCH 08/45] Add CMAKE in travis-doxygen --- travis-doxygen.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/travis-doxygen.sh b/travis-doxygen.sh index ad80536..399df05 100755 --- a/travis-doxygen.sh +++ b/travis-doxygen.sh @@ -78,6 +78,7 @@ gh_pages_prepare() gh_pages_commit() { cd "${TRAVIS_BUILD_DIR}/build/doc/html"; + echo "www.rapidjson.org" > CNAME git add --all; git diff-index --quiet HEAD || git commit -m "Automatic doxygen build"; } From 19687067b74c2a23963c99c817a5e07fc47824fa Mon Sep 17 00:00:00 2001 From: miloyip Date: Sat, 6 Jun 2015 21:29:52 +0800 Subject: [PATCH 09/45] Try to remove www --- readme.md | 4 ++-- travis-doxygen.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index 584e33b..8682df1 100644 --- a/readme.md +++ b/readme.md @@ -10,8 +10,8 @@ Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights * [RapidJSON GitHub](https://github.com/miloyip/rapidjson/) * RapidJSON Documentation - * [English](http://www.rapidjson.org/) - * [简体中文](http://www.rapidjson.org/zh-cn/) + * [English](http://rapidjson.org/) + * [简体中文](http://rapidjson.org/zh-cn/) * [GitBook](https://www.gitbook.com/book/miloyip/rapidjson/) with downloadable PDF/EPUB/MOBI, without API reference. ## Build status diff --git a/travis-doxygen.sh b/travis-doxygen.sh index 399df05..1023108 100755 --- a/travis-doxygen.sh +++ b/travis-doxygen.sh @@ -78,7 +78,7 @@ gh_pages_prepare() gh_pages_commit() { cd "${TRAVIS_BUILD_DIR}/build/doc/html"; - echo "www.rapidjson.org" > CNAME + echo "rapidjson.org" > CNAME git add --all; git diff-index --quiet HEAD || git commit -m "Automatic doxygen build"; } From 4e8e99c1578a8042565c64d1d481dce15b0da5a7 Mon Sep 17 00:00:00 2001 From: miloyip Date: Sat, 6 Jun 2015 21:41:19 +0800 Subject: [PATCH 10/45] Remove www in readme.zh-cn also --- readme.zh-cn.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.zh-cn.md b/readme.zh-cn.md index ce9456f..5124f8e 100644 --- a/readme.zh-cn.md +++ b/readme.zh-cn.md @@ -10,8 +10,8 @@ Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights * [RapidJSON GitHub](https://github.com/miloyip/rapidjson/) * RapidJSON 文档 - * [English](http://www.rapidjson.org/) - * [简体中文](http://www.rapidjson.org/zh-cn/) + * [English](http://rapidjson.org/) + * [简体中文](http://rapidjson.org/zh-cn/) * [GitBook](https://www.gitbook.com/book/miloyip/rapidjson/)可下载PDF/EPUB/MOBI,但不含API参考手册。 ## Build 状态 From 134369d990018b3229d163932e42bf4b684aa0b5 Mon Sep 17 00:00:00 2001 From: miloyip Date: Wed, 10 Jun 2015 16:19:24 +0800 Subject: [PATCH 11/45] Add google analytics to documentation --- doc/misc/header.html | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/misc/header.html b/doc/misc/header.html index 2dbe721..d43f2aa 100644 --- a/doc/misc/header.html +++ b/doc/misc/header.html @@ -16,6 +16,15 @@ $mathjax $extrastylesheet +
From a326314a6138b700b9443130ee6b0e76afe011ee Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Thu, 18 Jun 2015 15:40:39 +0800 Subject: [PATCH 12/45] Fix #538 --- include/rapidjson/reader.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/rapidjson/reader.h b/include/rapidjson/reader.h index 18c4ca5..9a17301 100644 --- a/include/rapidjson/reader.h +++ b/include/rapidjson/reader.h @@ -271,7 +271,7 @@ inline const char *SkipWhitespace_SIMD(const char* p) { // The rest of string using SIMD static const char whitespace[16] = " \n\r\t"; - const __m128i w = _mm_load_si128((const __m128i *)&whitespace[0]); + const __m128i w = _mm_loadu_si128((const __m128i *)&whitespace[0]); for (;; p += 16) { const __m128i s = _mm_load_si128((const __m128i *)p); From 74b41c1a430ed9e6b6f3c2e5c6f906f3c4520a63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20=C5=81oskot?= Date: Wed, 24 Jun 2015 17:22:48 +0200 Subject: [PATCH 13/45] Add missing allocator to uses of AddMember AddMember requires allocator, this fix keeps all uses of AddMember consistent across the whole tutorial. --- doc/tutorial.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/tutorial.md b/doc/tutorial.md index 3508918..1211023 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -292,12 +292,13 @@ The simple answer is performance. For fixed size JSON types (Number, True, False For example, if normal *copy* semantics was used: ~~~~~~~~~~cpp +Document d; Value o(kObjectType); { Value contacts(kArrayType); // adding elements to contacts array. // ... - o.AddMember("contacts", contacts); // deep clone contacts (may be with lots of allocations) + o.AddMember("contacts", contacts, d.GetAllocator()); // deep clone contacts (may be with lots of allocations) // destruct contacts. } ~~~~~~~~~~ @@ -313,11 +314,12 @@ To make RapidJSON simple and fast, we chose to use *move* semantics for assignme So, with move semantics, the above example becomes: ~~~~~~~~~~cpp +Document d; Value o(kObjectType); { Value contacts(kArrayType); // adding elements to contacts array. - o.AddMember("contacts", contacts); // just memcpy() of contacts itself to the value of new member (16 bytes) + o.AddMember("contacts", contacts, d.GetAllocator()); // just memcpy() of contacts itself to the value of new member (16 bytes) // contacts became Null here. Its destruction is trivial. } ~~~~~~~~~~ From 5d5d90c10079284c15b9a7a6795bdc8608f2be84 Mon Sep 17 00:00:00 2001 From: miloyip Date: Thu, 25 Jun 2015 09:53:31 +0800 Subject: [PATCH 14/45] Applies the same changes for Chinese as #365 --- doc/tutorial.zh-cn.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/tutorial.zh-cn.md b/doc/tutorial.zh-cn.md index d1381be..3ecaec8 100644 --- a/doc/tutorial.zh-cn.md +++ b/doc/tutorial.zh-cn.md @@ -297,7 +297,7 @@ Value o(kObjectType); Value contacts(kArrayType); // 把元素加进contacts数组。 // ... - o.AddMember("contacts", contacts); // 深度复制contacts (可能有大量内存分配) + o.AddMember("contacts", contacts, d.GetAllocator()); // 深度复制contacts (可能有大量内存分配) // 析构contacts。 } ~~~~~~~~~~ @@ -317,7 +317,7 @@ Value o(kObjectType); { Value contacts(kArrayType); // adding elements to contacts array. - o.AddMember("contacts", contacts); // 只需 memcpy() contacts本身至新成员的Value(16字节) + o.AddMember("contacts", contacts, d.GetAllocator()); // 只需 memcpy() contacts本身至新成员的Value(16字节) // contacts在这里变成Null。它的析构是平凡的。 } ~~~~~~~~~~ From 413144a8b21270883bfe9d20723441ac12b414dc Mon Sep 17 00:00:00 2001 From: Mateusz Loskot Date: Fri, 26 Jun 2015 16:00:49 +0200 Subject: [PATCH 15/45] Add GenericDocument ctor overload to specify JSON type. It unifies the interfaces with Value where kXXXType can be passed into constructor. It enables shortcut that helps to avoid extra SetXXX() call following construction of a document. --- include/rapidjson/document.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 889cdfa..1b3a4f3 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -1748,6 +1748,13 @@ public: typedef GenericValue ValueType; //!< Value type of the document. typedef Allocator AllocatorType; //!< Allocator type from template parameter. + GenericDocument(Type type, Allocator* allocator = 0, size_t stackCapacity = kDefaultStackCapacity, StackAllocator* stackAllocator = 0) : + GenericValue(type), allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_() + { + if (!allocator_) + ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator()); + } + //! Constructor /*! \param allocator Optional allocator for allocating memory. \param stackCapacity Optional initial capacity of stack in bytes. From a0177ca210c2e9e047ec747a71cca7c3d7683ece Mon Sep 17 00:00:00 2001 From: Mateusz Loskot Date: Tue, 30 Jun 2015 10:28:07 +0200 Subject: [PATCH 16/45] Add documentation for new GenericDocument ctor taking object type. Update also documentation of the existing GenericDocument constructor. --- include/rapidjson/document.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 1b3a4f3..026c2fb 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -1748,6 +1748,13 @@ public: typedef GenericValue ValueType; //!< Value type of the document. typedef Allocator AllocatorType; //!< Allocator type from template parameter. + //! Constructor + /*! Creates an empty document of specified type. + \param type Mandatory type of object to create. + \param allocator Optional allocator for allocating memory. + \param stackCapacity Optional initial capacity of stack in bytes. + \param stackAllocator Optional allocator for allocating memory for stack. + */ GenericDocument(Type type, Allocator* allocator = 0, size_t stackCapacity = kDefaultStackCapacity, StackAllocator* stackAllocator = 0) : GenericValue(type), allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_() { @@ -1756,7 +1763,8 @@ public: } //! Constructor - /*! \param allocator Optional allocator for allocating memory. + /*! Creates an empty document which type is Null. + \param allocator Optional allocator for allocating memory. \param stackCapacity Optional initial capacity of stack in bytes. \param stackAllocator Optional allocator for allocating memory for stack. */ From 3c47ae9fe47b39ea1073b7598c77dbf7abe94fd1 Mon Sep 17 00:00:00 2001 From: Mateusz Loskot Date: Tue, 30 Jun 2015 11:33:44 +0200 Subject: [PATCH 17/45] Add to FAQ: How to clear-and-minimize a document? Closes #368 --- doc/faq.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/doc/faq.md b/doc/faq.md index b00b4c6..093e8e7 100644 --- a/doc/faq.md +++ b/doc/faq.md @@ -102,6 +102,21 @@ Some applications use 64-bit unsigned/signed integers. And these integers cannot be converted into `double` without loss of precision. So the parsers detects whether a JSON number is convertible to different types of integers and/or `double`. +8. How to clear-and-minimize a document or value? + +* Call one of the `SetXXX()` methods - they call destructor which deallocates DOM data: + + ``` + Document d; + ... + d.SetObject(); // clear and minimize + ``` + +* Alternatively, use equivalent of the [C++ swap with temporary idiom](https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Clear-and-minimize): + ``` + d.Swap(Value(kObjectType).Move()) + ``` + ## Document/Value (DOM) 1. What is move semantics? Why? From 8197805208304499487e0719555d084625606850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20=C5=81oskot?= Date: Wed, 1 Jul 2015 22:36:26 +0200 Subject: [PATCH 18/45] Add explicit specifier to GenericDocument ctor. @pah recommended to mark this constructor as explicit to avoid accidentally creating a temporary GenericDocument from a Type enum value (because all arguments but the first one are optional). --- include/rapidjson/document.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 026c2fb..a20d644 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -1755,7 +1755,7 @@ public: \param stackCapacity Optional initial capacity of stack in bytes. \param stackAllocator Optional allocator for allocating memory for stack. */ - GenericDocument(Type type, Allocator* allocator = 0, size_t stackCapacity = kDefaultStackCapacity, StackAllocator* stackAllocator = 0) : + explicit GenericDocument(Type type, Allocator* allocator = 0, size_t stackCapacity = kDefaultStackCapacity, StackAllocator* stackAllocator = 0) : GenericValue(type), allocator_(allocator), ownAllocator_(0), stack_(stackAllocator, stackCapacity), parseResult_() { if (!allocator_) From 50660c093d7a483642fca27e5adfafe74fc601d0 Mon Sep 17 00:00:00 2001 From: Mateusz Loskot Date: Thu, 2 Jul 2015 14:00:52 +0200 Subject: [PATCH 19/45] Add to FAQ: How to insert a document node into another document? Closes #366 --- doc/faq.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/doc/faq.md b/doc/faq.md index 093e8e7..da0d39e 100644 --- a/doc/faq.md +++ b/doc/faq.md @@ -117,6 +117,45 @@ d.Swap(Value(kObjectType).Move()) ``` +9. How to insert a document node into another document? + +Let's take the following two DOM trees represented as JSON documents: + ``` + Document person; + person.Parse("{\"person\":{\"name\":{\"first\":\"Adam\",\"last\":\"Thomas\"}}}"); + + Document address; + address.Parse("{\"address\":{\"city\":\"Moscow\",\"street\":\"Quiet\"}}"); + ``` +Let's assume we want to merge them in such way that the whole `address` document becomes a node of the `person`: + ``` + { "person": { + "name": { "first": "Adam", "last": "Thomas" }, + "address": { "city": "Moscow", "street": "Quiet" } + } + } + ``` + +The most important requirement to take care of document and value life-cycle as well as consistent memory managent using the right allocator during the value transfer. + +* Simple yet most efficient way to achieve that is to modify the `address` definition above to initialize it with allocator of the `person` document, then we just add the root nenber of the value: + ``` + Documnet address(person.GetAllocator()); + ... + person["person"].AddMember("address", address["address"], person.GetAllocator()); + ``` +Alternatively, if we don't want to explicitly refer to the root value of `address` by name, we can refer to it via iterator: + ``` + auto addressRoot = address.MemberBegin(); + person["person"].AddMember(addressRoot->name, addressRoot->value, person.GetAllocator()); + ``` + +* Second way is to deep-clone the value from the address document: + ``` + Value addressValue = Value(address["address"], person.GetAllocator()); + person["person"].AddMember("address", addressValue, person.GetAllocator()); + ``` + ## Document/Value (DOM) 1. What is move semantics? Why? From 5ac04cb0123104c3cd5afc0bec6941ae149b2725 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20=C5=81oskot?= Date: Thu, 2 Jul 2015 14:05:30 +0200 Subject: [PATCH 20/45] Correct formatting of FAQ 8 and 9 --- doc/faq.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/faq.md b/doc/faq.md index da0d39e..1ff6e08 100644 --- a/doc/faq.md +++ b/doc/faq.md @@ -104,7 +104,7 @@ 8. How to clear-and-minimize a document or value? -* Call one of the `SetXXX()` methods - they call destructor which deallocates DOM data: + Call one of the `SetXXX()` methods - they call destructor which deallocates DOM data: ``` Document d; @@ -112,14 +112,14 @@ d.SetObject(); // clear and minimize ``` -* Alternatively, use equivalent of the [C++ swap with temporary idiom](https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Clear-and-minimize): + Alternatively, use equivalent of the [C++ swap with temporary idiom](https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Clear-and-minimize): ``` d.Swap(Value(kObjectType).Move()) ``` 9. How to insert a document node into another document? -Let's take the following two DOM trees represented as JSON documents: + Let's take the following two DOM trees represented as JSON documents: ``` Document person; person.Parse("{\"person\":{\"name\":{\"first\":\"Adam\",\"last\":\"Thomas\"}}}"); @@ -127,7 +127,7 @@ Let's take the following two DOM trees represented as JSON documents: Document address; address.Parse("{\"address\":{\"city\":\"Moscow\",\"street\":\"Quiet\"}}"); ``` -Let's assume we want to merge them in such way that the whole `address` document becomes a node of the `person`: + Let's assume we want to merge them in such way that the whole `address` document becomes a node of the `person`: ``` { "person": { "name": { "first": "Adam", "last": "Thomas" }, @@ -136,9 +136,9 @@ Let's assume we want to merge them in such way that the whole `address` document } ``` -The most important requirement to take care of document and value life-cycle as well as consistent memory managent using the right allocator during the value transfer. + The most important requirement to take care of document and value life-cycle as well as consistent memory managent using the right allocator during the value transfer. -* Simple yet most efficient way to achieve that is to modify the `address` definition above to initialize it with allocator of the `person` document, then we just add the root nenber of the value: + Simple yet most efficient way to achieve that is to modify the `address` definition above to initialize it with allocator of the `person` document, then we just add the root nenber of the value: ``` Documnet address(person.GetAllocator()); ... @@ -150,7 +150,7 @@ Alternatively, if we don't want to explicitly refer to the root value of `addres person["person"].AddMember(addressRoot->name, addressRoot->value, person.GetAllocator()); ``` -* Second way is to deep-clone the value from the address document: + Second way is to deep-clone the value from the address document: ``` Value addressValue = Value(address["address"], person.GetAllocator()); person["person"].AddMember("address", addressValue, person.GetAllocator()); From 6610577a3e38814e86abc04818643712f0db544a Mon Sep 17 00:00:00 2001 From: Mateusz Loskot Date: Thu, 2 Jul 2015 14:14:51 +0200 Subject: [PATCH 21/45] Update FAQ 8 with shorter version of clean-and-minimize idiom. Credits to @pah who suggested it in comment to #368. --- doc/faq.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/faq.md b/doc/faq.md index 093e8e7..2e8de47 100644 --- a/doc/faq.md +++ b/doc/faq.md @@ -114,7 +114,11 @@ * Alternatively, use equivalent of the [C++ swap with temporary idiom](https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Clear-and-minimize): ``` - d.Swap(Value(kObjectType).Move()) + Value(kObjectType).Swap(d); + ``` + or equivalent, but sightly longer to type: + ``` + d.Swap(Value(kObjectType).Move()); ``` ## Document/Value (DOM) From dd901f498b858ada40aaea8fc158d5d067701ae8 Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Sat, 4 Jul 2015 01:57:24 +0200 Subject: [PATCH 22/45] add GenericDocument<>::Swap See #368. --- include/rapidjson/document.h | 16 ++++++++++++++++ include/rapidjson/internal/stack.h | 13 +++++++++++++ test/unittest/documenttest.cpp | 14 +++++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 889cdfa..5eeef9c 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -1803,6 +1803,22 @@ public: } #endif + //! Exchange the contents of this document with those of another. + /*! + \param other Another document. + \note Constant complexity. + \see GenericValue::Swap + */ + GenericDocument& Swap(GenericDocument& rhs) RAPIDJSON_NOEXCEPT { + using std::swap; + ValueType::Swap(rhs); + stack_.Swap(rhs.stack_); + swap(allocator_, rhs.allocator_); + swap(ownAllocator_, rhs.ownAllocator_); + swap(parseResult_, rhs.parseResult_); + return *this; + } + //!@name Parse from stream //!@{ diff --git a/include/rapidjson/internal/stack.h b/include/rapidjson/internal/stack.h index bb31cc0..198c866 100644 --- a/include/rapidjson/internal/stack.h +++ b/include/rapidjson/internal/stack.h @@ -15,6 +15,8 @@ #ifndef RAPIDJSON_INTERNAL_STACK_H_ #define RAPIDJSON_INTERNAL_STACK_H_ +#include // std::swap + #include "../rapidjson.h" RAPIDJSON_NAMESPACE_BEGIN @@ -81,6 +83,17 @@ public: } #endif + void Swap(Stack& rhs) RAPIDJSON_NOEXCEPT { + using std::swap; + + swap(allocator_, rhs.allocator_); + swap(ownAllocator_, rhs.ownAllocator_); + swap(stack_, rhs.stack_); + swap(stackTop_, rhs.stackTop_); + swap(stackEnd_, rhs.stackEnd_); + swap(initialCapacity_, rhs.initialCapacity_); + } + void Clear() { stackTop_ = stack_; } void ShrinkToFit() { diff --git a/test/unittest/documenttest.cpp b/test/unittest/documenttest.cpp index 2ee6b10..3db7cd8 100644 --- a/test/unittest/documenttest.cpp +++ b/test/unittest/documenttest.cpp @@ -202,7 +202,8 @@ TEST(Document, Swap) { o.SetObject().AddMember("a", 1, a); // Swap between Document and Value - d1.Swap(o); + // d1.Swap(o); // doesn't compile + o.Swap(d1); EXPECT_TRUE(d1.IsObject()); EXPECT_TRUE(o.IsArray()); @@ -212,8 +213,19 @@ TEST(Document, Swap) { d1.Swap(d2); EXPECT_TRUE(d1.IsArray()); EXPECT_TRUE(d2.IsObject()); + EXPECT_EQ(&d2.GetAllocator(), &a); + + // reset value + Value().Swap(d1); + EXPECT_TRUE(d1.IsNull()); + + // reset document, including allocator + Document().Swap(d2); + EXPECT_TRUE(d2.IsNull()); + EXPECT_NE(&d2.GetAllocator(), &a); } + // This should be slow due to assignment in inner-loop. struct OutputStringStream : public std::ostringstream { typedef char Ch; From 8e61b726780511c71c47109abec75888d74358a2 Mon Sep 17 00:00:00 2001 From: yuzhaol Date: Thu, 9 Jul 2015 22:39:38 +0100 Subject: [PATCH 23/45] Declare intrinsic function to avoid LNK2019 in x64 debug mode Add #pragma intrinsic(_umul128) for MSVS 2005 --- include/rapidjson/internal/biginteger.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/rapidjson/internal/biginteger.h b/include/rapidjson/internal/biginteger.h index 99a30ac..e06e7e0 100755 --- a/include/rapidjson/internal/biginteger.h +++ b/include/rapidjson/internal/biginteger.h @@ -19,6 +19,7 @@ #if defined(_MSC_VER) && defined(_M_AMD64) #include // for _umul128 +#pragma intrinsic(_umul128) #endif RAPIDJSON_NAMESPACE_BEGIN From 7567752710bf4149dd0bb33f3c7f0fd6d1386328 Mon Sep 17 00:00:00 2001 From: yuzhaol Date: Thu, 9 Jul 2015 22:42:24 +0100 Subject: [PATCH 24/45] Declare intrinsic function to avoid LNK2019 in x64 debug mode Add #pragma intrinsic(_umul128) for MSVS 2005 --- include/rapidjson/internal/diyfp.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/rapidjson/internal/diyfp.h b/include/rapidjson/internal/diyfp.h index 3b6c423..d01bbe8 100644 --- a/include/rapidjson/internal/diyfp.h +++ b/include/rapidjson/internal/diyfp.h @@ -24,6 +24,7 @@ #if defined(_MSC_VER) && defined(_M_AMD64) #include #pragma intrinsic(_BitScanReverse64) +#pragma intrinsic(_umul128) #endif RAPIDJSON_NAMESPACE_BEGIN From 0ebe16e1695fd9ed31f933a269d13a05d73eaf2e Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Fri, 10 Jul 2015 17:06:52 +0200 Subject: [PATCH 25/45] add and use simplified "internal::Swap" This avoids the dependency on the header, as suggested by @miloyip in #376. --- include/rapidjson/document.h | 7 +++--- include/rapidjson/internal/stack.h | 17 ++++++-------- include/rapidjson/internal/swap.h | 37 ++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 14 deletions(-) create mode 100644 include/rapidjson/internal/swap.h diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 5eeef9c..3496c2b 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -1810,12 +1810,11 @@ public: \see GenericValue::Swap */ GenericDocument& Swap(GenericDocument& rhs) RAPIDJSON_NOEXCEPT { - using std::swap; ValueType::Swap(rhs); stack_.Swap(rhs.stack_); - swap(allocator_, rhs.allocator_); - swap(ownAllocator_, rhs.ownAllocator_); - swap(parseResult_, rhs.parseResult_); + internal::Swap(allocator_, rhs.allocator_); + internal::Swap(ownAllocator_, rhs.ownAllocator_); + internal::Swap(parseResult_, rhs.parseResult_); return *this; } diff --git a/include/rapidjson/internal/stack.h b/include/rapidjson/internal/stack.h index 198c866..0d4a7f7 100644 --- a/include/rapidjson/internal/stack.h +++ b/include/rapidjson/internal/stack.h @@ -15,9 +15,8 @@ #ifndef RAPIDJSON_INTERNAL_STACK_H_ #define RAPIDJSON_INTERNAL_STACK_H_ -#include // std::swap - #include "../rapidjson.h" +#include "swap.h" RAPIDJSON_NAMESPACE_BEGIN namespace internal { @@ -84,14 +83,12 @@ public: #endif void Swap(Stack& rhs) RAPIDJSON_NOEXCEPT { - using std::swap; - - swap(allocator_, rhs.allocator_); - swap(ownAllocator_, rhs.ownAllocator_); - swap(stack_, rhs.stack_); - swap(stackTop_, rhs.stackTop_); - swap(stackEnd_, rhs.stackEnd_); - swap(initialCapacity_, rhs.initialCapacity_); + internal::Swap(allocator_, rhs.allocator_); + internal::Swap(ownAllocator_, rhs.ownAllocator_); + internal::Swap(stack_, rhs.stack_); + internal::Swap(stackTop_, rhs.stackTop_); + internal::Swap(stackEnd_, rhs.stackEnd_); + internal::Swap(initialCapacity_, rhs.initialCapacity_); } void Clear() { stackTop_ = stack_; } diff --git a/include/rapidjson/internal/swap.h b/include/rapidjson/internal/swap.h new file mode 100644 index 0000000..41e7e20 --- /dev/null +++ b/include/rapidjson/internal/swap.h @@ -0,0 +1,37 @@ +// Tencent is pleased to support the open source community by making RapidJSON available. +// +// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. +// +// Licensed under the MIT License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// http://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software distributed +// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +// CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +#ifndef RAPIDJSON_INTERNAL_SWAP_H_ +#define RAPIDJSON_INTERNAL_SWAP_H_ + +#include "../rapidjson.h" + +RAPIDJSON_NAMESPACE_BEGIN +namespace internal { + +//! Custom swap() to avoid dependency on C++ header +/*! \tparam T Type of the arguments to swap, should be instantiated with primitive C++ types only. + \note This has the same semantics as std::swap(). +*/ +template +inline void Swap(T& a, T& b) RAPIDJSON_NOEXCEPT { + T tmp = a; + a = b; + b = tmp; +} + +} // namespace internal +RAPIDJSON_NAMESPACE_END + +#endif // RAPIDJSON_INTERNAL_SWAP_H_ From 46e1696316e2d33c0198af2138ab481d985439f0 Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Mon, 13 Jul 2015 09:35:15 +0200 Subject: [PATCH 26/45] add free inline `swap` functions --- include/rapidjson/document.h | 4 ++++ test/unittest/documenttest.cpp | 12 ++++++++++++ test/unittest/valuetest.cpp | 6 ++++++ 3 files changed, 22 insertions(+) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 3496c2b..007fa94 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -660,6 +660,8 @@ public: return *this; } + friend inline void swap(GenericValue& a, GenericValue& b) RAPIDJSON_NOEXCEPT { a.Swap(b); } + //! Prepare Value for move semantics /*! \return *this */ GenericValue& Move() RAPIDJSON_NOEXCEPT { return *this; } @@ -1818,6 +1820,8 @@ public: return *this; } + friend inline void swap(GenericDocument& a, GenericDocument& b) RAPIDJSON_NOEXCEPT { a.Swap(b); } + //!@name Parse from stream //!@{ diff --git a/test/unittest/documenttest.cpp b/test/unittest/documenttest.cpp index 3db7cd8..810a99c 100644 --- a/test/unittest/documenttest.cpp +++ b/test/unittest/documenttest.cpp @@ -19,6 +19,7 @@ #include "rapidjson/encodedstream.h" #include "rapidjson/stringbuffer.h" #include +#include using namespace rapidjson; @@ -223,6 +224,17 @@ TEST(Document, Swap) { Document().Swap(d2); EXPECT_TRUE(d2.IsNull()); EXPECT_NE(&d2.GetAllocator(), &a); + + // testing std::swap compatibility + d1.SetBool(true); + using std::swap; + swap(d1, d2); + EXPECT_TRUE(d1.IsNull()); + EXPECT_TRUE(d2.IsTrue()); + + swap(o, d2); + EXPECT_TRUE(o.IsTrue()); + EXPECT_TRUE(d2.IsArray()); } diff --git a/test/unittest/valuetest.cpp b/test/unittest/valuetest.cpp index f14669a..900783c 100644 --- a/test/unittest/valuetest.cpp +++ b/test/unittest/valuetest.cpp @@ -272,6 +272,12 @@ TEST(Value, Swap) { EXPECT_TRUE(v1.IsObject()); EXPECT_TRUE(v2.IsInt()); EXPECT_EQ(1234, v2.GetInt()); + + // testing std::swap compatibility + using std::swap; + swap(v1, v2); + EXPECT_TRUE(v1.IsInt()); + EXPECT_TRUE(v2.IsObject()); } TEST(Value, Null) { From c2b586492724c7bbfa8bf176caee400b19f66681 Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Mon, 13 Jul 2015 14:38:24 +0200 Subject: [PATCH 27/45] add documentation for 'swap' friend functions --- include/rapidjson/document.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 007fa94..ae7e829 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -660,6 +660,18 @@ public: return *this; } + //! free-standing swap function helper + /*! + Helper function to enable support for common swap implementation pattern based on \c std::swap: + \code + void swap(MyClass& a, MyClass& b) { + using std::swap; + swap(a.value, b.value); + // ... + } + \endcode + \see Swap() + */ friend inline void swap(GenericValue& a, GenericValue& b) RAPIDJSON_NOEXCEPT { a.Swap(b); } //! Prepare Value for move semantics @@ -1820,6 +1832,18 @@ public: return *this; } + //! free-standing swap function helper + /*! + Helper function to enable support for common swap implementation pattern based on \c std::swap: + \code + void swap(MyClass& a, MyClass& b) { + using std::swap; + swap(a.doc, b.doc); + // ... + } + \endcode + \see Swap() + */ friend inline void swap(GenericDocument& a, GenericDocument& b) RAPIDJSON_NOEXCEPT { a.Swap(b); } //!@name Parse from stream From fec9e8a4f2df708dc98e17e69f98823797f91f33 Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Fri, 17 Jul 2015 08:24:43 +0200 Subject: [PATCH 28/45] prohibit C++11 move from Document to Value As reported in #387, silently moving a `GenericDocument` to a `GenericValue` can lead to object slicing and premature deletion of the owning allocator of the (surviving) `GenericValue`. To reduce this risk, prohibit move construction of a `GenericValue` from a `GenericDocument`. --- include/rapidjson/document.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index d0f1c8f..f5c1be9 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -69,6 +69,9 @@ RAPIDJSON_NAMESPACE_BEGIN template class GenericValue; +template +class GenericDocument; + //! Name-value pair in a JSON object value. /*! This class was internal to GenericValue. It used to be a inner struct. @@ -446,6 +449,16 @@ private: //! Copy constructor is not permitted. GenericValue(const GenericValue& rhs); +#if RAPIDJSON_HAS_CXX11_RVALUE_REFS + //! Moving from a GenericDocument is not permitted. + template + GenericValue(GenericDocument&& rhs); + + //! Move assignment from a GenericDocument is not permitted. + template + GenericValue& operator=(GenericDocument&& rhs); +#endif + public: //! Constructor with JSON value type. @@ -1792,7 +1805,7 @@ public: #if RAPIDJSON_HAS_CXX11_RVALUE_REFS //! Move constructor in C++11 GenericDocument(GenericDocument&& rhs) RAPIDJSON_NOEXCEPT - : ValueType(std::move(rhs)), + : ValueType(std::forward(rhs)), // explicit cast to avoid prohibited move from Document allocator_(rhs.allocator_), ownAllocator_(rhs.ownAllocator_), stack_(std::move(rhs.stack_)), From 8c0e50f5962a3bd672a5fa85ae2ea0e5b8d2cffb Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Mon, 20 Jul 2015 09:29:15 +0800 Subject: [PATCH 29/45] Update dom.md --- doc/dom.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/dom.md b/doc/dom.md index f3e4208..24f1a39 100644 --- a/doc/dom.md +++ b/doc/dom.md @@ -124,7 +124,7 @@ And the `InputStream` is type of input stream. ## Parse Error {#ParseError} -When the parse processing succeeded, the `Document` contains the parse results. When there is an error, the original DOM is *unchanged*. And the error state of parsing can be obtained by `bool HasParseError()`, `ParseErrorCode GetParseError()` and `size_t GetParseOffet()`. +When the parse processing succeeded, the `Document` contains the parse results. When there is an error, the original DOM is *unchanged*. And the error state of parsing can be obtained by `bool HasParseError()`, `ParseErrorCode GetParseError()` and `size_t GetParseOffset()`. Parse Error Code | Description --------------------------------------------|--------------------------------------------------- @@ -159,8 +159,8 @@ Here shows an example of parse error handling. Document d; if (d.Parse(json).HasParseError()) { fprintf(stderr, "\nError(offset %u): %s\n", - (unsigned)reader.GetErrorOffset(), - GetParseError_En(reader.GetParseErrorCode())); + (unsigned)d.GetErrorOffset(), + GetParseError_En(d.GetParseErrorCode())); // ... } ~~~~~~~~~~ From f431aaff9dd9fd2f167b2a68d3a1f2e9666b6265 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Mon, 20 Jul 2015 09:29:46 +0800 Subject: [PATCH 30/45] Update dom.zh-cn.md --- doc/dom.zh-cn.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/dom.zh-cn.md b/doc/dom.zh-cn.md index c7fcfff..bb4eafb 100644 --- a/doc/dom.zh-cn.md +++ b/doc/dom.zh-cn.md @@ -124,7 +124,7 @@ GenericDocument& GenericDocument::Parse(const Ch* str); ## 解析错误 {#ParseError} -当解析过程顺利完成,`Document`便会含有解析结果。当过程出现错误,原来的DOM会*维持不便*。可使用`bool HasParseError()`、`ParseErrorCode GetParseError()`及`size_t GetParseOffet()`获取解析的错误状态。 +当解析过程顺利完成,`Document`便会含有解析结果。当过程出现错误,原来的DOM会*维持不便*。可使用`bool HasParseError()`、`ParseErrorCode GetParseError()`及`size_t GetParseOffset()`获取解析的错误状态。 解析错误代号 | 描述 --------------------------------------------|--------------------------------------------------- @@ -159,8 +159,8 @@ GenericDocument& GenericDocument::Parse(const Ch* str); Document d; if (d.Parse(json).HasParseError()) { fprintf(stderr, "\nError(offset %u): %s\n", - (unsigned)reader.GetErrorOffset(), - GetParseError_En(reader.GetParseErrorCode())); + (unsigned)d.GetErrorOffset(), + GetParseError_En(d.GetParseErrorCode())); // ... } ~~~~~~~~~~ From b4b1a39937fbd168ef72ea477f90f626773d56fc Mon Sep 17 00:00:00 2001 From: Bas Couwenberg Date: Tue, 21 Jul 2015 08:46:36 +0200 Subject: [PATCH 31/45] Clarify problematic JSON license (#377) --- license.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/license.txt b/license.txt index a1bb283..03e66d6 100644 --- a/license.txt +++ b/license.txt @@ -3,7 +3,7 @@ Tencent is pleased to support the open source community by making RapidJSON avai Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. If you have downloaded a copy of the RapidJSON binary from Tencent, please note that the RapidJSON binary is licensed under the MIT License. -If you have downloaded a copy of the RapidJSON source code from Tencent, please note that RapidJSON source code is licensed under the MIT License, except for the third-party components listed below which are subject to different license terms. Your integration of RapidJSON into your own projects may require compliance with the MIT License, as well as the other licenses applicable to the third-party components included within RapidJSON. +If you have downloaded a copy of the RapidJSON source code from Tencent, please note that RapidJSON source code is licensed under the MIT License, except for the third-party components listed below which are subject to different license terms. Your integration of RapidJSON into your own projects may require compliance with the MIT License, as well as the other licenses applicable to the third-party components included within RapidJSON. To avoid the problematic JSON license in your own projects, it's sufficient to exclude the bin/jsonchecker/ directory, as it's the only code under the JSON license. A copy of the MIT License is included in this file. Other dependencies and licenses: From d26d50092ddf2917a73137ff27c04fdc76271e73 Mon Sep 17 00:00:00 2001 From: scheiber Date: Tue, 21 Jul 2015 15:15:42 -0600 Subject: [PATCH 32/45] fixing sign conversion warnings and loss of precision warnings --- include/rapidjson/encodedstream.h | 2 +- include/rapidjson/internal/biginteger.h | 2 +- include/rapidjson/internal/diyfp.h | 4 ++-- include/rapidjson/internal/dtoa.h | 8 ++++---- include/rapidjson/internal/ieee754.h | 2 +- include/rapidjson/internal/strtod.h | 22 +++++++++++----------- include/rapidjson/writer.h | 10 +++++----- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/include/rapidjson/encodedstream.h b/include/rapidjson/encodedstream.h index 9a93b38..7bc6ad3 100644 --- a/include/rapidjson/encodedstream.h +++ b/include/rapidjson/encodedstream.h @@ -146,7 +146,7 @@ private: if (!c) return; - unsigned bom = c[0] | (c[1] << 8) | (c[2] << 16) | (c[3] << 24); + unsigned bom = static_cast(c[0] | (c[1] << 8) | (c[2] << 16) | (c[3] << 24)); hasBOM_ = false; if (bom == 0xFFFE0000) { type_ = kUTF32BE; hasBOM_ = true; is_->Take(); is_->Take(); is_->Take(); is_->Take(); } else if (bom == 0x0000FEFF) { type_ = kUTF32LE; hasBOM_ = true; is_->Take(); is_->Take(); is_->Take(); is_->Take(); } diff --git a/include/rapidjson/internal/biginteger.h b/include/rapidjson/internal/biginteger.h index 99a30ac..d1732a0 100755 --- a/include/rapidjson/internal/biginteger.h +++ b/include/rapidjson/internal/biginteger.h @@ -230,7 +230,7 @@ private: uint64_t r = 0; for (const char* p = begin; p != end; ++p) { RAPIDJSON_ASSERT(*p >= '0' && *p <= '9'); - r = r * 10 + (*p - '0'); + r = r * 10u + (unsigned)(*p - '0'); } return r; } diff --git a/include/rapidjson/internal/diyfp.h b/include/rapidjson/internal/diyfp.h index 3b6c423..42d8b3b 100644 --- a/include/rapidjson/internal/diyfp.h +++ b/include/rapidjson/internal/diyfp.h @@ -232,8 +232,8 @@ inline DiyFp GetCachedPower(int e, int* K) { } inline DiyFp GetCachedPower10(int exp, int *outExp) { - unsigned index = (exp + 348) / 8; - *outExp = -348 + index * 8; + unsigned index = (static_cast(exp) + 348u) / 8u; + *outExp = -348 + static_cast(index) * 8; return GetCachedPowerByIndex(index); } diff --git a/include/rapidjson/internal/dtoa.h b/include/rapidjson/internal/dtoa.h index 2d8d2e4..3695866 100644 --- a/include/rapidjson/internal/dtoa.h +++ b/include/rapidjson/internal/dtoa.h @@ -62,7 +62,7 @@ inline void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, char* buff const DiyFp wp_w = Mp - W; uint32_t p1 = static_cast(Mp.f >> -one.e); uint64_t p2 = Mp.f & (one.f - 1); - int kappa = CountDecimalDigit32(p1); // kappa in [0, 9] + unsigned kappa = CountDecimalDigit32(p1); // kappa in [0, 9] *len = 0; while (kappa > 0) { @@ -158,14 +158,14 @@ inline char* Prettify(char* buffer, int length, int k) { } else if (0 < kk && kk <= 21) { // 1234e-2 -> 12.34 - std::memmove(&buffer[kk + 1], &buffer[kk], length - kk); + std::memmove(&buffer[kk + 1], &buffer[kk], static_cast(length - kk)); buffer[kk] = '.'; return &buffer[length + 1]; } else if (-6 < kk && kk <= 0) { // 1234e-6 -> 0.001234 const int offset = 2 - kk; - std::memmove(&buffer[offset], &buffer[0], length); + std::memmove(&buffer[offset], &buffer[0], static_cast(length)); buffer[0] = '0'; buffer[1] = '.'; for (int i = 2; i < offset; i++) @@ -179,7 +179,7 @@ inline char* Prettify(char* buffer, int length, int k) { } else { // 1234e30 -> 1.234e33 - std::memmove(&buffer[2], &buffer[1], length - 1); + std::memmove(&buffer[2], &buffer[1], static_cast(length - 1)); buffer[1] = '.'; buffer[length + 1] = 'e'; return WriteExponent(kk - 1, &buffer[0 + length + 2]); diff --git a/include/rapidjson/internal/ieee754.h b/include/rapidjson/internal/ieee754.h index e3f0336..2fdaf54 100644 --- a/include/rapidjson/internal/ieee754.h +++ b/include/rapidjson/internal/ieee754.h @@ -53,7 +53,7 @@ public: else if (order <= -1074) return 0; else - return order + 1074; + return (unsigned)order + 1074; } private: diff --git a/include/rapidjson/internal/strtod.h b/include/rapidjson/internal/strtod.h index ace65f6..a1b8211 100644 --- a/include/rapidjson/internal/strtod.h +++ b/include/rapidjson/internal/strtod.h @@ -95,13 +95,13 @@ inline int CheckWithinHalfULP(double b, const BigInteger& d, int dExp) { hS_Exp2 -= common_Exp2; BigInteger dS = d; - dS.MultiplyPow5(dS_Exp5) <<= dS_Exp2; + dS.MultiplyPow5(static_cast(dS_Exp5)) <<= static_cast(dS_Exp2); BigInteger bS(bInt); - bS.MultiplyPow5(bS_Exp5) <<= bS_Exp2; + bS.MultiplyPow5(static_cast(bS_Exp5)) <<= static_cast(bS_Exp2); BigInteger hS(1); - hS.MultiplyPow5(hS_Exp5) <<= hS_Exp2; + hS.MultiplyPow5(static_cast(hS_Exp5)) <<= static_cast(hS_Exp2); BigInteger delta(0); dS.Difference(bS, &delta); @@ -134,7 +134,7 @@ inline bool StrtodDiyFp(const char* decimals, size_t length, size_t decimalPosit if (significand > RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) || (significand == RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) && decimals[i] > '5')) break; - significand = significand * 10 + (decimals[i] - '0'); + significand = significand * 10u + static_cast(decimals[i] - '0'); } if (i < length && decimals[i] >= '5') // Rounding @@ -163,10 +163,10 @@ inline bool StrtodDiyFp(const char* decimals, size_t length, size_t decimalPosit DiyFp(RAPIDJSON_UINT64_C2(0xf4240000, 00000000), -44), // 10^6 DiyFp(RAPIDJSON_UINT64_C2(0x98968000, 00000000), -40) // 10^7 }; - int adjustment = dExp - actualExp - 1; + int adjustment = dExp - actualExp - 1; RAPIDJSON_ASSERT(adjustment >= 0 && adjustment < 7); v = v * kPow10[adjustment]; - if (length + adjustment > 19) // has more digits than decimal digits in 64-bit + if (length + static_cast(adjustment)> 19u) // has more digits than decimal digits in 64-bit error += kUlp / 2; } @@ -184,14 +184,14 @@ inline bool StrtodDiyFp(const char* decimals, size_t length, size_t decimalPosit unsigned scaleExp = (precisionSize + kUlpShift) - 63; v.f >>= scaleExp; v.e += scaleExp; - error = (error >> scaleExp) + 1 + kUlp; + error = (error >> scaleExp) + 1 + static_cast(kUlp); precisionSize -= scaleExp; } - DiyFp rounded(v.f >> precisionSize, v.e + precisionSize); + DiyFp rounded(v.f >> precisionSize, v.e + static_cast(precisionSize)); const uint64_t precisionBits = (v.f & ((uint64_t(1) << precisionSize) - 1)) * kUlp; const uint64_t halfWay = (uint64_t(1) << (precisionSize - 1)) * kUlp; - if (precisionBits >= halfWay + error) { + if (precisionBits >= halfWay + static_cast(error)) { rounded.f++; if (rounded.f & (DiyFp::kDpHiddenBit << 1)) { // rounding overflows mantissa (issue #340) rounded.f >>= 1; @@ -201,7 +201,7 @@ inline bool StrtodDiyFp(const char* decimals, size_t length, size_t decimalPosit *result = rounded.ToDouble(); - return halfWay - error >= precisionBits || precisionBits >= halfWay + error; + return halfWay - static_cast(error) >= precisionBits || precisionBits >= halfWay + static_cast(error); } inline double StrtodBigInteger(double approx, const char* decimals, size_t length, size_t decimalPosition, int exp) { @@ -249,7 +249,7 @@ inline double StrtodFullPrecision(double d, int p, const char* decimals, size_t if ((int)length > kMaxDecimalDigit) { int delta = (int(length) - kMaxDecimalDigit); exp += delta; - decimalPosition -= delta; + decimalPosition -= static_cast(delta); length = kMaxDecimalDigit; } diff --git a/include/rapidjson/writer.h b/include/rapidjson/writer.h index 40cdb35..8fcffbe 100644 --- a/include/rapidjson/writer.h +++ b/include/rapidjson/writer.h @@ -350,7 +350,7 @@ template<> inline bool Writer::WriteInt(int i) { char *buffer = os_->Push(11); const char* end = internal::i32toa(i, buffer); - os_->Pop(11 - (end - buffer)); + os_->Pop(static_cast(11 - (end - buffer))); return true; } @@ -358,7 +358,7 @@ template<> inline bool Writer::WriteUint(unsigned u) { char *buffer = os_->Push(10); const char* end = internal::u32toa(u, buffer); - os_->Pop(10 - (end - buffer)); + os_->Pop(static_cast(10 - (end - buffer))); return true; } @@ -366,7 +366,7 @@ template<> inline bool Writer::WriteInt64(int64_t i64) { char *buffer = os_->Push(21); const char* end = internal::i64toa(i64, buffer); - os_->Pop(21 - (end - buffer)); + os_->Pop(static_cast(21 - (end - buffer))); return true; } @@ -374,7 +374,7 @@ template<> inline bool Writer::WriteUint64(uint64_t u) { char *buffer = os_->Push(20); const char* end = internal::u64toa(u, buffer); - os_->Pop(20 - (end - buffer)); + os_->Pop(static_cast(20 - (end - buffer))); return true; } @@ -382,7 +382,7 @@ template<> inline bool Writer::WriteDouble(double d) { char *buffer = os_->Push(25); char* end = internal::dtoa(d, buffer); - os_->Pop(25 - (end - buffer)); + os_->Pop(static_cast(25 - (end - buffer))); return true; } From f33b6740fcef78e8b3ffffe5f9d6627646c5f27e Mon Sep 17 00:00:00 2001 From: scheiber Date: Tue, 21 Jul 2015 16:39:00 -0600 Subject: [PATCH 33/45] Revert "update the submodule fore google test" This reverts commit 5be9b6e584656bbc94d894887ded663442a024fb. --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 25460de..b54b211 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "thirdparty/gtest"] path = thirdparty/gtest - url = ssh://git@git.eyesopen.com/common/googletest.git + url = ssh://git@git.eyesopen.com/common/rapidjson.git From a0f730e3d7b49455787e6061ca38fa8d3ec2ceff Mon Sep 17 00:00:00 2001 From: scheiber Date: Tue, 21 Jul 2015 16:42:50 -0600 Subject: [PATCH 34/45] use -Werror --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 68139ba..a6fd165 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,9 +26,9 @@ if(RAPIDJSON_HAS_STDSTRING) endif() if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Wall -Wextra") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Wall -Wextra -Werror") elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Wall -Wextra") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Wall -Wextra -Werror") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") add_definitions(-D_CRT_SECURE_NO_WARNINGS=1) endif() From 73cf03c2bf77c5c610abf39ec7745005364fdc01 Mon Sep 17 00:00:00 2001 From: scheiber Date: Tue, 21 Jul 2015 16:52:16 -0600 Subject: [PATCH 35/45] use google's servers for googletest --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index b54b211..8e9d1f3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "thirdparty/gtest"] path = thirdparty/gtest - url = ssh://git@git.eyesopen.com/common/rapidjson.git + url = https://chromium.googlesource.com/external/googletest.git From e527a4fe5e299ad928c9a316be14826a2bccbeac Mon Sep 17 00:00:00 2001 From: Justin Scheiber Date: Tue, 21 Jul 2015 17:42:28 -0600 Subject: [PATCH 36/45] adding -Wno-missing-field-initializers to keep the googletest source from erroring out on a warning --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a6fd165..51ee620 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,7 @@ endif() if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Wall -Wextra -Werror") elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Wall -Wextra -Werror") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Wall -Wextra -Werror -Wno-missing-field-initializers") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") add_definitions(-D_CRT_SECURE_NO_WARNINGS=1) endif() From fc50f103a67adeb4963a4fefdcd6c433daf31e23 Mon Sep 17 00:00:00 2001 From: blackball Date: Fri, 24 Jul 2015 16:19:08 +0200 Subject: [PATCH 37/45] Fix the error when compiled using vs2013 The error message for the original codes is: unary minus operator applied to unsigned type, result still unsigned. Added static casting to eliminate this message. --- include/rapidjson/internal/dtoa.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/rapidjson/internal/dtoa.h b/include/rapidjson/internal/dtoa.h index 3695866..d04ae21 100644 --- a/include/rapidjson/internal/dtoa.h +++ b/include/rapidjson/internal/dtoa.h @@ -101,7 +101,7 @@ inline void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, char* buff kappa--; if (p2 < delta) { *K += kappa; - GrisuRound(buffer, *len, delta, p2, one.f, wp_w.f * kPow10[-kappa]); + GrisuRound(buffer, *len, delta, p2, one.f, wp_w.f * kPow10[-static_cast(kappa)]); return; } } From 2a18d306b845fed167446f1c740f70413172433c Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Sat, 1 Aug 2015 13:05:28 +0300 Subject: [PATCH 38/45] @PlatformIO Library Registry manifest file * This library in Web Registry: http://platformio.org/#!/lib/show/438/RapidJSON * Specification: [PlatformIO Library Manager](http://docs.platformio.org/en/latest/librarymanager/index.html) * Integration: [IDE Integration](http://docs.platformio.org/en/latest/ide.html) --- library.json | Bin 0 -> 322 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 library.json diff --git a/library.json b/library.json new file mode 100644 index 0000000000000000000000000000000000000000..429e453ec704dc5b5e6ae4d8528de064291232a7 GIT binary patch literal 322 zcmYjMO>4t2487-92p`)}-*XGwWrM9_z4YqFZsX0igzV6o(*IsN31bHdq4%MudjlYX z@bp`VDMg{W>VX!I?R;%K;qiwTBRLS7`=#DOg(i=nD| zIIEbTTCNKDCxA0Dyll5{wP}PCmUifm@^$|KF=c0<|9V?YZ5Z67=Y;DhxhAcd7KXVg zPi|(cquj{NZXjB4HiXfZlv#A;vwNxXU&=H~E;h}yvYOb{++#` Date: Sat, 1 Aug 2015 13:10:26 +0300 Subject: [PATCH 39/45] Add examples for @PlatformIO Library Registry --- library.json | Bin 322 -> 323 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/library.json b/library.json index 429e453ec704dc5b5e6ae4d8528de064291232a7..3b53db4c122a9255a74dbc4055adfa11290fe08e 100644 GIT binary patch delta 11 ScmX@abeL(vS;pdtXG;Mcu>~#w delta 9 QcmX@ibckuf*@@>$0Tvbny8r+H From 720d1688f14ef43f35ea87ac4878d83951faa9d5 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Mon, 3 Aug 2015 16:30:37 +0300 Subject: [PATCH 40/45] Fix include location --- library.json | Bin 323 -> 313 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/library.json b/library.json index 3b53db4c122a9255a74dbc4055adfa11290fe08e..47fd352ac7efa35c343de9a2d74ee55ff19ba2eb 100644 GIT binary patch delta 9 QcmX@iw3BJVwuuLt0Tpcon*aa+ delta 20 bcmdnVbeL(vHZJ|5#DdI}tm6E Date: Fri, 7 Aug 2015 10:04:45 +0200 Subject: [PATCH 41/45] Implement = operator for BigInteger There's a copy constructor, but no '=' operator implemented. This is dangerous. --- include/rapidjson/internal/biginteger.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/rapidjson/internal/biginteger.h b/include/rapidjson/internal/biginteger.h index 512b6f9..f4d6d12 100755 --- a/include/rapidjson/internal/biginteger.h +++ b/include/rapidjson/internal/biginteger.h @@ -51,7 +51,14 @@ public: if (length > 0) AppendDecimal64(decimals + i, decimals + i + length); } - + + BigInteger& operator=(const BigInteger &rhs) + { + count_ = rhs.count_; + std::memcpy(digits_, rhs.digits_, count_ * sizeof(Type)); + return *this; + } + BigInteger& operator=(uint64_t u) { digits_[0] = u; count_ = 1; From 456975290375ef039cc18d15323f79dbe348db4c Mon Sep 17 00:00:00 2001 From: Ziyang LI Date: Mon, 10 Aug 2015 18:11:25 +0800 Subject: [PATCH 42/45] added missing fields of CMakeList.txt this fixed cmake error for me --- example/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 6463212..8063d89 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -1,6 +1,7 @@ # Copyright (c) 2011 Milo Yip (miloyip@gmail.com) # Copyright (c) 2013 Rafal Jeczalik (rjeczalik@gmail.com) # Distributed under the MIT License (see license.txt file) +cmake_minimum_required(VERSION 2.8) set(EXAMPLES capitalize @@ -13,6 +14,8 @@ set(EXAMPLES simplereader simplewriter tutorial) + +include_directories("../include/") if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wextra -Weffc++ -Wswitch-default") From ffd389befc3d828effcb7b72979546a3f5cd6a26 Mon Sep 17 00:00:00 2001 From: "Force.Charlie-I" Date: Wed, 12 Aug 2015 18:38:13 +0800 Subject: [PATCH 43/45] =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E6=B5=81?= =?UTF-8?q?=E5=BA=94=E5=BD=93=E4=BD=BF=E7=94=A8=20ParseStream=20=E8=80=8C?= =?UTF-8?q?=E4=B8=8D=E6=98=AF=20Parse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/stream.zh-cn.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/stream.zh-cn.md b/doc/stream.zh-cn.md index 5ac32f8..0f930a9 100644 --- a/doc/stream.zh-cn.md +++ b/doc/stream.zh-cn.md @@ -320,7 +320,7 @@ std::stringstream ss(json); IStreamWrapper is(ss); Document d; -d.Parse(is); +d.ParseStream(is); ~~~~~~~~~~ 但要注意,由于标准库的内部开销问,此实现的性能可能不如RapidJSON的内存/文件流。 From 3cf7228f4670d9ea3a283bf316c9be5abefa1777 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Thu, 13 Aug 2015 10:16:19 +0800 Subject: [PATCH 44/45] Port documentation fix from #407 --- doc/stream.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/stream.md b/doc/stream.md index 94bc10d..7b3c5ca 100644 --- a/doc/stream.md +++ b/doc/stream.md @@ -320,7 +320,7 @@ std::stringstream ss(json); IStreamWrapper is(ss); Document d; -d.Parse(is); +d.ParseStream(is); ~~~~~~~~~~ Note that, this implementation may not be as efficient as RapidJSON's memory or file streams, due to internal overheads of the standard library. From afbc0406f0a59fd5423b3127ed23ba3414a0c53f Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Thu, 13 Aug 2015 23:07:30 +0200 Subject: [PATCH 45/45] BigInteger: guard against self-assignment Related-to: #404. Suggested-by: @cosinekitty --- include/rapidjson/internal/biginteger.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/rapidjson/internal/biginteger.h b/include/rapidjson/internal/biginteger.h index f4d6d12..4477cf5 100755 --- a/include/rapidjson/internal/biginteger.h +++ b/include/rapidjson/internal/biginteger.h @@ -54,8 +54,10 @@ public: BigInteger& operator=(const BigInteger &rhs) { - count_ = rhs.count_; - std::memcpy(digits_, rhs.digits_, count_ * sizeof(Type)); + if (this != &rhs) { + count_ = rhs.count_; + std::memcpy(digits_, rhs.digits_, count_ * sizeof(Type)); + } return *this; }