From 72de00f672c7661a956cd6bf69fb1f851742b381 Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Sat, 1 Feb 2014 18:02:35 +0100 Subject: [PATCH 1/3] GenericValue/GenericDocument: fix alloctaor/Alloactor typos This patch fixes some misspellings of "allocator" in document.h. Fixes the Doxygen documentation of GenericDocument as well. --- include/rapidjson/document.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index a41288e..b7d5af9 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -642,17 +642,17 @@ private: }; // 12 bytes in 32-bit mode, 16 bytes in 64-bit mode // Initialize this value as array with initial data, without calling destructor. - void SetArrayRaw(GenericValue* values, SizeType count, Allocator& alloctaor) { + void SetArrayRaw(GenericValue* values, SizeType count, Allocator& allocator) { flags_ = kArrayFlag; - data_.a.elements = (GenericValue*)alloctaor.Malloc(count * sizeof(GenericValue)); + data_.a.elements = (GenericValue*)allocator.Malloc(count * sizeof(GenericValue)); memcpy(data_.a.elements, values, count * sizeof(GenericValue)); data_.a.size = data_.a.capacity = count; } //! Initialize this value as object with initial data, without calling destructor. - void SetObjectRaw(Member* members, SizeType count, Allocator& alloctaor) { + void SetObjectRaw(Member* members, SizeType count, Allocator& allocator) { flags_ = kObjectFlag; - data_.o.members = (Member*)alloctaor.Malloc(count * sizeof(Member)); + data_.o.members = (Member*)allocator.Malloc(count * sizeof(Member)); memcpy(data_.o.members, members, count * sizeof(Member)); data_.o.size = data_.o.capacity = count; } @@ -696,7 +696,7 @@ typedef GenericValue > Value; /*! \implements Handler \tparam Encoding encoding for both parsing and string storage. - \tparam Alloactor allocator for allocating memory for the DOM, and the stack during parsing. + \tparam Allocator allocator for allocating memory for the DOM, and the stack during parsing. */ template > class GenericDocument : public GenericValue { From 4b32a3059368d09948d219deb41023d30c3f8c47 Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Sat, 1 Feb 2014 18:05:12 +0100 Subject: [PATCH 2/3] MemoryPoolAllocator: prohibit copying and assignment The MemoryPoolAllocator implementation cannot and should not be copied (Rule of Three). Declare copy constructor and copy-assignment operator as private. --- include/rapidjson/allocators.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/rapidjson/allocators.h b/include/rapidjson/allocators.h index 6dfa85a..ad5f3cb 100644 --- a/include/rapidjson/allocators.h +++ b/include/rapidjson/allocators.h @@ -187,6 +187,11 @@ public: static void Free(void *ptr) { (void)ptr; } // Do nothing private: + //! Copy constructor is not permitted. + MemoryPoolAllocator(const MemoryPoolAllocator& rhs) /* = delete */; + //! Copy assignment operator is not permitted. + MemoryPoolAllocator& operator=(const MemoryPoolAllocator& rhs) /* = delete */; + //! Creates a new chunk. /*! \param capacity Capacity of the chunk in bytes. */ From 16029e6b33a217d05d08976d7fb34ce488e88634 Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Sat, 1 Feb 2014 18:03:52 +0100 Subject: [PATCH 3/3] FileStream: avoid warning about missing initialisation FileStream::current_ is now explicitly initialized in the constructor. Avoids reading the garbage value in case of an empty file. --- include/rapidjson/filestream.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/rapidjson/filestream.h b/include/rapidjson/filestream.h index 57ab0ba..4cd4cc4 100644 --- a/include/rapidjson/filestream.h +++ b/include/rapidjson/filestream.h @@ -16,7 +16,7 @@ class FileStream { public: typedef char Ch; //!< Character type. Only support char. - FileStream(FILE* fp) : fp_(fp), count_(0) { Read(); } + FileStream(FILE* fp) : fp_(fp), current_('\0'), count_(0) { Read(); } char Peek() const { return current_; } char Take() { char c = current_; Read(); return c; } size_t Tell() const { return count_; }