From b7e34100ed167b8134b41fcff0918895dd4e61fb Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Fri, 10 Apr 2015 20:36:27 +0800 Subject: [PATCH 001/116] Fix #288 double quote in unicode escape --- include/rapidjson/reader.h | 2 ++ test/unittest/readertest.cpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/include/rapidjson/reader.h b/include/rapidjson/reader.h index a59f26e..0ee2523 100644 --- a/include/rapidjson/reader.h +++ b/include/rapidjson/reader.h @@ -689,11 +689,13 @@ private: } else if (e == 'u') { // Unicode unsigned codepoint = ParseHex4(is); + RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; if (codepoint >= 0xD800 && codepoint <= 0xDBFF) { // Handle UTF-16 surrogate pair if (is.Take() != '\\' || is.Take() != 'u') RAPIDJSON_PARSE_ERROR(kParseErrorStringUnicodeSurrogateInvalid, is.Tell() - 2); unsigned codepoint2 = ParseHex4(is); + RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; if (codepoint2 < 0xDC00 || codepoint2 > 0xDFFF) RAPIDJSON_PARSE_ERROR(kParseErrorStringUnicodeSurrogateInvalid, is.Tell() - 2); codepoint = (((codepoint - 0xD800) << 10) | (codepoint2 - 0xDC00)) + 0x10000; diff --git a/test/unittest/readertest.cpp b/test/unittest/readertest.cpp index 64904b0..b6dffbc 100644 --- a/test/unittest/readertest.cpp +++ b/test/unittest/readertest.cpp @@ -517,6 +517,10 @@ TEST(Reader, ParseString_Error) { // Incorrect hex digit after \\u escape in string. TEST_STRING_ERROR(kParseErrorStringUnicodeEscapeInvalidHex, "[\"\\uABCG\"]"); + // Quotation in \\u escape in string (Issue #288) + TEST_STRING_ERROR(kParseErrorStringUnicodeEscapeInvalidHex, "[\"\\uaaa\"]"); + TEST_STRING_ERROR(kParseErrorStringUnicodeEscapeInvalidHex, "[\"\\uD800\\uFFF\"]"); + // The surrogate pair in string is invalid. TEST_STRING_ERROR(kParseErrorStringUnicodeSurrogateInvalid, "[\"\\uD800X\"]"); TEST_STRING_ERROR(kParseErrorStringUnicodeSurrogateInvalid, "[\"\\uD800\\uFFFF\"]"); From e5cf3b85f33b8b1adb417b355fbdf97bb0a3ddc9 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Fri, 10 Apr 2015 21:24:29 +0800 Subject: [PATCH 002/116] Fix #289 negative zero roundtrip (double only) --- include/rapidjson/internal/dtoa.h | 4 ++++ test/unittest/readertest.cpp | 3 +++ test/unittest/writertest.cpp | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/rapidjson/internal/dtoa.h b/include/rapidjson/internal/dtoa.h index c888402..bf686b0 100644 --- a/include/rapidjson/internal/dtoa.h +++ b/include/rapidjson/internal/dtoa.h @@ -21,6 +21,7 @@ #include "itoa.h" // GetDigitsLut() #include "diyfp.h" +#include "ieee754.h" RAPIDJSON_NAMESPACE_BEGIN namespace internal { @@ -193,6 +194,9 @@ inline char* Prettify(char* buffer, int length, int k) { inline char* dtoa(double value, char* buffer) { if (value == 0) { + Double d(value); + if (d.Sign()) + *buffer++ = '-'; // -0.0, Issue #289 buffer[0] = '0'; buffer[1] = '.'; buffer[2] = '0'; diff --git a/test/unittest/readertest.cpp b/test/unittest/readertest.cpp index 64904b0..3d2f7aa 100644 --- a/test/unittest/readertest.cpp +++ b/test/unittest/readertest.cpp @@ -187,6 +187,8 @@ static void TestParseDouble() { Reader reader; \ ASSERT_EQ(kParseErrorNone, reader.Parse(s, h).Code()); \ EXPECT_EQ(1u, h.step_); \ + internal::Double e(x), a(h.actual_); \ + EXPECT_EQ(e.Sign(), a.Sign()); \ if (fullPrecision) { \ EXPECT_EQ(x, h.actual_); \ if (x != h.actual_) \ @@ -197,6 +199,7 @@ static void TestParseDouble() { } TEST_DOUBLE(fullPrecision, "0.0", 0.0); + TEST_DOUBLE(fullPrecision, "-0.0", -0.0); // For checking issue #289 TEST_DOUBLE(fullPrecision, "1.0", 1.0); TEST_DOUBLE(fullPrecision, "-1.0", -1.0); TEST_DOUBLE(fullPrecision, "1.5", 1.5); diff --git a/test/unittest/writertest.cpp b/test/unittest/writertest.cpp index 0ef1423..642161a 100644 --- a/test/unittest/writertest.cpp +++ b/test/unittest/writertest.cpp @@ -93,7 +93,7 @@ TEST(Writer, String) { TEST(Writer, Double) { TEST_ROUNDTRIP("[1.2345,1.2345678,0.123456789012,1234567.8]"); - + TEST_ROUNDTRIP("[-0.0]"); // Issue #289 } TEST(Writer, Transcode) { From f73ec572412a6b3b7a7ea207144c8aa8eb84ab3a Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Fri, 10 Apr 2015 21:30:42 +0800 Subject: [PATCH 003/116] Add -Wfloat-equal to reproduce warnings --- test/unittest/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unittest/CMakeLists.txt b/test/unittest/CMakeLists.txt index 5e4a3e9..326e6de 100644 --- a/test/unittest/CMakeLists.txt +++ b/test/unittest/CMakeLists.txt @@ -14,9 +14,9 @@ set(UNITTEST_SOURCES writertest.cpp) if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Weffc++ -Wswitch-default") + 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 -Weffc++ -Wswitch-default") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wextra -Weffc++ -Wswitch-default -Wfloat-equal") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") add_definitions(-D_CRT_SECURE_NO_WARNINGS=1) endif() From dfba62e1432e19aa09a4c7be6e59d1d4c8b7535a Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Fri, 10 Apr 2015 22:57:41 +0800 Subject: [PATCH 004/116] Fixed two -Wfloat-equal warnings --- include/rapidjson/internal/diyfp.h | 2 +- include/rapidjson/internal/dtoa.h | 4 ++-- include/rapidjson/internal/ieee754.h | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/rapidjson/internal/diyfp.h b/include/rapidjson/internal/diyfp.h index 320d05d..0b098af 100644 --- a/include/rapidjson/internal/diyfp.h +++ b/include/rapidjson/internal/diyfp.h @@ -238,7 +238,7 @@ inline DiyFp GetCachedPower(int e, int* K) { //int k = static_cast(ceil((-61 - e) * 0.30102999566398114)) + 374; double dk = (-61 - e) * 0.30102999566398114 + 347; // dk must be positive, so can do ceiling in positive int k = static_cast(dk); - if (k != dk) + if (dk - k > 0.0) k++; unsigned index = static_cast((k >> 3) + 1); diff --git a/include/rapidjson/internal/dtoa.h b/include/rapidjson/internal/dtoa.h index bf686b0..aec6bcd 100644 --- a/include/rapidjson/internal/dtoa.h +++ b/include/rapidjson/internal/dtoa.h @@ -193,8 +193,8 @@ inline char* Prettify(char* buffer, int length, int k) { } inline char* dtoa(double value, char* buffer) { - if (value == 0) { - Double d(value); + Double d(value); + if (d.IsZero()) { if (d.Sign()) *buffer++ = '-'; // -0.0, Issue #289 buffer[0] = '0'; diff --git a/include/rapidjson/internal/ieee754.h b/include/rapidjson/internal/ieee754.h index 934cf19..0b9393e 100644 --- a/include/rapidjson/internal/ieee754.h +++ b/include/rapidjson/internal/ieee754.h @@ -49,6 +49,7 @@ public: bool IsNan() const { return (u & kExponentMask) == kExponentMask && Significand() != 0; } bool IsInf() const { return (u & kExponentMask) == kExponentMask && Significand() == 0; } bool IsNormal() const { return (u & kExponentMask) != 0 || Significand() == 0; } + bool IsZero() const { return (u & (kExponentMask | kSignificandMask)) == 0; } uint64_t IntegerSignificand() const { return IsNormal() ? Significand() | kHiddenBit : Significand(); } int IntegerExponent() const { return (IsNormal() ? Exponent() : kDenormalExponent) - kSignificandSize; } From fb4f321d82edf1334e376949b78a6eda28c49021 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Fri, 10 Apr 2015 23:10:08 +0800 Subject: [PATCH 005/116] Fix another -Wfloat-equal warning --- test/unittest/documenttest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/documenttest.cpp b/test/unittest/documenttest.cpp index 6ececf7..12ea751 100644 --- a/test/unittest/documenttest.cpp +++ b/test/unittest/documenttest.cpp @@ -63,7 +63,7 @@ void ParseTest() { EXPECT_TRUE(doc.HasMember("pi")); const ValueType& pi = doc["pi"]; EXPECT_TRUE(pi.IsNumber()); - EXPECT_EQ(3.1416, pi.GetDouble()); + EXPECT_DOUBLE_EQ(3.1416, pi.GetDouble()); EXPECT_TRUE(doc.HasMember("a")); const ValueType& a = doc["a"]; From 2524693cfd6f6dda75e9939eda312daa0d2b9d22 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Fri, 10 Apr 2015 23:24:33 +0800 Subject: [PATCH 006/116] Suppress float-equal in readertest.cpp --- test/unittest/readertest.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unittest/readertest.cpp b/test/unittest/readertest.cpp index 318f188..98ffcc9 100644 --- a/test/unittest/readertest.cpp +++ b/test/unittest/readertest.cpp @@ -30,6 +30,7 @@ using namespace rapidjson; #ifdef __GNUC__ RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_OFF(effc++) +RAPIDJSON_DIAG_OFF(float-equal) #endif template From c18812a36ac01a33b9e7a718509d3c53f2e68d54 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Fri, 10 Apr 2015 23:37:20 +0800 Subject: [PATCH 007/116] Fix yet another -Wfloat-equal warning --- test/unittest/readertest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/readertest.cpp b/test/unittest/readertest.cpp index 98ffcc9..6667ffc 100644 --- a/test/unittest/readertest.cpp +++ b/test/unittest/readertest.cpp @@ -663,7 +663,7 @@ struct ParseObjectHandler : BaseReaderHandler, ParseObjectHandler> { } } bool Uint(unsigned i) { return Int(i); } - bool Double(double d) { EXPECT_EQ(12u, step_); EXPECT_EQ(3.1416, d); step_++; return true; } + bool Double(double d) { EXPECT_EQ(12u, step_); EXPECT_DOUBLE_EQ(3.1416, d); step_++; return true; } bool String(const char* str, size_t, bool) { switch(step_) { case 1: EXPECT_STREQ("hello", str); step_++; return true; From e04d66bdd825309bc0658e60a54c9e444e2501f5 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Fri, 10 Apr 2015 23:47:53 +0800 Subject: [PATCH 008/116] Try to use EXPECT_NEAR --- test/unittest/readertest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/readertest.cpp b/test/unittest/readertest.cpp index 6667ffc..d41eed6 100644 --- a/test/unittest/readertest.cpp +++ b/test/unittest/readertest.cpp @@ -191,7 +191,7 @@ static void TestParseDouble() { internal::Double e(x), a(h.actual_); \ EXPECT_EQ(e.Sign(), a.Sign()); \ if (fullPrecision) { \ - EXPECT_EQ(x, h.actual_); \ + EXPECT_NEAR(x, h.actual_, 0.0); \ if (x != h.actual_) \ printf(" String: %s\n Actual: %.17g\nExpected: %.17g\n", str, h.actual_, x); \ } \ From 2452afbf3c116585221501bbb98b148df0fd5c08 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Sat, 11 Apr 2015 00:02:17 +0800 Subject: [PATCH 009/116] Fix -Wfloat-equal warnings in Value::operator== and valuetest --- include/rapidjson/document.h | 6 ++++-- test/unittest/valuetest.cpp | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index d41a87e..82a86ed 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -700,8 +700,10 @@ public: return StringEqual(rhs); case kNumberType: - if (IsDouble() || rhs.IsDouble()) - return GetDouble() == rhs.GetDouble(); // May convert one operand from integer to double. + if (IsDouble() || rhs.IsDouble()) { + float delta = GetDouble() - rhs.GetDouble(); // May convert one operand from integer to double. + return delta >= 0.0 && delta <= 0.0; // Prevent -Wfloat-equal + } else return data_.n.u64 == rhs.data_.n.u64; diff --git a/test/unittest/valuetest.cpp b/test/unittest/valuetest.cpp index b2647c0..c6a8879 100644 --- a/test/unittest/valuetest.cpp +++ b/test/unittest/valuetest.cpp @@ -339,7 +339,7 @@ TEST(Value, Int) { EXPECT_EQ(1234u, x.GetUint()); EXPECT_EQ(1234, x.GetInt64()); EXPECT_EQ(1234u, x.GetUint64()); - EXPECT_EQ(1234, x.GetDouble()); + EXPECT_NEAR(1234.0, x.GetDouble(), 0.0); //EXPECT_EQ(1234, (int)x); //EXPECT_EQ(1234, (unsigned)x); //EXPECT_EQ(1234, (int64_t)x); @@ -397,7 +397,7 @@ TEST(Value, Uint) { EXPECT_TRUE(x.IsUint()); EXPECT_TRUE(x.IsInt64()); EXPECT_TRUE(x.IsUint64()); - EXPECT_EQ(1234.0, x.GetDouble()); // Number can always be cast as double but !IsDouble(). + EXPECT_NEAR(1234.0, x.GetDouble(), 0.0); // Number can always be cast as double but !IsDouble(). EXPECT_FALSE(x.IsDouble()); EXPECT_FALSE(x.IsNull()); From 09448e980b1514c60ac5ee162a91f135e1bad94b Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Sat, 11 Apr 2015 00:12:15 +0800 Subject: [PATCH 010/116] Another warning in valuetest --- test/unittest/valuetest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/valuetest.cpp b/test/unittest/valuetest.cpp index c6a8879..dd7d192 100644 --- a/test/unittest/valuetest.cpp +++ b/test/unittest/valuetest.cpp @@ -517,7 +517,7 @@ TEST(Value, Double) { // Constructor with double Value x(12.34); EXPECT_EQ(kNumberType, x.GetType()); - EXPECT_EQ(12.34, x.GetDouble()); + EXPECT_NEAR(12.34, x.GetDouble(), 0.0); EXPECT_TRUE(x.IsNumber()); EXPECT_TRUE(x.IsDouble()); From d7ad55f49ebda9ddca72422fc3c8d23f6a82bd5d Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Sat, 11 Apr 2015 00:20:10 +0800 Subject: [PATCH 011/116] Another two warnings --- test/unittest/valuetest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unittest/valuetest.cpp b/test/unittest/valuetest.cpp index dd7d192..846b1c8 100644 --- a/test/unittest/valuetest.cpp +++ b/test/unittest/valuetest.cpp @@ -533,10 +533,10 @@ TEST(Value, Double) { // SetDouble() Value z; z.SetDouble(12.34); - EXPECT_EQ(12.34, z.GetDouble()); + EXPECT_NEAR(12.34, z.GetDouble(), 0.0); z = 56.78; - EXPECT_EQ(56.78, z.GetDouble()); + EXPECT_NEAR(56.78, z.GetDouble(), 0.0); } TEST(Value, String) { From 2e0a2f61f4b25bb1442af9940a20726357fbbd85 Mon Sep 17 00:00:00 2001 From: Danil Osherov Date: Fri, 10 Apr 2015 19:22:09 +0300 Subject: [PATCH 012/116] CMake: fixed 'Unknown CMake command "find_package_handle_standard_args"'. Added INCLUDE(FindPackageHandleStandardArgs) before using find_package_handle_standard_args(). --- CMakeModules/FindGTestSrc.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeModules/FindGTestSrc.cmake b/CMakeModules/FindGTestSrc.cmake index 89f132e..13b1c7b 100644 --- a/CMakeModules/FindGTestSrc.cmake +++ b/CMakeModules/FindGTestSrc.cmake @@ -17,6 +17,7 @@ FIND_PATH(GTEST_INCLUDE_DIR PATH_SUFFIXES include PATHS ${GTEST_SEARCH_PATH}) +INCLUDE(FindPackageHandleStandardArgs) find_package_handle_standard_args(GTestSrc DEFAULT_MSG GTEST_SOURCE_DIR GTEST_INCLUDE_DIR) From 5ae85e67f6f22e32f05bb8d1da3bc3854493be3e Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Sat, 11 Apr 2015 00:41:09 +0800 Subject: [PATCH 013/116] Yet two more warnings --- include/rapidjson/internal/ieee754.h | 2 +- include/rapidjson/reader.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/rapidjson/internal/ieee754.h b/include/rapidjson/internal/ieee754.h index 0b9393e..152be8f 100644 --- a/include/rapidjson/internal/ieee754.h +++ b/include/rapidjson/internal/ieee754.h @@ -36,7 +36,7 @@ public: double PreviousPositiveDouble() const { RAPIDJSON_ASSERT(!Sign()); - if (d == 0.0) + if (IsZero()) return 0.0; else return Double(u - 1).Value(); diff --git a/include/rapidjson/reader.h b/include/rapidjson/reader.h index 0ee2523..d9da869 100644 --- a/include/rapidjson/reader.h +++ b/include/rapidjson/reader.h @@ -896,7 +896,7 @@ private: if (significandDigit < 17) { d = d * 10.0 + (s.TakePush() - '0'); --expFrac; - if (d != 0.0) + if (d > 0.0) significandDigit++; } else From 55f8339a0a567e07dabbd3bd16198c138b0430c3 Mon Sep 17 00:00:00 2001 From: miloyip Date: Sat, 11 Apr 2015 11:26:47 +0800 Subject: [PATCH 014/116] Compare exact binary representation for full precision test Conflicts: doc/diagram/simpledom.png --- test/unittest/readertest.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/unittest/readertest.cpp b/test/unittest/readertest.cpp index d41eed6..8c8c63c 100644 --- a/test/unittest/readertest.cpp +++ b/test/unittest/readertest.cpp @@ -189,14 +189,15 @@ static void TestParseDouble() { ASSERT_EQ(kParseErrorNone, reader.Parse(s, h).Code()); \ EXPECT_EQ(1u, h.step_); \ internal::Double e(x), a(h.actual_); \ - EXPECT_EQ(e.Sign(), a.Sign()); \ if (fullPrecision) { \ - EXPECT_NEAR(x, h.actual_, 0.0); \ - if (x != h.actual_) \ - printf(" String: %s\n Actual: %.17g\nExpected: %.17g\n", str, h.actual_, x); \ + EXPECT_EQ(e.Uint64Value(), a.Uint64Value()); \ + if (e.Uint64Value() != a.Uint64Value()) \ + printf(" String: %s\n Actual: %.17g\nExpected: %.17g\n", str, h.actual_, x); \ } \ - else \ + else { \ + EXPECT_EQ(e.Sign(), a.Sign()); /* for 0.0 != -0.0 */ \ EXPECT_DOUBLE_EQ(x, h.actual_); \ + } \ } TEST_DOUBLE(fullPrecision, "0.0", 0.0); From cb59a5a9a2c7a0e93a6f23278a0ca3dead195f11 Mon Sep 17 00:00:00 2001 From: miloyip Date: Sat, 11 Apr 2015 11:34:44 +0800 Subject: [PATCH 015/116] Correct the Value::operator==() for double. --- include/rapidjson/document.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 82a86ed..8cc968a 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -701,8 +701,9 @@ public: case kNumberType: if (IsDouble() || rhs.IsDouble()) { - float delta = GetDouble() - rhs.GetDouble(); // May convert one operand from integer to double. - return delta >= 0.0 && delta <= 0.0; // Prevent -Wfloat-equal + double a = GetDouble(); // May convert from integer to double. + double b = rhs.GetDouble(); // Ditto + return a >= b && a <= b; // Prevent -Wfloat-equal } else return data_.n.u64 == rhs.data_.n.u64; From e346b933250fd14e9463ae8c542576222973b659 Mon Sep 17 00:00:00 2001 From: miloyip Date: Sat, 11 Apr 2015 12:10:44 +0800 Subject: [PATCH 016/116] Try to fix a potential set fault on some compiler Merge the fix from https://github.com/miloyip/itoa-benchmark/issues/8 --- include/rapidjson/internal/itoa.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/include/rapidjson/internal/itoa.h b/include/rapidjson/internal/itoa.h index a28001f..9ecf630 100644 --- a/include/rapidjson/internal/itoa.h +++ b/include/rapidjson/internal/itoa.h @@ -109,12 +109,13 @@ inline char* u32toa(uint32_t value, char* buffer) { } inline char* i32toa(int32_t value, char* buffer) { + uint32_t u = static_cast(value); if (value < 0) { *buffer++ = '-'; - value = -value; + u = ~u + 1; } - return u32toa(static_cast(value), buffer); + return u32toa(u, buffer); } inline char* u64toa(uint64_t value, char* buffer) { @@ -286,12 +287,13 @@ inline char* u64toa(uint64_t value, char* buffer) { } inline char* i64toa(int64_t value, char* buffer) { + uint64_t u = static_cast(value); if (value < 0) { *buffer++ = '-'; - value = -value; + u = ~u + 1; } - return u64toa(static_cast(value), buffer); + return u64toa(u, buffer); } } // namespace internal From d05801901a790414bbf9d5d91e682b55c09f6dae Mon Sep 17 00:00:00 2001 From: miloyip Date: Mon, 13 Apr 2015 00:32:24 +0800 Subject: [PATCH 017/116] Activate coveralls/gcov for code coverage analysis --- .travis.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index ac7240d..6a9adaa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,8 +18,9 @@ env: before_install: - sudo apt-get update -qq - - sudo apt-get install -qq cmake doxygen valgrind + - sudo apt-get install -qq cmake valgrind - if [ "$ARCH" = "x86" ]; then sudo apt-get install -qq g++-multilib libc6-dbg:i386; fi + - if [ "$CC" = "gcc" ] && [ "$CONF" = "debug" ]; then sudo pip install cpp-coveralls; export GCOV_FLAGS='--coverage'; fi install: true @@ -34,7 +35,9 @@ before_script: -DRAPIDJSON_HAS_STDSTRING=ON -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_BUILD_TYPE=$CONF - -DCMAKE_CXX_FLAGS="$ARCH_FLAGS" ..) + -DCMAKE_CXX_FLAGS="$ARCH_FLAGS $GCOV_FLAGS" + -DCMAKE_EXE_LINKER_FLAGS=$GCOV_FLAGS + ..) script: - cd build @@ -42,3 +45,6 @@ script: - make examples - ctest -V `[ "$CONF" = "release" ] || echo "-E perftest"` - make travis_doc + +after_success: + - coveralls -r .. --gcov-options '\-lp' -e thirdparty -e example -e test -e build/CMakeFiles -e include/rapidjson/msinttypes From 35d0577e803a5df97e1670fc92969b32da3b6d4a Mon Sep 17 00:00:00 2001 From: miloyip Date: Mon, 13 Apr 2015 00:44:52 +0800 Subject: [PATCH 018/116] Try to fix doxygen problem --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 6a9adaa..c64d62b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,6 +19,7 @@ env: before_install: - sudo apt-get update -qq - sudo apt-get install -qq cmake valgrind + - sudo apt-get --no-install-recommends install doxygen # Don't install LaTeX stuffs - if [ "$ARCH" = "x86" ]; then sudo apt-get install -qq g++-multilib libc6-dbg:i386; fi - if [ "$CC" = "gcc" ] && [ "$CONF" = "debug" ]; then sudo pip install cpp-coveralls; export GCOV_FLAGS='--coverage'; fi From 752afa7b796389590c44798d4254c03941c857f1 Mon Sep 17 00:00:00 2001 From: miloyip Date: Mon, 13 Apr 2015 10:58:05 +0800 Subject: [PATCH 019/116] Add prettywritertest --- test/unittest/CMakeLists.txt | 1 + test/unittest/prettywritertest.cpp | 73 ++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 test/unittest/prettywritertest.cpp diff --git a/test/unittest/CMakeLists.txt b/test/unittest/CMakeLists.txt index 326e6de..3c49651 100644 --- a/test/unittest/CMakeLists.txt +++ b/test/unittest/CMakeLists.txt @@ -6,6 +6,7 @@ set(UNITTEST_SOURCES filestreamtest.cpp jsoncheckertest.cpp namespacetest.cpp + prettywritertest.cpp readertest.cpp stringbuffertest.cpp strtodtest.cpp diff --git a/test/unittest/prettywritertest.cpp b/test/unittest/prettywritertest.cpp new file mode 100644 index 0000000..c37f76e --- /dev/null +++ b/test/unittest/prettywritertest.cpp @@ -0,0 +1,73 @@ +// Copyright (C) 2011 Milo Yip +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#include "unittest.h" +#include "rapidjson/reader.h" +#include "rapidjson/prettywriter.h" +#include "rapidjson/stringbuffer.h" + +using namespace rapidjson; + +static const char kJson[] = "{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3]}"; + +TEST(PrettyWriter, Basic) { + StringBuffer buffer; + PrettyWriter writer(buffer); + Reader reader; + reader.Parse(StringStream(kJson), writer); + EXPECT_STREQ( + "{\n" + " \"hello\": \"world\",\n" + " \"t\": true,\n" + " \"f\": false,\n" + " \"n\": null,\n" + " \"i\": 123,\n" + " \"pi\": 3.1416,\n" + " \"a\": [\n" + " 1,\n" + " 2,\n" + " 3\n" + " ]\n" + "}", + buffer.GetString()); +} + +TEST(PrettyWriter, SetIndent) { + StringBuffer buffer; + PrettyWriter writer(buffer); + writer.SetIndent('\t', 1); + Reader reader; + reader.Parse(StringStream(kJson), writer); + EXPECT_STREQ( + "{\n" + "\t\"hello\": \"world\",\n" + "\t\"t\": true,\n" + "\t\"f\": false,\n" + "\t\"n\": null,\n" + "\t\"i\": 123,\n" + "\t\"pi\": 3.1416,\n" + "\t\"a\": [\n" + "\t\t1,\n" + "\t\t2,\n" + "\t\t3\n" + "\t]\n" + "}", + buffer.GetString()); +} From a0a6d737fc3241db5429467267f2b037d9b18f18 Mon Sep 17 00:00:00 2001 From: miloyip Date: Mon, 13 Apr 2015 11:13:03 +0800 Subject: [PATCH 020/116] Fix gcc compilation --- test/unittest/prettywritertest.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/unittest/prettywritertest.cpp b/test/unittest/prettywritertest.cpp index c37f76e..9c22bd3 100644 --- a/test/unittest/prettywritertest.cpp +++ b/test/unittest/prettywritertest.cpp @@ -31,7 +31,8 @@ TEST(PrettyWriter, Basic) { StringBuffer buffer; PrettyWriter writer(buffer); Reader reader; - reader.Parse(StringStream(kJson), writer); + StringStream s(kJson); + reader.Parse(s, writer); EXPECT_STREQ( "{\n" " \"hello\": \"world\",\n" @@ -54,7 +55,8 @@ TEST(PrettyWriter, SetIndent) { PrettyWriter writer(buffer); writer.SetIndent('\t', 1); Reader reader; - reader.Parse(StringStream(kJson), writer); + StringStream s(kJson); + reader.Parse(s, writer); EXPECT_STREQ( "{\n" "\t\"hello\": \"world\",\n" From 6a622aa0d095998bf6619b613643cb240c5336e3 Mon Sep 17 00:00:00 2001 From: miloyip Date: Mon, 13 Apr 2015 13:08:29 +0800 Subject: [PATCH 021/116] Try disabling inline for coverage --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c64d62b..dba5f8d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,7 @@ before_install: - sudo apt-get install -qq cmake valgrind - sudo apt-get --no-install-recommends install doxygen # Don't install LaTeX stuffs - if [ "$ARCH" = "x86" ]; then sudo apt-get install -qq g++-multilib libc6-dbg:i386; fi - - if [ "$CC" = "gcc" ] && [ "$CONF" = "debug" ]; then sudo pip install cpp-coveralls; export GCOV_FLAGS='--coverage'; fi + - if [ "$CC" = "gcc" ] && [ "$CONF" = "debug" ]; then sudo pip install cpp-coveralls; export GCOV_FLAGS='--coverage -O0 -fno-default-inline -fno-inline'; fi install: true From fddffbe82b9b76c5919852144f84d0828c15d835 Mon Sep 17 00:00:00 2001 From: miloyip Date: Mon, 13 Apr 2015 13:21:45 +0800 Subject: [PATCH 022/116] Revert "Try disabling inline for coverage" This reverts commit 6a622aa0d095998bf6619b613643cb240c5336e3. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index dba5f8d..c64d62b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,7 @@ before_install: - sudo apt-get install -qq cmake valgrind - sudo apt-get --no-install-recommends install doxygen # Don't install LaTeX stuffs - if [ "$ARCH" = "x86" ]; then sudo apt-get install -qq g++-multilib libc6-dbg:i386; fi - - if [ "$CC" = "gcc" ] && [ "$CONF" = "debug" ]; then sudo pip install cpp-coveralls; export GCOV_FLAGS='--coverage -O0 -fno-default-inline -fno-inline'; fi + - if [ "$CC" = "gcc" ] && [ "$CONF" = "debug" ]; then sudo pip install cpp-coveralls; export GCOV_FLAGS='--coverage'; fi install: true From 79433827e8744b857128fb3c3684e97abe7a3d11 Mon Sep 17 00:00:00 2001 From: miloyip Date: Mon, 13 Apr 2015 13:41:56 +0800 Subject: [PATCH 023/116] Add Tests for WriteUInt64(), WriteInt64() of generic stream --- test/unittest/prettywritertest.cpp | 10 +++++++--- test/unittest/writertest.cpp | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/test/unittest/prettywritertest.cpp b/test/unittest/prettywritertest.cpp index 9c22bd3..9be4f03 100644 --- a/test/unittest/prettywritertest.cpp +++ b/test/unittest/prettywritertest.cpp @@ -25,7 +25,7 @@ using namespace rapidjson; -static const char kJson[] = "{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3]}"; +static const char kJson[] = "{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3],\"u64\":1234567890123456789,\"i64\":-1234567890123456789}"; TEST(PrettyWriter, Basic) { StringBuffer buffer; @@ -45,7 +45,9 @@ TEST(PrettyWriter, Basic) { " 1,\n" " 2,\n" " 3\n" - " ]\n" + " ],\n" + " \"u64\": 1234567890123456789,\n" + " \"i64\": -1234567890123456789\n" "}", buffer.GetString()); } @@ -69,7 +71,9 @@ TEST(PrettyWriter, SetIndent) { "\t\t1,\n" "\t\t2,\n" "\t\t3\n" - "\t]\n" + "\t],\n" + "\t\"u64\": 1234567890123456789,\n" + "\t\"i64\": -1234567890123456789\n" "}", buffer.GetString()); } diff --git a/test/unittest/writertest.cpp b/test/unittest/writertest.cpp index 642161a..54ade34 100644 --- a/test/unittest/writertest.cpp +++ b/test/unittest/writertest.cpp @@ -152,7 +152,7 @@ private: }; TEST(Writer, OStreamWrapper) { - StringStream s("{ \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3] } "); + StringStream s("{ \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3], \"u64\": 1234567890123456789, \"i64\":-1234567890123456789 } "); std::stringstream ss; OStreamWrapper os(ss); @@ -163,7 +163,7 @@ TEST(Writer, OStreamWrapper) { reader.Parse<0>(s, writer); std::string actual = ss.str(); - EXPECT_STREQ("{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3]}", actual.c_str()); + EXPECT_STREQ("{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3],\"u64\":1234567890123456789,\"i64\":-1234567890123456789}", actual.c_str()); } TEST(Writer, AssertRootMayBeAnyValue) { From 127ce7175ab43bf83c334f2e3589f8bbadeee7c5 Mon Sep 17 00:00:00 2001 From: miloyip Date: Mon, 13 Apr 2015 14:05:43 +0800 Subject: [PATCH 024/116] Add a missing error handling for Writer, and add tests for invalid encoding. --- include/rapidjson/writer.h | 3 ++- test/unittest/writertest.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/include/rapidjson/writer.h b/include/rapidjson/writer.h index 6030fe0..5a4d156 100644 --- a/include/rapidjson/writer.h +++ b/include/rapidjson/writer.h @@ -303,7 +303,8 @@ protected: } } else - Transcoder::Transcode(is, *os_); + if (!Transcoder::Transcode(is, *os_)) + return false; } os_->Put('\"'); return true; diff --git a/test/unittest/writertest.cpp b/test/unittest/writertest.cpp index 54ade34..2a0f484 100644 --- a/test/unittest/writertest.cpp +++ b/test/unittest/writertest.cpp @@ -306,3 +306,32 @@ TEST(Writer, RootValueIsComplete) { T(writer.String("")); #undef T } + +TEST(Writer, InvalidEncoding) { + // Fail in decoding invalid UTF-8 sequence http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt + { + GenericStringBuffer > buffer; + Writer >, UTF8<>, UTF16<> > writer(buffer); + writer.StartArray(); + EXPECT_FALSE(writer.String("\xfe")); + EXPECT_FALSE(writer.String("\xff")); + EXPECT_FALSE(writer.String("\xfe\xfe\xff\xff")); + writer.EndArray(); + } + + // Fail in encoding + { + StringBuffer buffer; + Writer > writer(buffer); + static const UTF32<>::Ch s[] = { 0x110000, 0 }; // Out of U+0000 to U+10FFFF + EXPECT_FALSE(writer.String(s)); + } + + // Fail in unicode escaping in ASCII output + { + StringBuffer buffer; + Writer, ASCII<> > writer(buffer); + static const UTF32<>::Ch s[] = { 0x110000, 0 }; // Out of U+0000 to U+10FFFF + EXPECT_FALSE(writer.String(s)); + } +} \ No newline at end of file From 3d82781a7539a14fe1f04d3d94f9e37eafb1a115 Mon Sep 17 00:00:00 2001 From: miloyip Date: Mon, 13 Apr 2015 14:17:21 +0800 Subject: [PATCH 025/116] Improve PrettyWriter coverage --- test/unittest/prettywritertest.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/unittest/prettywritertest.cpp b/test/unittest/prettywritertest.cpp index 9be4f03..d0abf33 100644 --- a/test/unittest/prettywritertest.cpp +++ b/test/unittest/prettywritertest.cpp @@ -25,7 +25,7 @@ using namespace rapidjson; -static const char kJson[] = "{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3],\"u64\":1234567890123456789,\"i64\":-1234567890123456789}"; +static const char kJson[] = "{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3,-1],\"u64\":1234567890123456789,\"i64\":-1234567890123456789}"; TEST(PrettyWriter, Basic) { StringBuffer buffer; @@ -44,7 +44,8 @@ TEST(PrettyWriter, Basic) { " \"a\": [\n" " 1,\n" " 2,\n" - " 3\n" + " 3,\n" + " -1\n" " ],\n" " \"u64\": 1234567890123456789,\n" " \"i64\": -1234567890123456789\n" @@ -70,7 +71,8 @@ TEST(PrettyWriter, SetIndent) { "\t\"a\": [\n" "\t\t1,\n" "\t\t2,\n" - "\t\t3\n" + "\t\t3,\n" + "\t\t-1\n" "\t],\n" "\t\"u64\": 1234567890123456789,\n" "\t\"i64\": -1234567890123456789\n" From 3c028685dfdb23ba3a8c28defa857640b9c93ed1 Mon Sep 17 00:00:00 2001 From: miloyip Date: Mon, 13 Apr 2015 14:25:05 +0800 Subject: [PATCH 026/116] Add tests for Writer API for RAPIDJSON_HAS_STDSTRING --- include/rapidjson/prettywriter.h | 2 +- include/rapidjson/writer.h | 2 +- test/unittest/prettywritertest.cpp | 11 +++++++++++ test/unittest/writertest.cpp | 9 +++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/include/rapidjson/prettywriter.h b/include/rapidjson/prettywriter.h index 90d1983..14b8477 100644 --- a/include/rapidjson/prettywriter.h +++ b/include/rapidjson/prettywriter.h @@ -78,7 +78,7 @@ public: #if RAPIDJSON_HAS_STDSTRING bool String(const std::basic_string& str) { - return String(str.data(), SizeType(str.size())); + return String(str.data(), SizeType(str.size())); } #endif diff --git a/include/rapidjson/writer.h b/include/rapidjson/writer.h index 5a4d156..bf17f3a 100644 --- a/include/rapidjson/writer.h +++ b/include/rapidjson/writer.h @@ -127,7 +127,7 @@ public: #if RAPIDJSON_HAS_STDSTRING bool String(const std::basic_string& str) { - return String(str.data(), SizeType(str.size())); + return String(str.data(), SizeType(str.size())); } #endif diff --git a/test/unittest/prettywritertest.cpp b/test/unittest/prettywritertest.cpp index d0abf33..fcb1121 100644 --- a/test/unittest/prettywritertest.cpp +++ b/test/unittest/prettywritertest.cpp @@ -79,3 +79,14 @@ TEST(PrettyWriter, SetIndent) { "}", buffer.GetString()); } + +#if RAPIDJSON_HAS_STDSTRING +TEST(PrettyWriter, String_STDSTRING) { + StringBuffer buffer; + PrettyWriter writer(buffer); + EXPECT_TRUE(writer.StartArray()); + EXPECT_TRUE(writer.String(std::string("Hello\n"))); + EXPECT_TRUE(writer.EndArray()); + EXPECT_STREQ("[\n \"Hello\\n\"\n]", buffer.GetString()); +} +#endif diff --git a/test/unittest/writertest.cpp b/test/unittest/writertest.cpp index 2a0f484..7b9fa9a 100644 --- a/test/unittest/writertest.cpp +++ b/test/unittest/writertest.cpp @@ -89,6 +89,15 @@ TEST(Writer, String) { TEST_ROUNDTRIP("[\"Hello\"]"); TEST_ROUNDTRIP("[\"Hello\\u0000World\"]"); TEST_ROUNDTRIP("[\"\\\"\\\\/\\b\\f\\n\\r\\t\"]"); + +#if RAPIDJSON_HAS_STDSTRING + { + StringBuffer buffer; + Writer writer(buffer); + writer.String(std::string("Hello\n")); + EXPECT_STREQ("\"Hello\\n\"", buffer.GetString()); + } +#endif } TEST(Writer, Double) { From 18a8891f0d8a233d3ae4827b238631e920594f96 Mon Sep 17 00:00:00 2001 From: miloyip Date: Mon, 13 Apr 2015 14:50:08 +0800 Subject: [PATCH 027/116] Improve coverage for Writer and PrettyWriter --- include/rapidjson/prettywriter.h | 10 ++++++---- include/rapidjson/writer.h | 5 ++--- test/unittest/prettywritertest.cpp | 9 +++++++++ test/unittest/writertest.cpp | 31 +++++++++++++++++++++++++++++- 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/include/rapidjson/prettywriter.h b/include/rapidjson/prettywriter.h index 14b8477..fff8886 100644 --- a/include/rapidjson/prettywriter.h +++ b/include/rapidjson/prettywriter.h @@ -100,8 +100,9 @@ public: Base::os_->Put('\n'); WriteIndent(); } - if (!Base::WriteEndObject()) - return false; + bool ret = Base::WriteEndObject(); + (void)ret; + RAPIDJSON_ASSERT(ret == true); if (Base::level_stack_.Empty()) // end of json text Base::os_->Flush(); return true; @@ -123,8 +124,9 @@ public: Base::os_->Put('\n'); WriteIndent(); } - if (!Base::WriteEndArray()) - return false; + bool ret = Base::WriteEndArray(); + (void)ret; + RAPIDJSON_ASSERT(ret == true); if (Base::level_stack_.Empty()) // end of json text Base::os_->Flush(); return true; diff --git a/include/rapidjson/writer.h b/include/rapidjson/writer.h index bf17f3a..40cdb35 100644 --- a/include/rapidjson/writer.h +++ b/include/rapidjson/writer.h @@ -272,7 +272,8 @@ protected: os_->Put(hexDigits[(codepoint >> 4) & 15]); os_->Put(hexDigits[(codepoint ) & 15]); } - else if (codepoint >= 0x010000 && codepoint <= 0x10FFFF) { + else { + RAPIDJSON_ASSERT(codepoint >= 0x010000 && codepoint <= 0x10FFFF); // Surrogate pair unsigned s = codepoint - 0x010000; unsigned lead = (s >> 10) + 0xD800; @@ -288,8 +289,6 @@ protected: os_->Put(hexDigits[(trail >> 4) & 15]); os_->Put(hexDigits[(trail ) & 15]); } - else - return false; // invalid code point } else if ((sizeof(Ch) == 1 || (unsigned)c < 256) && escape[(unsigned char)c]) { is.Take(); diff --git a/test/unittest/prettywritertest.cpp b/test/unittest/prettywritertest.cpp index fcb1121..3b2355f 100644 --- a/test/unittest/prettywritertest.cpp +++ b/test/unittest/prettywritertest.cpp @@ -80,6 +80,15 @@ TEST(PrettyWriter, SetIndent) { buffer.GetString()); } +TEST(PrettyWriter, String) { + StringBuffer buffer; + PrettyWriter writer(buffer); + EXPECT_TRUE(writer.StartArray()); + EXPECT_TRUE(writer.String("Hello\n")); + EXPECT_TRUE(writer.EndArray()); + EXPECT_STREQ("[\n \"Hello\\n\"\n]", buffer.GetString()); +} + #if RAPIDJSON_HAS_STDSTRING TEST(PrettyWriter, String_STDSTRING) { StringBuffer buffer; diff --git a/test/unittest/writertest.cpp b/test/unittest/writertest.cpp index 7b9fa9a..d8193ca 100644 --- a/test/unittest/writertest.cpp +++ b/test/unittest/writertest.cpp @@ -343,4 +343,33 @@ TEST(Writer, InvalidEncoding) { static const UTF32<>::Ch s[] = { 0x110000, 0 }; // Out of U+0000 to U+10FFFF EXPECT_FALSE(writer.String(s)); } -} \ No newline at end of file +} + +TEST(Writer, InvalidEventSequence) { + // {] + { + StringBuffer buffer; + Writer writer(buffer); + writer.StartObject(); + EXPECT_THROW(writer.EndArray(), AssertException); + EXPECT_FALSE(writer.IsComplete()); + } + + // [} + { + StringBuffer buffer; + Writer writer(buffer); + writer.StartArray(); + EXPECT_THROW(writer.EndObject(), AssertException); + EXPECT_FALSE(writer.IsComplete()); + } + + // { 1: + { + StringBuffer buffer; + Writer writer(buffer); + writer.StartObject(); + EXPECT_THROW(writer.Int(1), AssertException); + EXPECT_FALSE(writer.IsComplete()); + } +} From e9b92256a263a6ddb2636ee1f725cf8a09ca5900 Mon Sep 17 00:00:00 2001 From: miloyip Date: Mon, 13 Apr 2015 15:11:32 +0800 Subject: [PATCH 028/116] Add itoatest --- include/rapidjson/internal/itoa.h | 2 + test/unittest/CMakeLists.txt | 1 + test/unittest/itoatest.cpp | 155 ++++++++++++++++++++++++++++++ 3 files changed, 158 insertions(+) create mode 100644 test/unittest/itoatest.cpp diff --git a/include/rapidjson/internal/itoa.h b/include/rapidjson/internal/itoa.h index 9ecf630..01a4e7e 100644 --- a/include/rapidjson/internal/itoa.h +++ b/include/rapidjson/internal/itoa.h @@ -15,6 +15,8 @@ #ifndef RAPIDJSON_ITOA_ #define RAPIDJSON_ITOA_ +#include "../rapidjson.h" + RAPIDJSON_NAMESPACE_BEGIN namespace internal { diff --git a/test/unittest/CMakeLists.txt b/test/unittest/CMakeLists.txt index 3c49651..76b598f 100644 --- a/test/unittest/CMakeLists.txt +++ b/test/unittest/CMakeLists.txt @@ -4,6 +4,7 @@ set(UNITTEST_SOURCES encodedstreamtest.cpp encodingstest.cpp filestreamtest.cpp + itoatest.cpp jsoncheckertest.cpp namespacetest.cpp prettywritertest.cpp diff --git a/test/unittest/itoatest.cpp b/test/unittest/itoatest.cpp new file mode 100644 index 0000000..4ad6d67 --- /dev/null +++ b/test/unittest/itoatest.cpp @@ -0,0 +1,155 @@ +// Copyright (C) 2011 Milo Yip +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#include "unittest.h" +#include "rapidjson/internal/itoa.h" + +using namespace rapidjson::internal; + +template +struct Traits { +}; + +template <> +struct Traits { + enum { kBufferSize = 11 }; + enum { kMaxDigit = 10 }; + static uint32_t Negate(uint32_t x) { return x; }; +}; + +template <> +struct Traits { + enum { kBufferSize = 12 }; + enum { kMaxDigit = 10 }; + static int32_t Negate(int32_t x) { return -x; }; +}; + +template <> +struct Traits { + enum { kBufferSize = 21 }; + enum { kMaxDigit = 20 }; + static uint64_t Negate(uint64_t x) { return x; }; +}; + +template <> +struct Traits { + enum { kBufferSize = 22 }; + enum { kMaxDigit = 20 }; + static int64_t Negate(int64_t x) { return -x; }; +}; + +template +static void VerifyValue(T value, void(*f)(T, char*), char* (*g)(T, char*)) { + char buffer1[Traits::kBufferSize]; + char buffer2[Traits::kBufferSize]; + + f(value, buffer1); + *g(value, buffer2) = '\0'; + + + EXPECT_STREQ(buffer1, buffer2); +} + +template +static void Verify(void(*f)(T, char*), char* (*g)(T, char*)) { + // Boundary cases + VerifyValue(0, f, g); + VerifyValue(std::numeric_limits::min(), f, g); + VerifyValue(std::numeric_limits::max(), f, g); + + // 2^n - 1, 2^n, 10^n - 1, 10^n until overflow + for (uint32_t power = 2; power <= 10; power += 8) { + T i = 1, last; + do { + VerifyValue(i - 1, f, g); + VerifyValue(i, f, g); + if (std::numeric_limits::min() < 0) { + VerifyValue(Traits::Negate(i), f, g); + VerifyValue(Traits::Negate(i + 1), f, g); + } + last = i; + i *= power; + } while (last < i); + } +} + +static void u32toa_naive(uint32_t value, char* buffer) { + char temp[10]; + char *p = temp; + do { + *p++ = char(value % 10) + '0'; + value /= 10; + } while (value > 0); + + do { + *buffer++ = *--p; + } while (p != temp); + + *buffer = '\0'; +} + +static void i32toa_naive(int32_t value, char* buffer) { + uint32_t u = static_cast(value); + if (value < 0) { + *buffer++ = '-'; + u = ~u + 1; + } + u32toa_naive(u, buffer); +} + +static void u64toa_naive(uint64_t value, char* buffer) { + char temp[20]; + char *p = temp; + do { + *p++ = char(value % 10) + '0'; + value /= 10; + } while (value > 0); + + do { + *buffer++ = *--p; + } while (p != temp); + + *buffer = '\0'; +} + +static void i64toa_naive(int64_t value, char* buffer) { + uint64_t u = static_cast(value); + if (value < 0) { + *buffer++ = '-'; + u = ~u + 1; + } + u64toa_naive(u, buffer); +} + +TEST(itoa, u32toa) { + Verify(u32toa_naive, u32toa); +} + +TEST(itoa, i32toa) { + Verify(i32toa_naive, i32toa); +} + +TEST(itoa, u64toa) { + Verify(u64toa_naive, u64toa); +} + +TEST(itoa, i64toa) { + Verify(i64toa_naive, i64toa); +} From 0b793ea58a947fb6ea3b5b518399d8561a0eef33 Mon Sep 17 00:00:00 2001 From: miloyip Date: Mon, 13 Apr 2015 15:18:26 +0800 Subject: [PATCH 029/116] Add test for covering PutN() generic version --- test/unittest/prettywritertest.cpp | 57 ++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/test/unittest/prettywritertest.cpp b/test/unittest/prettywritertest.cpp index 3b2355f..b18ad3f 100644 --- a/test/unittest/prettywritertest.cpp +++ b/test/unittest/prettywritertest.cpp @@ -99,3 +99,60 @@ TEST(PrettyWriter, String_STDSTRING) { EXPECT_STREQ("[\n \"Hello\\n\"\n]", buffer.GetString()); } #endif + +#include + +class OStreamWrapper { +public: + typedef char Ch; + + OStreamWrapper(std::ostream& os) : os_(os) {} + + Ch Peek() const { assert(false); return '\0'; } + Ch Take() { assert(false); return '\0'; } + size_t Tell() const { return 0; } + + Ch* PutBegin() { assert(false); return 0; } + void Put(Ch c) { os_.put(c); } + void Flush() { os_.flush(); } + size_t PutEnd(Ch*) { assert(false); return 0; } + +private: + OStreamWrapper(const OStreamWrapper&); + OStreamWrapper& operator=(const OStreamWrapper&); + + std::ostream& os_; +}; + +// For covering PutN() generic version +TEST(PrettyWriter, OStreamWrapper) { + StringStream s(kJson); + + std::stringstream ss; + OStreamWrapper os(ss); + + PrettyWriter writer(os); + + Reader reader; + reader.Parse(s, writer); + + std::string actual = ss.str(); + EXPECT_STREQ( + "{\n" + " \"hello\": \"world\",\n" + " \"t\": true,\n" + " \"f\": false,\n" + " \"n\": null,\n" + " \"i\": 123,\n" + " \"pi\": 3.1416,\n" + " \"a\": [\n" + " 1,\n" + " 2,\n" + " 3,\n" + " -1\n" + " ],\n" + " \"u64\": 1234567890123456789,\n" + " \"i64\": -1234567890123456789\n" + "}", + actual.c_str()); +} From affd2736c33a82ebbf2e1d6fd3f311355aea6686 Mon Sep 17 00:00:00 2001 From: miloyip Date: Mon, 13 Apr 2015 15:22:26 +0800 Subject: [PATCH 030/116] Fix gcc warning for itoatest --- test/unittest/itoatest.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/unittest/itoatest.cpp b/test/unittest/itoatest.cpp index 4ad6d67..31a008c 100644 --- a/test/unittest/itoatest.cpp +++ b/test/unittest/itoatest.cpp @@ -21,6 +21,11 @@ #include "unittest.h" #include "rapidjson/internal/itoa.h" +#ifdef __GNUC__ +RAPIDJSON_DIAG_PUSH +RAPIDJSON_DIAG_OFF(type-limits) +#endif + using namespace rapidjson::internal; template @@ -153,3 +158,7 @@ TEST(itoa, u64toa) { TEST(itoa, i64toa) { Verify(i64toa_naive, i64toa); } + +#ifdef __GNUC__ +RAPIDJSON_DIAG_POP +#endif From bcd879653fd0044931db5387dca2ac22005e0101 Mon Sep 17 00:00:00 2001 From: miloyip Date: Mon, 13 Apr 2015 16:13:39 +0800 Subject: [PATCH 031/116] Enable SIMD macros in unit tests --- test/unittest/unittest.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/unittest/unittest.h b/test/unittest/unittest.h index 800fbab..87bb083 100644 --- a/test/unittest/unittest.h +++ b/test/unittest/unittest.h @@ -40,6 +40,14 @@ #pragma GCC diagnostic ignored "-Weffc++" #endif +// __SSE2__ and __SSE4_2__ are recognized by gcc, clang, and the Intel compiler. +// We use -march=native with gmake to enable -msse2 and -msse4.2, if supported. +#if defined(__SSE4_2__) +# define RAPIDJSON_SSE42 +#elif defined(__SSE2__) +# define RAPIDJSON_SSE2 +#endif + #include "gtest/gtest.h" #include From 23809ddef6735a7195a67f7253c049feecf1ffe2 Mon Sep 17 00:00:00 2001 From: miloyip Date: Mon, 13 Apr 2015 16:27:49 +0800 Subject: [PATCH 032/116] Revert "Enable SIMD macros in unit tests" This reverts commit bcd879653fd0044931db5387dca2ac22005e0101. --- test/unittest/unittest.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/test/unittest/unittest.h b/test/unittest/unittest.h index 87bb083..800fbab 100644 --- a/test/unittest/unittest.h +++ b/test/unittest/unittest.h @@ -40,14 +40,6 @@ #pragma GCC diagnostic ignored "-Weffc++" #endif -// __SSE2__ and __SSE4_2__ are recognized by gcc, clang, and the Intel compiler. -// We use -march=native with gmake to enable -msse2 and -msse4.2, if supported. -#if defined(__SSE4_2__) -# define RAPIDJSON_SSE42 -#elif defined(__SSE2__) -# define RAPIDJSON_SSE2 -#endif - #include "gtest/gtest.h" #include From 7e1a6a1bb2da4f6aee77423b19517fdcc15e71ef Mon Sep 17 00:00:00 2001 From: miloyip Date: Mon, 13 Apr 2015 16:45:00 +0800 Subject: [PATCH 033/116] Add Reader kParseErrorTermination coverage --- test/unittest/readertest.cpp | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/test/unittest/readertest.cpp b/test/unittest/readertest.cpp index 8c8c63c..25a7261 100644 --- a/test/unittest/readertest.cpp +++ b/test/unittest/readertest.cpp @@ -1177,6 +1177,56 @@ TEST(Reader, IterativeParsing_ShortCircuit) { } } +// For covering BaseReaderHandler default functions +TEST(Reader, BaseReaderHandler_Default) { + BaseReaderHandler<> h; + Reader reader; + StringStream is("[null, true, -1, 1, -1234567890123456789, 1234567890123456789, 3.14, \"s\", { \"a\" : 1 }]"); + EXPECT_TRUE(reader.Parse(is, h)); +} + +template +struct TerminateHandler { + bool Null() { return e != 0; } + bool Bool(bool) { return e != 1; } + bool Int(int) { return e != 2; } + bool Uint(unsigned) { return e != 3; } + bool Int64(int64_t) { return e != 4; } + bool Uint64(uint64_t) { return e != 5; } + bool Double(double) { return e != 6; } + bool String(const char*, SizeType, bool) { return e != 7; } + bool StartObject() { return e != 8; } + bool Key(const char* str, SizeType length, bool copy) { return e != 9; } + bool EndObject(SizeType memberCount) { return e != 10; } + bool StartArray() { return e != 11; } + bool EndArray(SizeType elementCount) { return e != 12; } +}; + +#define TEST_TERMINATION(e, json)\ +{\ + Reader reader;\ + TerminateHandler h;\ + StringStream is(json);\ + EXPECT_FALSE(reader.Parse(is, h));\ + EXPECT_EQ(kParseErrorTermination, reader.GetParseErrorCode());\ +} + +TEST(Reader, ParseTerminationByHandler) { + TEST_TERMINATION(0, "[null"); + TEST_TERMINATION(1, "[true"); + TEST_TERMINATION(2, "[-1"); + TEST_TERMINATION(3, "[1"); + TEST_TERMINATION(4, "[-1234567890123456789"); + TEST_TERMINATION(5, "[1234567890123456789"); + TEST_TERMINATION(6, "[0.5]"); + TEST_TERMINATION(7, "[\"a\""); + TEST_TERMINATION(8, "[{"); + TEST_TERMINATION(9, "[{\"a\""); + TEST_TERMINATION(10, "[{}"); + TEST_TERMINATION(11, "{\"a\":["); + TEST_TERMINATION(12, "{\"a\":[]"); +} + #ifdef __GNUC__ RAPIDJSON_DIAG_POP #endif From 331009a321e4064afe99023add0aa7afb70f0abe Mon Sep 17 00:00:00 2001 From: miloyip Date: Mon, 13 Apr 2015 16:49:10 +0800 Subject: [PATCH 034/116] Fix gcc warning --- test/unittest/readertest.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/unittest/readertest.cpp b/test/unittest/readertest.cpp index 25a7261..a808d90 100644 --- a/test/unittest/readertest.cpp +++ b/test/unittest/readertest.cpp @@ -1196,10 +1196,10 @@ struct TerminateHandler { bool Double(double) { return e != 6; } bool String(const char*, SizeType, bool) { return e != 7; } bool StartObject() { return e != 8; } - bool Key(const char* str, SizeType length, bool copy) { return e != 9; } - bool EndObject(SizeType memberCount) { return e != 10; } + bool Key(const char*, SizeType, bool) { return e != 9; } + bool EndObject(SizeType) { return e != 10; } bool StartArray() { return e != 11; } - bool EndArray(SizeType elementCount) { return e != 12; } + bool EndArray(SizeType) { return e != 12; } }; #define TEST_TERMINATION(e, json)\ From 074554965dfca1d6d5e64e2fc871f37a57d9ffb7 Mon Sep 17 00:00:00 2001 From: miloyip Date: Mon, 13 Apr 2015 17:07:15 +0800 Subject: [PATCH 035/116] Improve Reading kParseErrorTermination coverage --- test/unittest/readertest.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/unittest/readertest.cpp b/test/unittest/readertest.cpp index a808d90..1461353 100644 --- a/test/unittest/readertest.cpp +++ b/test/unittest/readertest.cpp @@ -1214,6 +1214,7 @@ struct TerminateHandler { TEST(Reader, ParseTerminationByHandler) { TEST_TERMINATION(0, "[null"); TEST_TERMINATION(1, "[true"); + TEST_TERMINATION(1, "[false"); TEST_TERMINATION(2, "[-1"); TEST_TERMINATION(3, "[1"); TEST_TERMINATION(4, "[-1234567890123456789"); @@ -1223,8 +1224,10 @@ TEST(Reader, ParseTerminationByHandler) { TEST_TERMINATION(8, "[{"); TEST_TERMINATION(9, "[{\"a\""); TEST_TERMINATION(10, "[{}"); + TEST_TERMINATION(10, "[{\"a\":1}"); // non-empty object TEST_TERMINATION(11, "{\"a\":["); TEST_TERMINATION(12, "{\"a\":[]"); + TEST_TERMINATION(12, "{\"a\":[1]"); // non-empty array } #ifdef __GNUC__ From d439f989bfe20d188e10a5b039437306db10b4f1 Mon Sep 17 00:00:00 2001 From: miloyip Date: Mon, 13 Apr 2015 18:10:07 +0800 Subject: [PATCH 036/116] Add valuetest coverage --- test/unittest/valuetest.cpp | 86 +++++++++++++++++++++++++++++++++---- 1 file changed, 78 insertions(+), 8 deletions(-) diff --git a/test/unittest/valuetest.cpp b/test/unittest/valuetest.cpp index 846b1c8..26fde3b 100644 --- a/test/unittest/valuetest.cpp +++ b/test/unittest/valuetest.cpp @@ -203,12 +203,28 @@ TEST(Value, EqualtoOperator) { EXPECT_TRUE(z.RemoveMember("t")); TestUnequal(x, z); TestEqual(y, z); - y.AddMember("t", true, crtAllocator); - z.AddMember("t", true, z.GetAllocator()); + y.AddMember("t", false, crtAllocator); + z.AddMember("t", false, z.GetAllocator()); + TestUnequal(x, y); + TestUnequal(z, x); + y["t"] = true; + z["t"] = true; TestEqual(x, y); TestEqual(y, z); TestEqual(z, x); + // Swapping element order is not OK + x["a"][0].Swap(x["a"][1]); + TestUnequal(x, y); + x["a"][0].Swap(x["a"][1]); + TestEqual(x, y); + + // Array of different size + x["a"].PushBack(4, allocator); + TestUnequal(x, y); + x["a"].PopBack(); + TestEqual(x, y); + // Issue #129: compare Uint64 x.SetUint64(RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0xFFFFFFF0)); y.SetUint64(RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0xFFFFFFFF)); @@ -462,10 +478,19 @@ TEST(Value, Int64) { z.SetInt64(2147483648LL); // 2^31, cannot cast as int EXPECT_FALSE(z.IsInt()); EXPECT_TRUE(z.IsUint()); + EXPECT_NEAR(2147483648.0, z.GetDouble(), 0.0); z.SetInt64(4294967296LL); // 2^32, cannot cast as uint EXPECT_FALSE(z.IsInt()); EXPECT_FALSE(z.IsUint()); + EXPECT_NEAR(4294967296.0, z.GetDouble(), 0.0); + + z.SetInt64(-2147483649LL); // -2^31-1, cannot cast as int + EXPECT_FALSE(z.IsInt()); + EXPECT_NEAR(-2147483649.0, z.GetDouble(), 0.0); + + z.SetInt64(-9223372036854775808LL); + EXPECT_DOUBLE_EQ(-9223372036854775808.0, z.GetDouble()); } TEST(Value, Uint64) { @@ -508,9 +533,8 @@ TEST(Value, Uint64) { z.SetUint64(9223372036854775808uLL); // 2^63 cannot cast as int64 EXPECT_FALSE(z.IsInt64()); - - // Issue 48 - EXPECT_EQ(9223372036854775808uLL, z.GetUint64()); + EXPECT_EQ(9223372036854775808uLL, z.GetUint64()); // Issue 48 + EXPECT_DOUBLE_EQ(9223372036854775808.0, z.GetDouble()); } TEST(Value, Double) { @@ -977,6 +1001,7 @@ TEST(Value, Object) { EXPECT_STREQ("Banana", x["B"].GetString()); EXPECT_STREQ("CherryD", x[C0D].GetString()); EXPECT_STREQ("CherryD", x[othername].GetString()); + EXPECT_THROW(x["nonexist"], AssertException); // const operator[] EXPECT_STREQ("Apple", y["A"].GetString()); @@ -1041,13 +1066,15 @@ TEST(Value, Object) { EXPECT_FALSE(citr >= itr); // RemoveMember() - x.RemoveMember("A"); + EXPECT_TRUE(x.RemoveMember("A")); EXPECT_FALSE(x.HasMember("A")); - x.RemoveMember("B"); + EXPECT_TRUE(x.RemoveMember("B")); EXPECT_FALSE(x.HasMember("B")); - x.RemoveMember(othername); + EXPECT_FALSE(x.RemoveMember("nonexist")); + + EXPECT_TRUE(x.RemoveMember(othername)); EXPECT_FALSE(x.HasMember(name)); EXPECT_TRUE(x.MemberBegin() == x.MemberEnd()); @@ -1237,3 +1264,46 @@ TEST(Value, AllocateShortString) { TestShortStringOptimization("123456789012345"); // edge case: 15 chars in 64-bit mode (=> short string) TestShortStringOptimization("1234567890123456"); // edge case: 16 chars in 64-bit mode (=> regular string) } + +template +struct TerminateHandler { + bool Null() { return e != 0; } + bool Bool(bool) { return e != 1; } + bool Int(int) { return e != 2; } + bool Uint(unsigned) { return e != 3; } + bool Int64(int64_t) { return e != 4; } + bool Uint64(uint64_t) { return e != 5; } + bool Double(double) { return e != 6; } + bool String(const char*, SizeType, bool) { return e != 7; } + bool StartObject() { return e != 8; } + bool Key(const char*, SizeType, bool) { return e != 9; } + bool EndObject(SizeType) { return e != 10; } + bool StartArray() { return e != 11; } + bool EndArray(SizeType) { return e != 12; } +}; + +#define TEST_TERMINATION(e, json)\ +{\ + Document d; \ + EXPECT_FALSE(d.Parse(json).HasParseError()); \ + Reader reader; \ + TerminateHandler h;\ + EXPECT_FALSE(d.Accept(h));\ +} + +TEST(Value, AcceptTerminationByHandler) { + TEST_TERMINATION(0, "[null]"); + TEST_TERMINATION(1, "[true]"); + TEST_TERMINATION(1, "[false]"); + TEST_TERMINATION(2, "[-1]"); + TEST_TERMINATION(3, "[2147483648]"); + TEST_TERMINATION(4, "[-1234567890123456789]"); + TEST_TERMINATION(5, "[9223372036854775808]"); + TEST_TERMINATION(6, "[0.5]"); + TEST_TERMINATION(7, "[\"a\"]"); + TEST_TERMINATION(8, "[{}]"); + TEST_TERMINATION(9, "[{\"a\":1}]"); + TEST_TERMINATION(10, "[{}]"); + TEST_TERMINATION(11, "{\"a\":[]}"); + TEST_TERMINATION(12, "{\"a\":[]}"); +} From e7f1c6dd08b522cfcf9aed58a333bd9a0c0ccbeb Mon Sep 17 00:00:00 2001 From: miloyip Date: Mon, 13 Apr 2015 18:21:15 +0800 Subject: [PATCH 037/116] Remove an invalid Document::ParseInsitu() API --- doc/dom.md | 14 +++++--------- doc/dom.zh-cn.md | 14 +++++--------- include/rapidjson/document.h | 17 +++-------------- 3 files changed, 13 insertions(+), 32 deletions(-) diff --git a/doc/dom.md b/doc/dom.md index c047ede..f3e4208 100644 --- a/doc/dom.md +++ b/doc/dom.md @@ -84,29 +84,25 @@ template GenericDocument& GenericDocument::ParseStream(InputStream& is); // (4) In situ parsing -template -GenericDocument& GenericDocument::ParseInsitu(Ch* str); - -// (5) In situ parsing, using same Encoding of Document template GenericDocument& GenericDocument::ParseInsitu(Ch* str); -// (6) In situ parsing, using default parse flags +// (5) In situ parsing, using default parse flags GenericDocument& GenericDocument::ParseInsitu(Ch* str); -// (7) Normal parsing of a string +// (6) Normal parsing of a string template GenericDocument& GenericDocument::Parse(const Ch* str); -// (8) Normal parsing of a string, using same Encoding of Document +// (7) Normal parsing of a string, using same Encoding of Document template GenericDocument& GenericDocument::Parse(const Ch* str); -// (9) Normal parsing of a string, using default parse flags +// (8) Normal parsing of a string, using default parse flags GenericDocument& GenericDocument::Parse(const Ch* str); ~~~~~~~~~~ -The examples of [tutorial](doc/tutorial.md) uses (9) for normal parsing of string. The examples of [stream](doc/stream.md) uses the first three. *In situ* parsing will be described soon. +The examples of [tutorial](doc/tutorial.md) uses (8) for normal parsing of string. The examples of [stream](doc/stream.md) uses the first three. *In situ* parsing will be described soon. The `parseFlags` are combination of the following bit-flags: diff --git a/doc/dom.zh-cn.md b/doc/dom.zh-cn.md index 8fb3ee4..c7fcfff 100644 --- a/doc/dom.zh-cn.md +++ b/doc/dom.zh-cn.md @@ -84,29 +84,25 @@ template GenericDocument& GenericDocument::ParseStream(InputStream& is); // (4) 原位解析 -template -GenericDocument& GenericDocument::ParseInsitu(Ch* str); - -// (5) 原位解析,使用Document的编码 template GenericDocument& GenericDocument::ParseInsitu(Ch* str); -// (6) 原位解析,使用缺省标志 +// (5) 原位解析,使用缺省标志 GenericDocument& GenericDocument::ParseInsitu(Ch* str); -// (7) 正常解析一个字符串 +// (6) 正常解析一个字符串 template GenericDocument& GenericDocument::Parse(const Ch* str); -// (8) 正常解析一个字符串,使用Document的编码 +// (7) 正常解析一个字符串,使用Document的编码 template GenericDocument& GenericDocument::Parse(const Ch* str); -// (9) 正常解析一个字符串,使用缺省标志 +// (8) 正常解析一个字符串,使用缺省标志 GenericDocument& GenericDocument::Parse(const Ch* str); ~~~~~~~~~~ -[教程](tutorial.md)中的例使用(9)去正常解析字符串。而[流](stream.md)的例子使用前3个函数。我们将稍后介绍原位(*In situ*) 解析。 +[教程](tutorial.md)中的例使用(8)去正常解析字符串。而[流](stream.md)的例子使用前3个函数。我们将稍后介绍原位(*In situ*) 解析。 `parseFlags`是以下位标置的组合: diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 8cc968a..c843524 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -1770,18 +1770,6 @@ public: //!@name Parse in-place from mutable string //!@{ - //! Parse JSON text from a mutable string (with Encoding conversion) - /*! \tparam parseFlags Combination of \ref ParseFlag. - \tparam SourceEncoding Transcoding from input Encoding - \param str Mutable zero-terminated string to be parsed. - \return The document itself for fluent API. - */ - template - GenericDocument& ParseInsitu(Ch* str) { - GenericInsituStringStream s(str); - return ParseStream(s); - } - //! Parse JSON text from a mutable string /*! \tparam parseFlags Combination of \ref ParseFlag. \param str Mutable zero-terminated string to be parsed. @@ -1789,7 +1777,8 @@ public: */ template GenericDocument& ParseInsitu(Ch* str) { - return ParseInsitu(str); + GenericInsituStringStream s(str); + return ParseStream(s); } //! Parse JSON text from a mutable string (with \ref kParseDefaultFlags) @@ -1797,7 +1786,7 @@ public: \return The document itself for fluent API. */ GenericDocument& ParseInsitu(Ch* str) { - return ParseInsitu(str); + return ParseInsitu(str); } //!@} From 2d07198863f226529fe724ee6c6a67993245feaf Mon Sep 17 00:00:00 2001 From: miloyip Date: Mon, 13 Apr 2015 18:24:10 +0800 Subject: [PATCH 038/116] Fix compilation --- 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 c843524..204e3bd 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -1778,7 +1778,7 @@ public: template GenericDocument& ParseInsitu(Ch* str) { GenericInsituStringStream s(str); - return ParseStream(s); + return ParseStream(s); } //! Parse JSON text from a mutable string (with \ref kParseDefaultFlags) From 59ffb9e5f0b5aae07c6d4a507a02cd1a0a7114a3 Mon Sep 17 00:00:00 2001 From: miloyip Date: Mon, 13 Apr 2015 18:32:11 +0800 Subject: [PATCH 039/116] Try to fix a gcc/clang error --- test/unittest/valuetest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/valuetest.cpp b/test/unittest/valuetest.cpp index 26fde3b..bb4cc04 100644 --- a/test/unittest/valuetest.cpp +++ b/test/unittest/valuetest.cpp @@ -489,7 +489,7 @@ TEST(Value, Int64) { EXPECT_FALSE(z.IsInt()); EXPECT_NEAR(-2147483649.0, z.GetDouble(), 0.0); - z.SetInt64(-9223372036854775808LL); + z.SetInt64(static_cast(RAPIDJSON_UINT64_C2(0x80000000, 00000000))); EXPECT_DOUBLE_EQ(-9223372036854775808.0, z.GetDouble()); } From 3bc95ecd7c8e2cc8aa1c053dc97294fa5e807587 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Mon, 13 Apr 2015 22:04:00 +0800 Subject: [PATCH 040/116] Add coverage for Document::ParseXXX() --- test/unittest/documenttest.cpp | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/test/unittest/documenttest.cpp b/test/unittest/documenttest.cpp index 12ea751..e185efb 100644 --- a/test/unittest/documenttest.cpp +++ b/test/unittest/documenttest.cpp @@ -28,13 +28,9 @@ using namespace rapidjson; -template -void ParseTest() { - typedef GenericDocument, Allocator, StackAllocator> DocumentType; +template +void ParseCheck(DocumentType& doc) { typedef typename DocumentType::ValueType ValueType; - DocumentType doc; - - doc.Parse(" { \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3, 4] } "); EXPECT_TRUE(doc.IsObject()); @@ -73,6 +69,28 @@ void ParseTest() { EXPECT_EQ(i + 1, a[i].GetUint()); } +template +void ParseTest() { + typedef GenericDocument, Allocator, StackAllocator> DocumentType; + DocumentType doc; + + const char* json = " { \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3, 4] } "; + + EXPECT_FALSE(doc.Parse(json).HasParseError()); + ParseCheck(doc); + + doc.SetNull(); + StringStream s(json); + EXPECT_FALSE(doc.ParseStream<0>( s).HasParseError()); + ParseCheck(doc); + + doc.SetNull(); + char *buffer = strdup(json); + EXPECT_FALSE(doc.ParseInsitu(buffer).HasParseError()); + ParseCheck(doc); + free(buffer); +} + TEST(Document, Parse) { ParseTest, CrtAllocator>(); ParseTest, MemoryPoolAllocator<> >(); From 985971a563b35c28d6085554c110d28ccffcdf4d Mon Sep 17 00:00:00 2001 From: miloyip Date: Mon, 13 Apr 2015 22:46:09 +0800 Subject: [PATCH 041/116] Fix gcc/clang compilation --- test/unittest/documenttest.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/unittest/documenttest.cpp b/test/unittest/documenttest.cpp index e185efb..7adf9b9 100644 --- a/test/unittest/documenttest.cpp +++ b/test/unittest/documenttest.cpp @@ -32,6 +32,8 @@ template void ParseCheck(DocumentType& doc) { typedef typename DocumentType::ValueType ValueType; + EXPECT_FALSE(doc.HasParseError()); + EXPECT_TRUE(doc.IsObject()); EXPECT_TRUE(doc.HasMember("hello")); @@ -76,17 +78,17 @@ void ParseTest() { const char* json = " { \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3, 4] } "; - EXPECT_FALSE(doc.Parse(json).HasParseError()); + doc.Parse(json); ParseCheck(doc); doc.SetNull(); StringStream s(json); - EXPECT_FALSE(doc.ParseStream<0>( s).HasParseError()); + doc.template ParseStream<0>(s); ParseCheck(doc); doc.SetNull(); char *buffer = strdup(json); - EXPECT_FALSE(doc.ParseInsitu(buffer).HasParseError()); + doc.ParseInsitu(buffer); ParseCheck(doc); free(buffer); } From 04011cdae2889c2154373220a39686343998ae9e Mon Sep 17 00:00:00 2001 From: miloyip Date: Mon, 13 Apr 2015 22:46:27 +0800 Subject: [PATCH 042/116] Adjust spaces --- 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 204e3bd..e436b8a 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -1753,7 +1753,7 @@ public: */ template GenericDocument& ParseStream(InputStream& is) { - return ParseStream(is); + return ParseStream(is); } //! Parse JSON text from an input stream (with \ref kParseDefaultFlags) From 4bcedab513123c7620eb30f53f314852eba5ba10 Mon Sep 17 00:00:00 2001 From: miloyip Date: Mon, 13 Apr 2015 23:03:00 +0800 Subject: [PATCH 043/116] Try to improve coverage of encodings --- test/unittest/readertest.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/unittest/readertest.cpp b/test/unittest/readertest.cpp index 1461353..c5a8a5a 100644 --- a/test/unittest/readertest.cpp +++ b/test/unittest/readertest.cpp @@ -487,6 +487,17 @@ TEST(Reader, ParseString_Transcoding) { EXPECT_EQ(StrLen(e), h.length_); } +TEST(Reader, ParseString_TranscodingWithValidation) { + const char* x = "\"Hello\""; + const wchar_t* e = L"Hello"; + GenericStringStream > is(x); + GenericReader, UTF16<> > reader; + ParseStringHandler > h; + reader.Parse(is, h); + EXPECT_EQ(0, StrCmp::Ch>(e, h.str_)); + EXPECT_EQ(StrLen(e), h.length_); +} + TEST(Reader, ParseString_NonDestructive) { StringStream s("\"Hello\\nWorld\""); ParseStringHandler > h; From 933c4a6cb1ea91063b5c9b23918eea516c37c40f Mon Sep 17 00:00:00 2001 From: miloyip Date: Mon, 13 Apr 2015 23:12:57 +0800 Subject: [PATCH 044/116] Improve Value deep-clone coverage --- test/unittest/valuetest.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/unittest/valuetest.cpp b/test/unittest/valuetest.cpp index bb4cc04..fa9547b 100644 --- a/test/unittest/valuetest.cpp +++ b/test/unittest/valuetest.cpp @@ -245,6 +245,13 @@ void TestCopyFrom() { EXPECT_STREQ(v1.GetString(), v2.GetString()); EXPECT_EQ(v1.GetString(), v2.GetString()); // string NOT copied + v1.SetString("bar", a); // copy string + v2.CopyFrom(v1, a); + EXPECT_TRUE(v1.GetType() == v2.GetType()); + EXPECT_STREQ(v1.GetString(), v2.GetString()); + EXPECT_NE(v1.GetString(), v2.GetString()); // string copied + + v1.SetArray().PushBack(1234, a); v2.CopyFrom(v1, a); EXPECT_TRUE(v2.IsArray()); From f51c0141c57b37b81351f75321932b1c19fc56e2 Mon Sep 17 00:00:00 2001 From: miloyip Date: Tue, 14 Apr 2015 00:39:54 +0800 Subject: [PATCH 045/116] Improve coverage of encodings --- test/unittest/readertest.cpp | 67 ++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 25 deletions(-) diff --git a/test/unittest/readertest.cpp b/test/unittest/readertest.cpp index c5a8a5a..f5f6cce 100644 --- a/test/unittest/readertest.cpp +++ b/test/unittest/readertest.cpp @@ -507,24 +507,31 @@ TEST(Reader, ParseString_NonDestructive) { EXPECT_EQ(11u, h.length_); } -ParseErrorCode TestString(const char* str) { - StringStream s(str); - BaseReaderHandler<> h; - Reader reader; - reader.Parse(s, h); +template +ParseErrorCode TestString(const typename Encoding::Ch* str) { + GenericStringStream s(str); + BaseReaderHandler h; + GenericReader reader; + reader.template Parse(s, h); return reader.GetParseErrorCode(); } TEST(Reader, ParseString_Error) { #define TEST_STRING_ERROR(errorCode, str)\ - EXPECT_EQ(errorCode, TestString(str)) + EXPECT_EQ(errorCode, TestString >(str)) #define ARRAY(...) { __VA_ARGS__ } -#define TEST_STRINGENCODING_ERROR(Encoding, utype, array) \ +#define TEST_STRINGENCODING_ERROR(Encoding, TargetEncoding, utype, array) \ { \ static const utype ue[] = array; \ static const Encoding::Ch* e = reinterpret_cast(&ue[0]); \ - EXPECT_EQ(kParseErrorStringInvalidEncoding, TestString(e));\ + EXPECT_EQ(kParseErrorStringInvalidEncoding, TestString(e));\ + /* decode error */\ + GenericStringStream s(e);\ + BaseReaderHandler h;\ + GenericReader reader;\ + reader.Parse(s, h);\ + EXPECT_EQ(kParseErrorStringInvalidEncoding, reader.GetParseErrorCode());\ } // Invalid escape character in string. @@ -553,7 +560,7 @@ TEST(Reader, ParseString_Error) { char e[] = { '[', '\"', 0, '\"', ']', '\0' }; for (unsigned char c = 0x80u; c <= 0xBFu; c++) { e[2] = c; - ParseErrorCode error = TestString(e); + ParseErrorCode error = TestString >(e); EXPECT_EQ(kParseErrorStringInvalidEncoding, error); if (error != kParseErrorStringInvalidEncoding) std::cout << (unsigned)(unsigned char)c << std::endl; @@ -572,30 +579,40 @@ TEST(Reader, ParseString_Error) { // 4 Overlong sequences // 4.1 Examples of an overlong ASCII character - TEST_STRINGENCODING_ERROR(UTF8<>, unsigned char, ARRAY('[', '\"', 0xC0u, 0xAFu, '\"', ']', '\0')); - TEST_STRINGENCODING_ERROR(UTF8<>, unsigned char, ARRAY('[', '\"', 0xE0u, 0x80u, 0xAFu, '\"', ']', '\0')); - TEST_STRINGENCODING_ERROR(UTF8<>, unsigned char, ARRAY('[', '\"', 0xF0u, 0x80u, 0x80u, 0xAFu, '\"', ']', '\0')); + TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xC0u, 0xAFu, '\"', ']', '\0')); + TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xE0u, 0x80u, 0xAFu, '\"', ']', '\0')); + TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xF0u, 0x80u, 0x80u, 0xAFu, '\"', ']', '\0')); // 4.2 Maximum overlong sequences - TEST_STRINGENCODING_ERROR(UTF8<>, unsigned char, ARRAY('[', '\"', 0xC1u, 0xBFu, '\"', ']', '\0')); - TEST_STRINGENCODING_ERROR(UTF8<>, unsigned char, ARRAY('[', '\"', 0xE0u, 0x9Fu, 0xBFu, '\"', ']', '\0')); - TEST_STRINGENCODING_ERROR(UTF8<>, unsigned char, ARRAY('[', '\"', 0xF0u, 0x8Fu, 0xBFu, 0xBFu, '\"', ']', '\0')); + TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xC1u, 0xBFu, '\"', ']', '\0')); + TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xE0u, 0x9Fu, 0xBFu, '\"', ']', '\0')); + TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xF0u, 0x8Fu, 0xBFu, 0xBFu, '\"', ']', '\0')); // 4.3 Overlong representation of the NUL character - TEST_STRINGENCODING_ERROR(UTF8<>, unsigned char, ARRAY('[', '\"', 0xC0u, 0x80u, '\"', ']', '\0')); - TEST_STRINGENCODING_ERROR(UTF8<>, unsigned char, ARRAY('[', '\"', 0xE0u, 0x80u, 0x80u, '\"', ']', '\0')); - TEST_STRINGENCODING_ERROR(UTF8<>, unsigned char, ARRAY('[', '\"', 0xF0u, 0x80u, 0x80u, 0x80u, '\"', ']', '\0')); + TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xC0u, 0x80u, '\"', ']', '\0')); + TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xE0u, 0x80u, 0x80u, '\"', ']', '\0')); + TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xF0u, 0x80u, 0x80u, 0x80u, '\"', ']', '\0')); // 5 Illegal code positions // 5.1 Single UTF-16 surrogates - TEST_STRINGENCODING_ERROR(UTF8<>, unsigned char, ARRAY('[', '\"', 0xEDu, 0xA0u, 0x80u, '\"', ']', '\0')); - TEST_STRINGENCODING_ERROR(UTF8<>, unsigned char, ARRAY('[', '\"', 0xEDu, 0xADu, 0xBFu, '\"', ']', '\0')); - TEST_STRINGENCODING_ERROR(UTF8<>, unsigned char, ARRAY('[', '\"', 0xEDu, 0xAEu, 0x80u, '\"', ']', '\0')); - TEST_STRINGENCODING_ERROR(UTF8<>, unsigned char, ARRAY('[', '\"', 0xEDu, 0xAFu, 0xBFu, '\"', ']', '\0')); - TEST_STRINGENCODING_ERROR(UTF8<>, unsigned char, ARRAY('[', '\"', 0xEDu, 0xB0u, 0x80u, '\"', ']', '\0')); - TEST_STRINGENCODING_ERROR(UTF8<>, unsigned char, ARRAY('[', '\"', 0xEDu, 0xBEu, 0x80u, '\"', ']', '\0')); - TEST_STRINGENCODING_ERROR(UTF8<>, unsigned char, ARRAY('[', '\"', 0xEDu, 0xBFu, 0xBFu, '\"', ']', '\0')); + TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xEDu, 0xA0u, 0x80u, '\"', ']', '\0')); + TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xEDu, 0xADu, 0xBFu, '\"', ']', '\0')); + TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xEDu, 0xAEu, 0x80u, '\"', ']', '\0')); + TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xEDu, 0xAFu, 0xBFu, '\"', ']', '\0')); + TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xEDu, 0xB0u, 0x80u, '\"', ']', '\0')); + TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xEDu, 0xBEu, 0x80u, '\"', ']', '\0')); + TEST_STRINGENCODING_ERROR(UTF8<>, UTF16<>, unsigned char, ARRAY('[', '\"', 0xEDu, 0xBFu, 0xBFu, '\"', ']', '\0')); + + // Malform UTF-16 sequences + TEST_STRINGENCODING_ERROR(UTF16<>, UTF8<>, wchar_t, ARRAY('[', '\"', 0xDC00, 0xDC00, '\"', ']', '\0')); + TEST_STRINGENCODING_ERROR(UTF16<>, UTF8<>, wchar_t, ARRAY('[', '\"', 0xD800, 0xD800, '\"', ']', '\0')); + + // Malform UTF-32 sequence + TEST_STRINGENCODING_ERROR(UTF32<>, UTF8<>, unsigned, ARRAY('[', '\"', 0x110000, '\"', ']', '\0')); + + // Malform ASCII sequence + TEST_STRINGENCODING_ERROR(ASCII<>, UTF8<>, char, ARRAY('[', '\"', 0x80, '\"', ']', '\0')); #undef ARRAY #undef TEST_STRINGARRAY_ERROR From 5dde9ae45e79d9a27c4d89225990001afc6f9ebc Mon Sep 17 00:00:00 2001 From: miloyip Date: Tue, 14 Apr 2015 09:49:55 +0800 Subject: [PATCH 046/116] Cover MemoryPoolAllocator::Capacity() --- test/unittest/documenttest.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/unittest/documenttest.cpp b/test/unittest/documenttest.cpp index 7adf9b9..6e8370e 100644 --- a/test/unittest/documenttest.cpp +++ b/test/unittest/documenttest.cpp @@ -243,6 +243,10 @@ TEST(Document, UserBuffer) { EXPECT_FALSE(doc.HasParseError()); EXPECT_LE(valueAllocator.Size(), sizeof(valueBuffer)); EXPECT_LE(parseAllocator.Size(), sizeof(parseBuffer)); + + // Cover MemoryPool::Capacity() + EXPECT_LE(valueAllocator.Size(), valueAllocator.Capacity()); + EXPECT_LE(parseAllocator.Size(), parseAllocator.Capacity()); } // Issue 226: Value of string type should not point to NULL From bff588e6650d687a04472a306d880618a88e31d4 Mon Sep 17 00:00:00 2001 From: miloyip Date: Tue, 14 Apr 2015 09:50:22 +0800 Subject: [PATCH 047/116] Typo --- test/unittest/documenttest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/documenttest.cpp b/test/unittest/documenttest.cpp index 6e8370e..bf6f3a2 100644 --- a/test/unittest/documenttest.cpp +++ b/test/unittest/documenttest.cpp @@ -244,7 +244,7 @@ TEST(Document, UserBuffer) { EXPECT_LE(valueAllocator.Size(), sizeof(valueBuffer)); EXPECT_LE(parseAllocator.Size(), sizeof(parseBuffer)); - // Cover MemoryPool::Capacity() + // Cover MemoryPoolAllocator::Capacity() EXPECT_LE(valueAllocator.Size(), valueAllocator.Capacity()); EXPECT_LE(parseAllocator.Size(), parseAllocator.Capacity()); } From 056125db82bdd0f15d43b0e7cfbe95ad14f128aa Mon Sep 17 00:00:00 2001 From: miloyip Date: Tue, 14 Apr 2015 10:00:53 +0800 Subject: [PATCH 048/116] Improve coverage of Stack --- test/unittest/stringbuffertest.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/unittest/stringbuffertest.cpp b/test/unittest/stringbuffertest.cpp index 71e0caf..e6ebbcf 100644 --- a/test/unittest/stringbuffertest.cpp +++ b/test/unittest/stringbuffertest.cpp @@ -54,6 +54,9 @@ TEST(StringBuffer, Push) { buffer.Push(5); EXPECT_EQ(5u, buffer.GetSize()); + + buffer.Push(65536u); + EXPECT_EQ(5u + 65536u, buffer.GetSize()); } TEST(StringBuffer, Pop) { From c0ba5cffcdc39ab0207f62f3a96047a2077224ca Mon Sep 17 00:00:00 2001 From: miloyip Date: Tue, 14 Apr 2015 10:01:22 +0800 Subject: [PATCH 049/116] Add comment --- test/unittest/stringbuffertest.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unittest/stringbuffertest.cpp b/test/unittest/stringbuffertest.cpp index e6ebbcf..7cfde4f 100644 --- a/test/unittest/stringbuffertest.cpp +++ b/test/unittest/stringbuffertest.cpp @@ -55,6 +55,7 @@ TEST(StringBuffer, Push) { EXPECT_EQ(5u, buffer.GetSize()); + // Causes sudden expansion to make the stack's capacity equal to size buffer.Push(65536u); EXPECT_EQ(5u + 65536u, buffer.GetSize()); } From 3f7a3bcc042feb667732667a07807259921e009c Mon Sep 17 00:00:00 2001 From: miloyip Date: Tue, 14 Apr 2015 10:19:05 +0800 Subject: [PATCH 050/116] Add separate allocators test --- test/unittest/CMakeLists.txt | 1 + test/unittest/allocatorstest.cpp | 64 ++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 test/unittest/allocatorstest.cpp diff --git a/test/unittest/CMakeLists.txt b/test/unittest/CMakeLists.txt index 76b598f..52d5acd 100644 --- a/test/unittest/CMakeLists.txt +++ b/test/unittest/CMakeLists.txt @@ -1,4 +1,5 @@ set(UNITTEST_SOURCES + allocatorstest.cpp bigintegertest.cpp documenttest.cpp encodedstreamtest.cpp diff --git a/test/unittest/allocatorstest.cpp b/test/unittest/allocatorstest.cpp new file mode 100644 index 0000000..2cf9a2e --- /dev/null +++ b/test/unittest/allocatorstest.cpp @@ -0,0 +1,64 @@ +// Copyright (C) 2011 Milo Yip +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#include "unittest.h" + +#include "rapidjson/allocators.h" + +using namespace rapidjson; + +template +void TestAllocator(Allocator& a) { + uint8_t* p = (uint8_t*)a.Malloc(100); + EXPECT_TRUE(p != 0); + for (size_t i = 0; i < 100; i++) + p[i] = (uint8_t)i; + + // Expand + uint8_t* q = (uint8_t*)a.Realloc(p, 100, 200); + EXPECT_TRUE(q != 0); + for (size_t i = 0; i < 100; i++) + EXPECT_EQ(i, q[i]); + for (size_t i = 100; i < 200; i++) + q[i] = (uint8_t)i; + + // Shrink + uint8_t *r = (uint8_t*)a.Realloc(q, 200, 150); + EXPECT_TRUE(r != 0); + for (size_t i = 0; i < 150; i++) + EXPECT_EQ(i, r[i]); + + Allocator::Free(r); +} + +TEST(Allocator, CrtAllocator) { + CrtAllocator a; + TestAllocator(a); +} + +TEST(Allocator, MemoryPoolAllocator) { + MemoryPoolAllocator<> a; + TestAllocator(a); + + for (int i = 0; i < 1000; i++) { + EXPECT_TRUE(a.Malloc(i) != 0); + EXPECT_LE(a.Size(), a.Capacity()); + } +} From 3675b33a2a77a16160e42783ec1199444cca0bf5 Mon Sep 17 00:00:00 2001 From: miloyip Date: Tue, 14 Apr 2015 10:35:45 +0800 Subject: [PATCH 051/116] Search more paths for different build situations --- test/unittest/documenttest.cpp | 19 ++++++++----- test/unittest/encodedstreamtest.cpp | 19 ++++++++----- test/unittest/filestreamtest.cpp | 18 ++++++++++--- test/unittest/jsoncheckertest.cpp | 41 ++++++++++++++++------------- 4 files changed, 64 insertions(+), 33 deletions(-) diff --git a/test/unittest/documenttest.cpp b/test/unittest/documenttest.cpp index bf6f3a2..dd4fb13 100644 --- a/test/unittest/documenttest.cpp +++ b/test/unittest/documenttest.cpp @@ -101,14 +101,21 @@ TEST(Document, Parse) { } static FILE* OpenEncodedFile(const char* filename) { + const char *paths[] = { + "encodings/%s", + "bin/encodings/%s", + "../bin/encodings/%s", + "../../bin/encodings/%s", + "../../../bin/encodings/%s" + }; char buffer[1024]; - sprintf(buffer, "encodings/%s", filename); - FILE *fp = fopen(buffer, "rb"); - if (!fp) { - sprintf(buffer, "../../bin/encodings/%s", filename); - fp = fopen(buffer, "rb"); + for (size_t i = 0; i < sizeof(paths) / sizeof(paths[0]); i++) { + sprintf(buffer, paths[i], filename); + FILE *fp = fopen(buffer, "rb"); + if (fp) + return fp; } - return fp; + return 0; } TEST(Document, ParseStream_EncodedInputStream) { diff --git a/test/unittest/encodedstreamtest.cpp b/test/unittest/encodedstreamtest.cpp index 3580608..c2920a0 100644 --- a/test/unittest/encodedstreamtest.cpp +++ b/test/unittest/encodedstreamtest.cpp @@ -47,14 +47,21 @@ private: protected: static FILE* Open(const char* filename) { + const char *paths[] = { + "encodings/%s", + "bin/encodings/%s", + "../bin/encodings/%s", + "../../bin/encodings/%s", + "../../../bin/encodings/%s" + }; char buffer[1024]; - sprintf(buffer, "encodings/%s", filename); - FILE *fp = fopen(buffer, "rb"); - if (!fp) { - sprintf(buffer, "../../bin/encodings/%s", filename); - fp = fopen(buffer, "rb"); + for (size_t i = 0; i < sizeof(paths) / sizeof(paths[0]); i++) { + sprintf(buffer, paths[i], filename); + FILE *fp = fopen(buffer, "rb"); + if (fp) + return fp; } - return fp; + return 0; } static char *ReadFile(const char* filename, bool appendPath, size_t* outLength) { diff --git a/test/unittest/filestreamtest.cpp b/test/unittest/filestreamtest.cpp index a176332..5b3df53 100644 --- a/test/unittest/filestreamtest.cpp +++ b/test/unittest/filestreamtest.cpp @@ -31,9 +31,21 @@ public: FileStreamTest() : filename_(), json_(), length_() {} virtual void SetUp() { - FILE *fp = fopen(filename_ = "data/sample.json", "rb"); - if (!fp) - fp = fopen(filename_ = "../../bin/data/sample.json", "rb"); + const char *paths[] = { + "data/sample.json", + "bin/data/sample.json", + "../bin/data/sample.json", + "../../bin/data/sample.json", + "../../../bin/data/sample.json" + }; + FILE* fp = 0; + for (size_t i = 0; i < sizeof(paths) / sizeof(paths[0]); i++) { + fp = fopen(paths[i], "rb"); + if (fp) { + filename_ = paths[i]; + break; + } + } ASSERT_TRUE(fp != 0); fseek(fp, 0, SEEK_END); diff --git a/test/unittest/jsoncheckertest.cpp b/test/unittest/jsoncheckertest.cpp index caa1b8a..a89b8d2 100644 --- a/test/unittest/jsoncheckertest.cpp +++ b/test/unittest/jsoncheckertest.cpp @@ -25,9 +25,22 @@ using namespace rapidjson; static char* ReadFile(const char* filename, size_t& length) { - FILE *fp = fopen(filename, "rb"); - if (!fp) - fp = fopen(filename, "rb"); + const char *paths[] = { + "jsonchecker/%s", + "bin/jsonchecker/%s", + "../bin/jsonchecker/%s", + "../../bin/jsonchecker/%s", + "../../../bin/jsonchecker/%s" + }; + char buffer[1024]; + FILE *fp = 0; + for (size_t i = 0; i < sizeof(paths) / sizeof(paths[0]); i++) { + sprintf(buffer, paths[i], filename); + fp = fopen(buffer, "rb"); + if (fp) + break; + } + if (!fp) return 0; @@ -51,17 +64,13 @@ TEST(JsonChecker, Reader) { if (i == 18) // fail18.json is valid in rapidjson, which has no limitation on depth of nesting. continue; - sprintf(filename, "jsonchecker/fail%d.json", i); + sprintf(filename, "fail%d.json", i); size_t length; char* json = ReadFile(filename, length); if (!json) { - sprintf(filename, "../../bin/jsonchecker/fail%d.json", i); - json = ReadFile(filename, length); - if (!json) { - printf("jsonchecker file %s not found", filename); - ADD_FAILURE(); - continue; - } + printf("jsonchecker file %s not found", filename); + ADD_FAILURE(); + continue; } GenericDocument, CrtAllocator> document; // Use Crt allocator to check exception-safety (no memory leak) @@ -76,16 +85,12 @@ TEST(JsonChecker, Reader) { // passX.json for (int i = 1; i <= 3; i++) { - sprintf(filename, "jsonchecker/pass%d.json", i); + sprintf(filename, "pass%d.json", i); size_t length; char* json = ReadFile(filename, length); if (!json) { - sprintf(filename, "../../bin/jsonchecker/pass%d.json", i); - json = ReadFile(filename, length); - if (!json) { - printf("jsonchecker file %s not found", filename); - continue; - } + printf("jsonchecker file %s not found", filename); + continue; } GenericDocument, CrtAllocator> document; // Use Crt allocator to check exception-safety (no memory leak) From f89c4b52b6644e19fb8becc3d4c999a6330e557b Mon Sep 17 00:00:00 2001 From: miloyip Date: Tue, 14 Apr 2015 10:50:39 +0800 Subject: [PATCH 052/116] Use PrettyWriter to cover FileWriteStream::PutN() --- test/unittest/prettywritertest.cpp | 81 +++++++++++++++++------------- 1 file changed, 45 insertions(+), 36 deletions(-) diff --git a/test/unittest/prettywritertest.cpp b/test/unittest/prettywritertest.cpp index b18ad3f..6ae14b9 100644 --- a/test/unittest/prettywritertest.cpp +++ b/test/unittest/prettywritertest.cpp @@ -22,10 +22,28 @@ #include "rapidjson/reader.h" #include "rapidjson/prettywriter.h" #include "rapidjson/stringbuffer.h" +#include "rapidjson/filewritestream.h" using namespace rapidjson; static const char kJson[] = "{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3,-1],\"u64\":1234567890123456789,\"i64\":-1234567890123456789}"; +static const char kPrettyJson[] = +"{\n" +" \"hello\": \"world\",\n" +" \"t\": true,\n" +" \"f\": false,\n" +" \"n\": null,\n" +" \"i\": 123,\n" +" \"pi\": 3.1416,\n" +" \"a\": [\n" +" 1,\n" +" 2,\n" +" 3,\n" +" -1\n" +" ],\n" +" \"u64\": 1234567890123456789,\n" +" \"i64\": -1234567890123456789\n" +"}"; TEST(PrettyWriter, Basic) { StringBuffer buffer; @@ -33,24 +51,7 @@ TEST(PrettyWriter, Basic) { Reader reader; StringStream s(kJson); reader.Parse(s, writer); - EXPECT_STREQ( - "{\n" - " \"hello\": \"world\",\n" - " \"t\": true,\n" - " \"f\": false,\n" - " \"n\": null,\n" - " \"i\": 123,\n" - " \"pi\": 3.1416,\n" - " \"a\": [\n" - " 1,\n" - " 2,\n" - " 3,\n" - " -1\n" - " ],\n" - " \"u64\": 1234567890123456789,\n" - " \"i64\": -1234567890123456789\n" - "}", - buffer.GetString()); + EXPECT_STREQ(kPrettyJson, buffer.GetString()); } TEST(PrettyWriter, SetIndent) { @@ -137,22 +138,30 @@ TEST(PrettyWriter, OStreamWrapper) { reader.Parse(s, writer); std::string actual = ss.str(); - EXPECT_STREQ( - "{\n" - " \"hello\": \"world\",\n" - " \"t\": true,\n" - " \"f\": false,\n" - " \"n\": null,\n" - " \"i\": 123,\n" - " \"pi\": 3.1416,\n" - " \"a\": [\n" - " 1,\n" - " 2,\n" - " 3,\n" - " -1\n" - " ],\n" - " \"u64\": 1234567890123456789,\n" - " \"i64\": -1234567890123456789\n" - "}", - actual.c_str()); + EXPECT_STREQ(kPrettyJson, actual.c_str()); } + +// For covering FileWriteStream::PutN() +TEST(PrettyWriter, FileWriteStream) { + char filename[L_tmpnam]; + FILE* fp = TempFile(filename); + char buffer[16]; + FileWriteStream os(fp, buffer, sizeof(buffer)); + PrettyWriter writer(os); + Reader reader; + StringStream s(kJson); + reader.Parse(s, writer); + fclose(fp); + + fp = fopen(filename, "rb"); + fseek(fp, 0, SEEK_END); + size_t size = (size_t)ftell(fp); + fseek(fp, 0, SEEK_SET); + char* json = (char*)malloc(size + 1); + size_t readLength = fread(json, 1, size, fp); + json[readLength] = '\0'; + fclose(fp); + remove(filename); + EXPECT_STREQ(kPrettyJson, json); + free(json); +} \ No newline at end of file From 67be9ed2cb89edeb3548f2d907a8a282fff451c7 Mon Sep 17 00:00:00 2001 From: miloyip Date: Tue, 14 Apr 2015 11:08:47 +0800 Subject: [PATCH 053/116] Remove depreciated FileStream --- example/serialize/serialize.cpp | 7 ++-- example/tutorial/tutorial.cpp | 6 +-- include/rapidjson/filestream.h | 67 -------------------------------- test/perftest/rapidjsontest.cpp | 1 - test/unittest/filestreamtest.cpp | 19 --------- 5 files changed, 7 insertions(+), 93 deletions(-) delete mode 100644 include/rapidjson/filestream.h diff --git a/example/serialize/serialize.cpp b/example/serialize/serialize.cpp index 4f9278b..7427939 100644 --- a/example/serialize/serialize.cpp +++ b/example/serialize/serialize.cpp @@ -2,7 +2,6 @@ // This example shows writing JSON string with writer directly. #include "rapidjson/prettywriter.h" // for stringify JSON -#include "rapidjson/filestream.h" // wrapper of C stream for prettywriter as output #include #include #include @@ -144,13 +143,15 @@ int main(int, char*[]) { employees.push_back(Employee("Percy TSE", 30, false)); - FileStream s(stdout); - PrettyWriter writer(s); // Can also use Writer for condensed formatting + StringBuffer sb; + PrettyWriter writer(sb); writer.StartArray(); for (std::vector::const_iterator employeeItr = employees.begin(); employeeItr != employees.end(); ++employeeItr) employeeItr->Serialize(writer); writer.EndArray(); + puts(sb.GetString()); + return 0; } diff --git a/example/tutorial/tutorial.cpp b/example/tutorial/tutorial.cpp index 49704c1..206fdb9 100644 --- a/example/tutorial/tutorial.cpp +++ b/example/tutorial/tutorial.cpp @@ -3,7 +3,6 @@ #include "rapidjson/document.h" // rapidjson's DOM-style API #include "rapidjson/prettywriter.h" // for stringify JSON -#include "rapidjson/filestream.h" // wrapper of C stream for prettywriter as output #include using namespace rapidjson; @@ -143,9 +142,10 @@ int main(int, char*[]) { // 4. Stringify JSON printf("\nModified JSON with reformatting:\n"); - FileStream f(stdout); - PrettyWriter writer(f); + StringBuffer sb; + PrettyWriter writer(sb); document.Accept(writer); // Accept() traverses the DOM and generates Handler events. + puts(sb.GetString()); return 0; } diff --git a/include/rapidjson/filestream.h b/include/rapidjson/filestream.h deleted file mode 100644 index 12701e2..0000000 --- a/include/rapidjson/filestream.h +++ /dev/null @@ -1,67 +0,0 @@ -// 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_FILESTREAM_H_ -#define RAPIDJSON_FILESTREAM_H_ - -#include "rapidjson.h" -#include - -RAPIDJSON_NAMESPACE_BEGIN - -//! (Deprecated) Wrapper of C file stream for input or output. -/*! - This simple wrapper does not check the validity of the stream. - \note implements Stream concept - \note deprecated: This was only for basic testing in version 0.1, it is found that the performance is very low by using fgetc(). Use FileReadStream instead. -*/ -class FileStream { -public: - typedef char Ch; //!< Character type. Only support char. - - FileStream(std::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_; } - void Put(char c) { fputc(c, fp_); } - void Flush() { fflush(fp_); } - - // Not implemented - char* PutBegin() { return 0; } - size_t PutEnd(char*) { return 0; } - -private: - // Prohibit copy constructor & assignment operator. - FileStream(const FileStream&); - FileStream& operator=(const FileStream&); - - void Read() { - RAPIDJSON_ASSERT(fp_ != 0); - int c = fgetc(fp_); - if (c != EOF) { - current_ = (char)c; - count_++; - } - else if (current_ != '\0') - current_ = '\0'; - } - - std::FILE* fp_; - char current_; - size_t count_; -}; - -RAPIDJSON_NAMESPACE_END - -#endif // RAPIDJSON_FILESTREAM_H_ diff --git a/test/perftest/rapidjsontest.cpp b/test/perftest/rapidjsontest.cpp index 74bdf27..315403c 100644 --- a/test/perftest/rapidjsontest.cpp +++ b/test/perftest/rapidjsontest.cpp @@ -26,7 +26,6 @@ #include "rapidjson/document.h" #include "rapidjson/prettywriter.h" #include "rapidjson/stringbuffer.h" -#include "rapidjson/filestream.h" #include "rapidjson/filereadstream.h" #include "rapidjson/encodedstream.h" #include "rapidjson/memorystream.h" diff --git a/test/unittest/filestreamtest.cpp b/test/unittest/filestreamtest.cpp index a176332..253a9d8 100644 --- a/test/unittest/filestreamtest.cpp +++ b/test/unittest/filestreamtest.cpp @@ -19,7 +19,6 @@ // THE SOFTWARE. #include "unittest.h" -#include "rapidjson/filestream.h" #include "rapidjson/filereadstream.h" #include "rapidjson/filewritestream.h" #include "rapidjson/encodedstream.h" @@ -60,24 +59,6 @@ protected: size_t length_; }; -// Deprecated -//TEST_F(FileStreamTest, FileStream_Read) { -// FILE *fp = fopen(filename_, "rb"); -// ASSERT_TRUE(fp != 0); -// FileStream s(fp); -// -// for (size_t i = 0; i < length_; i++) { -// EXPECT_EQ(json_[i], s.Peek()); -// EXPECT_EQ(json_[i], s.Peek()); // 2nd time should be the same -// EXPECT_EQ(json_[i], s.Take()); -// } -// -// EXPECT_EQ(length_, s.Tell()); -// EXPECT_EQ('\0', s.Peek()); -// -// fclose(fp); -//} - TEST_F(FileStreamTest, FileReadStream) { FILE *fp = fopen(filename_, "rb"); ASSERT_TRUE(fp != 0); From 9dcc1f44f59cf046a079f6f19bfcaa78d29ba1a4 Mon Sep 17 00:00:00 2001 From: miloyip Date: Tue, 14 Apr 2015 11:09:45 +0800 Subject: [PATCH 054/116] Remove deprecated test --- test/perftest/rapidjsontest.cpp | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/test/perftest/rapidjsontest.cpp b/test/perftest/rapidjsontest.cpp index 315403c..875c5eb 100644 --- a/test/perftest/rapidjsontest.cpp +++ b/test/perftest/rapidjsontest.cpp @@ -323,17 +323,6 @@ TEST_F(RapidJson, UTF8_Validate) { } } -// Deprecated. -//TEST_F(RapidJson, FileStream_Read) { -// for (size_t i = 0; i < kTrialCount; i++) { -// FILE *fp = fopen(filename_, "rb"); -// FileStream s(fp); -// while (s.Take() != '\0') -// ; -// fclose(fp); -// } -//} - TEST_F(RapidJson, FileReadStream) { for (size_t i = 0; i < kTrialCount; i++) { FILE *fp = fopen(filename_, "rb"); From 5dc52afd1e15ac72f3ef7a964f2d4b486a5a9439 Mon Sep 17 00:00:00 2001 From: miloyip Date: Tue, 14 Apr 2015 11:40:09 +0800 Subject: [PATCH 055/116] Ignore files for coverage --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c64d62b..be06f35 100644 --- a/.travis.yml +++ b/.travis.yml @@ -48,4 +48,4 @@ script: - make travis_doc after_success: - - coveralls -r .. --gcov-options '\-lp' -e thirdparty -e example -e test -e build/CMakeFiles -e include/rapidjson/msinttypes + - coveralls -r .. --gcov-options '\-lp' -e thirdparty -e example -e test -e build/CMakeFiles -e include/rapidjson/msinttypes -e include/rapidjson/internal/meta.h -e include/rapidjson/error/en.h From 3a92374011bb7e7b8f1dac3819d7a0e0cfc3aebc Mon Sep 17 00:00:00 2001 From: miloyip Date: Tue, 14 Apr 2015 12:01:41 +0800 Subject: [PATCH 056/116] Try turning on slow test on number parsing --- test/unittest/readertest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/readertest.cpp b/test/unittest/readertest.cpp index f5f6cce..38abe68 100644 --- a/test/unittest/readertest.cpp +++ b/test/unittest/readertest.cpp @@ -263,7 +263,7 @@ static void TestParseDouble() { TEST_DOUBLE(fullPrecision, n1e308, 1E308); } -#if 0 // Very slow +#if 1 // Very slow static const unsigned count = 10000000; // Random test for double { From 4cc62876aee842156c6b2e550dd4d70599a62b0e Mon Sep 17 00:00:00 2001 From: miloyip Date: Tue, 14 Apr 2015 13:22:39 +0800 Subject: [PATCH 057/116] Add some parsing number tests --- test/unittest/readertest.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/test/unittest/readertest.cpp b/test/unittest/readertest.cpp index 38abe68..6115609 100644 --- a/test/unittest/readertest.cpp +++ b/test/unittest/readertest.cpp @@ -254,6 +254,32 @@ static void TestParseDouble() { TEST_DOUBLE(fullPrecision, "1.00000000000000011102230246251565404236316680908203124", 1.0); // previous double TEST_DOUBLE(fullPrecision, "1.00000000000000011102230246251565404236316680908203126", 1.00000000000000022); // next double + // Numbers from https://github.com/floitsch/double-conversion/blob/master/test/cctest/test-strtod.cc + + TEST_DOUBLE(fullPrecision, "72057594037927928.0", 72057594037927928.0); + TEST_DOUBLE(fullPrecision, "72057594037927936.0", 72057594037927936.0); + TEST_DOUBLE(fullPrecision, "72057594037927932.0", 72057594037927936.0); + TEST_DOUBLE(fullPrecision, "7205759403792793199999e-5", 72057594037927928.0); + TEST_DOUBLE(fullPrecision, "7205759403792793200001e-5", 72057594037927936.0); + + TEST_DOUBLE(fullPrecision, "9223372036854774784.0", 9223372036854774784.0); + TEST_DOUBLE(fullPrecision, "9223372036854775808.0", 9223372036854775808.0); + TEST_DOUBLE(fullPrecision, "9223372036854775296.0", 9223372036854775808.0); + TEST_DOUBLE(fullPrecision, "922337203685477529599999e-5", 9223372036854774784.0); + TEST_DOUBLE(fullPrecision, "922337203685477529600001e-5", 9223372036854775808.0); + + TEST_DOUBLE(fullPrecision, "10141204801825834086073718800384", 10141204801825834086073718800384.0); + TEST_DOUBLE(fullPrecision, "10141204801825835211973625643008", 10141204801825835211973625643008.0); + TEST_DOUBLE(fullPrecision, "10141204801825834649023672221696", 10141204801825835211973625643008.0); + TEST_DOUBLE(fullPrecision, "1014120480182583464902367222169599999e-5", 10141204801825834086073718800384.0); + TEST_DOUBLE(fullPrecision, "1014120480182583464902367222169600001e-5", 10141204801825835211973625643008.0); + + TEST_DOUBLE(fullPrecision, "5708990770823838890407843763683279797179383808", 5708990770823838890407843763683279797179383808.0); + TEST_DOUBLE(fullPrecision, "5708990770823839524233143877797980545530986496", 5708990770823839524233143877797980545530986496.0); + TEST_DOUBLE(fullPrecision, "5708990770823839207320493820740630171355185152", 5708990770823839524233143877797980545530986496.0); + TEST_DOUBLE(fullPrecision, "5708990770823839207320493820740630171355185151999e-3", 5708990770823838890407843763683279797179383808.0); + TEST_DOUBLE(fullPrecision, "5708990770823839207320493820740630171355185152001e-3", 5708990770823839524233143877797980545530986496.0); + { char n1e308[310]; // '1' followed by 308 '0' n1e308[0] = '1'; @@ -263,7 +289,7 @@ static void TestParseDouble() { TEST_DOUBLE(fullPrecision, n1e308, 1E308); } -#if 1 // Very slow +#if 0 // Very slow static const unsigned count = 10000000; // Random test for double { From 4824f12efbf01af72b8cb6fc96fae7b097b73015 Mon Sep 17 00:00:00 2001 From: miloyip Date: Tue, 14 Apr 2015 13:59:05 +0800 Subject: [PATCH 058/116] Fixed a bug in trimming long number sequence --- include/rapidjson/internal/strtod.h | 4 +++- test/unittest/readertest.cpp | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/rapidjson/internal/strtod.h b/include/rapidjson/internal/strtod.h index 805c752..980b2c5 100644 --- a/include/rapidjson/internal/strtod.h +++ b/include/rapidjson/internal/strtod.h @@ -258,7 +258,9 @@ inline double StrtodFullPrecision(double d, int p, const char* decimals, size_t // Trim right-most digits const int kMaxDecimalDigit = 780; if ((int)length > kMaxDecimalDigit) { - exp += (int(length) - kMaxDecimalDigit); + int delta = (int(length) - kMaxDecimalDigit); + exp += delta; + decimalPosition -= delta; length = kMaxDecimalDigit; } diff --git a/test/unittest/readertest.cpp b/test/unittest/readertest.cpp index 6115609..bccfbd6 100644 --- a/test/unittest/readertest.cpp +++ b/test/unittest/readertest.cpp @@ -289,6 +289,19 @@ static void TestParseDouble() { TEST_DOUBLE(fullPrecision, n1e308, 1E308); } + // Cover trimming + TEST_DOUBLE(fullPrecision, +"2.22507385850720113605740979670913197593481954635164564802342610972482222202107694551652952390813508" +"7914149158913039621106870086438694594645527657207407820621743379988141063267329253552286881372149012" +"9811224514518898490572223072852551331557550159143974763979834118019993239625482890171070818506906306" +"6665599493827577257201576306269066333264756530000924588831643303777979186961204949739037782970490505" +"1080609940730262937128958950003583799967207254304360284078895771796150945516748243471030702609144621" +"5722898802581825451803257070188608721131280795122334262883686223215037756666225039825343359745688844" +"2390026549819838548794829220689472168983109969836584681402285424333066033985088644580400103493397042" +"7567186443383770486037861622771738545623065874679014086723327636718751234567890123456789012345678901" +"e-308", + 2.2250738585072014e-308); + #if 0 // Very slow static const unsigned count = 10000000; // Random test for double From 3621235cd0b4b75bb72293af077a0322df6d27d3 Mon Sep 17 00:00:00 2001 From: miloyip Date: Tue, 14 Apr 2015 14:52:42 +0800 Subject: [PATCH 059/116] Improve dtoa coverage --- test/unittest/writertest.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unittest/writertest.cpp b/test/unittest/writertest.cpp index d8193ca..f6e023a 100644 --- a/test/unittest/writertest.cpp +++ b/test/unittest/writertest.cpp @@ -103,6 +103,7 @@ TEST(Writer, String) { TEST(Writer, Double) { TEST_ROUNDTRIP("[1.2345,1.2345678,0.123456789012,1234567.8]"); TEST_ROUNDTRIP("[-0.0]"); // Issue #289 + TEST_ROUNDTRIP("1e30"); } TEST(Writer, Transcode) { From 4be4857a19d48430fc32b9939cc4ce30403fe522 Mon Sep 17 00:00:00 2001 From: miloyip Date: Tue, 14 Apr 2015 14:58:48 +0800 Subject: [PATCH 060/116] Remove ununused BigInteger::FullAdd() --- include/rapidjson/internal/biginteger.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/include/rapidjson/internal/biginteger.h b/include/rapidjson/internal/biginteger.h index e4703d6..b088204 100755 --- a/include/rapidjson/internal/biginteger.h +++ b/include/rapidjson/internal/biginteger.h @@ -269,12 +269,6 @@ private: #endif } - static Type FullAdd(Type a, Type b, bool inCarry, bool* outCarry) { - Type c = a + b + (inCarry ? 1 : 0); - *outCarry = c < a; - return c; - } - static const size_t kBitCount = 3328; // 64bit * 54 > 10^1000 static const size_t kCapacity = kBitCount / sizeof(Type); static const size_t kTypeBit = sizeof(Type) * 8; From 872aba660cb1f22b8871ff5a28e8560aac3fbfa7 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Tue, 14 Apr 2015 21:08:33 +0800 Subject: [PATCH 061/116] Improve coverage of encoded streams --- include/rapidjson/encodedstream.h | 7 +++--- test/unittest/encodedstreamtest.cpp | 34 +++++++++++++++++++---------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/include/rapidjson/encodedstream.h b/include/rapidjson/encodedstream.h index f2f3ea3..25936d2 100644 --- a/include/rapidjson/encodedstream.h +++ b/include/rapidjson/encodedstream.h @@ -109,6 +109,7 @@ public: \param type UTF encoding type if it is not detected from the stream. */ AutoUTFInputStream(InputByteStream& is, UTFType type = kUTF8) : is_(&is), type_(type), hasBOM_(false) { + RAPIDJSON_ASSERT(type >= kUTF8 && type <= kUTF32BE); DetectType(); static const TakeFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(Take) }; takeFunc_ = f[type_]; @@ -189,8 +190,6 @@ private: case kUTF32BE: RAPIDJSON_ASSERT(sizeof(Ch) >= 4); break; - default: - RAPIDJSON_ASSERT(false); // Invalid type } } @@ -220,6 +219,8 @@ public: \param putBOM Whether to write BOM at the beginning of the stream. */ AutoUTFOutputStream(OutputByteStream& os, UTFType type, bool putBOM) : os_(&os), type_(type) { + RAPIDJSON_ASSERT(type >= kUTF8 && type <= kUTF32BE); + // RUntime check whether the size of character type is sufficient. It only perform checks with assertion. switch (type_) { case kUTF16LE: @@ -233,8 +234,6 @@ public: case kUTF8: // Do nothing break; - default: - RAPIDJSON_ASSERT(false); // Invalid UTFType } static const PutFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(Put) }; diff --git a/test/unittest/encodedstreamtest.cpp b/test/unittest/encodedstreamtest.cpp index c2920a0..af2171a 100644 --- a/test/unittest/encodedstreamtest.cpp +++ b/test/unittest/encodedstreamtest.cpp @@ -119,10 +119,11 @@ protected: } EXPECT_EQ('\0', s.Peek()); free(data); + EXPECT_EQ(size, eis.Tell()); } } - void TestAutoUTFInputStream(const char *filename) { + void TestAutoUTFInputStream(const char *filename, bool expectHasBOM) { // Test FileReadStream { char buffer[16]; @@ -130,6 +131,7 @@ protected: ASSERT_TRUE(fp != 0); FileReadStream fs(fp, buffer, sizeof(buffer)); AutoUTFInputStream eis(fs); + EXPECT_EQ(expectHasBOM, eis.HasBOM()); StringStream s(json_); while (eis.Peek() != '\0') { unsigned expected, actual; @@ -147,6 +149,7 @@ protected: char* data = ReadFile(filename, true, &size); MemoryStream ms(data, size); AutoUTFInputStream eis(ms); + EXPECT_EQ(expectHasBOM, eis.HasBOM()); StringStream s(json_); while (eis.Peek() != '\0') { @@ -264,16 +267,25 @@ TEST_F(EncodedStreamTest, EncodedInputStream) { } TEST_F(EncodedStreamTest, AutoUTFInputStream) { - TestAutoUTFInputStream("utf8.json"); - TestAutoUTFInputStream("utf8bom.json"); - TestAutoUTFInputStream("utf16le.json"); - TestAutoUTFInputStream("utf16lebom.json"); - TestAutoUTFInputStream("utf16be.json"); - TestAutoUTFInputStream("utf16bebom.json"); - TestAutoUTFInputStream("utf32le.json"); - TestAutoUTFInputStream("utf32lebom.json"); - TestAutoUTFInputStream("utf32be.json"); - TestAutoUTFInputStream("utf32bebom.json"); + TestAutoUTFInputStream("utf8.json", false); + TestAutoUTFInputStream("utf8bom.json", true); + TestAutoUTFInputStream("utf16le.json", false); + TestAutoUTFInputStream("utf16lebom.json",true); + TestAutoUTFInputStream("utf16be.json", false); + TestAutoUTFInputStream("utf16bebom.json",true); + TestAutoUTFInputStream("utf32le.json", false); + TestAutoUTFInputStream("utf32lebom.json",true); + TestAutoUTFInputStream("utf32be.json", false); + TestAutoUTFInputStream("utf32bebom.json", true); + + { + // Auto detection fail, use user defined UTF type + const char json[] = "{}"; + MemoryStream ms(json, sizeof(json)); + AutoUTFInputStream eis(ms, kUTF8); + EXPECT_FALSE(eis.HasBOM()); + EXPECT_EQ(kUTF8, eis.GetType()); + } } TEST_F(EncodedStreamTest, EncodedOutputStream) { From 84e57412047aa214695dcb4a8d300b1e5a6a2034 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Tue, 14 Apr 2015 21:23:44 +0800 Subject: [PATCH 062/116] Fix gcc warning --- include/rapidjson/encodedstream.h | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/include/rapidjson/encodedstream.h b/include/rapidjson/encodedstream.h index 25936d2..f2cfd61 100644 --- a/include/rapidjson/encodedstream.h +++ b/include/rapidjson/encodedstream.h @@ -178,19 +178,10 @@ private: } // Runtime check whether the size of character type is sufficient. It only perform checks with assertion. - switch (type_) { - case kUTF8: - // Do nothing - break; - case kUTF16LE: - case kUTF16BE: + if (type_ == kUTF16LE || type_ == kUTF16BE) RAPIDJSON_ASSERT(sizeof(Ch) >= 2); - break; - case kUTF32LE: - case kUTF32BE: + else if (type_ == kUTF32LE || type_ == kUTF32BE) RAPIDJSON_ASSERT(sizeof(Ch) >= 4); - break; - } } typedef Ch (*TakeFunc)(InputByteStream& is); @@ -221,20 +212,11 @@ public: AutoUTFOutputStream(OutputByteStream& os, UTFType type, bool putBOM) : os_(&os), type_(type) { RAPIDJSON_ASSERT(type >= kUTF8 && type <= kUTF32BE); - // RUntime check whether the size of character type is sufficient. It only perform checks with assertion. - switch (type_) { - case kUTF16LE: - case kUTF16BE: + // Runtime check whether the size of character type is sufficient. It only perform checks with assertion. + if (type_ == kUTF16LE || type_ == kUTF16BE) RAPIDJSON_ASSERT(sizeof(Ch) >= 2); - break; - case kUTF32LE: - case kUTF32BE: + else if (type_ == kUTF32LE || type_ == kUTF32BE) RAPIDJSON_ASSERT(sizeof(Ch) >= 4); - break; - case kUTF8: - // Do nothing - break; - } static const PutFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(Put) }; putFunc_ = f[type_]; From afe2fbdc3fd908e8d673bdf2d44408744e61f723 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Tue, 14 Apr 2015 21:30:57 +0800 Subject: [PATCH 063/116] Fix the warnings again --- include/rapidjson/encodedstream.h | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/include/rapidjson/encodedstream.h b/include/rapidjson/encodedstream.h index f2cfd61..9a93b38 100644 --- a/include/rapidjson/encodedstream.h +++ b/include/rapidjson/encodedstream.h @@ -178,10 +178,8 @@ private: } // Runtime check whether the size of character type is sufficient. It only perform checks with assertion. - if (type_ == kUTF16LE || type_ == kUTF16BE) - RAPIDJSON_ASSERT(sizeof(Ch) >= 2); - else if (type_ == kUTF32LE || type_ == kUTF32BE) - RAPIDJSON_ASSERT(sizeof(Ch) >= 4); + if (type_ == kUTF16LE || type_ == kUTF16BE) RAPIDJSON_ASSERT(sizeof(Ch) >= 2); + if (type_ == kUTF32LE || type_ == kUTF32BE) RAPIDJSON_ASSERT(sizeof(Ch) >= 4); } typedef Ch (*TakeFunc)(InputByteStream& is); @@ -213,10 +211,8 @@ public: RAPIDJSON_ASSERT(type >= kUTF8 && type <= kUTF32BE); // Runtime check whether the size of character type is sufficient. It only perform checks with assertion. - if (type_ == kUTF16LE || type_ == kUTF16BE) - RAPIDJSON_ASSERT(sizeof(Ch) >= 2); - else if (type_ == kUTF32LE || type_ == kUTF32BE) - RAPIDJSON_ASSERT(sizeof(Ch) >= 4); + if (type_ == kUTF16LE || type_ == kUTF16BE) RAPIDJSON_ASSERT(sizeof(Ch) >= 2); + if (type_ == kUTF32LE || type_ == kUTF32BE) RAPIDJSON_ASSERT(sizeof(Ch) >= 4); static const PutFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(Put) }; putFunc_ = f[type_]; From f8909e875b367ee56003fd23fca69288e8f1e7e3 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Tue, 14 Apr 2015 21:50:13 +0800 Subject: [PATCH 064/116] Improve coverage of encoded streams --- test/unittest/encodedstreamtest.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/unittest/encodedstreamtest.cpp b/test/unittest/encodedstreamtest.cpp index af2171a..5affb5d 100644 --- a/test/unittest/encodedstreamtest.cpp +++ b/test/unittest/encodedstreamtest.cpp @@ -160,6 +160,7 @@ protected: } EXPECT_EQ('\0', s.Peek()); free(data); + EXPECT_EQ(size, eis.Tell()); } } @@ -280,7 +281,7 @@ TEST_F(EncodedStreamTest, AutoUTFInputStream) { { // Auto detection fail, use user defined UTF type - const char json[] = "{}"; + const char json[] = "{ }"; MemoryStream ms(json, sizeof(json)); AutoUTFInputStream eis(ms, kUTF8); EXPECT_FALSE(eis.HasBOM()); From 5f5758bc228a4831b94416b2ea41a103e613d377 Mon Sep 17 00:00:00 2001 From: miloyip Date: Tue, 14 Apr 2015 23:26:00 +0800 Subject: [PATCH 065/116] Try coverage on gcc/release also --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index be06f35..f26c944 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,7 @@ before_install: - sudo apt-get install -qq cmake valgrind - sudo apt-get --no-install-recommends install doxygen # Don't install LaTeX stuffs - if [ "$ARCH" = "x86" ]; then sudo apt-get install -qq g++-multilib libc6-dbg:i386; fi - - if [ "$CC" = "gcc" ] && [ "$CONF" = "debug" ]; then sudo pip install cpp-coveralls; export GCOV_FLAGS='--coverage'; fi + - if [ "$CC" = "gcc" ]; then sudo pip install cpp-coveralls; export GCOV_FLAGS='--coverage'; fi install: true From 5b89f331c580f41132c359c2b4b2715aa1a83d7e Mon Sep 17 00:00:00 2001 From: miloyip Date: Wed, 15 Apr 2015 00:18:22 +0800 Subject: [PATCH 066/116] Add more test numbers for writer --- test/unittest/writertest.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/unittest/writertest.cpp b/test/unittest/writertest.cpp index f6e023a..85d533d 100644 --- a/test/unittest/writertest.cpp +++ b/test/unittest/writertest.cpp @@ -46,7 +46,7 @@ TEST(Writer, Compact) { StringBuffer buffer; \ Writer writer(buffer); \ Reader reader; \ - reader.Parse<0>(s, writer); \ + reader.Parse(s, writer); \ EXPECT_STREQ(json, buffer.GetString()); \ EXPECT_TRUE(writer.IsComplete()); \ } @@ -102,8 +102,15 @@ TEST(Writer, String) { TEST(Writer, Double) { TEST_ROUNDTRIP("[1.2345,1.2345678,0.123456789012,1234567.8]"); - TEST_ROUNDTRIP("[-0.0]"); // Issue #289 + TEST_ROUNDTRIP("0.0"); + TEST_ROUNDTRIP("-0.0"); // Issue #289 TEST_ROUNDTRIP("1e30"); + TEST_ROUNDTRIP("1.0"); + TEST_ROUNDTRIP("5e-324"); // Min subnormal positive double + TEST_ROUNDTRIP("2.225073858507201e-308"); // Max subnormal positive double + TEST_ROUNDTRIP("2.2250738585072014e-308"); // Min normal positive double + TEST_ROUNDTRIP("1.7976931348623157e308"); // Max double + } TEST(Writer, Transcode) { From 37d820a13e66e57a6ebb9444593485614ed5e982 Mon Sep 17 00:00:00 2001 From: miloyip Date: Wed, 15 Apr 2015 10:58:49 +0800 Subject: [PATCH 067/116] Remove unused code paths in double conversions --- include/rapidjson/internal/diyfp.h | 22 +++--------------- include/rapidjson/internal/dtoa.h | 19 +++++----------- include/rapidjson/internal/ieee754.h | 8 ------- include/rapidjson/internal/strtod.h | 34 ++++++++++++---------------- 4 files changed, 23 insertions(+), 60 deletions(-) diff --git a/include/rapidjson/internal/diyfp.h b/include/rapidjson/internal/diyfp.h index 0b098af..de3d1f0 100644 --- a/include/rapidjson/internal/diyfp.h +++ b/include/rapidjson/internal/diyfp.h @@ -135,25 +135,9 @@ struct DiyFp { double d; uint64_t u64; }u; - uint64_t significand = f; - int exponent = e; - while (significand > kDpHiddenBit + kDpSignificandMask) { - significand >>= 1; - exponent++; - } - while (exponent > kDpDenormalExponent && (significand & kDpHiddenBit) == 0) { - significand <<= 1; - exponent--; - } - if (exponent >= kDpMaxExponent) { - u.u64 = kDpExponentMask; // Infinity - return u.d; - } - else if (exponent < kDpDenormalExponent) - return 0.0; - const uint64_t be = (exponent == kDpDenormalExponent && (significand & kDpHiddenBit) == 0) ? 0 : - static_cast(exponent + kDpExponentBias); - u.u64 = (significand & kDpSignificandMask) | (be << kDpSignificandSize); + const uint64_t be = (e == kDpDenormalExponent && (f & kDpHiddenBit) == 0) ? 0 : + static_cast(e + kDpExponentBias); + u.u64 = (f & kDpSignificandMask) | (be << kDpSignificandSize); return u.d; } diff --git a/include/rapidjson/internal/dtoa.h b/include/rapidjson/internal/dtoa.h index aec6bcd..55dae8a 100644 --- a/include/rapidjson/internal/dtoa.h +++ b/include/rapidjson/internal/dtoa.h @@ -50,8 +50,10 @@ inline unsigned CountDecimalDigit32(uint32_t n) { if (n < 1000000) return 6; if (n < 10000000) return 7; if (n < 100000000) return 8; - if (n < 1000000000) return 9; - return 10; + // Will not reach 10 digits in DigitGen() + //if (n < 1000000000) return 9; + //return 10; + return 9; } inline void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, char* buffer, int* len, int* K) { @@ -60,13 +62,12 @@ 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); + int kappa = CountDecimalDigit32(p1); // kappa in [0, 9] *len = 0; while (kappa > 0) { - uint32_t d; + uint32_t d = 0; switch (kappa) { - case 10: d = p1 / 1000000000; p1 %= 1000000000; break; case 9: d = p1 / 100000000; p1 %= 100000000; break; case 8: d = p1 / 10000000; p1 %= 10000000; break; case 7: d = p1 / 1000000; p1 %= 1000000; break; @@ -76,14 +77,6 @@ inline void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, char* buff case 3: d = p1 / 100; p1 %= 100; break; case 2: d = p1 / 10; p1 %= 10; break; case 1: d = p1; p1 = 0; break; - default: -#if defined(_MSC_VER) - __assume(0); -#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) - __builtin_unreachable(); -#else - d = 0; -#endif } if (d || *len) buffer[(*len)++] = static_cast('0' + static_cast(d)); diff --git a/include/rapidjson/internal/ieee754.h b/include/rapidjson/internal/ieee754.h index 152be8f..9a82880 100644 --- a/include/rapidjson/internal/ieee754.h +++ b/include/rapidjson/internal/ieee754.h @@ -34,14 +34,6 @@ public: return Double(u + 1).Value(); } - double PreviousPositiveDouble() const { - RAPIDJSON_ASSERT(!Sign()); - if (IsZero()) - return 0.0; - else - return Double(u - 1).Value(); - } - bool Sign() const { return (u & kSignMask) != 0; } uint64_t Significand() const { return u & kSignificandMask; } int Exponent() const { return ((u & kExponentMask) >> kSignificandSize) - kExponentBias; } diff --git a/include/rapidjson/internal/strtod.h b/include/rapidjson/internal/strtod.h index 980b2c5..6644f37 100644 --- a/include/rapidjson/internal/strtod.h +++ b/include/rapidjson/internal/strtod.h @@ -52,7 +52,7 @@ inline T Min3(T a, T b, T c) { return m; } -inline int CheckWithinHalfULP(double b, const BigInteger& d, int dExp, bool* adjustToNegative) { +inline int CheckWithinHalfULP(double b, const BigInteger& d, int dExp) { const Double db(b); const uint64_t bInt = db.IntegerSignificand(); const int bExp = db.IntegerExponent(); @@ -104,12 +104,12 @@ inline int CheckWithinHalfULP(double b, const BigInteger& d, int dExp, bool* adj hS.MultiplyPow5(hS_Exp5) <<= hS_Exp2; BigInteger delta(0); - *adjustToNegative = dS.Difference(bS, &delta); + bool adjustToNegative = dS.Difference(bS, &delta); int cmp = delta.Compare(hS); // If delta is within 1/2 ULP, check for special case when significand is power of two. // In this case, need to compare with 1/2h in the lower bound. - if (cmp < 0 && *adjustToNegative && // within and dS < bS + if (cmp < 0 && adjustToNegative && // within and dS < bS db.IsNormal() && (bInt & (bInt - 1)) == 0 && // Power of 2 db.Uint64Value() != RAPIDJSON_UINT64_C2(0x00100000, 0x00000000)) // minimum normal number must not do this { @@ -213,24 +213,18 @@ inline double StrtodBigInteger(double approx, const char* decimals, size_t lengt const BigInteger dInt(decimals, length); const int dExp = (int)decimalPosition - (int)length + exp; Double a(approx); - for (int i = 0; i < 10; i++) { - bool adjustToNegative; - int cmp = CheckWithinHalfULP(a.Value(), dInt, dExp, &adjustToNegative); - if (cmp < 0) - return a.Value(); // within half ULP - else if (cmp == 0) { - // Round towards even - if (a.Significand() & 1) - return adjustToNegative ? a.PreviousPositiveDouble() : a.NextPositiveDouble(); - else - return a.Value(); - } - else // adjustment - a = adjustToNegative ? a.PreviousPositiveDouble() : a.NextPositiveDouble(); + int cmp = CheckWithinHalfULP(a.Value(), dInt, dExp); + if (cmp < 0) + return a.Value(); // within half ULP + else if (cmp == 0) { + // Round towards even + if (a.Significand() & 1) + return a.NextPositiveDouble(); + else + return a.Value(); } - - // This should not happen, but in case there is really a bug, break the infinite-loop - return a.Value(); + else // adjustment + return a.NextPositiveDouble(); } inline double StrtodFullPrecision(double d, int p, const char* decimals, size_t length, size_t decimalPosition, int exp) { From 402d75a80100dc01ae87e152ab47c2d120cd4cf9 Mon Sep 17 00:00:00 2001 From: miloyip Date: Wed, 15 Apr 2015 11:07:13 +0800 Subject: [PATCH 068/116] Fix gcc warning --- include/rapidjson/internal/dtoa.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/rapidjson/internal/dtoa.h b/include/rapidjson/internal/dtoa.h index 55dae8a..2d8d2e4 100644 --- a/include/rapidjson/internal/dtoa.h +++ b/include/rapidjson/internal/dtoa.h @@ -77,6 +77,7 @@ inline void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, char* buff case 3: d = p1 / 100; p1 %= 100; break; case 2: d = p1 / 10; p1 %= 10; break; case 1: d = p1; p1 = 0; break; + default:; } if (d || *len) buffer[(*len)++] = static_cast('0' + static_cast(d)); From 2689cc4974f314b99716b6fbad137e7e1bcecfdb Mon Sep 17 00:00:00 2001 From: miloyip Date: Wed, 15 Apr 2015 11:52:24 +0800 Subject: [PATCH 069/116] Remove more unused code paths in double conversions --- include/rapidjson/internal/biginteger.h | 7 ++----- include/rapidjson/internal/strtod.h | 14 ++------------ 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/include/rapidjson/internal/biginteger.h b/include/rapidjson/internal/biginteger.h index b088204..5baba9b 100755 --- a/include/rapidjson/internal/biginteger.h +++ b/include/rapidjson/internal/biginteger.h @@ -172,13 +172,10 @@ public: } // Compute absolute difference of this and rhs. - // Return false if this < rhs + // Assume this != rhs bool Difference(const BigInteger& rhs, BigInteger* out) const { int cmp = Compare(rhs); - if (cmp == 0) { - *out = BigInteger(0); - return false; - } + RAPIDJSON_ASSERT(cmp != 0); const BigInteger *a, *b; // Makes a > b bool ret; if (cmp < 0) { a = &rhs; b = this; ret = true; } diff --git a/include/rapidjson/internal/strtod.h b/include/rapidjson/internal/strtod.h index 6644f37..fa85286 100644 --- a/include/rapidjson/internal/strtod.h +++ b/include/rapidjson/internal/strtod.h @@ -104,19 +104,9 @@ inline int CheckWithinHalfULP(double b, const BigInteger& d, int dExp) { hS.MultiplyPow5(hS_Exp5) <<= hS_Exp2; BigInteger delta(0); - bool adjustToNegative = dS.Difference(bS, &delta); + dS.Difference(bS, &delta); - int cmp = delta.Compare(hS); - // If delta is within 1/2 ULP, check for special case when significand is power of two. - // In this case, need to compare with 1/2h in the lower bound. - if (cmp < 0 && adjustToNegative && // within and dS < bS - db.IsNormal() && (bInt & (bInt - 1)) == 0 && // Power of 2 - db.Uint64Value() != RAPIDJSON_UINT64_C2(0x00100000, 0x00000000)) // minimum normal number must not do this - { - delta <<= 1; - return delta.Compare(hS); - } - return cmp; + return delta.Compare(hS); } inline bool StrtodFast(double d, int p, double* result) { From 76d67b7eae55f48223d815184348bcdb0701f6ad Mon Sep 17 00:00:00 2001 From: miloyip Date: Wed, 15 Apr 2015 12:16:16 +0800 Subject: [PATCH 070/116] Improves coverage of Value::Accept() --- include/rapidjson/document.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index e436b8a..9ef0d91 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -1459,17 +1459,14 @@ public: case kStringType: return handler.String(GetString(), GetStringLength(), (flags_ & kCopyFlag) != 0); - case kNumberType: + default: + RAPIDJSON_ASSERT(GetType() == kNumberType); if (IsInt()) return handler.Int(data_.n.i.i); else if (IsUint()) return handler.Uint(data_.n.u.u); else if (IsInt64()) return handler.Int64(data_.n.i64); else if (IsUint64()) return handler.Uint64(data_.n.u64); else return handler.Double(data_.n.d); - - default: - RAPIDJSON_ASSERT(false); } - return false; } private: From c69ff41fc26731bd5b83ce5f242184eea0358bc7 Mon Sep 17 00:00:00 2001 From: miloyip Date: Wed, 15 Apr 2015 14:23:00 +0800 Subject: [PATCH 071/116] Add tests for parsing number with exhaustive exponents and random signifcant --- test/unittest/readertest.cpp | 42 +++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/test/unittest/readertest.cpp b/test/unittest/readertest.cpp index bccfbd6..7c70bc9 100644 --- a/test/unittest/readertest.cpp +++ b/test/unittest/readertest.cpp @@ -302,28 +302,40 @@ static void TestParseDouble() { "e-308", 2.2250738585072014e-308); -#if 0 // Very slow - static const unsigned count = 10000000; - // Random test for double { + static const unsigned count = 1000; // Tested with 1000000 locally Random r; + Reader reader; // Reusing reader to prevent heap allocation - for (unsigned i = 0; i < count; i++) { - internal::Double d; - do { + // Exhaustively test different exponents with random significant + for (uint64_t exp = 0; exp < 2047; exp++) { + ; + for (unsigned i = 0; i < count; i++) { // Need to call r() in two statements for cross-platform coherent sequence. - uint64_t u = uint64_t(r()) << 32; + uint64_t u = (exp << 52) | uint64_t(r() & 0x000FFFFF) << 32; u |= uint64_t(r()); - d = internal::Double(u); - } while (d.IsNan() || d.IsInf()/* || !d.IsNormal()*/); // Also work for subnormal now + internal::Double d = internal::Double(u); - char buffer[32]; - *internal::dtoa(d.Value(), buffer) = '\0'; - TEST_DOUBLE(fullPrecision, buffer, d.Value()); + char buffer[32]; + *internal::dtoa(d.Value(), buffer) = '\0'; + + StringStream s(buffer); + ParseDoubleHandler h; + ASSERT_EQ(kParseErrorNone, reader.Parse(s, h).Code()); + EXPECT_EQ(1u, h.step_); + internal::Double a(h.actual_); + if (fullPrecision) { + EXPECT_EQ(d.Uint64Value(), a.Uint64Value()); + if (d.Uint64Value() != a.Uint64Value()) + printf(" String: %sn Actual: %.17gnExpected: %.17gn", buffer, h.actual_, d.Value()); + } + else { + EXPECT_EQ(d.Sign(), a.Sign()); /* for 0.0 != -0.0 */ + EXPECT_DOUBLE_EQ(d.Value(), h.actual_); + } + } } } -#endif - #undef TEST_DOUBLE } @@ -651,7 +663,7 @@ TEST(Reader, ParseString_Error) { TEST_STRINGENCODING_ERROR(UTF32<>, UTF8<>, unsigned, ARRAY('[', '\"', 0x110000, '\"', ']', '\0')); // Malform ASCII sequence - TEST_STRINGENCODING_ERROR(ASCII<>, UTF8<>, char, ARRAY('[', '\"', 0x80, '\"', ']', '\0')); + TEST_STRINGENCODING_ERROR(ASCII<>, UTF8<>, char, ARRAY('[', '\"', char(0x80), '\"', ']', '\0')); #undef ARRAY #undef TEST_STRINGARRAY_ERROR From 631302e68e888f77fbbf22123137b575d9271fa0 Mon Sep 17 00:00:00 2001 From: miloyip Date: Wed, 15 Apr 2015 14:41:33 +0800 Subject: [PATCH 072/116] Reduce random test iterations to speedup travis --- test/unittest/readertest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/readertest.cpp b/test/unittest/readertest.cpp index 7c70bc9..1ff90ca 100644 --- a/test/unittest/readertest.cpp +++ b/test/unittest/readertest.cpp @@ -303,7 +303,7 @@ static void TestParseDouble() { 2.2250738585072014e-308); { - static const unsigned count = 1000; // Tested with 1000000 locally + static const unsigned count = 100; // Tested with 1000000 locally Random r; Reader reader; // Reusing reader to prevent heap allocation From 7cb031cc03d510d05f2d7ea4348503e81bc6cf25 Mon Sep 17 00:00:00 2001 From: thebusytypist Date: Wed, 15 Apr 2015 14:45:07 +0800 Subject: [PATCH 073/116] Add unittests for parsing root JSON value other than array and object. --- test/unittest/readertest.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/unittest/readertest.cpp b/test/unittest/readertest.cpp index bccfbd6..b9a5adc 100644 --- a/test/unittest/readertest.cpp +++ b/test/unittest/readertest.cpp @@ -1041,6 +1041,15 @@ TEST(Reader, IterativeParsing_ErrorHandling) { TESTERRORHANDLING("{\"a\"}", kParseErrorObjectMissColon, 4u); TESTERRORHANDLING("{\"a\": 1", kParseErrorObjectMissCommaOrCurlyBracket, 7u); TESTERRORHANDLING("[1 2 3]", kParseErrorArrayMissCommaOrSquareBracket, 3u); + + // Any JSON value can be a valid root element in RFC7159. + TESTERRORHANDLING("\"ab", kParseErrorStringMissQuotationMark, 2u); + TESTERRORHANDLING("truE", kParseErrorValueInvalid, 3u); + TESTERRORHANDLING("False", kParseErrorValueInvalid, 0u); + TESTERRORHANDLING("true, false", kParseErrorDocumentRootNotSingular, 4u); + TESTERRORHANDLING("false, false", kParseErrorDocumentRootNotSingular, 5u); + TESTERRORHANDLING("nulL", kParseErrorValueInvalid, 3u); + TESTERRORHANDLING("null , null", kParseErrorDocumentRootNotSingular, 5u); } template > From 857674737345c5aa2b4251480455578f1787d62f Mon Sep 17 00:00:00 2001 From: thebusytypist Date: Wed, 15 Apr 2015 14:51:48 +0800 Subject: [PATCH 074/116] Add unittest for state transition to IterativeParsingMemberKeyState. --- test/unittest/readertest.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unittest/readertest.cpp b/test/unittest/readertest.cpp index b9a5adc..942f8d6 100644 --- a/test/unittest/readertest.cpp +++ b/test/unittest/readertest.cpp @@ -1041,6 +1041,7 @@ TEST(Reader, IterativeParsing_ErrorHandling) { TESTERRORHANDLING("{\"a\"}", kParseErrorObjectMissColon, 4u); TESTERRORHANDLING("{\"a\": 1", kParseErrorObjectMissCommaOrCurlyBracket, 7u); TESTERRORHANDLING("[1 2 3]", kParseErrorArrayMissCommaOrSquareBracket, 3u); + TESTERRORHANDLING("{\"a: 1", kParseErrorStringMissQuotationMark, 5u); // Any JSON value can be a valid root element in RFC7159. TESTERRORHANDLING("\"ab", kParseErrorStringMissQuotationMark, 2u); From 399333226b64f389e9358a07018c2798b91f7543 Mon Sep 17 00:00:00 2001 From: thebusytypist Date: Wed, 15 Apr 2015 14:54:44 +0800 Subject: [PATCH 075/116] Use assertion for impossible case(The Predict() can ensure the token is ColonToken, otherwise it would be marked as Error state. So there is no need to check ColonToken again). --- include/rapidjson/reader.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/include/rapidjson/reader.h b/include/rapidjson/reader.h index d9da869..a2b6379 100644 --- a/include/rapidjson/reader.h +++ b/include/rapidjson/reader.h @@ -1273,12 +1273,9 @@ private: return dst; case IterativeParsingKeyValueDelimiterState: - if (token == ColonToken) { - is.Take(); - return dst; - } - else - return IterativeParsingErrorState; + RAPIDJSON_ASSERT(token == ColonToken); + is.Take(); + return dst; case IterativeParsingMemberValueState: // Must be non-compound value. Or it would be ObjectInitial or ArrayInitial state. From 3f562e118f263cf21e56bf4383a2278dab73278b Mon Sep 17 00:00:00 2001 From: miloyip Date: Wed, 15 Apr 2015 14:57:20 +0800 Subject: [PATCH 076/116] Fix "SSE 4.1 -> SSE 4.2" typo and add some comments about SIMD in internals and FAQ --- doc/faq.md | 2 +- doc/faq.zh-cn.md | 2 +- doc/features.md | 2 +- doc/features.zh-cn.md | 2 +- doc/internals.md | 16 +++++++++++++++- readme.md | 2 +- readme.zh-cn.md | 2 +- 7 files changed, 21 insertions(+), 7 deletions(-) diff --git a/doc/faq.md b/doc/faq.md index bab7f5f..85afcd3 100644 --- a/doc/faq.md +++ b/doc/faq.md @@ -198,7 +198,7 @@ 3. What is SIMD? How it is applied in RapidJSON? - [SIMD](http://en.wikipedia.org/wiki/SIMD) instructions can perform parallel computation in modern CPUs. RapidJSON support Intel's SSE2/SSE4.1 to accelerate whitespace skipping. This improves performance of parsing indent formatted JSON. + [SIMD](http://en.wikipedia.org/wiki/SIMD) instructions can perform parallel computation in modern CPUs. RapidJSON support Intel's SSE2/SSE4.2 to accelerate whitespace skipping. This improves performance of parsing indent formatted JSON. Define `RAPIDJSON_SSE2` or `RAPIDJSON_SSE42` macro to enable this feature. However, running the executable on a machine without such instruction set support will make it crash. 4. Does it consume a lot of memory? diff --git a/doc/faq.zh-cn.md b/doc/faq.zh-cn.md index ce6acf1..c6e7557 100644 --- a/doc/faq.zh-cn.md +++ b/doc/faq.zh-cn.md @@ -198,7 +198,7 @@ 3. 什是是SIMD?它如何用于RapidJSON? - [SIMD](http://en.wikipedia.org/wiki/SIMD)指令可以在现代CPU中执行并行运算。RapidJSON支持了Intel的SSE2/SSE4.1去加速跳过空白字符。在解析含缩进的JSON时,这能提升性能。 + [SIMD](http://en.wikipedia.org/wiki/SIMD)指令可以在现代CPU中执行并行运算。RapidJSON支持了Intel的SSE2/SSE4.2去加速跳过空白字符。在解析含缩进的JSON时,这能提升性能。只要定义名为`RAPIDJSON_SSE2`或`RAPIDJSON_SSE42`的宏,就能启动这个功能。然而,若在不支持这些指令集的机器上执行这些可执行文件,会导致崩溃。 4. 它会消耗许多内存么? diff --git a/doc/features.md b/doc/features.md index 15de259..fc54cd0 100644 --- a/doc/features.md +++ b/doc/features.md @@ -15,7 +15,7 @@ * High performance * Use template and inline functions to reduce function call overheads. * Internal optimized Grisu2 and floating point parsing implementations. - * Optional SSE2/SSE4.1 support. + * Optional SSE2/SSE4.2 support. ## Standard compliance diff --git a/doc/features.zh-cn.md b/doc/features.zh-cn.md index b56c424..3a01a4b 100644 --- a/doc/features.zh-cn.md +++ b/doc/features.zh-cn.md @@ -15,7 +15,7 @@ * 高性能 * 使用模版及内联函数去降低函数调用开销。 * 内部经优化的Grisu2及浮点数解析实现。 - * 可选的SSE2/SSE4.1支持。 + * 可选的SSE2/SSE4.2支持。 ## 符合标准 diff --git a/doc/internals.md b/doc/internals.md index ebfbc8f..de482cb 100644 --- a/doc/internals.md +++ b/doc/internals.md @@ -183,7 +183,21 @@ void SkipWhitespace(InputStream& s) { However, this requires 4 comparisons and a few branching for each character. This was found to be a hot spot. -To accelerate this process, SIMD was applied to compare 16 characters with 4 white spaces for each iteration. Currently RapidJSON only supports SSE2 and SSE4.1 instructions for this. And it is only activated for UTF-8 memory streams, including string stream or *in situ* parsing. +To accelerate this process, SIMD was applied to compare 16 characters with 4 white spaces for each iteration. Currently RapidJSON only supports SSE2 and SSE4.2 instructions for this. And it is only activated for UTF-8 memory streams, including string stream or *in situ* parsing. + +To enable this optimization, need to define `RAPIDJSON_SSE2` or `RAPIDJSON_SSE42` before including `rapidjson.h`. Some compilers can detect the setting, as in `perftest.h`: + +~~~cpp +// __SSE2__ and __SSE4_2__ are recognized by gcc, clang, and the Intel compiler. +// We use -march=native with gmake to enable -msse2 and -msse4.2, if supported. +#if defined(__SSE4_2__) +# define RAPIDJSON_SSE42 +#elif defined(__SSE2__) +# define RAPIDJSON_SSE2 +#endif +~~~ + +Note that, these are compile-time settings. Running the executable on a machine without such instruction set support will make it crash. ## Local Stream Copy {#LocalStreamCopy} diff --git a/readme.md b/readme.md index 59fd776..1314864 100644 --- a/readme.md +++ b/readme.md @@ -28,7 +28,7 @@ RapidJSON is a JSON parser and generator for C++. It was inspired by [RapidXml]( * RapidJSON is small but complete. It supports both SAX and DOM style API. The SAX parser is only a half thousand lines of code. -* RapidJSON is fast. Its performance can be comparable to `strlen()`. It also optionally supports SSE2/SSE4.1 for acceleration. +* RapidJSON is fast. Its performance can be comparable to `strlen()`. It also optionally supports SSE2/SSE4.2 for acceleration. * RapidJSON is self-contained. It does not depend on external libraries such as BOOST. It even does not depend on STL. diff --git a/readme.zh-cn.md b/readme.zh-cn.md index 569044b..cf26f49 100644 --- a/readme.zh-cn.md +++ b/readme.zh-cn.md @@ -16,7 +16,7 @@ RapidJSON是一个C++的JSON解析器及生成器。它的灵感来自[RapidXml] * RapidJSON小而全。它同时支持SAX和DOM风格的API。SAX解析器只有约500行代码。 -* RapidJSON快。它的性能可与`strlen()`相比。可支持SSE2/SSE4.1加速。 +* RapidJSON快。它的性能可与`strlen()`相比。可支持SSE2/SSE4.2加速。 * RapidJSON独立。它不依赖于BOOST等外部库。它甚至不依赖于STL。 From 5ae48a0380b3377d43f1cb06d6061af796b5fa6d Mon Sep 17 00:00:00 2001 From: thebusytypist Date: Wed, 15 Apr 2015 15:21:42 +0800 Subject: [PATCH 077/116] Assert on impossible state transition in Transit(); Put the last case and all non-enumerated cases(also supply assertion for them) in for code coverage. --- include/rapidjson/reader.h | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/include/rapidjson/reader.h b/include/rapidjson/reader.h index a2b6379..e0b9c8c 100644 --- a/include/rapidjson/reader.h +++ b/include/rapidjson/reader.h @@ -1228,13 +1228,6 @@ private: template RAPIDJSON_FORCEINLINE IterativeParsingState Transit(IterativeParsingState src, Token token, IterativeParsingState dst, InputStream& is, Handler& handler) { switch (dst) { - case IterativeParsingStartState: - RAPIDJSON_ASSERT(false); - return IterativeParsingErrorState; - - case IterativeParsingFinishState: - return dst; - case IterativeParsingErrorState: return dst; @@ -1350,17 +1343,25 @@ private: } } - case IterativeParsingValueState: + default: + // This branch is for IterativeParsingValueState actually. + // Use `default:` rather than + // `case IterativeParsingValueState:` is for code coverage. + + // The IterativeParsingStartState is not enumerated in this switch-case. + // It is impossible for that case. And it can be caught by following assertion. + + // The IterativeParsingFinishState is not enumerated in this switch-case either. + // It is a "derivative" state which cannot triggered from Predict() directly. + // Therefore it cannot happen here. And it can be caught by following assertion. + RAPIDJSON_ASSERT(dst == IterativeParsingValueState); + // Must be non-compound value. Or it would be ObjectInitial or ArrayInitial state. ParseValue(is, handler); if (HasParseError()) { return IterativeParsingErrorState; } return IterativeParsingFinishState; - - default: - RAPIDJSON_ASSERT(false); - return IterativeParsingErrorState; } } From 0d28bb13c7833a8cdf5c946a9ab1622eed528492 Mon Sep 17 00:00:00 2001 From: thebusytypist Date: Wed, 15 Apr 2015 15:46:31 +0800 Subject: [PATCH 078/116] Add a missing error handling check(a single number as JSON root). --- test/unittest/readertest.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unittest/readertest.cpp b/test/unittest/readertest.cpp index 942f8d6..11f3e78 100644 --- a/test/unittest/readertest.cpp +++ b/test/unittest/readertest.cpp @@ -1051,6 +1051,7 @@ TEST(Reader, IterativeParsing_ErrorHandling) { TESTERRORHANDLING("false, false", kParseErrorDocumentRootNotSingular, 5u); TESTERRORHANDLING("nulL", kParseErrorValueInvalid, 3u); TESTERRORHANDLING("null , null", kParseErrorDocumentRootNotSingular, 5u); + TESTERRORHANDLING("1a", kParseErrorDocumentRootNotSingular, 1u); } template > From 6ef29ff431ece1a7a63283bfc568f919dc78b311 Mon Sep 17 00:00:00 2001 From: thebusytypist Date: Wed, 15 Apr 2015 16:09:29 +0800 Subject: [PATCH 079/116] Fix warning about unused argument. --- include/rapidjson/reader.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/rapidjson/reader.h b/include/rapidjson/reader.h index e0b9c8c..31a145f 100644 --- a/include/rapidjson/reader.h +++ b/include/rapidjson/reader.h @@ -1227,6 +1227,8 @@ private: // May return a new state on state pop. template RAPIDJSON_FORCEINLINE IterativeParsingState Transit(IterativeParsingState src, Token token, IterativeParsingState dst, InputStream& is, Handler& handler) { + (void)token; + switch (dst) { case IterativeParsingErrorState: return dst; From a32d8b765089cbfaf73cab0ca9ea695eb06e50ca Mon Sep 17 00:00:00 2001 From: miloyip Date: Wed, 15 Apr 2015 18:18:49 +0800 Subject: [PATCH 080/116] Add SIMD SkipWhitespace() unit test which don't run in Valgrind --- test/unittest/CMakeLists.txt | 4 ++- test/unittest/simdtest.cpp | 59 ++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 test/unittest/simdtest.cpp diff --git a/test/unittest/CMakeLists.txt b/test/unittest/CMakeLists.txt index 52d5acd..bcc16d9 100644 --- a/test/unittest/CMakeLists.txt +++ b/test/unittest/CMakeLists.txt @@ -10,6 +10,7 @@ set(UNITTEST_SOURCES namespacetest.cpp prettywritertest.cpp readertest.cpp + simdtest.cpp stringbuffertest.cpp strtodtest.cpp unittest.cpp @@ -36,8 +37,9 @@ add_test(NAME unittest WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) if(NOT MSVC) + # Not running SIMD.* unit test cases for Valgrind add_test(NAME valgrind_unittest - COMMAND valgrind --leak-check=full --error-exitcode=1 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittest + COMMAND valgrind --leak-check=full --error-exitcode=1 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittest --gtest_filter=-SIMD.* WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) if(CMAKE_BUILD_TYPE STREQUAL "Debug") diff --git a/test/unittest/simdtest.cpp b/test/unittest/simdtest.cpp new file mode 100644 index 0000000..42fb10f --- /dev/null +++ b/test/unittest/simdtest.cpp @@ -0,0 +1,59 @@ +// Copyright (C) 2011 Milo Yip +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +// Since Travis CI installs old Valgrind 3.7.0, which fails with some SSE4.2 +// The unit tests prefix with SIMD should be skipped by Valgrind test + +// __SSE2__ and __SSE4_2__ are recognized by gcc, clang, and the Intel compiler. +// We use -march=native with gmake to enable -msse2 and -msse4.2, if supported. +#if defined(__SSE4_2__) +# define RAPIDJSON_SSE42 +#elif defined(__SSE2__) +# define RAPIDJSON_SSE2 +#endif + +#include "unittest.h" + +#include "rapidjson/reader.h" + +using namespace rapidjson; + +#ifdef RAPIDJSON_SSE2 +#define SIMD_SUFFIX(name) name##_SSE2 +#elif defined(RAPIDJSON_SSE42) +#define SIMD_SUFFIX(name) name##_SSE42 +#else +#define SIMD_SUFFIX(name) name +#endif + +TEST(SIMD, SIMD_SUFFIX(SkipWhitespace)) { + char buffer[258]; + for (size_t i = 0; i < 256; i++) + buffer[i] = " \t\r\n"[i % 4]; + buffer[256] = 'X'; + buffer[257] = '\0'; + + // Try to start from different position, to test different memory alignments + for (size_t i = 0; i < 256; i++) { + StringStream s(buffer + i); + SkipWhitespace(s); + EXPECT_EQ('X', s.Peek()); + } +} From ee505261c13b5901a1bd63b2df781bd8f4eb5a49 Mon Sep 17 00:00:00 2001 From: miloyip Date: Wed, 15 Apr 2015 18:34:18 +0800 Subject: [PATCH 081/116] Try to use another namespace for SIMD version --- test/unittest/simdtest.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/unittest/simdtest.cpp b/test/unittest/simdtest.cpp index 42fb10f..ebbbead 100644 --- a/test/unittest/simdtest.cpp +++ b/test/unittest/simdtest.cpp @@ -29,11 +29,13 @@ # define RAPIDJSON_SSE2 #endif +#define RAPIDJSON_NAMESPACE rapidjson_simd + #include "unittest.h" #include "rapidjson/reader.h" -using namespace rapidjson; +using namespace rapidjson_simd; #ifdef RAPIDJSON_SSE2 #define SIMD_SUFFIX(name) name##_SSE2 From 998e76fecc9495a5738ce5747f41a28a68ce9bee Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Wed, 15 Apr 2015 20:38:46 +0800 Subject: [PATCH 082/116] Improves SkipWhitespace coverage --- test/unittest/simdtest.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/test/unittest/simdtest.cpp b/test/unittest/simdtest.cpp index ebbbead..66d1e8b 100644 --- a/test/unittest/simdtest.cpp +++ b/test/unittest/simdtest.cpp @@ -46,16 +46,18 @@ using namespace rapidjson_simd; #endif TEST(SIMD, SIMD_SUFFIX(SkipWhitespace)) { - char buffer[258]; + char buffer[257]; for (size_t i = 0; i < 256; i++) buffer[i] = " \t\r\n"[i % 4]; - buffer[256] = 'X'; - buffer[257] = '\0'; + for (size_t i = 0; i < 256; i += 15) + buffer[i] = 'X'; + buffer[256] = '\0'; - // Try to start from different position, to test different memory alignments - for (size_t i = 0; i < 256; i++) { - StringStream s(buffer + i); + StringStream s(buffer); + for(;;) { SkipWhitespace(s); - EXPECT_EQ('X', s.Peek()); + if (s.Peek() == '\0') + break; + EXPECT_EQ('X', s.Take()); } } From a81585b5e23fbb0e1831f9d81eba152571149c56 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Wed, 15 Apr 2015 20:51:36 +0800 Subject: [PATCH 083/116] Further improve SkipWhitespace coverage --- test/unittest/simdtest.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/unittest/simdtest.cpp b/test/unittest/simdtest.cpp index 66d1e8b..4f103ef 100644 --- a/test/unittest/simdtest.cpp +++ b/test/unittest/simdtest.cpp @@ -46,12 +46,12 @@ using namespace rapidjson_simd; #endif TEST(SIMD, SIMD_SUFFIX(SkipWhitespace)) { - char buffer[257]; - for (size_t i = 0; i < 256; i++) + char buffer[1025]; + for (size_t i = 0; i < 1024; i++) buffer[i] = " \t\r\n"[i % 4]; - for (size_t i = 0; i < 256; i += 15) + for (size_t i = 0; i < 1024; i += 31) buffer[i] = 'X'; - buffer[256] = '\0'; + buffer[1024] = '\0'; StringStream s(buffer); for(;;) { From 4d3c64acee7e07e94be5ba46407736d1dd2c8111 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Wed, 15 Apr 2015 21:07:30 +0800 Subject: [PATCH 084/116] Improves SkipWhitespace test --- test/unittest/simdtest.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/test/unittest/simdtest.cpp b/test/unittest/simdtest.cpp index 4f103ef..6b49034 100644 --- a/test/unittest/simdtest.cpp +++ b/test/unittest/simdtest.cpp @@ -46,18 +46,23 @@ using namespace rapidjson_simd; #endif TEST(SIMD, SIMD_SUFFIX(SkipWhitespace)) { - char buffer[1025]; - for (size_t i = 0; i < 1024; i++) - buffer[i] = " \t\r\n"[i % 4]; - for (size_t i = 0; i < 1024; i += 31) - buffer[i] = 'X'; - buffer[1024] = '\0'; + for (int step = 1; step < 32; step++) { + char buffer[1025]; + for (size_t i = 0; i < 1024; i++) + buffer[i] = " \t\r\n"[i % 4]; + for (size_t i = 0; i < 1024; i += step) + buffer[i] = 'X'; + buffer[1024] = '\0'; - StringStream s(buffer); - for(;;) { - SkipWhitespace(s); - if (s.Peek() == '\0') - break; - EXPECT_EQ('X', s.Take()); + StringStream s(buffer); + size_t i = 0; + for (;;) { + SkipWhitespace(s); + if (s.Peek() == '\0') + break; + EXPECT_EQ(i, s.Tell()); + EXPECT_EQ('X', s.Take()); + i += step; + } } } From 8f2add7527c6035a719217c4dc01075392c4d3ed Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Wed, 15 Apr 2015 22:23:00 +0800 Subject: [PATCH 085/116] Not enforce force inline for debug configuration --- include/rapidjson/rapidjson.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/rapidjson/rapidjson.h b/include/rapidjson/rapidjson.h index b847ac7..602dabd 100644 --- a/include/rapidjson/rapidjson.h +++ b/include/rapidjson/rapidjson.h @@ -122,9 +122,9 @@ #ifndef RAPIDJSON_FORCEINLINE //!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(NDEBUG) #define RAPIDJSON_FORCEINLINE __forceinline -#elif defined(__GNUC__) && __GNUC__ >= 4 +#elif defined(__GNUC__) && __GNUC__ >= 4 && !defined(NDEBUG) #define RAPIDJSON_FORCEINLINE __attribute__((always_inline)) #else #define RAPIDJSON_FORCEINLINE From 0571a211bdd33ba00b46e207695b359d38d9b1ab Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Wed, 15 Apr 2015 22:36:00 +0800 Subject: [PATCH 086/116] Cover SkipWhiteSpace for InsituStringStream --- test/unittest/simdtest.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/unittest/simdtest.cpp b/test/unittest/simdtest.cpp index 6b49034..217db07 100644 --- a/test/unittest/simdtest.cpp +++ b/test/unittest/simdtest.cpp @@ -45,7 +45,8 @@ using namespace rapidjson_simd; #define SIMD_SUFFIX(name) name #endif -TEST(SIMD, SIMD_SUFFIX(SkipWhitespace)) { +template +void TestSkipWhitespace() { for (int step = 1; step < 32; step++) { char buffer[1025]; for (size_t i = 0; i < 1024; i++) @@ -54,7 +55,7 @@ TEST(SIMD, SIMD_SUFFIX(SkipWhitespace)) { buffer[i] = 'X'; buffer[1024] = '\0'; - StringStream s(buffer); + StreamType s(buffer); size_t i = 0; for (;;) { SkipWhitespace(s); @@ -66,3 +67,8 @@ TEST(SIMD, SIMD_SUFFIX(SkipWhitespace)) { } } } + +TEST(SIMD, SIMD_SUFFIX(SkipWhitespace)) { + TestSkipWhitespace(); + TestSkipWhitespace(); +} From 0edf27fa0cb7a1b076f1f3ad96b39eeb2c9a337a Mon Sep 17 00:00:00 2001 From: miloyip Date: Wed, 15 Apr 2015 22:55:35 +0800 Subject: [PATCH 087/116] Only do coverage on gcc/debug --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f26c944..8c29fe5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,7 @@ before_install: - sudo apt-get install -qq cmake valgrind - sudo apt-get --no-install-recommends install doxygen # Don't install LaTeX stuffs - if [ "$ARCH" = "x86" ]; then sudo apt-get install -qq g++-multilib libc6-dbg:i386; fi - - if [ "$CC" = "gcc" ]; then sudo pip install cpp-coveralls; export GCOV_FLAGS='--coverage'; fi + - if [ "$CC" = "gcc" ] && [ "CONF" = "debug" ]; then sudo pip install cpp-coveralls; export GCOV_FLAGS='--coverage'; fi install: true From e857b082fbef19e0234ecda50bcb6d5e021a2960 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Thu, 16 Apr 2015 00:11:41 +0800 Subject: [PATCH 088/116] Update readme.md Add coverall badges --- readme.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/readme.md b/readme.md index 1314864..8a7264f 100644 --- a/readme.md +++ b/readme.md @@ -13,14 +13,16 @@ Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights ## Build status -| [Linux][lin-link] | [Windows][win-link] | -| :---------------: | :-----------------: | -| ![lin-badge] | ![win-badge] | +| [Linux][lin-link] | [Windows][win-link] | [Coveralls][cov-link] | +| :---------------: | :-----------------: | :-------------------: | +| ![lin-badge] | ![win-badge] | ![cov-badge] | -[lin-badge]: https://travis-ci.org/miloyip/rapidjson.png "Travis build status" +[lin-badge]: https://travis-ci.org/miloyip/rapidjson.png?branch=master "Travis build status" [lin-link]: https://travis-ci.org/miloyip/rapidjson "Travis build status" -[win-badge]: https://ci.appveyor.com/api/projects/status/u658dcuwxo14a8m9/branch/master?svg=true "AppVeyor build status" +[win-badge]: https://ci.appveyor.com/api/projects/status/u658dcuwxo14a8m9/branch/master "AppVeyor build status" [win-link]: https://ci.appveyor.com/project/miloyip/rapidjson/branch/master "AppVeyor build status" +[cov-badge]: https://coveralls.io/repos/miloyip/rapidjson/badge.png?branch=master +[cov-link]: https://coveralls.io/r/miloyip/rapidjson?branch=master ## Introduction From b1fd2f18e18c3cae9b4de2f5a4f0e5ffb28bdb5e Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Thu, 16 Apr 2015 00:16:34 +0800 Subject: [PATCH 089/116] Update readme.zh-cn.md Add build status --- readme.zh-cn.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/readme.zh-cn.md b/readme.zh-cn.md index cf26f49..91ab10d 100644 --- a/readme.zh-cn.md +++ b/readme.zh-cn.md @@ -10,6 +10,19 @@ Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights * [简体中文](http://miloyip.github.io/rapidjson/zh-cn/) * [GitBook](https://www.gitbook.com/book/miloyip/rapidjson/)可下载PDF/EPUB/MOBI,但不含API参考手册。 +## Build 状态 + +| [Linux][lin-link] | [Windows][win-link] | [Coveralls][cov-link] | +| :---------------: | :-----------------: | :-------------------: | +| ![lin-badge] | ![win-badge] | ![cov-badge] | + +[lin-badge]: https://travis-ci.org/miloyip/rapidjson.png?branch=master "Travis build status" +[lin-link]: https://travis-ci.org/miloyip/rapidjson "Travis build status" +[win-badge]: https://ci.appveyor.com/api/projects/status/u658dcuwxo14a8m9/branch/master "AppVeyor build status" +[win-link]: https://ci.appveyor.com/project/miloyip/rapidjson/branch/master "AppVeyor build status" +[cov-badge]: https://coveralls.io/repos/miloyip/rapidjson/badge.png?branch=master +[cov-link]: https://coveralls.io/r/miloyip/rapidjson?branch=master + ## 简介 RapidJSON是一个C++的JSON解析器及生成器。它的灵感来自[RapidXml](http://rapidxml.sourceforge.net/)。 From 67a3ee39b5cf81824447135e8667dc727291337e Mon Sep 17 00:00:00 2001 From: miloyip Date: Thu, 16 Apr 2015 00:29:28 +0800 Subject: [PATCH 090/116] Fix coveralls --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8c29fe5..be06f35 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,7 @@ before_install: - sudo apt-get install -qq cmake valgrind - sudo apt-get --no-install-recommends install doxygen # Don't install LaTeX stuffs - if [ "$ARCH" = "x86" ]; then sudo apt-get install -qq g++-multilib libc6-dbg:i386; fi - - if [ "$CC" = "gcc" ] && [ "CONF" = "debug" ]; then sudo pip install cpp-coveralls; export GCOV_FLAGS='--coverage'; fi + - if [ "$CC" = "gcc" ] && [ "$CONF" = "debug" ]; then sudo pip install cpp-coveralls; export GCOV_FLAGS='--coverage'; fi install: true From a7763cbecac80f9e4cdf8321440614aaf281fb71 Mon Sep 17 00:00:00 2001 From: miloyip Date: Thu, 16 Apr 2015 09:42:22 +0800 Subject: [PATCH 091/116] Fix allocator test --- test/unittest/allocatorstest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/allocatorstest.cpp b/test/unittest/allocatorstest.cpp index 2cf9a2e..774bf9b 100644 --- a/test/unittest/allocatorstest.cpp +++ b/test/unittest/allocatorstest.cpp @@ -57,7 +57,7 @@ TEST(Allocator, MemoryPoolAllocator) { MemoryPoolAllocator<> a; TestAllocator(a); - for (int i = 0; i < 1000; i++) { + for (int i = 1; i < 1000; i++) { EXPECT_TRUE(a.Malloc(i) != 0); EXPECT_LE(a.Size(), a.Capacity()); } From 22021d6622ec6650ba64bccb17fc491af7aeb02f Mon Sep 17 00:00:00 2001 From: miloyip Date: Thu, 16 Apr 2015 10:15:23 +0800 Subject: [PATCH 092/116] Converts tabs to spaces --- include/rapidjson/reader.h | 68 +++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/include/rapidjson/reader.h b/include/rapidjson/reader.h index 31a145f..08297a0 100644 --- a/include/rapidjson/reader.h +++ b/include/rapidjson/reader.h @@ -255,23 +255,23 @@ void SkipWhitespace(InputStream& is) { #ifdef RAPIDJSON_SSE42 //! Skip whitespace with SSE 4.2 pcmpistrm instruction, testing 16 8-byte characters at once. inline const char *SkipWhitespace_SIMD(const char* p) { - // Fast return for single non-whitespace - if (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t') - ++p; - else - return p; + // Fast return for single non-whitespace + if (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t') + ++p; + else + return p; - // 16-byte align to the next boundary - const char* nextAligned = reinterpret_cast((reinterpret_cast(p) + 15) & ~15); - while (p != nextAligned) - if (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t') - ++p; - else - return p; + // 16-byte align to the next boundary + const char* nextAligned = reinterpret_cast((reinterpret_cast(p) + 15) & ~15); + while (p != nextAligned) + if (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t') + ++p; + else + return 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]); + static const char whitespace[16] = " \n\r\t"; + const __m128i w = _mm_load_si128((const __m128i *)&whitespace[0]); for (;; p += 16) { const __m128i s = _mm_load_si128((const __m128i *)p); @@ -292,31 +292,31 @@ inline const char *SkipWhitespace_SIMD(const char* p) { //! Skip whitespace with SSE2 instructions, testing 16 8-byte characters at once. inline const char *SkipWhitespace_SIMD(const char* p) { - // Fast return for single non-whitespace - if (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t') - ++p; - else - return p; + // Fast return for single non-whitespace + if (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t') + ++p; + else + return p; // 16-byte align to the next boundary - const char* nextAligned = reinterpret_cast((reinterpret_cast(p) + 15) & ~15); - while (p != nextAligned) - if (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t') - ++p; - else - return p; + const char* nextAligned = reinterpret_cast((reinterpret_cast(p) + 15) & ~15); + while (p != nextAligned) + if (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t') + ++p; + else + return p; // The rest of string - static const char whitespaces[4][17] = { - " ", - "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", - "\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r", - "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"}; + static const char whitespaces[4][17] = { + " ", + "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", + "\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r", + "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"}; - const __m128i w0 = _mm_loadu_si128((const __m128i *)&whitespaces[0][0]); - const __m128i w1 = _mm_loadu_si128((const __m128i *)&whitespaces[1][0]); - const __m128i w2 = _mm_loadu_si128((const __m128i *)&whitespaces[2][0]); - const __m128i w3 = _mm_loadu_si128((const __m128i *)&whitespaces[3][0]); + const __m128i w0 = _mm_loadu_si128((const __m128i *)&whitespaces[0][0]); + const __m128i w1 = _mm_loadu_si128((const __m128i *)&whitespaces[1][0]); + const __m128i w2 = _mm_loadu_si128((const __m128i *)&whitespaces[2][0]); + const __m128i w3 = _mm_loadu_si128((const __m128i *)&whitespaces[3][0]); for (;; p += 16) { const __m128i s = _mm_load_si128((const __m128i *)p); From 556d154bed5329abb479def1a32431ca6721df39 Mon Sep 17 00:00:00 2001 From: miloyip Date: Thu, 16 Apr 2015 10:34:45 +0800 Subject: [PATCH 093/116] Search sample data in more folders for perftest --- test/perftest/perftest.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/test/perftest/perftest.h b/test/perftest/perftest.h index 2fca203..4c955a4 100644 --- a/test/perftest/perftest.h +++ b/test/perftest/perftest.h @@ -71,9 +71,20 @@ public: PerfTest() : filename_(), json_(), length_(), whitespace_(), whitespace_length_() {} virtual void SetUp() { - FILE *fp = fopen(filename_ = "data/sample.json", "rb"); - if (!fp) - fp = fopen(filename_ = "../../bin/data/sample.json", "rb"); + + const char *paths[] = { + "data/sample.json", + "bin/data/sample.json", + "../bin/data/sample.json", + "../../bin/data/sample.json", + "../../../bin/data/sample.json" + }; + FILE *fp = 0; + for (size_t i = 0; i < sizeof(paths) / sizeof(paths[0]); i++) { + fp = fopen(paths[i], "rb"); + if (fp) + break; + } ASSERT_TRUE(fp != 0); fseek(fp, 0, SEEK_END); From 30ace6fa95f692743dd0f0e3efff6cafe4168691 Mon Sep 17 00:00:00 2001 From: miloyip Date: Thu, 16 Apr 2015 10:55:42 +0800 Subject: [PATCH 094/116] Fix mistake in perftest --- test/perftest/perftest.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/perftest/perftest.h b/test/perftest/perftest.h index 4c955a4..3198905 100644 --- a/test/perftest/perftest.h +++ b/test/perftest/perftest.h @@ -81,7 +81,7 @@ public: }; FILE *fp = 0; for (size_t i = 0; i < sizeof(paths) / sizeof(paths[0]); i++) { - fp = fopen(paths[i], "rb"); + fp = fopen(filename_ = paths[i], "rb"); if (fp) break; } From 0c5c1538dcfc7f160e5a4aa208ddf092c787be5a Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Thu, 16 Apr 2015 21:05:08 +0200 Subject: [PATCH 095/116] Avoid calling memcpy with NULL pointers According to the C/C++ standards, calling `memcpy(NULL, NULL, 0)` is undefined behaviour. Recent GCC versions may rely on this by optimizing NULL pointer checks more aggressively, see [1]. This patch tries to avoid calling std::memcpy with zero elements. As a side effect, explicitly return NULL when requesting an empty block from MemoryPoolAllocator::Malloc. This may be related to #301. [1] https://gcc.gnu.org/gcc-4.9/porting_to.html --- include/rapidjson/allocators.h | 7 ++++++- include/rapidjson/document.h | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/include/rapidjson/allocators.h b/include/rapidjson/allocators.h index 7b348b6..d3dcb12 100644 --- a/include/rapidjson/allocators.h +++ b/include/rapidjson/allocators.h @@ -160,6 +160,9 @@ public: //! Allocates a memory block. (concept Allocator) void* Malloc(size_t size) { + if (!size) + return NULL; + size = RAPIDJSON_ALIGN(size); if (chunkHead_ == 0 || chunkHead_->size + size > chunkHead_->capacity) AddChunk(chunk_capacity_ > size ? chunk_capacity_ : size); @@ -191,7 +194,9 @@ public: // Realloc process: allocate and copy memory, do not free original buffer. void* newBuffer = Malloc(newSize); RAPIDJSON_ASSERT(newBuffer != 0); // Do not handle out-of-memory explicitly. - return std::memcpy(newBuffer, originalPtr, originalSize); + if (originalSize) + std::memcpy(newBuffer, originalPtr, originalSize); + return newBuffer; } //! Frees a memory block (concept Allocator) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 204e3bd..3aaef13 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -1582,16 +1582,24 @@ private: // Initialize this value as array with initial data, without calling destructor. void SetArrayRaw(GenericValue* values, SizeType count, Allocator& allocator) { flags_ = kArrayFlag; - data_.a.elements = (GenericValue*)allocator.Malloc(count * sizeof(GenericValue)); - std::memcpy(data_.a.elements, values, count * sizeof(GenericValue)); + if (count) { + data_.a.elements = (GenericValue*)allocator.Malloc(count * sizeof(GenericValue)); + std::memcpy(data_.a.elements, values, count * sizeof(GenericValue)); + } + else + data_.a.elements = NULL; 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& allocator) { flags_ = kObjectFlag; - data_.o.members = (Member*)allocator.Malloc(count * sizeof(Member)); - std::memcpy(data_.o.members, members, count * sizeof(Member)); + if (count) { + data_.o.members = (Member*)allocator.Malloc(count * sizeof(Member)); + std::memcpy(data_.o.members, members, count * sizeof(Member)); + } + else + data_.o.members = NULL; data_.o.size = data_.o.capacity = count; } From 0e8bbe5e3ef375e7f052f556878be0bd79e9062d Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Fri, 17 Apr 2015 13:01:14 +0800 Subject: [PATCH 096/116] Standardize behavior of CrtAllocator::Malloc() --- include/rapidjson/allocators.h | 7 ++++++- test/unittest/allocatorstest.cpp | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/rapidjson/allocators.h b/include/rapidjson/allocators.h index d3dcb12..d68b74c 100644 --- a/include/rapidjson/allocators.h +++ b/include/rapidjson/allocators.h @@ -62,7 +62,12 @@ concept Allocator { class CrtAllocator { public: static const bool kNeedFree = true; - void* Malloc(size_t size) { return std::malloc(size); } + void* Malloc(size_t size) { + if (size) // behavior of malloc(0) is implementation defined. + return std::malloc(size); + else + return NULL; // standardize to returning NULL. + } void* Realloc(void* originalPtr, size_t originalSize, size_t newSize) { (void)originalSize; return std::realloc(originalPtr, newSize); } static void Free(void *ptr) { std::free(ptr); } }; diff --git a/test/unittest/allocatorstest.cpp b/test/unittest/allocatorstest.cpp index 774bf9b..1dba812 100644 --- a/test/unittest/allocatorstest.cpp +++ b/test/unittest/allocatorstest.cpp @@ -26,6 +26,8 @@ using namespace rapidjson; template void TestAllocator(Allocator& a) { + EXPECT_TRUE(a.Malloc(0) == 0); + uint8_t* p = (uint8_t*)a.Malloc(100); EXPECT_TRUE(p != 0); for (size_t i = 0; i < 100; i++) From aa61b08d11b84921e595aa51767726c1bd6f8233 Mon Sep 17 00:00:00 2001 From: miloyip Date: Sat, 18 Apr 2015 20:30:40 +0800 Subject: [PATCH 097/116] Fix warnings for misctest --- test/perftest/misctest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/perftest/misctest.cpp b/test/perftest/misctest.cpp index 3edadda..6b276e4 100644 --- a/test/perftest/misctest.cpp +++ b/test/perftest/misctest.cpp @@ -768,7 +768,7 @@ template void itoa_Writer_StringBufferVerify() { rapidjson::StringBuffer sb; Writer writer(sb); - for (int j = 0; j < randvalCount; j++) { + for (size_t j = 0; j < randvalCount; j++) { char buffer[32]; sprintf(buffer, "%d", randval[j]); writer.WriteInt(randval[j]); @@ -780,7 +780,7 @@ void itoa_Writer_StringBufferVerify() { template void itoa_Writer_InsituStringStreamVerify() { Writer writer; - for (int j = 0; j < randvalCount; j++) { + for (size_t j = 0; j < randvalCount; j++) { char buffer[32]; sprintf(buffer, "%d", randval[j]); char buffer2[32]; From 8d39282af507629575215de919189babd5d35f01 Mon Sep 17 00:00:00 2001 From: miloyip Date: Sat, 18 Apr 2015 21:41:38 +0800 Subject: [PATCH 098/116] Update license headers for tests --- include/rapidjson/rapidjson.h | 3 --- test/perftest/misctest.cpp | 26 ++++++++++---------------- test/perftest/perftest.cpp | 26 ++++++++++---------------- test/perftest/perftest.h | 26 ++++++++++---------------- test/perftest/platformtest.cpp | 26 ++++++++++---------------- test/perftest/rapidjsontest.cpp | 26 ++++++++++---------------- test/unittest/allocatorstest.cpp | 26 ++++++++++---------------- test/unittest/bigintegertest.cpp | 26 ++++++++++---------------- test/unittest/documenttest.cpp | 26 ++++++++++---------------- test/unittest/encodedstreamtest.cpp | 26 ++++++++++---------------- test/unittest/encodingstest.cpp | 26 ++++++++++---------------- test/unittest/filestreamtest.cpp | 26 ++++++++++---------------- test/unittest/itoatest.cpp | 26 ++++++++++---------------- test/unittest/jsoncheckertest.cpp | 26 ++++++++++---------------- test/unittest/namespacetest.cpp | 26 ++++++++++---------------- test/unittest/prettywritertest.cpp | 26 ++++++++++---------------- test/unittest/readertest.cpp | 26 ++++++++++---------------- test/unittest/simdtest.cpp | 26 ++++++++++---------------- test/unittest/stringbuffertest.cpp | 26 ++++++++++---------------- test/unittest/strtodtest.cpp | 26 ++++++++++---------------- test/unittest/unittest.cpp | 26 ++++++++++---------------- test/unittest/unittest.h | 26 ++++++++++---------------- test/unittest/valuetest.cpp | 26 ++++++++++---------------- test/unittest/writertest.cpp | 26 ++++++++++---------------- 24 files changed, 230 insertions(+), 371 deletions(-) diff --git a/include/rapidjson/rapidjson.h b/include/rapidjson/rapidjson.h index 602dabd..4351aea 100644 --- a/include/rapidjson/rapidjson.h +++ b/include/rapidjson/rapidjson.h @@ -15,9 +15,6 @@ #ifndef RAPIDJSON_RAPIDJSON_H_ #define RAPIDJSON_RAPIDJSON_H_ -// Copyright (c) 2011 Milo Yip (miloyip@gmail.com) -// Version 0.1 - /*!\file rapidjson.h \brief common definitions and configuration diff --git a/test/perftest/misctest.cpp b/test/perftest/misctest.cpp index 6b276e4..c6b3353 100644 --- a/test/perftest/misctest.cpp +++ b/test/perftest/misctest.cpp @@ -1,22 +1,16 @@ -// Copyright (C) 2011 Milo Yip +// 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. // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: +// 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 // -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. +// http://opensource.org/licenses/MIT // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// 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. #include "perftest.h" diff --git a/test/perftest/perftest.cpp b/test/perftest/perftest.cpp index 4366e1c..38ba07e 100644 --- a/test/perftest/perftest.cpp +++ b/test/perftest/perftest.cpp @@ -1,22 +1,16 @@ -// Copyright (C) 2011 Milo Yip +// 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. // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: +// 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 // -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. +// http://opensource.org/licenses/MIT // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// 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. #include "perftest.h" diff --git a/test/perftest/perftest.h b/test/perftest/perftest.h index 3198905..2b0984c 100644 --- a/test/perftest/perftest.h +++ b/test/perftest/perftest.h @@ -1,22 +1,16 @@ -// Copyright (C) 2011 Milo Yip +// 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. // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: +// 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 // -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. +// http://opensource.org/licenses/MIT // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// 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 PERFTEST_H_ #define PERFTEST_H_ diff --git a/test/perftest/platformtest.cpp b/test/perftest/platformtest.cpp index 30b690c..7ea2a8e 100644 --- a/test/perftest/platformtest.cpp +++ b/test/perftest/platformtest.cpp @@ -1,22 +1,16 @@ -// Copyright (C) 2011 Milo Yip +// 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. // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: +// 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 // -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. +// http://opensource.org/licenses/MIT // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// 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. #include "perftest.h" diff --git a/test/perftest/rapidjsontest.cpp b/test/perftest/rapidjsontest.cpp index 875c5eb..05ecf6e 100644 --- a/test/perftest/rapidjsontest.cpp +++ b/test/perftest/rapidjsontest.cpp @@ -1,22 +1,16 @@ -// Copyright (C) 2011 Milo Yip +// 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. // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: +// 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 // -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. +// http://opensource.org/licenses/MIT // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// 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. #include "perftest.h" diff --git a/test/unittest/allocatorstest.cpp b/test/unittest/allocatorstest.cpp index 1dba812..3f33724 100644 --- a/test/unittest/allocatorstest.cpp +++ b/test/unittest/allocatorstest.cpp @@ -1,22 +1,16 @@ -// Copyright (C) 2011 Milo Yip +// 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. // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: +// 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 // -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. +// http://opensource.org/licenses/MIT // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// 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. #include "unittest.h" diff --git a/test/unittest/bigintegertest.cpp b/test/unittest/bigintegertest.cpp index e7b3b8f..a68e144 100644 --- a/test/unittest/bigintegertest.cpp +++ b/test/unittest/bigintegertest.cpp @@ -1,22 +1,16 @@ -// Copyright (C) 2011 Milo Yip +// 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. // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: +// 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 // -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. +// http://opensource.org/licenses/MIT // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// 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. #include "unittest.h" diff --git a/test/unittest/documenttest.cpp b/test/unittest/documenttest.cpp index dd4fb13..71cd777 100644 --- a/test/unittest/documenttest.cpp +++ b/test/unittest/documenttest.cpp @@ -1,22 +1,16 @@ -// Copyright (C) 2011 Milo Yip +// 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. // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: +// 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 // -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. +// http://opensource.org/licenses/MIT // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// 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. #include "unittest.h" #include "rapidjson/document.h" diff --git a/test/unittest/encodedstreamtest.cpp b/test/unittest/encodedstreamtest.cpp index 5affb5d..8cef208 100644 --- a/test/unittest/encodedstreamtest.cpp +++ b/test/unittest/encodedstreamtest.cpp @@ -1,22 +1,16 @@ -// Copyright (C) 2011 Milo Yip +// 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. // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: +// 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 // -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. +// http://opensource.org/licenses/MIT // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// 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. #include "unittest.h" #include "rapidjson/filereadstream.h" diff --git a/test/unittest/encodingstest.cpp b/test/unittest/encodingstest.cpp index 3beebe6..b697d91 100644 --- a/test/unittest/encodingstest.cpp +++ b/test/unittest/encodingstest.cpp @@ -1,22 +1,16 @@ -// Copyright (C) 2011 Milo Yip +// 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. // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: +// 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 // -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. +// http://opensource.org/licenses/MIT // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// 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. #include "unittest.h" #include "rapidjson/filereadstream.h" diff --git a/test/unittest/filestreamtest.cpp b/test/unittest/filestreamtest.cpp index 1fd5d19..2850b56 100644 --- a/test/unittest/filestreamtest.cpp +++ b/test/unittest/filestreamtest.cpp @@ -1,22 +1,16 @@ -// Copyright (C) 2011 Milo Yip +// 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. // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: +// 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 // -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. +// http://opensource.org/licenses/MIT // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// 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. #include "unittest.h" #include "rapidjson/filereadstream.h" diff --git a/test/unittest/itoatest.cpp b/test/unittest/itoatest.cpp index 31a008c..5ceb99f 100644 --- a/test/unittest/itoatest.cpp +++ b/test/unittest/itoatest.cpp @@ -1,22 +1,16 @@ -// Copyright (C) 2011 Milo Yip +// 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. // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: +// 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 // -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. +// http://opensource.org/licenses/MIT // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// 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. #include "unittest.h" #include "rapidjson/internal/itoa.h" diff --git a/test/unittest/jsoncheckertest.cpp b/test/unittest/jsoncheckertest.cpp index a89b8d2..34f8569 100644 --- a/test/unittest/jsoncheckertest.cpp +++ b/test/unittest/jsoncheckertest.cpp @@ -1,22 +1,16 @@ -// Copyright (C) 2011 Milo Yip +// 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. // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: +// 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 // -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. +// http://opensource.org/licenses/MIT // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// 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. #include "unittest.h" diff --git a/test/unittest/namespacetest.cpp b/test/unittest/namespacetest.cpp index ed74ae3..5db83cc 100644 --- a/test/unittest/namespacetest.cpp +++ b/test/unittest/namespacetest.cpp @@ -1,22 +1,16 @@ -// Copyright (C) 2011 Milo Yip +// 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. // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: +// 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 // -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. +// http://opensource.org/licenses/MIT // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// 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. #include "unittest.h" diff --git a/test/unittest/prettywritertest.cpp b/test/unittest/prettywritertest.cpp index 6ae14b9..1a63c82 100644 --- a/test/unittest/prettywritertest.cpp +++ b/test/unittest/prettywritertest.cpp @@ -1,22 +1,16 @@ -// Copyright (C) 2011 Milo Yip +// 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. // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: +// 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 // -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. +// http://opensource.org/licenses/MIT // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// 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. #include "unittest.h" #include "rapidjson/reader.h" diff --git a/test/unittest/readertest.cpp b/test/unittest/readertest.cpp index 0b4196f..4e8d4e4 100644 --- a/test/unittest/readertest.cpp +++ b/test/unittest/readertest.cpp @@ -1,22 +1,16 @@ -// Copyright (C) 2011 Milo Yip +// 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. // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: +// 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 // -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. +// http://opensource.org/licenses/MIT // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// 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. #include "unittest.h" diff --git a/test/unittest/simdtest.cpp b/test/unittest/simdtest.cpp index 217db07..c8f4587 100644 --- a/test/unittest/simdtest.cpp +++ b/test/unittest/simdtest.cpp @@ -1,22 +1,16 @@ -// Copyright (C) 2011 Milo Yip +// 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. // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: +// 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 // -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. +// http://opensource.org/licenses/MIT // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// 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. // Since Travis CI installs old Valgrind 3.7.0, which fails with some SSE4.2 // The unit tests prefix with SIMD should be skipped by Valgrind test diff --git a/test/unittest/stringbuffertest.cpp b/test/unittest/stringbuffertest.cpp index 7cfde4f..fbacf51 100644 --- a/test/unittest/stringbuffertest.cpp +++ b/test/unittest/stringbuffertest.cpp @@ -1,22 +1,16 @@ -// Copyright (C) 2011 Milo Yip +// 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. // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: +// 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 // -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. +// http://opensource.org/licenses/MIT // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// 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. #include "unittest.h" #include "rapidjson/stringbuffer.h" diff --git a/test/unittest/strtodtest.cpp b/test/unittest/strtodtest.cpp index d8849be..dc2378b 100644 --- a/test/unittest/strtodtest.cpp +++ b/test/unittest/strtodtest.cpp @@ -1,22 +1,16 @@ -// Copyright (C) 2011 Milo Yip +// 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. // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: +// 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 // -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. +// http://opensource.org/licenses/MIT // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// 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. #include "unittest.h" diff --git a/test/unittest/unittest.cpp b/test/unittest/unittest.cpp index 4604d9d..c475179 100644 --- a/test/unittest/unittest.cpp +++ b/test/unittest/unittest.cpp @@ -1,22 +1,16 @@ -// Copyright (C) 2011 Milo Yip +// 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. // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: +// 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 // -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. +// http://opensource.org/licenses/MIT // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// 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. #include "unittest.h" diff --git a/test/unittest/unittest.h b/test/unittest/unittest.h index 800fbab..dbba754 100644 --- a/test/unittest/unittest.h +++ b/test/unittest/unittest.h @@ -1,22 +1,16 @@ -// Copyright (C) 2011 Milo Yip +// 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. // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: +// 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 // -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. +// http://opensource.org/licenses/MIT // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// 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 UNITTEST_H_ #define UNITTEST_H_ diff --git a/test/unittest/valuetest.cpp b/test/unittest/valuetest.cpp index fa9547b..1922222 100644 --- a/test/unittest/valuetest.cpp +++ b/test/unittest/valuetest.cpp @@ -1,22 +1,16 @@ -// Copyright (C) 2011 Milo Yip +// 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. // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: +// 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 // -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. +// http://opensource.org/licenses/MIT // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// 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. #include "unittest.h" #include "rapidjson/document.h" diff --git a/test/unittest/writertest.cpp b/test/unittest/writertest.cpp index 85d533d..2adb551 100644 --- a/test/unittest/writertest.cpp +++ b/test/unittest/writertest.cpp @@ -1,22 +1,16 @@ -// Copyright (C) 2011 Milo Yip +// 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. // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: +// 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 // -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. +// http://opensource.org/licenses/MIT // -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// 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. #include "unittest.h" From 5ab1e9361db34edfb228e6d7df81e1842ef7b4ab Mon Sep 17 00:00:00 2001 From: miloyip Date: Tue, 21 Apr 2015 16:38:49 +0800 Subject: [PATCH 099/116] Add version macros for RapidJSON --- CMakeLists.txt | 4 ++-- include/rapidjson/rapidjson.h | 39 ++++++++++++++++++++++++++++++----- test/unittest/unittest.cpp | 3 +++ 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c823ac..94919f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,8 +3,8 @@ SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMakeModules) PROJECT(RapidJSON CXX) -set(LIB_MAJOR_VERSION "0") -set(LIB_MINOR_VERSION "12") +set(LIB_MAJOR_VERSION "1") +set(LIB_MINOR_VERSION "0") set(LIB_PATCH_VERSION "0") set(LIB_VERSION_STRING "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_PATCH_VERSION}") diff --git a/include/rapidjson/rapidjson.h b/include/rapidjson/rapidjson.h index 4351aea..021468b 100644 --- a/include/rapidjson/rapidjson.h +++ b/include/rapidjson/rapidjson.h @@ -17,7 +17,7 @@ /*!\file rapidjson.h \brief common definitions and configuration - + \see RAPIDJSON_CONFIG */ @@ -39,6 +39,39 @@ #include // malloc(), realloc(), free(), size_t #include // memset(), memcpy(), memmove(), memcmp() +/////////////////////////////////////////////////////////////////////////////// +// RAPIDJSON_VERSION_STRING +// +// ALWAYS synchronize the following 3 macros with corresponding variables in /CMakeLists.txt. +// + +//!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN +// token stringification +#define RAPIDJSON_STRINGIFY(x) RAPIDJSON_DO_STRINGIFY(x) +#define RAPIDJSON_DO_STRINGIFY(x) #x +//!@endcond + +/*! \def RAPIDJSON_MAJOR_VERSION + \ingroup RAPIDJSON_CONFIG + \brief Major version of RapidJSON in integer. +*/ +/*! \def RAPIDJSON_MINOR_VERSION + \ingroup RAPIDJSON_CONFIG + \brief Minor version of RapidJSON in integer. +*/ +/*! \def RAPIDJSON_PATCH_VERSION + \ingroup RAPIDJSON_CONFIG + \brief Patch version of RapidJSON in integer. +*/ +/*! \def RAPIDJSON_VERSION_STRING + \ingroup RAPIDJSON_CONFIG + \brief Version of RapidJSON in ".." string format. +*/ +#define RAPIDJSON_MAJOR_VERSION 1 +#define RAPIDJSON_MINOR_VERSION 0 +#define RAPIDJSON_PATCH_VERSION 0 +#define RAPIDJSON_VERSION_STRING RAPIDJSON_STRINGIFY(RAPIDJSON_MAJOR_VERSION) "." RAPIDJSON_STRINGIFY(RAPIDJSON_MINOR_VERSION) "." RAPIDJSON_STRINGIFY(RAPIDJSON_PATCH_VERSION) + /////////////////////////////////////////////////////////////////////////////// // RAPIDJSON_NAMESPACE_(BEGIN|END) /*! \def RAPIDJSON_NAMESPACE @@ -353,10 +386,6 @@ RAPIDJSON_NAMESPACE_END #define RAPIDJSON_VERSION_CODE(x,y,z) \ (((x)*100000) + ((y)*100) + (z)) -// token stringification -#define RAPIDJSON_STRINGIFY(x) RAPIDJSON_DO_STRINGIFY(x) -#define RAPIDJSON_DO_STRINGIFY(x) #x - /////////////////////////////////////////////////////////////////////////////// // RAPIDJSON_DIAG_PUSH/POP, RAPIDJSON_DIAG_OFF diff --git a/test/unittest/unittest.cpp b/test/unittest/unittest.cpp index c475179..4e3bc11 100644 --- a/test/unittest/unittest.cpp +++ b/test/unittest/unittest.cpp @@ -13,10 +13,13 @@ // specific language governing permissions and limitations under the License. #include "unittest.h" +#include "rapidjson/rapidjson.h" int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); + std::cout << "RapidJSON v" << RAPIDJSON_VERSION_STRING << std::endl; + #if _MSC_VER _CrtMemState memoryState = { 0 }; _CrtMemCheckpoint(&memoryState); From 95c6ec97c419da7832db28f5b1a01f6cdc0580ab Mon Sep 17 00:00:00 2001 From: miloyip Date: Tue, 21 Apr 2015 17:28:31 +0800 Subject: [PATCH 100/116] Add release badge to readmes --- readme.md | 3 +++ readme.zh-cn.md | 2 ++ 2 files changed, 5 insertions(+) diff --git a/readme.md b/readme.md index 8a7264f..007596a 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,7 @@ ![](doc/logo/rapidjson.png) + +![](https://img.shields.io/badge/release-v1.0.0-blue.png) + ## A fast JSON parser/generator for C++ with both SAX/DOM style API Tencent is pleased to support the open source community by making RapidJSON available. diff --git a/readme.zh-cn.md b/readme.zh-cn.md index 91ab10d..be3849a 100644 --- a/readme.zh-cn.md +++ b/readme.zh-cn.md @@ -1,5 +1,7 @@ ![](doc/logo/rapidjson.png) +![](https://img.shields.io/badge/release-v1.0.0-blue.png) + 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. From 04b673686af52d673185f822812799812dd161a3 Mon Sep 17 00:00:00 2001 From: Andrii Senkovych Date: Tue, 21 Apr 2015 13:10:08 +0300 Subject: [PATCH 101/116] Introduce option to select default gtest installation. Refs #309 This will introduce RAPIDJSON_BUILD_THIRDPARTY_GTEST option. If it is set to TRUE, cmake will look for GTest installation in `thirdparty/gtest` before looking in other places. Current default value (OFF) for RAPIDJSON_BUILD_THIRDPARTY_GTEST represents previous behaviour when system-wide gtest installation is used whenever possible. This commit will as well eliminate problem described in #309 when source directory found is `thirdparty/gtest` while include files are found system-wide. This however won't give the user possibility to select gtest installation to use. --- CMakeLists.txt | 2 ++ CMakeModules/FindGTestSrc.cmake | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c823ac..cf6b46f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,8 @@ SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) option(RAPIDJSON_BUILD_DOC "Build rapidjson documentation." ON) option(RAPIDJSON_BUILD_EXAMPLES "Build rapidjson examples." ON) option(RAPIDJSON_BUILD_TESTS "Build rapidjson perftests and unittests." ON) +option(RAPIDJSON_BUILD_THIRDPARTY_GTEST + "Use gtest installation in `thirdparty/gtest` by default if available" OFF) option(RAPIDJSON_HAS_STDSTRING "" OFF) if(RAPIDJSON_HAS_STDSTRING) diff --git a/CMakeModules/FindGTestSrc.cmake b/CMakeModules/FindGTestSrc.cmake index 13b1c7b..b5abc19 100644 --- a/CMakeModules/FindGTestSrc.cmake +++ b/CMakeModules/FindGTestSrc.cmake @@ -1,9 +1,14 @@ + SET(GTEST_SEARCH_PATH "${GTEST_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/thirdparty/gtest") IF(UNIX) - LIST(INSERT GTEST_SEARCH_PATH 1 "/usr/src/gtest") + IF(RAPIDJSON_BUILD_THIRDPARTY_GTEST) + LIST(APPEND GTEST_SEARCH_PATH "/usr/src/gtest") + ELSE() + LIST(INSERT GTEST_SEARCH_PATH 1 "/usr/src/gtest") + ENDIF() ENDIF() FIND_PATH(GTEST_SOURCE_DIR @@ -15,6 +20,7 @@ FIND_PATH(GTEST_SOURCE_DIR FIND_PATH(GTEST_INCLUDE_DIR NAMES gtest/gtest.h PATH_SUFFIXES include + HINTS ${GTEST_SOURCE_DIR} PATHS ${GTEST_SEARCH_PATH}) INCLUDE(FindPackageHandleStandardArgs) From 5ab3f69910ce33b6aed5d8de5ff56c2c6b277f88 Mon Sep 17 00:00:00 2001 From: miloyip Date: Wed, 22 Apr 2015 09:19:18 +0800 Subject: [PATCH 102/116] Simplify RAPIDJSON_VERSION_STRING --- include/rapidjson/rapidjson.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/rapidjson/rapidjson.h b/include/rapidjson/rapidjson.h index 021468b..938a3ce 100644 --- a/include/rapidjson/rapidjson.h +++ b/include/rapidjson/rapidjson.h @@ -70,7 +70,8 @@ #define RAPIDJSON_MAJOR_VERSION 1 #define RAPIDJSON_MINOR_VERSION 0 #define RAPIDJSON_PATCH_VERSION 0 -#define RAPIDJSON_VERSION_STRING RAPIDJSON_STRINGIFY(RAPIDJSON_MAJOR_VERSION) "." RAPIDJSON_STRINGIFY(RAPIDJSON_MINOR_VERSION) "." RAPIDJSON_STRINGIFY(RAPIDJSON_PATCH_VERSION) +#define RAPIDJSON_VERSION_STRING \ + RAPIDJSON_STRINGIFY(RAPIDJSON_MAJOR_VERSION.RAPIDJSON_MINOR_VERSION.RAPIDJSON_PATCH_VERSION) /////////////////////////////////////////////////////////////////////////////// // RAPIDJSON_NAMESPACE_(BEGIN|END) From b2e53523bf4a12fe120ceaa16e3b5c7da1672f41 Mon Sep 17 00:00:00 2001 From: miloyip Date: Wed, 22 Apr 2015 09:24:56 +0800 Subject: [PATCH 103/116] Change version in appveyor --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index d1a9108..890f9d9 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 0.12.{build} +version: 1.0.0.{build} configuration: - Debug From 93d13ad2acc6a52d58e09d84e76826cd36ee64f0 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Fri, 24 Apr 2015 21:44:42 +0800 Subject: [PATCH 104/116] Fix #313 Assertion In `Pow10.h` is triggered in Document::Parse --- include/rapidjson/reader.h | 5 +++++ test/unittest/readertest.cpp | 14 +++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/include/rapidjson/reader.h b/include/rapidjson/reader.h index 08297a0..320428f 100644 --- a/include/rapidjson/reader.h +++ b/include/rapidjson/reader.h @@ -929,6 +929,11 @@ private: exp = exp * 10 + (s.Take() - '0'); if (exp > 308 && !expMinus) // exp > 308 should be rare, so it should be checked first. RAPIDJSON_PARSE_ERROR(kParseErrorNumberTooBig, s.Tell()); + else if (exp >= 429496729 && expMinus) { // Issue #313: prevent overflow exponent + while (s.Peek() >= '0' && s.Peek() <= '9') // Consume the rest of exponent + s.Take(); + break; + } } } else diff --git a/test/unittest/readertest.cpp b/test/unittest/readertest.cpp index 4e8d4e4..86199fa 100644 --- a/test/unittest/readertest.cpp +++ b/test/unittest/readertest.cpp @@ -219,13 +219,17 @@ static void TestParseDouble() { TEST_DOUBLE(fullPrecision, "2.2250738585072009e-308", 2.2250738585072009e-308); // Max subnormal double TEST_DOUBLE(fullPrecision, "2.2250738585072014e-308", 2.2250738585072014e-308); // Min normal positive double TEST_DOUBLE(fullPrecision, "1.7976931348623157e+308", 1.7976931348623157e+308); // Max double - TEST_DOUBLE(fullPrecision, "1e-10000", 0.0); // must underflow - TEST_DOUBLE(fullPrecision, "18446744073709551616", 18446744073709551616.0); // 2^64 (max of uint64_t + 1, force to use double) - TEST_DOUBLE(fullPrecision, "-9223372036854775809", -9223372036854775809.0); // -2^63 - 1(min of int64_t + 1, force to use double) - TEST_DOUBLE(fullPrecision, "0.9868011474609375", 0.9868011474609375); // https://github.com/miloyip/rapidjson/issues/120 - TEST_DOUBLE(fullPrecision, "123e34", 123e34); // Fast Path Cases In Disguise + TEST_DOUBLE(fullPrecision, "1e-10000", 0.0); // must underflow + TEST_DOUBLE(fullPrecision, "18446744073709551616", 18446744073709551616.0); // 2^64 (max of uint64_t + 1, force to use double) + TEST_DOUBLE(fullPrecision, "-9223372036854775809", -9223372036854775809.0); // -2^63 - 1(min of int64_t + 1, force to use double) + TEST_DOUBLE(fullPrecision, "0.9868011474609375", 0.9868011474609375); // https://github.com/miloyip/rapidjson/issues/120 + TEST_DOUBLE(fullPrecision, "123e34", 123e34); // Fast Path Cases In Disguise TEST_DOUBLE(fullPrecision, "45913141877270640000.0", 45913141877270640000.0); TEST_DOUBLE(fullPrecision, "2.2250738585072011e-308", 2.2250738585072011e-308); // http://www.exploringbinary.com/php-hangs-on-numeric-value-2-2250738585072011e-308/ + TEST_DOUBLE(fullPrecision, "1e-00011111111111", 0.0); // Issue #313 + TEST_DOUBLE(fullPrecision, "-1e-00011111111111", -0.0); + TEST_DOUBLE(fullPrecision, "1e-429496729", 0.0); // Maximum supported negative exponent + // Since // abs((2^-1022 - 2^-1074) - 2.2250738585072012e-308) = 3.109754131239141401123495768877590405345064751974375599... 10^-324 From 735354efd328709a8efb6a2a43a584bb85f2de6b Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Fri, 24 Apr 2015 22:50:42 +0800 Subject: [PATCH 105/116] Separate handling for pos/neg exp and improve pos exp overflow --- include/rapidjson/reader.h | 23 +++++++++++++++-------- test/unittest/readertest.cpp | 1 + 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/include/rapidjson/reader.h b/include/rapidjson/reader.h index 320428f..d809d57 100644 --- a/include/rapidjson/reader.h +++ b/include/rapidjson/reader.h @@ -925,14 +925,21 @@ private: if (s.Peek() >= '0' && s.Peek() <= '9') { exp = s.Take() - '0'; - while (s.Peek() >= '0' && s.Peek() <= '9') { - exp = exp * 10 + (s.Take() - '0'); - if (exp > 308 && !expMinus) // exp > 308 should be rare, so it should be checked first. - RAPIDJSON_PARSE_ERROR(kParseErrorNumberTooBig, s.Tell()); - else if (exp >= 429496729 && expMinus) { // Issue #313: prevent overflow exponent - while (s.Peek() >= '0' && s.Peek() <= '9') // Consume the rest of exponent - s.Take(); - break; + if (expMinus) { + while (s.Peek() >= '0' && s.Peek() <= '9') { + exp = exp * 10 + (s.Take() - '0'); + if (exp >= 429496729) { // Issue #313: prevent overflow exponent + while (s.Peek() >= '0' && s.Peek() <= '9') // Consume the rest of exponent + s.Take(); + } + } + } + else { // positive exp + int maxExp = 308 - expFrac; + while (s.Peek() >= '0' && s.Peek() <= '9') { + exp = exp * 10 + (s.Take() - '0'); + if (exp > maxExp) + RAPIDJSON_PARSE_ERROR(kParseErrorNumberTooBig, s.Tell()); } } } diff --git a/test/unittest/readertest.cpp b/test/unittest/readertest.cpp index 86199fa..e55380c 100644 --- a/test/unittest/readertest.cpp +++ b/test/unittest/readertest.cpp @@ -229,6 +229,7 @@ static void TestParseDouble() { TEST_DOUBLE(fullPrecision, "1e-00011111111111", 0.0); // Issue #313 TEST_DOUBLE(fullPrecision, "-1e-00011111111111", -0.0); TEST_DOUBLE(fullPrecision, "1e-429496729", 0.0); // Maximum supported negative exponent + TEST_DOUBLE(fullPrecision, "0.017976931348623157e+310", 1.7976931348623157e+308); // Max double in another form // Since From 7708215b609733bcfa06074b67463920c03782e8 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Sat, 25 Apr 2015 00:13:09 +0800 Subject: [PATCH 106/116] Try to fix #313 again --- include/rapidjson/reader.h | 2 +- test/unittest/readertest.cpp | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/rapidjson/reader.h b/include/rapidjson/reader.h index d809d57..be0d9fb 100644 --- a/include/rapidjson/reader.h +++ b/include/rapidjson/reader.h @@ -928,7 +928,7 @@ private: if (expMinus) { while (s.Peek() >= '0' && s.Peek() <= '9') { exp = exp * 10 + (s.Take() - '0'); - if (exp >= 429496729) { // Issue #313: prevent overflow exponent + if (exp >= 214748364) { // Issue #313: prevent overflow exponent while (s.Peek() >= '0' && s.Peek() <= '9') // Consume the rest of exponent s.Take(); } diff --git a/test/unittest/readertest.cpp b/test/unittest/readertest.cpp index e55380c..bee19a8 100644 --- a/test/unittest/readertest.cpp +++ b/test/unittest/readertest.cpp @@ -228,9 +228,10 @@ static void TestParseDouble() { TEST_DOUBLE(fullPrecision, "2.2250738585072011e-308", 2.2250738585072011e-308); // http://www.exploringbinary.com/php-hangs-on-numeric-value-2-2250738585072011e-308/ TEST_DOUBLE(fullPrecision, "1e-00011111111111", 0.0); // Issue #313 TEST_DOUBLE(fullPrecision, "-1e-00011111111111", -0.0); - TEST_DOUBLE(fullPrecision, "1e-429496729", 0.0); // Maximum supported negative exponent + TEST_DOUBLE(fullPrecision, "1e-214748363", 0.0); // Maximum supported negative exponent + TEST_DOUBLE(fullPrecision, "1e-214748364", 0.0); + TEST_DOUBLE(fullPrecision, "1e-21474836311", 0.0); TEST_DOUBLE(fullPrecision, "0.017976931348623157e+310", 1.7976931348623157e+308); // Max double in another form - // Since // abs((2^-1022 - 2^-1074) - 2.2250738585072012e-308) = 3.109754131239141401123495768877590405345064751974375599... 10^-324 From a9250d170dc7474bf4c7441de587b4933515b127 Mon Sep 17 00:00:00 2001 From: Adam Mitz Date: Fri, 24 Apr 2015 13:32:00 -0500 Subject: [PATCH 107/116] Fixed to build on older versions of 32-bit MSVC --- include/rapidjson/internal/diyfp.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/include/rapidjson/internal/diyfp.h b/include/rapidjson/internal/diyfp.h index de3d1f0..033a2a2 100644 --- a/include/rapidjson/internal/diyfp.h +++ b/include/rapidjson/internal/diyfp.h @@ -19,12 +19,10 @@ #ifndef RAPIDJSON_DIYFP_H_ #define RAPIDJSON_DIYFP_H_ -#if defined(_MSC_VER) +#if defined(_MSC_VER) && defined(_M_AMD64) #include -#if defined(_M_AMD64) #pragma intrinsic(_BitScanReverse64) #endif -#endif RAPIDJSON_NAMESPACE_BEGIN namespace internal { From 4f20541339bb5ba251ded2b14cef348e43eb0e7c Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Sat, 25 Apr 2015 09:49:31 +0800 Subject: [PATCH 108/116] Add change log --- CHANGELOG.md | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..3938cbf --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,59 @@ +# Change Log +All notable changes to this project will be documented in this file. +This project adheres to [Semantic Versioning](http://semver.org/). + +## [Unreleased] + +## [1.0.1] - 2015-04-25 + +### Added +* Changelog following [Keep a CHANGELOG](https://github.com/olivierlacan/keep-a-changelog) suggestions. + +### Fixed +* Parsing of some numbers (e.g. "1e-00011111111111") causing assertion (#314). +* Visual C++ 32-bit compilation error in `diyfp.h` (#317). + +## [1.0.0] - 2015-04-22 + +### Added +* 100% [Coverall](https://coveralls.io/r/miloyip/rapidjson?branch=master) coverage. +* Version macros (#311) + +### Fixed +* A bug in trimming long number sequence (4824f12efbf01af72b8cb6fc96fae7b097b73015). +* Double quote in unicode escape (#288). +* Negative zero roundtrip (double only) (#289). +* Standardize behavior of `memcpy()` and `malloc()` (0c5c1538dcfc7f160e5a4aa208ddf092c787be5a, #305, 0e8bbe5e3ef375e7f052f556878be0bd79e9062d). + +### Removed +* Remove an invalid `Document::ParseInsitu()` API (e7f1c6dd08b522cfcf9aed58a333bd9a0c0ccbeb). + +## [1.0 Beta] - 2015-04-8 + +### Added +* RFC 7159 (#101) +* Optional Iterative Parser (#76) +* Deep-copy values (#20) +* Error code and message (#27) +* ASCII Encoding (#70) +* `kParseStopWhenDoneFlag` (#83) +* `kParseFullPrecisionFlag` (881c91d696f06b7f302af6d04ec14dd08db66ceb) +* Add `Key()` to handler concept (#134) +* C++11 compatibility and support (#128) +* Optimized number-to-string and vice versa conversions (#137, #80) +* Short-String Optimization (#131) +* Local stream optimization by traits (#32) +* Travis & Appveyor Continuous Integration, with Valgrind verification (#24, #242) +* Redo all documentation (English, Simplified Chinese) + +### Changed +* Copyright ownership transfered to THL A29 Limited (a Tencent company). +* Migrating from Premake to CMAKE (#192) +* Resolve all warning reports + +### Removed +* Remove other JSON libraries for performance comparison (#180) + +## [0.11] - 2012-11-16 + +## [0.1] - 2011-11-18 From 316292d5189e9e7e3565b6d9423576a6a3cf73f4 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Sat, 25 Apr 2015 09:52:59 +0800 Subject: [PATCH 109/116] Change version to 1.0.1 --- CMakeLists.txt | 2 +- appveyor.yml | 2 +- include/rapidjson/rapidjson.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 559312b..380bdcd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ PROJECT(RapidJSON CXX) set(LIB_MAJOR_VERSION "1") set(LIB_MINOR_VERSION "0") -set(LIB_PATCH_VERSION "0") +set(LIB_PATCH_VERSION "1") set(LIB_VERSION_STRING "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_PATCH_VERSION}") # compile in release with debug info mode by default diff --git a/appveyor.yml b/appveyor.yml index 890f9d9..add4017 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 1.0.0.{build} +version: 1.0.1.{build} configuration: - Debug diff --git a/include/rapidjson/rapidjson.h b/include/rapidjson/rapidjson.h index 938a3ce..0c41ab6 100644 --- a/include/rapidjson/rapidjson.h +++ b/include/rapidjson/rapidjson.h @@ -69,7 +69,7 @@ */ #define RAPIDJSON_MAJOR_VERSION 1 #define RAPIDJSON_MINOR_VERSION 0 -#define RAPIDJSON_PATCH_VERSION 0 +#define RAPIDJSON_PATCH_VERSION 1 #define RAPIDJSON_VERSION_STRING \ RAPIDJSON_STRINGIFY(RAPIDJSON_MAJOR_VERSION.RAPIDJSON_MINOR_VERSION.RAPIDJSON_PATCH_VERSION) From 2e913bfea6fd199126a0bb343fb2e86bda2359cf Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Sat, 25 Apr 2015 10:18:30 +0800 Subject: [PATCH 110/116] Update readme badge to version 1.0.1 also --- readme.md | 2 +- readme.zh-cn.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 007596a..98f81a7 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ ![](doc/logo/rapidjson.png) -![](https://img.shields.io/badge/release-v1.0.0-blue.png) +![](https://img.shields.io/badge/release-v1.0.1-blue.png) ## A fast JSON parser/generator for C++ with both SAX/DOM style API diff --git a/readme.zh-cn.md b/readme.zh-cn.md index be3849a..2dd27cf 100644 --- a/readme.zh-cn.md +++ b/readme.zh-cn.md @@ -1,6 +1,6 @@ ![](doc/logo/rapidjson.png) -![](https://img.shields.io/badge/release-v1.0.0-blue.png) +![](https://img.shields.io/badge/release-v1.0.1-blue.png) Tencent is pleased to support the open source community by making RapidJSON available. From a592e199e7e9ef10a4059f2ec18f59dcd1b7ec3c Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Sat, 25 Apr 2015 15:53:51 +0800 Subject: [PATCH 111/116] Update CHANGELOG.md --- CHANGELOG.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3938cbf..dd0e4ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] -## [1.0.1] - 2015-04-25 +## [v1.0.1] - 2015-04-25 ### Added * Changelog following [Keep a CHANGELOG](https://github.com/olivierlacan/keep-a-changelog) suggestions. @@ -13,7 +13,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). * Parsing of some numbers (e.g. "1e-00011111111111") causing assertion (#314). * Visual C++ 32-bit compilation error in `diyfp.h` (#317). -## [1.0.0] - 2015-04-22 +## [v1.0.0] - 2015-04-22 ### Added * 100% [Coverall](https://coveralls.io/r/miloyip/rapidjson?branch=master) coverage. @@ -28,7 +28,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Removed * Remove an invalid `Document::ParseInsitu()` API (e7f1c6dd08b522cfcf9aed58a333bd9a0c0ccbeb). -## [1.0 Beta] - 2015-04-8 +## [v1.0 Beta] - 2015-04-8 ### Added * RFC 7159 (#101) @@ -54,6 +54,6 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Removed * Remove other JSON libraries for performance comparison (#180) -## [0.11] - 2012-11-16 +## 0.11 - 2012-11-16 -## [0.1] - 2011-11-18 +## 0.1 - 2011-11-18 From d2269f65f60d12b96228918619d8df606fc61de2 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Sat, 25 Apr 2015 16:01:10 +0800 Subject: [PATCH 112/116] Update CHANGELOG.md --- CHANGELOG.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd0e4ed..07d732b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] -## [v1.0.1] - 2015-04-25 +## [1.0.1] - 2015-04-25 ### Added * Changelog following [Keep a CHANGELOG](https://github.com/olivierlacan/keep-a-changelog) suggestions. @@ -13,7 +13,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). * Parsing of some numbers (e.g. "1e-00011111111111") causing assertion (#314). * Visual C++ 32-bit compilation error in `diyfp.h` (#317). -## [v1.0.0] - 2015-04-22 +## [1.0.0] - 2015-04-22 ### Added * 100% [Coverall](https://coveralls.io/r/miloyip/rapidjson?branch=master) coverage. @@ -28,7 +28,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Removed * Remove an invalid `Document::ParseInsitu()` API (e7f1c6dd08b522cfcf9aed58a333bd9a0c0ccbeb). -## [v1.0 Beta] - 2015-04-8 +## 1.0-beta - 2015-04-8 ### Added * RFC 7159 (#101) @@ -57,3 +57,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## 0.11 - 2012-11-16 ## 0.1 - 2011-11-18 + +[Unreleased]: https://github.com/miloyip/rapidjson/compare/v1.0.1...HEAD +[1.0.1]: https://github.com/miloyip/rapidjson/compare/v1.0.0...v1.0.1 +[1.0.0]: https://github.com/miloyip/rapidjson/compare/v1.0-beta...v1.0.0 From 8f891403bc22f691173898c2e7b76574eac2a86b Mon Sep 17 00:00:00 2001 From: Guo Xiao Date: Sun, 26 Apr 2015 20:54:03 +0800 Subject: [PATCH 113/116] Fix warnings when visited via https --- doc/faq.md | 2 +- doc/misc/footer.html | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/faq.md b/doc/faq.md index 85afcd3..b00b4c6 100644 --- a/doc/faq.md +++ b/doc/faq.md @@ -28,7 +28,7 @@ 6. How to install RapidJSON? - Check [Installation section](http://miloyip.github.io/rapidjson/). + Check [Installation section](https://miloyip.github.io/rapidjson/). 7. Can RapidJSON run on my platform? diff --git a/doc/misc/footer.html b/doc/misc/footer.html index edf3e69..843aa11 100644 --- a/doc/misc/footer.html +++ b/doc/misc/footer.html @@ -18,10 +18,10 @@ (document.getElementsByClassName('contents')[0]).appendChild(dt); var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; - dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js'; + dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })(); - \ No newline at end of file + From dba6d6f1b51f03016fcd62dd90b480ea50f29dc8 Mon Sep 17 00:00:00 2001 From: miloyip Date: Tue, 28 Apr 2015 10:09:37 +0800 Subject: [PATCH 114/116] Include rapidjson.h in error/error.h and internal/*.h Fixes #321 --- CHANGELOG.md | 2 ++ include/rapidjson/error/error.h | 2 ++ include/rapidjson/internal/diyfp.h | 2 ++ include/rapidjson/internal/meta.h | 4 +--- include/rapidjson/internal/pow10.h | 2 ++ include/rapidjson/internal/stack.h | 2 ++ include/rapidjson/internal/strfunc.h | 2 ++ 7 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07d732b..92a4054 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +* Include rapidjson.h for all internal/error headers. + ## [1.0.1] - 2015-04-25 ### Added diff --git a/include/rapidjson/error/error.h b/include/rapidjson/error/error.h index aa5700c..f9094fb 100644 --- a/include/rapidjson/error/error.h +++ b/include/rapidjson/error/error.h @@ -15,6 +15,8 @@ #ifndef RAPIDJSON_ERROR_ERROR_H__ #define RAPIDJSON_ERROR_ERROR_H__ +#include "../rapidjson.h" + /*! \file error.h */ /*! \defgroup RAPIDJSON_ERRORS RapidJSON error handling */ diff --git a/include/rapidjson/internal/diyfp.h b/include/rapidjson/internal/diyfp.h index 033a2a2..4ef53d9 100644 --- a/include/rapidjson/internal/diyfp.h +++ b/include/rapidjson/internal/diyfp.h @@ -19,6 +19,8 @@ #ifndef RAPIDJSON_DIYFP_H_ #define RAPIDJSON_DIYFP_H_ +#include "../rapidjson.h" + #if defined(_MSC_VER) && defined(_M_AMD64) #include #pragma intrinsic(_BitScanReverse64) diff --git a/include/rapidjson/internal/meta.h b/include/rapidjson/internal/meta.h index 594e259..2daad96 100644 --- a/include/rapidjson/internal/meta.h +++ b/include/rapidjson/internal/meta.h @@ -15,9 +15,7 @@ #ifndef RAPIDJSON_INTERNAL_META_H_ #define RAPIDJSON_INTERNAL_META_H_ -#ifndef RAPIDJSON_RAPIDJSON_H_ -#error not yet included. Do not include this file directly. -#endif +#include "../rapidjson.h" #ifdef __GNUC__ RAPIDJSON_DIAG_PUSH diff --git a/include/rapidjson/internal/pow10.h b/include/rapidjson/internal/pow10.h index c552d9f..1d2dff0 100644 --- a/include/rapidjson/internal/pow10.h +++ b/include/rapidjson/internal/pow10.h @@ -15,6 +15,8 @@ #ifndef RAPIDJSON_POW10_ #define RAPIDJSON_POW10_ +#include "../rapidjson.h" + RAPIDJSON_NAMESPACE_BEGIN namespace internal { diff --git a/include/rapidjson/internal/stack.h b/include/rapidjson/internal/stack.h index 2f2c76a..bb31cc0 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 "../rapidjson.h" + RAPIDJSON_NAMESPACE_BEGIN namespace internal { diff --git a/include/rapidjson/internal/strfunc.h b/include/rapidjson/internal/strfunc.h index e6d1c21..f6c99db 100644 --- a/include/rapidjson/internal/strfunc.h +++ b/include/rapidjson/internal/strfunc.h @@ -15,6 +15,8 @@ #ifndef RAPIDJSON_INTERNAL_STRFUNC_H_ #define RAPIDJSON_INTERNAL_STRFUNC_H_ +#include "../rapidjson.h" + RAPIDJSON_NAMESPACE_BEGIN namespace internal { From c1b66cc082b5500f3410be0d367b0044c46e3153 Mon Sep 17 00:00:00 2001 From: miloyip Date: Tue, 28 Apr 2015 22:41:31 +0800 Subject: [PATCH 115/116] Fix incorrect API in tutorial document. --- doc/tutorial.md | 2 +- doc/tutorial.zh-cn.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/tutorial.md b/doc/tutorial.md index 811833d..3508918 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -192,7 +192,7 @@ Checking | Obtaining `bool IsNumber()` | N/A `bool IsUint()` | `unsigned GetUint()` `bool IsInt()` | `int GetInt()` -`bool IsUint64()` | `uint64_t GetUint()` +`bool IsUint64()` | `uint64_t GetUint64()` `bool IsInt64()` | `int64_t GetInt64()` `bool IsDouble()` | `double GetDouble()` diff --git a/doc/tutorial.zh-cn.md b/doc/tutorial.zh-cn.md index 24456d5..d1381be 100644 --- a/doc/tutorial.zh-cn.md +++ b/doc/tutorial.zh-cn.md @@ -192,7 +192,7 @@ JSON只提供一种数值类型──Number。数字可以是整数或实数。R `bool IsNumber()` | 不适用 `bool IsUint()` | `unsigned GetUint()` `bool IsInt()` | `int GetInt()` -`bool IsUint64()` | `uint64_t GetUint()` +`bool IsUint64()` | `uint64_t GetUint64()` `bool IsInt64()` | `int64_t GetInt64()` `bool IsDouble()` | `double GetDouble()` From ea7b39b960fa1f2baed5d3587dffe1b42f39e3fe Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Fri, 1 May 2015 08:10:21 +0800 Subject: [PATCH 116/116] Update installation section of zh-cn readme --- readme.zh-cn.md | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/readme.zh-cn.md b/readme.zh-cn.md index 2dd27cf..eb6c21d 100644 --- a/readme.zh-cn.md +++ b/readme.zh-cn.md @@ -2,6 +2,8 @@ ![](https://img.shields.io/badge/release-v1.0.1-blue.png) +## 高效的C++ JSON解析/生成器,提供SAX及DOM风格API + 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. @@ -60,21 +62,21 @@ RapidJSON是跨平台的。以下是一些曾测试的平台/编译器组合 RapidJSON是只有头文件的C++库。只需把`include/rapidjson`目录复制至系统或项目的include目录中。 +RapidJSON依赖于以下软件: +* [CMake](http://www.cmake.org) 作为通用生成工具 +* (optional)[Doxygen](http://www.doxygen.org)用于生成文档 +* (optional)[googletest](https://code.google.com/p/googletest/)用于单元及性能测试 + 生成测试及例子的步骤: 1. 执行 `git submodule update --init` 去获取 thirdparty submodules (google test)。 -2. 下载 [premake4](http://industriousone.com/premake/download)。 -3. 复制 premake4 可执行文件至 `rapidjson/build` (或系统路径)。 -4. 进入`rapidjson/build/`目录,在Windows下执行`premake.bat`,在Linux或其他平台下执行`premake.sh`。 -5. 在Windows上,生成位于`rapidjson/build/vs2008/`或`/vs2010/`内的项目方案. -6. 在其他平台上,在`rapidjson/build/gmake/`目录执行GNU `make`(如 `make -f test.make config=release32`、`make -f example.make config=debug32`)。 -7. 若成功,可执行文件会生成在`rapidjson/bin`目录。 +2. 在rapidjson目渌下,建立一个`build`目录。 +3. 在`build`目录下执行`cmake ..`命令以设置生成。Windows用户可使用cmake-gui应用程序。 +4. 在Windows下,编译生成在build目录中的solution。在Linux下,于build目录运行`make`。 -生成[Doxygen](http://doxygen.org)文档的步骤: +成功生成后,你会在`bin`的目录下找到编译后的测试及例子可执行文件。而生成的文档将位于build下的`doc/html`目录。要执行测试,请在build下执行`make test`或`ctest`。使用`ctest -V`命令可获取详细的输出。 -1. 下载及安装[Doxygen](http://doxygen.org/download.html)。 -2. 在顶层目录执行`doxygen build/Doxyfile`。 -3. 在`doc/html`浏览文档。 +我们也可以把程序库安装至全系统中,只要在具管理權限下从build目录执行`make install`命令。这样会按系统的偏好设置安装所有文件。当安装RapidJSON后,其他的CMake项目需要使用它时,可以通过在`CMakeLists.txt`加入一句`find_package(RapidJSON)`。 ## 用法一览