From 13d78e3da3c605bc55faec1d5209369e4d41337b Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Tue, 27 Jan 2015 12:18:36 -0600 Subject: [PATCH 01/54] 0.10.z (based on 1.6.z, but binary-compat w/ 0.6.0-rc2) --- CMakeLists.txt | 2 +- include/json/version.h | 6 +++--- version | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3cf63ea07..8146a3319 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,7 +60,7 @@ ENDMACRO(jsoncpp_parse_version) #SET( JSONCPP_VERSION_MAJOR X ) #SET( JSONCPP_VERSION_MINOR Y ) #SET( JSONCPP_VERSION_PATCH Z ) -SET( JSONCPP_VERSION 1.6.2 ) +SET( JSONCPP_VERSION 0.10.2 ) jsoncpp_parse_version( ${JSONCPP_VERSION} JSONCPP_VERSION ) #IF(NOT JSONCPP_VERSION_FOUND) # MESSAGE(FATAL_ERROR "Failed to parse version string properly. Expect X.Y.Z") diff --git a/include/json/version.h b/include/json/version.h index a4db8b0ae..1c52a5cec 100644 --- a/include/json/version.h +++ b/include/json/version.h @@ -4,9 +4,9 @@ #ifndef JSON_VERSION_H_INCLUDED # define JSON_VERSION_H_INCLUDED -# define JSONCPP_VERSION_STRING "1.6.2" -# define JSONCPP_VERSION_MAJOR 1 -# define JSONCPP_VERSION_MINOR 6 +# define JSONCPP_VERSION_STRING "0.10.2" +# define JSONCPP_VERSION_MAJOR 0 +# define JSONCPP_VERSION_MINOR 10 # define JSONCPP_VERSION_PATCH 2 # define JSONCPP_VERSION_QUALIFIER # define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8)) diff --git a/version b/version index fdd3be6df..5eef0f10e 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.6.2 +0.10.2 From e49bd3095011c8e1b105faeeffa992efda38d3bb Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Tue, 27 Jan 2015 12:18:56 -0600 Subject: [PATCH 02/54] NOT C++11 --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8146a3319..27418aefd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,10 +94,10 @@ endif( MSVC ) if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") # using regular Clang or AppleClang - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") # using GCC - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wall -Wextra -pedantic") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic") endif() IF(JSONCPP_WITH_WARNING_AS_ERROR) From 1c4f6a2d79d466bb501cb84626f269e40e60ba7c Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Mon, 17 Nov 2014 00:13:18 -0600 Subject: [PATCH 03/54] partially revert "Switch to copy-and-swap idiom for operator=." This partially reverts commit 45cd9490cd261da31cef84a44d2c587be7e26e99. Ignored ValueInternal* changes, since those did not produce symbols for Debian build. (They must not have used the INTERNAL stuff.) Ignored CZString changes since those are private (and sizeof struct did not change). https://github.com/open-source-parsers/jsoncpp/issues/78 Conflicts: include/json/value.h src/lib_json/json_internalarray.inl src/lib_json/json_internalmap.inl src/lib_json/json_value.cpp --- include/json/value.h | 2 +- src/lib_json/json_value.cpp | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/json/value.h b/include/json/value.h index 26bb38b69..62bee430b 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -283,7 +283,7 @@ Json::Value obj_value(Json::objectValue); // {} /// Deep copy, then swap(other). /// \note Over-write existing comments. To preserve comments, use #swapPayload(). - Value& operator=(Value other); + Value &operator=(const Value &other); /// Swap everything. void swap(Value& other); /// Swap values but leave comments and source offsets in place. diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 8fbce5425..5b7e64a24 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -466,8 +466,9 @@ Value::~Value() { delete[] comments_; } -Value& Value::operator=(Value other) { - swap(other); +Value &Value::operator=(const Value &other) { + Value temp(other); + swap(temp); return *this; } From a9d06d265001caa6f7f3e75e524f83028b529a6a Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Thu, 29 Jan 2015 11:35:42 -0600 Subject: [PATCH 04/54] revert 'Add public semantic error reporting' for binary-compatibility with 0.6.0 issue #147 was #57 --- include/json/reader.h | 23 ---------- src/lib_json/json_reader.cpp | 83 +----------------------------------- 2 files changed, 2 insertions(+), 104 deletions(-) diff --git a/include/json/reader.h b/include/json/reader.h index f8c3186df..90b47ee9c 100644 --- a/include/json/reader.h +++ b/include/json/reader.h @@ -132,29 +132,6 @@ class JSON_API Reader { */ std::vector getStructuredErrors() const; - /** \brief Add a semantic error message. - * \param value JSON Value location associated with the error - * \param message The error message. - * \return \c true if the error was successfully added, \c false if the - * Value offset exceeds the document size. - */ - bool pushError(const Value& value, const std::string& message); - - /** \brief Add a semantic error message with extra context. - * \param value JSON Value location associated with the error - * \param message The error message. - * \param extra Additional JSON Value location to contextualize the error - * \return \c true if the error was successfully added, \c false if either - * Value offset exceeds the document size. - */ - bool pushError(const Value& value, const std::string& message, const Value& extra); - - /** \brief Return whether there are any errors. - * \return \c true if there are no errors to report \c false if - * errors have occurred. - */ - bool good() const; - private: enum TokenType { tokenEndOfStream = 0, diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index 51cd6a19e..e1a741875 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -864,45 +864,8 @@ std::vector Reader::getStructuredErrors() const { } return allErrors; } - -bool Reader::pushError(const Value& value, const std::string& message) { - size_t length = end_ - begin_; - if(value.getOffsetStart() > length - || value.getOffsetLimit() > length) - return false; - Token token; - token.type_ = tokenError; - token.start_ = begin_ + value.getOffsetStart(); - token.end_ = end_ + value.getOffsetLimit(); - ErrorInfo info; - info.token_ = token; - info.message_ = message; - info.extra_ = 0; - errors_.push_back(info); - return true; -} - -bool Reader::pushError(const Value& value, const std::string& message, const Value& extra) { - size_t length = end_ - begin_; - if(value.getOffsetStart() > length - || value.getOffsetLimit() > length - || extra.getOffsetLimit() > length) - return false; - Token token; - token.type_ = tokenError; - token.start_ = begin_ + value.getOffsetStart(); - token.end_ = begin_ + value.getOffsetLimit(); - ErrorInfo info; - info.token_ = token; - info.message_ = message; - info.extra_ = begin_ + extra.getOffsetStart(); - errors_.push_back(info); - return true; -} - -bool Reader::good() const { - return !errors_.size(); -} +// Reader +///////////////////////// // exact copy of Features class OurFeatures { @@ -953,9 +916,6 @@ class OurReader { bool collectComments = true); std::string getFormattedErrorMessages() const; std::vector getStructuredErrors() const; - bool pushError(const Value& value, const std::string& message); - bool pushError(const Value& value, const std::string& message, const Value& extra); - bool good() const; private: OurReader(OurReader const&); // no impl @@ -1823,45 +1783,6 @@ std::vector OurReader::getStructuredErrors() const { return allErrors; } -bool OurReader::pushError(const Value& value, const std::string& message) { - size_t length = end_ - begin_; - if(value.getOffsetStart() > length - || value.getOffsetLimit() > length) - return false; - Token token; - token.type_ = tokenError; - token.start_ = begin_ + value.getOffsetStart(); - token.end_ = end_ + value.getOffsetLimit(); - ErrorInfo info; - info.token_ = token; - info.message_ = message; - info.extra_ = 0; - errors_.push_back(info); - return true; -} - -bool OurReader::pushError(const Value& value, const std::string& message, const Value& extra) { - size_t length = end_ - begin_; - if(value.getOffsetStart() > length - || value.getOffsetLimit() > length - || extra.getOffsetLimit() > length) - return false; - Token token; - token.type_ = tokenError; - token.start_ = begin_ + value.getOffsetStart(); - token.end_ = begin_ + value.getOffsetLimit(); - ErrorInfo info; - info.token_ = token; - info.message_ = message; - info.extra_ = begin_ + extra.getOffsetStart(); - errors_.push_back(info); - return true; -} - -bool OurReader::good() const { - return !errors_.size(); -} - class OurCharReader : public CharReader { bool const collectComments_; From 00d7bea0f6b7e8fc9c1cb7bf652bcef12f3aff87 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Thu, 29 Jan 2015 11:32:34 -0600 Subject: [PATCH 05/54] revert 'Added structured error reporting to Reader.' revert 68db6553471bb9cb050b1bb888b5933ee758b82d issue #147 --- include/json/reader.h | 21 ---------- include/json/value.h | 12 ------ src/lib_json/json_reader.cpp | 74 +----------------------------------- src/lib_json/json_value.cpp | 16 +------- src/test_lib_json/main.cpp | 60 ----------------------------- 5 files changed, 3 insertions(+), 180 deletions(-) diff --git a/include/json/reader.h b/include/json/reader.h index 90b47ee9c..27f9ff05b 100644 --- a/include/json/reader.h +++ b/include/json/reader.h @@ -35,18 +35,6 @@ class JSON_API Reader { typedef char Char; typedef const Char* Location; - /** \brief An error tagged with where in the JSON text it was encountered. - * - * The offsets give the [start, limit) range of bytes within the text. Note - * that this is bytes, not codepoints. - * - */ - struct StructuredError { - size_t offset_start; - size_t offset_limit; - std::string message; - }; - /** \brief Constructs a Reader allowing all features * for parsing. */ @@ -123,15 +111,6 @@ class JSON_API Reader { */ std::string getFormattedErrorMessages() const; - /** \brief Returns a vector of structured erros encounted while parsing. - * \return A (possibly empty) vector of StructuredError objects. Currently - * only one error can be returned, but the caller should tolerate - * multiple - * errors. This can occur if the parser recovers from a non-fatal - * parse error and then encounters additional errors. - */ - std::vector getStructuredErrors() const; - private: enum TokenType { tokenEndOfStream = 0, diff --git a/include/json/value.h b/include/json/value.h index 62bee430b..b2bd136c7 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -530,13 +530,6 @@ Json::Value obj_value(Json::objectValue); // {} iterator begin(); iterator end(); - // Accessors for the [start, limit) range of bytes within the JSON text from - // which this value was parsed, if any. - void setOffsetStart(size_t start); - void setOffsetLimit(size_t limit); - size_t getOffsetStart() const; - size_t getOffsetLimit() const; - private: void initBasic(ValueType type, bool allocated = false); @@ -573,11 +566,6 @@ Json::Value obj_value(Json::objectValue); // {} unsigned int allocated_ : 1; // Notes: if declared as bool, bitfield is useless. // If not allocated_, string_ must be null-terminated. CommentInfo* comments_; - - // [start, limit) byte offsets in the source JSON text from which this Value - // was extracted. - size_t start_; - size_t limit_; }; /** \brief Experimental and untested: represents an element of the "path" to diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index e1a741875..60345cbfd 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -162,11 +162,9 @@ bool Reader::readValue() { switch (token.type_) { case tokenObjectBegin: successful = readObject(token); - currentValue().setOffsetLimit(current_ - begin_); break; case tokenArrayBegin: successful = readArray(token); - currentValue().setOffsetLimit(current_ - begin_); break; case tokenNumber: successful = decodeNumber(token); @@ -178,24 +176,18 @@ bool Reader::readValue() { { Value v(true); currentValue().swapPayload(v); - currentValue().setOffsetStart(token.start_ - begin_); - currentValue().setOffsetLimit(token.end_ - begin_); } break; case tokenFalse: { Value v(false); currentValue().swapPayload(v); - currentValue().setOffsetStart(token.start_ - begin_); - currentValue().setOffsetLimit(token.end_ - begin_); } break; case tokenNull: { Value v; currentValue().swapPayload(v); - currentValue().setOffsetStart(token.start_ - begin_); - currentValue().setOffsetLimit(token.end_ - begin_); } break; case tokenArraySeparator: @@ -207,13 +199,9 @@ bool Reader::readValue() { current_--; Value v; currentValue().swapPayload(v); - currentValue().setOffsetStart(current_ - begin_ - 1); - currentValue().setOffsetLimit(current_ - begin_); break; } // Else, fall through... default: - currentValue().setOffsetStart(token.start_ - begin_); - currentValue().setOffsetLimit(token.end_ - begin_); return addError("Syntax error: value, object or array expected.", token); } @@ -441,12 +429,11 @@ bool Reader::readString() { return c == '"'; } -bool Reader::readObject(Token& tokenStart) { +bool Reader::readObject(Token& /*tokenStart*/) { Token tokenName; std::string name; Value init(objectValue); currentValue().swapPayload(init); - currentValue().setOffsetStart(tokenStart.start_ - begin_); while (readToken(tokenName)) { bool initialTokenOk = true; while (tokenName.type_ == tokenComment && initialTokenOk) @@ -497,10 +484,9 @@ bool Reader::readObject(Token& tokenStart) { "Missing '}' or object member name", tokenName, tokenObjectEnd); } -bool Reader::readArray(Token& tokenStart) { +bool Reader::readArray(Token& /*tokenStart*/) { Value init(arrayValue); currentValue().swapPayload(init); - currentValue().setOffsetStart(tokenStart.start_ - begin_); skipSpaces(); if (*current_ == ']') // empty array { @@ -540,8 +526,6 @@ bool Reader::decodeNumber(Token& token) { if (!decodeNumber(token, decoded)) return false; currentValue().swapPayload(decoded); - currentValue().setOffsetStart(token.start_ - begin_); - currentValue().setOffsetLimit(token.end_ - begin_); return true; } @@ -590,8 +574,6 @@ bool Reader::decodeDouble(Token& token) { if (!decodeDouble(token, decoded)) return false; currentValue().swapPayload(decoded); - currentValue().setOffsetStart(token.start_ - begin_); - currentValue().setOffsetLimit(token.end_ - begin_); return true; } @@ -637,8 +619,6 @@ bool Reader::decodeString(Token& token) { return false; Value decoded(decoded_string); currentValue().swapPayload(decoded); - currentValue().setOffsetStart(token.start_ - begin_); - currentValue().setOffsetLimit(token.end_ - begin_); return true; } @@ -850,20 +830,6 @@ std::string Reader::getFormattedErrorMessages() const { return formattedMessage; } -std::vector Reader::getStructuredErrors() const { - std::vector allErrors; - for (Errors::const_iterator itError = errors_.begin(); - itError != errors_.end(); - ++itError) { - const ErrorInfo& error = *itError; - Reader::StructuredError structured; - structured.offset_start = error.token_.start_ - begin_; - structured.offset_limit = error.token_.end_ - begin_; - structured.message = error.message_; - allErrors.push_back(structured); - } - return allErrors; -} // Reader ///////////////////////// @@ -915,7 +881,6 @@ class OurReader { Value& root, bool collectComments = true); std::string getFormattedErrorMessages() const; - std::vector getStructuredErrors() const; private: OurReader(OurReader const&); // no impl @@ -1080,11 +1045,9 @@ bool OurReader::readValue() { switch (token.type_) { case tokenObjectBegin: successful = readObject(token); - currentValue().setOffsetLimit(current_ - begin_); break; case tokenArrayBegin: successful = readArray(token); - currentValue().setOffsetLimit(current_ - begin_); break; case tokenNumber: successful = decodeNumber(token); @@ -1096,24 +1059,18 @@ bool OurReader::readValue() { { Value v(true); currentValue().swapPayload(v); - currentValue().setOffsetStart(token.start_ - begin_); - currentValue().setOffsetLimit(token.end_ - begin_); } break; case tokenFalse: { Value v(false); currentValue().swapPayload(v); - currentValue().setOffsetStart(token.start_ - begin_); - currentValue().setOffsetLimit(token.end_ - begin_); } break; case tokenNull: { Value v; currentValue().swapPayload(v); - currentValue().setOffsetStart(token.start_ - begin_); - currentValue().setOffsetLimit(token.end_ - begin_); } break; case tokenArraySeparator: @@ -1125,13 +1082,9 @@ bool OurReader::readValue() { current_--; Value v; currentValue().swapPayload(v); - currentValue().setOffsetStart(current_ - begin_ - 1); - currentValue().setOffsetLimit(current_ - begin_); break; } // else, fall through ... default: - currentValue().setOffsetStart(token.start_ - begin_); - currentValue().setOffsetLimit(token.end_ - begin_); return addError("Syntax error: value, object or array expected.", token); } @@ -1363,7 +1316,6 @@ bool OurReader::readObject(Token& tokenStart) { std::string name; Value init(objectValue); currentValue().swapPayload(init); - currentValue().setOffsetStart(tokenStart.start_ - begin_); while (readToken(tokenName)) { bool initialTokenOk = true; while (tokenName.type_ == tokenComment && initialTokenOk) @@ -1423,7 +1375,6 @@ bool OurReader::readObject(Token& tokenStart) { bool OurReader::readArray(Token& tokenStart) { Value init(arrayValue); currentValue().swapPayload(init); - currentValue().setOffsetStart(tokenStart.start_ - begin_); skipSpaces(); if (*current_ == ']') // empty array { @@ -1463,8 +1414,6 @@ bool OurReader::decodeNumber(Token& token) { if (!decodeNumber(token, decoded)) return false; currentValue().swapPayload(decoded); - currentValue().setOffsetStart(token.start_ - begin_); - currentValue().setOffsetLimit(token.end_ - begin_); return true; } @@ -1513,8 +1462,6 @@ bool OurReader::decodeDouble(Token& token) { if (!decodeDouble(token, decoded)) return false; currentValue().swapPayload(decoded); - currentValue().setOffsetStart(token.start_ - begin_); - currentValue().setOffsetLimit(token.end_ - begin_); return true; } @@ -1560,8 +1507,6 @@ bool OurReader::decodeString(Token& token) { return false; Value decoded(decoded_string); currentValue().swapPayload(decoded); - currentValue().setOffsetStart(token.start_ - begin_); - currentValue().setOffsetLimit(token.end_ - begin_); return true; } @@ -1768,21 +1713,6 @@ std::string OurReader::getFormattedErrorMessages() const { return formattedMessage; } -std::vector OurReader::getStructuredErrors() const { - std::vector allErrors; - for (Errors::const_iterator itError = errors_.begin(); - itError != errors_.end(); - ++itError) { - const ErrorInfo& error = *itError; - OurReader::StructuredError structured; - structured.offset_start = error.token_.start_ - begin_; - structured.offset_limit = error.token_.end_ - begin_; - structured.message = error.message_; - allErrors.push_back(structured); - } - return allErrors; -} - class OurCharReader : public CharReader { bool const collectComments_; diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 5b7e64a24..c770c0b4d 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -401,7 +401,7 @@ Value::Value(bool value) { Value::Value(Value const& other) : type_(other.type_), allocated_(false) , - comments_(0), start_(other.start_), limit_(other.limit_) + comments_(0) { switch (type_) { case nullValue: @@ -485,8 +485,6 @@ void Value::swapPayload(Value& other) { void Value::swap(Value& other) { swapPayload(other); std::swap(comments_, other.comments_); - std::swap(start_, other.start_); - std::swap(limit_, other.limit_); } ValueType Value::type() const { return type_; } @@ -888,8 +886,6 @@ void Value::clear() { JSON_ASSERT_MESSAGE(type_ == nullValue || type_ == arrayValue || type_ == objectValue, "in Json::Value::clear(): requires complex value"); - start_ = 0; - limit_ = 0; switch (type_) { case arrayValue: case objectValue: @@ -965,8 +961,6 @@ void Value::initBasic(ValueType type, bool allocated) { type_ = type; allocated_ = allocated; comments_ = 0; - start_ = 0; - limit_ = 0; } // Access an object value by name, create a null member if it does not exist. @@ -1336,14 +1330,6 @@ std::string Value::getComment(CommentPlacement placement) const { return ""; } -void Value::setOffsetStart(size_t start) { start_ = start; } - -void Value::setOffsetLimit(size_t limit) { limit_ = limit; } - -size_t Value::getOffsetStart() const { return start_; } - -size_t Value::getOffsetLimit() const { return limit_; } - std::string Value::toStyledString() const { StyledWriter writer; return writer.write(*this); diff --git a/src/test_lib_json/main.cpp b/src/test_lib_json/main.cpp index f0e34366e..cb5c6eb35 100644 --- a/src/test_lib_json/main.cpp +++ b/src/test_lib_json/main.cpp @@ -1498,25 +1498,6 @@ JSONTEST_FIXTURE(ValueTest, typeChecksThrowExceptions) { #endif } -JSONTEST_FIXTURE(ValueTest, offsetAccessors) { - Json::Value x; - JSONTEST_ASSERT(x.getOffsetStart() == 0); - JSONTEST_ASSERT(x.getOffsetLimit() == 0); - x.setOffsetStart(10); - x.setOffsetLimit(20); - JSONTEST_ASSERT(x.getOffsetStart() == 10); - JSONTEST_ASSERT(x.getOffsetLimit() == 20); - Json::Value y(x); - JSONTEST_ASSERT(y.getOffsetStart() == 10); - JSONTEST_ASSERT(y.getOffsetLimit() == 20); - Json::Value z; - z.swap(y); - JSONTEST_ASSERT(z.getOffsetStart() == 10); - JSONTEST_ASSERT(z.getOffsetLimit() == 20); - JSONTEST_ASSERT(y.getOffsetStart() == 0); - JSONTEST_ASSERT(y.getOffsetLimit() == 0); -} - JSONTEST_FIXTURE(ValueTest, StaticString) { char mutant[] = "hello"; Json::StaticString ss(mutant); @@ -1689,7 +1670,6 @@ JSONTEST_FIXTURE(ReaderTest, parseWithNoErrors) { bool ok = reader.parse("{ \"property\" : \"value\" }", root); JSONTEST_ASSERT(ok); JSONTEST_ASSERT(reader.getFormattedErrorMessages().size() == 0); - JSONTEST_ASSERT(reader.getStructuredErrors().size() == 0); } JSONTEST_FIXTURE(ReaderTest, parseWithNoErrorsTestingOffsets) { @@ -1701,25 +1681,6 @@ JSONTEST_FIXTURE(ReaderTest, parseWithNoErrorsTestingOffsets) { root); JSONTEST_ASSERT(ok); JSONTEST_ASSERT(reader.getFormattedErrorMessages().size() == 0); - JSONTEST_ASSERT(reader.getStructuredErrors().size() == 0); - JSONTEST_ASSERT(root["property"].getOffsetStart() == 15); - JSONTEST_ASSERT(root["property"].getOffsetLimit() == 34); - JSONTEST_ASSERT(root["property"][0].getOffsetStart() == 16); - JSONTEST_ASSERT(root["property"][0].getOffsetLimit() == 23); - JSONTEST_ASSERT(root["property"][1].getOffsetStart() == 25); - JSONTEST_ASSERT(root["property"][1].getOffsetLimit() == 33); - JSONTEST_ASSERT(root["obj"].getOffsetStart() == 44); - JSONTEST_ASSERT(root["obj"].getOffsetLimit() == 76); - JSONTEST_ASSERT(root["obj"]["nested"].getOffsetStart() == 57); - JSONTEST_ASSERT(root["obj"]["nested"].getOffsetLimit() == 60); - JSONTEST_ASSERT(root["obj"]["bool"].getOffsetStart() == 71); - JSONTEST_ASSERT(root["obj"]["bool"].getOffsetLimit() == 75); - JSONTEST_ASSERT(root["null"].getOffsetStart() == 87); - JSONTEST_ASSERT(root["null"].getOffsetLimit() == 91); - JSONTEST_ASSERT(root["false"].getOffsetStart() == 103); - JSONTEST_ASSERT(root["false"].getOffsetLimit() == 108); - JSONTEST_ASSERT(root.getOffsetStart() == 0); - JSONTEST_ASSERT(root.getOffsetLimit() == 110); } JSONTEST_FIXTURE(ReaderTest, parseWithOneError) { @@ -1730,13 +1691,6 @@ JSONTEST_FIXTURE(ReaderTest, parseWithOneError) { JSONTEST_ASSERT(reader.getFormattedErrorMessages() == "* Line 1, Column 15\n Syntax error: value, object or array " "expected.\n"); - std::vector errors = - reader.getStructuredErrors(); - JSONTEST_ASSERT(errors.size() == 1); - JSONTEST_ASSERT(errors.at(0).offset_start == 14); - JSONTEST_ASSERT(errors.at(0).offset_limit == 15); - JSONTEST_ASSERT(errors.at(0).message == - "Syntax error: value, object or array expected."); } JSONTEST_FIXTURE(ReaderTest, parseChineseWithOneError) { @@ -1747,13 +1701,6 @@ JSONTEST_FIXTURE(ReaderTest, parseChineseWithOneError) { JSONTEST_ASSERT(reader.getFormattedErrorMessages() == "* Line 1, Column 19\n Syntax error: value, object or array " "expected.\n"); - std::vector errors = - reader.getStructuredErrors(); - JSONTEST_ASSERT(errors.size() == 1); - JSONTEST_ASSERT(errors.at(0).offset_start == 18); - JSONTEST_ASSERT(errors.at(0).offset_limit == 19); - JSONTEST_ASSERT(errors.at(0).message == - "Syntax error: value, object or array expected."); } JSONTEST_FIXTURE(ReaderTest, parseWithDetailError) { @@ -1764,12 +1711,6 @@ JSONTEST_FIXTURE(ReaderTest, parseWithDetailError) { JSONTEST_ASSERT(reader.getFormattedErrorMessages() == "* Line 1, Column 16\n Bad escape sequence in string\nSee " "Line 1, Column 20 for detail.\n"); - std::vector errors = - reader.getStructuredErrors(); - JSONTEST_ASSERT(errors.size() == 1); - JSONTEST_ASSERT(errors.at(0).offset_start == 15); - JSONTEST_ASSERT(errors.at(0).offset_limit == 23); - JSONTEST_ASSERT(errors.at(0).message == "Bad escape sequence in string"); } struct CharReaderTest : JsonTest::TestCase {}; @@ -2338,7 +2279,6 @@ int main(int argc, const char* argv[]) { JSONTEST_REGISTER_FIXTURE(runner, ValueTest, compareArray); JSONTEST_REGISTER_FIXTURE(runner, ValueTest, compareObject); JSONTEST_REGISTER_FIXTURE(runner, ValueTest, compareType); - JSONTEST_REGISTER_FIXTURE(runner, ValueTest, offsetAccessors); JSONTEST_REGISTER_FIXTURE(runner, ValueTest, typeChecksThrowExceptions); JSONTEST_REGISTER_FIXTURE(runner, ValueTest, StaticString); JSONTEST_REGISTER_FIXTURE(runner, ValueTest, CommentBefore); From 254fe6a07a4ad6cdde18c187afb4cc1b253c4238 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Thu, 29 Jan 2015 11:49:37 -0600 Subject: [PATCH 06/54] Revert "added option to FastWriter which omits the trailing new line character" This reverts commit 5bf16105b5a90f9fa7d5d4d43452feee46603a52. --- include/json/writer.h | 3 --- src/lib_json/json_writer.cpp | 8 ++------ 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/include/json/writer.h b/include/json/writer.h index f5f0a389e..40421c6ed 100644 --- a/include/json/writer.h +++ b/include/json/writer.h @@ -165,8 +165,6 @@ class JSON_API FastWriter : public Writer { */ void dropNullPlaceholders(); - void omitEndingLineFeed(); - public: // overridden from Writer virtual std::string write(const Value& root); @@ -176,7 +174,6 @@ class JSON_API FastWriter : public Writer { std::string document_; bool yamlCompatiblityEnabled_; bool dropNullPlaceholders_; - bool omitEndingLineFeed_; }; /** \brief Writes a Value in JSON format in a diff --git a/src/lib_json/json_writer.cpp b/src/lib_json/json_writer.cpp index 66ca21727..0be11847c 100644 --- a/src/lib_json/json_writer.cpp +++ b/src/lib_json/json_writer.cpp @@ -284,20 +284,16 @@ Writer::~Writer() {} // ////////////////////////////////////////////////////////////////// FastWriter::FastWriter() - : yamlCompatiblityEnabled_(false), dropNullPlaceholders_(false), - omitEndingLineFeed_(false) {} + : yamlCompatiblityEnabled_(false), dropNullPlaceholders_(false) {} void FastWriter::enableYAMLCompatibility() { yamlCompatiblityEnabled_ = true; } void FastWriter::dropNullPlaceholders() { dropNullPlaceholders_ = true; } -void FastWriter::omitEndingLineFeed() { omitEndingLineFeed_ = true; } - std::string FastWriter::write(const Value& root) { document_ = ""; writeValue(root); - if (!omitEndingLineFeed_) - document_ += "\n"; + document_ += "\n"; return document_; } From 6f6ddaa91c73499ef46c01a87ef81bfa11cae1d7 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Thu, 29 Jan 2015 11:54:33 -0600 Subject: [PATCH 07/54] revert 'Made it possible to drop null placeholders from array output.' revert ae3c7a7aabfb345968a65001ea9bc25f1e2bb405 --- include/json/writer.h | 8 -------- src/lib_json/json_writer.cpp | 7 ++----- src/test_lib_json/main.cpp | 12 ------------ 3 files changed, 2 insertions(+), 25 deletions(-) diff --git a/include/json/writer.h b/include/json/writer.h index 40421c6ed..2da72b688 100644 --- a/include/json/writer.h +++ b/include/json/writer.h @@ -158,13 +158,6 @@ class JSON_API FastWriter : public Writer { void enableYAMLCompatibility(); - /** \brief Drop the "null" string from the writer's output for nullValues. - * Strictly speaking, this is not valid JSON. But when the output is being - * fed to a browser's Javascript, it makes for smaller output and the - * browser can handle the output just fine. - */ - void dropNullPlaceholders(); - public: // overridden from Writer virtual std::string write(const Value& root); @@ -173,7 +166,6 @@ class JSON_API FastWriter : public Writer { std::string document_; bool yamlCompatiblityEnabled_; - bool dropNullPlaceholders_; }; /** \brief Writes a Value in JSON format in a diff --git a/src/lib_json/json_writer.cpp b/src/lib_json/json_writer.cpp index 0be11847c..5510eb119 100644 --- a/src/lib_json/json_writer.cpp +++ b/src/lib_json/json_writer.cpp @@ -284,12 +284,10 @@ Writer::~Writer() {} // ////////////////////////////////////////////////////////////////// FastWriter::FastWriter() - : yamlCompatiblityEnabled_(false), dropNullPlaceholders_(false) {} + : yamlCompatiblityEnabled_(false) {} void FastWriter::enableYAMLCompatibility() { yamlCompatiblityEnabled_ = true; } -void FastWriter::dropNullPlaceholders() { dropNullPlaceholders_ = true; } - std::string FastWriter::write(const Value& root) { document_ = ""; writeValue(root); @@ -300,8 +298,7 @@ std::string FastWriter::write(const Value& root) { void FastWriter::writeValue(const Value& value) { switch (value.type()) { case nullValue: - if (!dropNullPlaceholders_) - document_ += "null"; + document_ += "null"; break; case intValue: document_ += valueToString(value.asLargestInt()); diff --git a/src/test_lib_json/main.cpp b/src/test_lib_json/main.cpp index cb5c6eb35..9331c16f8 100644 --- a/src/test_lib_json/main.cpp +++ b/src/test_lib_json/main.cpp @@ -1618,17 +1618,6 @@ JSONTEST_FIXTURE(ValueTest, zeroesInKeys) { } } -struct WriterTest : JsonTest::TestCase {}; - -JSONTEST_FIXTURE(WriterTest, dropNullPlaceholders) { - Json::FastWriter writer; - Json::Value nullValue; - JSONTEST_ASSERT(writer.write(nullValue) == "null\n"); - - writer.dropNullPlaceholders(); - JSONTEST_ASSERT(writer.write(nullValue) == "\n"); -} - struct StreamWriterTest : JsonTest::TestCase {}; JSONTEST_FIXTURE(StreamWriterTest, dropNullPlaceholders) { @@ -2286,7 +2275,6 @@ int main(int argc, const char* argv[]) { JSONTEST_REGISTER_FIXTURE(runner, ValueTest, zeroes); JSONTEST_REGISTER_FIXTURE(runner, ValueTest, zeroesInKeys); - JSONTEST_REGISTER_FIXTURE(runner, WriterTest, dropNullPlaceholders); JSONTEST_REGISTER_FIXTURE(runner, StreamWriterTest, dropNullPlaceholders); JSONTEST_REGISTER_FIXTURE(runner, StreamWriterTest, writeZeroes); From 93f45d065cc54d3c7282d9a4c5c5d2225ef5cf76 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Thu, 29 Jan 2015 14:02:56 -0600 Subject: [PATCH 08/54] partially revert 'fix bug for static init' re: 28836b8acc2c002b0488c13dba28fd5be864970a A global instance of a Value (viz. 'null') was a mistake, but dropping it breaks binary-compatibility. So we will keep it everywhere except the one platform where it was crashing, ARM. --- include/json/value.h | 7 +++++-- src/lib_json/json_value.cpp | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/json/value.h b/include/json/value.h index b2bd136c7..8e9548f84 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -160,8 +160,11 @@ class JSON_API Value { typedef Json::LargestUInt LargestUInt; typedef Json::ArrayIndex ArrayIndex; - static const Value& null; ///< We regret this reference to a global instance; prefer the simpler Value(). - static const Value& nullRef; ///< just a kludge for binary-compatibility; same as null + static const Value& nullRef; +#if !defined(__ARMEL__) + /// \deprecated This exists for binary compatibility only. Use nullRef. + static const Value null; +#endif /// Minimum signed integer value that can be stored in a Json::Value. static const LargestInt minLargestInt; /// Maximum signed integer value that can be stored in a Json::Value. diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index c770c0b4d..5a7a5480f 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -29,12 +29,13 @@ namespace Json { #if defined(__ARMEL__) #define ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment))) #else +// This exists for binary compatibility only. Use nullRef. +const Value Value::null; #define ALIGNAS(byte_alignment) #endif static const unsigned char ALIGNAS(8) kNull[sizeof(Value)] = { 0 }; const unsigned char& kNullRef = kNull[0]; -const Value& Value::null = reinterpret_cast(kNullRef); -const Value& Value::nullRef = null; +const Value& Value::nullRef = reinterpret_cast(kNullRef); const Int Value::minInt = Int(~(UInt(-1) / 2)); const Int Value::maxInt = Int(UInt(-1) / 2); From f4bdc1b60290e89c3388010648030f21551b0ff7 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sun, 8 Feb 2015 14:39:52 -0600 Subject: [PATCH 09/54] partially revert 'Added features that allow the reader to accept common non-standard JSON.' revert '642befc836ac5093b528e7d8b4fd66b66735a98c', but keep the *added* methods for `decodedNumber()` and `decodedDouble()`. --- include/json/features.h | 6 ------ src/lib_json/json_reader.cpp | 24 +++--------------------- 2 files changed, 3 insertions(+), 27 deletions(-) diff --git a/include/json/features.h b/include/json/features.h index 1bb7bb614..781354783 100644 --- a/include/json/features.h +++ b/include/json/features.h @@ -44,12 +44,6 @@ class JSON_API Features { /// \c true if root must be either an array or an object value. Default: \c /// false. bool strictRoot_; - - /// \c true if dropped null placeholders are allowed. Default: \c false. - bool allowDroppedNullPlaceholders_; - - /// \c true if numeric object key are allowed. Default: \c false. - bool allowNumericKeys_; }; } // namespace Json diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index 60345cbfd..6e26794e1 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -42,17 +42,14 @@ typedef std::auto_ptr CharReaderPtr; // //////////////////////////////// Features::Features() - : allowComments_(true), strictRoot_(false), - allowDroppedNullPlaceholders_(false), allowNumericKeys_(false) {} - + : allowComments_(true), strictRoot_(false) +{} Features Features::all() { return Features(); } Features Features::strictMode() { Features features; features.allowComments_ = false; features.strictRoot_ = true; - features.allowDroppedNullPlaceholders_ = false; - features.allowNumericKeys_ = false; return features; } @@ -190,17 +187,7 @@ bool Reader::readValue() { currentValue().swapPayload(v); } break; - case tokenArraySeparator: - case tokenObjectEnd: - case tokenArrayEnd: - if (features_.allowDroppedNullPlaceholders_) { - // "Un-read" the current token and mark the current value as a null - // token. - current_--; - Value v; - currentValue().swapPayload(v); - break; - } // Else, fall through... + // Else, fall through... default: return addError("Syntax error: value, object or array expected.", token); } @@ -446,11 +433,6 @@ bool Reader::readObject(Token& /*tokenStart*/) { if (tokenName.type_ == tokenString) { if (!decodeString(tokenName, name)) return recoverFromError(tokenObjectEnd); - } else if (tokenName.type_ == tokenNumber && features_.allowNumericKeys_) { - Value numberName; - if (!decodeNumber(tokenName, numberName)) - return recoverFromError(tokenObjectEnd); - name = numberName.asString(); } else { break; } From db7ad7579413b13cfe3e81b601427172fd72e377 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Thu, 9 Apr 2015 17:45:35 -0700 Subject: [PATCH 10/54] Don't use unique_ptr on pre-c++11 branch Don't use C++11 unique_ptr in the 0.y.z branch. Although this usage is guarded with __cplusplus >= 201103 some build configurations (notably chromium) use a C++11-compliant compiler but a pre-11 library. pull #238 --- src/lib_json/json_reader.cpp | 4 ---- src/lib_json/json_writer.cpp | 4 ---- 2 files changed, 8 deletions(-) diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index 6e26794e1..590bb2a03 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -32,11 +32,7 @@ static int stackDepth_g = 0; // see readValue() namespace Json { -#if __cplusplus >= 201103L -typedef std::unique_ptr CharReaderPtr; -#else typedef std::auto_ptr CharReaderPtr; -#endif // Implementation of class Features // //////////////////////////////// diff --git a/src/lib_json/json_writer.cpp b/src/lib_json/json_writer.cpp index 5510eb119..6ec3820a1 100644 --- a/src/lib_json/json_writer.cpp +++ b/src/lib_json/json_writer.cpp @@ -40,11 +40,7 @@ namespace Json { -#if __cplusplus >= 201103L -typedef std::unique_ptr StreamWriterPtr; -#else typedef std::auto_ptr StreamWriterPtr; -#endif static bool containsControlCharacter(const char* str) { while (*str) { From 2760c7902a5cc7173aabe4e1f31dcf93e79377d5 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Wed, 10 Jun 2015 21:22:24 -0500 Subject: [PATCH 11/54] fix #290 --- src/test_lib_json/main.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test_lib_json/main.cpp b/src/test_lib_json/main.cpp index 85110adb6..080ba6e44 100644 --- a/src/test_lib_json/main.cpp +++ b/src/test_lib_json/main.cpp @@ -296,7 +296,10 @@ JSONTEST_FIXTURE(ValueTest, null) { JSONTEST_ASSERT_EQUAL(0.0, null_.asFloat()); JSONTEST_ASSERT_STRING_EQUAL("", null_.asString()); +#if !defined(__ARMEL__) + // See line #165 of include/json/value.h JSONTEST_ASSERT_EQUAL(Json::Value::null, null_); +#endif } JSONTEST_FIXTURE(ValueTest, strings) { From 7bc97db496c40d2cbbbc0d4dddd36f4479fbd81d Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sat, 11 Jul 2015 10:46:24 -0500 Subject: [PATCH 12/54] fix appveyor 32-bit windows build * http://help.appveyor.com/discussions/problems/2229-v140-not-found-on-vs2105rc ``` Done Building Project "C:\projects\jsoncpp\jsoncpp.sln" (default targets) -- FAILED. Build FAILED. "C:\projects\jsoncpp\jsoncpp.sln" (default target) (1) -> "C:\projects\jsoncpp\ALL_BUILD.vcxproj.metaproj" (default target) (2) -> "C:\projects\jsoncpp\ZERO_CHECK.vcxproj" (default target) (3) -> (PlatformPrepareForBuild target) -> C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets(64,5): error MSB8020: The build tools for v140 (Platform Toolset = 'v140') cannot be found. To build using the v140 build tools, please install v140 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Upgrade Solution...". [C:\projects\jsoncpp\ZERO_CHECK.vcxproj] ``` --- appveyor.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/appveyor.yml b/appveyor.yml index 546cb7ed1..f4966a34d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -19,6 +19,7 @@ before_build: - echo "Running cmake..." - cd c:\projects\jsoncpp - cmake --version + - set PATH=C:\Program Files (x86)\MSBuild\14.0\Bin;%PATH% - if %PLATFORM% == Win32 cmake . - if %PLATFORM% == x64 cmake -G "Visual Studio 12 2013 Win64" . From f1cafb6ded2d76392c6bffe71c4d06990a018f27 Mon Sep 17 00:00:00 2001 From: Gaurav Date: Sat, 4 Jul 2015 12:30:24 +0530 Subject: [PATCH 13/54] GCC warning removal for long long MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (was #300) I got below warning message on x86 linux machine : ``` "jsoncpp-0.10.2-p1/include/json/config.h:100: warning: ISO C++ 1998 does not support ‘long long’" gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC) ``` In reference to * https://github.com/open-source-parsers/jsoncpp/pull/292 **long long** is supported in c++-11; for old compilers i.e `0.y.z` branch this patch should be merged. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b266b4a7..29ab19e75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,7 +99,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") # using GCC - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Wno-long-long") endif() IF(JSONCPP_WITH_WARNING_AS_ERROR) From ef38374e993747f53130191b5bf5ca5d1737a053 Mon Sep 17 00:00:00 2001 From: Gaurav Date: Sun, 5 Jul 2015 14:24:35 +0530 Subject: [PATCH 14/54] Gcc warning unused "tokenStart" (was #301) In `0.y.z` branch, `tokenStart` is not used. Comment it as done in other cases. --- src/lib_json/json_reader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index 9f9d4de20..15e030450 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -1265,7 +1265,7 @@ bool OurReader::readStringSingleQuote() { return c == '\''; } -bool OurReader::readObject(Token& tokenStart) { +bool OurReader::readObject(Token& /*tokenStart*/) { Token tokenName; std::string name; Value init(objectValue); @@ -1326,7 +1326,7 @@ bool OurReader::readObject(Token& tokenStart) { "Missing '}' or object member name", tokenName, tokenObjectEnd); } -bool OurReader::readArray(Token& tokenStart) { +bool OurReader::readArray(Token& /*tokenStart*/) { Value init(arrayValue); currentValue().swapPayload(init); skipSpaces(); From 710260d07060e95bebad01fa6bc9c81531075fa8 Mon Sep 17 00:00:00 2001 From: Martyn Gigg Date: Mon, 29 Jun 2015 19:20:08 +0100 Subject: [PATCH 15/54] Allow an optional suffix on the debug library name in CMake. --- CMakeLists.txt | 1 + src/lib_json/CMakeLists.txt | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 29ab19e75..e8f2156d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,7 @@ IF(NOT WIN32) ENDIF(NOT CMAKE_BUILD_TYPE) ENDIF(NOT WIN32) +SET(DEBUG_LIBNAME_SUFFIX "" CACHE STRING "Optional suffix to append to the library name for a debug build") SET(LIB_SUFFIX "" CACHE STRING "Optional arch-dependent suffix for the library installation directory") SET(RUNTIME_INSTALL_DIR bin diff --git a/src/lib_json/CMakeLists.txt b/src/lib_json/CMakeLists.txt index 97b70198f..79ffa2ec5 100644 --- a/src/lib_json/CMakeLists.txt +++ b/src/lib_json/CMakeLists.txt @@ -2,7 +2,7 @@ if( CMAKE_COMPILER_IS_GNUCXX ) #Get compiler version. execute_process( COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GNUCXX_VERSION ) - + #-Werror=* was introduced -after- GCC 4.1.2 if( GNUCXX_VERSION VERSION_GREATER 4.1.2 ) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=strict-aliasing") @@ -43,7 +43,8 @@ IF(BUILD_SHARED_LIBS) ADD_DEFINITIONS( -DJSON_DLL_BUILD ) ADD_LIBRARY(jsoncpp_lib SHARED ${PUBLIC_HEADERS} ${jsoncpp_sources}) SET_TARGET_PROPERTIES( jsoncpp_lib PROPERTIES VERSION ${JSONCPP_VERSION} SOVERSION ${JSONCPP_VERSION_MAJOR}) - SET_TARGET_PROPERTIES( jsoncpp_lib PROPERTIES OUTPUT_NAME jsoncpp ) + SET_TARGET_PROPERTIES( jsoncpp_lib PROPERTIES OUTPUT_NAME jsoncpp + DEBUG_OUTPUT_NAME jsoncpp${DEBUG_LIBNAME_SUFFIX} ) INSTALL( TARGETS jsoncpp_lib ${INSTALL_EXPORT} RUNTIME DESTINATION ${RUNTIME_INSTALL_DIR} @@ -61,7 +62,8 @@ ENDIF() IF(BUILD_STATIC_LIBS) ADD_LIBRARY(jsoncpp_lib_static STATIC ${PUBLIC_HEADERS} ${jsoncpp_sources}) SET_TARGET_PROPERTIES( jsoncpp_lib_static PROPERTIES VERSION ${JSONCPP_VERSION} SOVERSION ${JSONCPP_VERSION_MAJOR}) - SET_TARGET_PROPERTIES( jsoncpp_lib_static PROPERTIES OUTPUT_NAME jsoncpp ) + SET_TARGET_PROPERTIES( jsoncpp_lib_static PROPERTIES OUTPUT_NAME jsoncpp + DEBUG_OUTPUT_NAME jsoncpp${DEBUG_LIBNAME_SUFFIX} ) INSTALL( TARGETS jsoncpp_lib_static ${INSTALL_EXPORT} RUNTIME DESTINATION ${RUNTIME_INSTALL_DIR} From bb5d0249ed8f592169e1fdb617531b4e5dfe84ad Mon Sep 17 00:00:00 2001 From: Stuart Eichert Date: Wed, 1 Jul 2015 14:05:54 -0700 Subject: [PATCH 16/54] Warn about implicit 64 to 32 bit conversions when using clang --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e8f2156d0..3eeacf164 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,7 +97,7 @@ endif( MSVC ) if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") # using regular Clang or AppleClang - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wshorten-64-to-32") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") # using GCC set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Wno-long-long") From cb8259f545d940c1b87b9142e234f1b9a4568d3b Mon Sep 17 00:00:00 2001 From: Stuart Eichert Date: Wed, 1 Jul 2015 14:18:15 -0700 Subject: [PATCH 17/54] Fix #296: Explicitly cast size_t results to unsigned when needed This is rebased from #297, where AppVeyor had been failing, and which was not properly based on the master branch. --- src/lib_json/json_value.cpp | 2 +- src/lib_json/json_writer.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 5a7a5480f..8e9af9407 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -126,7 +126,7 @@ inline static void decodePrefixedString( unsigned* length, char const** value) { if (!isPrefixed) { - *length = strlen(prefixed); + *length = static_cast(strlen(prefixed)); *value = prefixed; } else { *length = *reinterpret_cast(prefixed); diff --git a/src/lib_json/json_writer.cpp b/src/lib_json/json_writer.cpp index 0a48f95c1..b2f5583eb 100644 --- a/src/lib_json/json_writer.cpp +++ b/src/lib_json/json_writer.cpp @@ -343,7 +343,7 @@ void FastWriter::writeValue(const Value& value) { const std::string& name = *it; if (it != members.begin()) document_ += ','; - document_ += valueToQuotedStringN(name.data(), name.length()); + document_ += valueToQuotedStringN(name.data(), static_cast(name.length())); document_ += yamlCompatiblityEnabled_ ? ": " : ":"; writeValue(value[name]); } @@ -903,7 +903,7 @@ void BuiltStyledStreamWriter::writeValue(Value const& value) { std::string const& name = *it; Value const& childValue = value[name]; writeCommentBeforeValue(childValue); - writeWithIndent(valueToQuotedStringN(name.data(), name.length())); + writeWithIndent(valueToQuotedStringN(name.data(), static_cast(name.length()))); *sout_ << colonSymbol_; writeValue(childValue); if (++it == members.end()) { From 2e185081b2d05123c69a77b1535a27e047632646 Mon Sep 17 00:00:00 2001 From: Mike Naberezny Date: Fri, 3 Jul 2015 15:47:00 -0700 Subject: [PATCH 18/54] Fix undefined name "sys" Same as #299 (bca0eff81a1c5ef160d9858b8e89b1c919b71c1f), but an earlier commit needed to be rebased. --- devtools/fixeol.py | 1 + 1 file changed, 1 insertion(+) diff --git a/devtools/fixeol.py b/devtools/fixeol.py index 054eb9b22..b55e14616 100644 --- a/devtools/fixeol.py +++ b/devtools/fixeol.py @@ -5,6 +5,7 @@ from __future__ import print_function import os.path +import sys def fix_source_eol(path, is_dry_run = True, verbose = True, eol = '\n'): """Makes sure that all sources have the specified eol sequence (default: unix).""" From 7670e5151b0dcf28362932e1abdb5a535c69bd17 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sat, 11 Jul 2015 13:53:05 -0500 Subject: [PATCH 19/54] 0.10.3 --- CMakeLists.txt | 2 +- include/json/version.h | 4 ++-- version | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3eeacf164..666f21f73 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,7 +63,7 @@ ENDMACRO(jsoncpp_parse_version) #SET( JSONCPP_VERSION_MAJOR X ) #SET( JSONCPP_VERSION_MINOR Y ) #SET( JSONCPP_VERSION_PATCH Z ) -SET( JSONCPP_VERSION 0.10.2 ) +SET( JSONCPP_VERSION 0.10.3 ) jsoncpp_parse_version( ${JSONCPP_VERSION} JSONCPP_VERSION ) #IF(NOT JSONCPP_VERSION_FOUND) # MESSAGE(FATAL_ERROR "Failed to parse version string properly. Expect X.Y.Z") diff --git a/include/json/version.h b/include/json/version.h index 1c52a5cec..19a346fa2 100644 --- a/include/json/version.h +++ b/include/json/version.h @@ -4,10 +4,10 @@ #ifndef JSON_VERSION_H_INCLUDED # define JSON_VERSION_H_INCLUDED -# define JSONCPP_VERSION_STRING "0.10.2" +# define JSONCPP_VERSION_STRING "0.10.3" # define JSONCPP_VERSION_MAJOR 0 # define JSONCPP_VERSION_MINOR 10 -# define JSONCPP_VERSION_PATCH 2 +# define JSONCPP_VERSION_PATCH 3 # define JSONCPP_VERSION_QUALIFIER # define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8)) diff --git a/version b/version index 5eef0f10e..a3f5a8ed4 100644 --- a/version +++ b/version @@ -1 +1 @@ -0.10.2 +0.10.3 From c6fa95931872316a235c801a490bcd618445b530 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sat, 11 Jul 2015 14:06:18 -0500 Subject: [PATCH 20/54] dockerize the Travis build Docker builds are *much* faster in Travis. Also, we prepare to enable C++11. --- .travis.yml | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 17e52dcf8..4180688f1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,13 +2,20 @@ # http://about.travis-ci.org/docs/user/build-configuration/ # This file can be validated on: # http://lint.travis-ci.org/ +# See also +# http://stackoverflow.com/questions/22111549/travis-ci-with-clang-3-4-and-c11/30925448#30925448 +# to allow C++11, though we are not yet building with -std=c++11 -#before_install: sudo apt-get install -y cmake -# cmake is pre-installed in Travis for both linux and osx - -before_install: - - sudo apt-get update -qq - - sudo apt-get install -qq valgrind +install: +- if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - gcc-4.8 + - g++-4.8 + - clang os: - linux language: cpp @@ -23,3 +30,4 @@ env: notifications: email: - aaronjjacobs@gmail.com +sudo: false From 72fb4a5b08d941b631c9b5bcc104718be18c6965 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sat, 11 Jul 2015 14:09:52 -0500 Subject: [PATCH 21/54] valgrind in Travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 4180688f1..591b3546c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,7 @@ addons: - gcc-4.8 - g++-4.8 - clang + - valgrind os: - linux language: cpp From 138c48b7e8b370fb0e86c3a2239eaf1cc54acb2b Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sat, 11 Jul 2015 14:27:19 -0500 Subject: [PATCH 22/54] gcc-4.6, clang-3.3 --- .travis.yml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 591b3546c..bc2f45ea3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,15 +7,24 @@ # to allow C++11, though we are not yet building with -std=c++11 install: -- if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi +# /usr/bin/gcc is 4.6 always, but gcc-X.Y is available. +#- if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi +- if [ "$CXX" = "g++" ]; then export CXX="g++-4.6" CC="gcc-4.6"; fi +# /usr/bin/clang is our version already, and clang-X.Y does not exist. +#- if [ "$CXX" = "clang++" ]; then export CXX="clang++-3.3" CC="clang-3.3"; fi +- echo ${PATH} +- ls /usr/local +- export PATH=/usr/bin:${PATH} +- echo ${CXX} +- ${CXX} --version addons: apt: sources: - ubuntu-toolchain-r-test packages: - - gcc-4.8 - - g++-4.8 - - clang + - gcc-4.6 + - g++-4.6 + - clang-3.3 - valgrind os: - linux From 75747db30c1bde38a9c55e226c4a47c39412815d Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sun, 12 Jul 2015 12:32:33 -0500 Subject: [PATCH 23/54] -Wshadow * https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html * http://programmers.stackexchange.com/questions/122608/clang-warning-flags-for-objective-c-development/124574#124574 In clang: `-Wconversion` implies `-Wshorten-64-to-32`, but we cannot use `-Wconversion` yet. --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 666f21f73..954cbf3e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,10 +97,10 @@ endif( MSVC ) if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") # using regular Clang or AppleClang - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wshorten-64-to-32") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wshadow -Wshorten-64-to-32") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") # using GCC - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Wno-long-long") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wshadow -Wextra -pedantic -Wno-long-long") endif() IF(JSONCPP_WITH_WARNING_AS_ERROR) From 17360f3d4bbfe9c5b47cf5aef11554d3a02c854a Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sun, 12 Jul 2015 12:55:18 -0500 Subject: [PATCH 24/54] fix some warnings --- src/lib_json/json_tool.h | 6 ++-- src/lib_json/json_value.cpp | 53 +++++++++++++++-------------- src/lib_json/json_valueiterator.inl | 20 +++++------ 3 files changed, 40 insertions(+), 39 deletions(-) diff --git a/src/lib_json/json_tool.h b/src/lib_json/json_tool.h index f9b61c38c..e6d4e9229 100644 --- a/src/lib_json/json_tool.h +++ b/src/lib_json/json_tool.h @@ -30,8 +30,8 @@ static inline std::string codePointToUTF8(unsigned int cp) { } else if (cp <= 0xFFFF) { result.resize(3); result[2] = static_cast(0x80 | (0x3f & cp)); - result[1] = 0x80 | static_cast((0x3f & (cp >> 6))); - result[0] = 0xE0 | static_cast((0xf & (cp >> 12))); + result[1] = static_cast(0x80 | (0x3f & (cp >> 6))); + result[0] = static_cast(0xE0 | (0xf & (cp >> 12))); } else if (cp <= 0x10FFFF) { result.resize(4); result[3] = static_cast(0x80 | (0x3f & cp)); @@ -63,7 +63,7 @@ typedef char UIntToStringBuffer[uintToStringBufferSize]; static inline void uintToString(LargestUInt value, char*& current) { *--current = 0; do { - *--current = char(value % 10) + '0'; + *--current = static_cast(value % 10U + static_cast('0')); value /= 10; } while (value != 0); } diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 8e9af9407..e3d45ecbb 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -109,7 +109,7 @@ static inline char* duplicateAndPrefixStringValue( JSON_ASSERT_MESSAGE(length <= (unsigned)Value::maxInt - sizeof(unsigned) - 1U, "in Json::Value::duplicateAndPrefixStringValue(): " "length too big for prefixing"); - unsigned actualLength = length + sizeof(unsigned) + 1U; + unsigned actualLength = length + static_cast(sizeof(unsigned)) + 1U; char* newString = static_cast(malloc(actualLength)); if (newString == 0) { throwRuntimeError( @@ -233,14 +233,14 @@ void Value::CommentInfo::setComment(const char* text, size_t len) { // Notes: policy_ indicates if the string was allocated when // a string is stored. -Value::CZString::CZString(ArrayIndex index) : cstr_(0), index_(index) {} +Value::CZString::CZString(ArrayIndex aindex) : cstr_(0), index_(aindex) {} -Value::CZString::CZString(char const* str, unsigned length, DuplicationPolicy allocate) +Value::CZString::CZString(char const* str, unsigned ulength, DuplicationPolicy allocate) : cstr_(str) { // allocate != duplicate - storage_.policy_ = allocate; - storage_.length_ = length; + storage_.policy_ = allocate & 0x3; + storage_.length_ = ulength & 0x3FFFFFFF; } Value::CZString::CZString(const CZString& other) @@ -249,9 +249,9 @@ Value::CZString::CZString(const CZString& other) : other.cstr_) { storage_.policy_ = (other.cstr_ - ? (other.storage_.policy_ == noDuplication + ? (static_cast(other.storage_.policy_) == noDuplication ? noDuplication : duplicate) - : other.storage_.policy_); + : static_cast(other.storage_.policy_)); storage_.length_ = other.storage_.length_; } @@ -313,9 +313,9 @@ bool Value::CZString::isStaticString() const { return storage_.policy_ == noDupl * memset( this, 0, sizeof(Value) ) * This optimization is used in ValueInternalMap fast allocator. */ -Value::Value(ValueType type) { - initBasic(type); - switch (type) { +Value::Value(ValueType vtype) { + initBasic(vtype); + switch (vtype) { case nullValue: break; case intValue: @@ -480,7 +480,7 @@ void Value::swapPayload(Value& other) { std::swap(value_, other.value_); int temp2 = allocated_; allocated_ = other.allocated_; - other.allocated_ = temp2; + other.allocated_ = temp2 & 0x1; } void Value::swap(Value& other) { @@ -606,12 +606,12 @@ const char* Value::asCString() const { return this_str; } -bool Value::getString(char const** str, char const** end) const { +bool Value::getString(char const** str, char const** cend) const { if (type_ != stringValue) return false; if (value_.string_ == 0) return false; unsigned length; decodePrefixedString(this->allocated_, this->value_.string_, &length, str); - *end = *str + length; + *cend = *str + length; return true; } @@ -810,7 +810,8 @@ bool Value::asBool() const { case uintValue: return value_.uint_ ? true : false; case realValue: - return value_.real_ ? true : false; + // This is kind of strange. Not recommended. + return (value_.real_ != 0.0) ? true : false; default: break; } @@ -958,8 +959,8 @@ const Value& Value::operator[](int index) const { return (*this)[ArrayIndex(index)]; } -void Value::initBasic(ValueType type, bool allocated) { - type_ = type; +void Value::initBasic(ValueType vtype, bool allocated) { + type_ = vtype; allocated_ = allocated; comments_ = 0; } @@ -986,7 +987,7 @@ Value& Value::resolveReference(const char* key) { } // @param key is not null-terminated. -Value& Value::resolveReference(char const* key, char const* end) +Value& Value::resolveReference(char const* key, char const* cend) { JSON_ASSERT_MESSAGE( type_ == nullValue || type_ == objectValue, @@ -994,7 +995,7 @@ Value& Value::resolveReference(char const* key, char const* end) if (type_ == nullValue) *this = Value(objectValue); CZString actualKey( - key, static_cast(end-key), CZString::duplicateOnCopy); + key, static_cast(cend-key), CZString::duplicateOnCopy); ObjectValues::iterator it = value_.map_->lower_bound(actualKey); if (it != value_.map_->end() && (*it).first == actualKey) return (*it).second; @@ -1012,13 +1013,13 @@ Value Value::get(ArrayIndex index, const Value& defaultValue) const { bool Value::isValidIndex(ArrayIndex index) const { return index < size(); } -Value const* Value::find(char const* key, char const* end) const +Value const* Value::find(char const* key, char const* cend) const { JSON_ASSERT_MESSAGE( type_ == nullValue || type_ == objectValue, "in Json::Value::find(key, end, found): requires objectValue or nullValue"); if (type_ == nullValue) return NULL; - CZString actualKey(key, static_cast(end-key), CZString::noDuplication); + CZString actualKey(key, static_cast(cend-key), CZString::noDuplication); ObjectValues::const_iterator it = value_.map_->find(actualKey); if (it == value_.map_->end()) return NULL; return &(*it).second; @@ -1062,9 +1063,9 @@ Value const& Value::operator[](CppTL::ConstString const& key) const Value& Value::append(const Value& value) { return (*this)[size()] = value; } -Value Value::get(char const* key, char const* end, Value const& defaultValue) const +Value Value::get(char const* key, char const* cend, Value const& defaultValue) const { - Value const* found = find(key, end); + Value const* found = find(key, cend); return !found ? defaultValue : *found; } Value Value::get(char const* key, Value const& defaultValue) const @@ -1077,12 +1078,12 @@ Value Value::get(std::string const& key, Value const& defaultValue) const } -bool Value::removeMember(const char* key, const char* end, Value* removed) +bool Value::removeMember(const char* key, const char* cend, Value* removed) { if (type_ != objectValue) { return false; } - CZString actualKey(key, static_cast(end-key), CZString::noDuplication); + CZString actualKey(key, static_cast(cend-key), CZString::noDuplication); ObjectValues::iterator it = value_.map_->find(actualKey); if (it == value_.map_->end()) return false; @@ -1144,9 +1145,9 @@ Value Value::get(const CppTL::ConstString& key, } #endif -bool Value::isMember(char const* key, char const* end) const +bool Value::isMember(char const* key, char const* cend) const { - Value const* value = find(key, end); + Value const* value = find(key, cend); return NULL != value; } bool Value::isMember(char const* key) const diff --git a/src/lib_json/json_valueiterator.inl b/src/lib_json/json_valueiterator.inl index d01d3c018..b3bbc354f 100644 --- a/src/lib_json/json_valueiterator.inl +++ b/src/lib_json/json_valueiterator.inl @@ -93,26 +93,26 @@ UInt ValueIteratorBase::index() const { } std::string ValueIteratorBase::name() const { - char const* key; + char const* keey; char const* end; - key = memberName(&end); - if (!key) return std::string(); - return std::string(key, end); + keey = memberName(&end); + if (!keey) return std::string(); + return std::string(keey, end); } char const* ValueIteratorBase::memberName() const { - const char* name = (*current_).first.data(); - return name ? name : ""; + const char* cname = (*current_).first.data(); + return cname ? cname : ""; } char const* ValueIteratorBase::memberName(char const** end) const { - const char* name = (*current_).first.data(); - if (!name) { + const char* cname = (*current_).first.data(); + if (!cname) { *end = NULL; return NULL; } - *end = name + (*current_).first.length(); - return name; + *end = cname + (*current_).first.length(); + return cname; } // ////////////////////////////////////////////////////////////////// From 542354902e42529da3156d9b56f460342eabfe09 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sun, 12 Jul 2015 12:58:54 -0500 Subject: [PATCH 25/54] fixed a bug found by -Wshadow --- src/lib_json/json_value.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index e3d45ecbb..95f60cca2 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -1128,8 +1128,8 @@ bool Value::removeIndex(ArrayIndex index, Value* removed) { ArrayIndex oldSize = size(); // shift left all items left, into the place of the "removed" for (ArrayIndex i = index; i < (oldSize - 1); ++i){ - CZString key(i); - (*value_.map_)[key] = (*this)[i + 1]; + CZString keey(i); + (*value_.map_)[keey] = (*this)[i + 1]; } // erase the last one ("leftover") CZString keyLast(oldSize - 1); From b97e624ac1f9f29dbfeeb85b548119107fdc8968 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sun, 12 Jul 2015 14:25:21 -0500 Subject: [PATCH 26/54] -Werror --- CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 954cbf3e9..01f2047d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,10 +97,11 @@ endif( MSVC ) if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") # using regular Clang or AppleClang - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wshadow -Wshorten-64-to-32") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Werror -Wall -Wshadow -Wshorten-64-to-32") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") # using GCC - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wshadow -Wextra -pedantic -Wno-long-long") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wshadow -Wextra -pedantic -Wno-long-long") + # not yet ready for -Wconversion endif() IF(JSONCPP_WITH_WARNING_AS_ERROR) From ed5d73fe1dc28086d9bd576467482c227a22cb1e Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sun, 12 Jul 2015 14:37:38 -0500 Subject: [PATCH 27/54] 0.6.4 --- CMakeLists.txt | 2 +- include/json/version.h | 4 ++-- version | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 01f2047d5..685cacf70 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,7 +63,7 @@ ENDMACRO(jsoncpp_parse_version) #SET( JSONCPP_VERSION_MAJOR X ) #SET( JSONCPP_VERSION_MINOR Y ) #SET( JSONCPP_VERSION_PATCH Z ) -SET( JSONCPP_VERSION 0.10.3 ) +SET( JSONCPP_VERSION 0.10.4 ) jsoncpp_parse_version( ${JSONCPP_VERSION} JSONCPP_VERSION ) #IF(NOT JSONCPP_VERSION_FOUND) # MESSAGE(FATAL_ERROR "Failed to parse version string properly. Expect X.Y.Z") diff --git a/include/json/version.h b/include/json/version.h index 19a346fa2..73d3370a0 100644 --- a/include/json/version.h +++ b/include/json/version.h @@ -4,10 +4,10 @@ #ifndef JSON_VERSION_H_INCLUDED # define JSON_VERSION_H_INCLUDED -# define JSONCPP_VERSION_STRING "0.10.3" +# define JSONCPP_VERSION_STRING "0.10.4" # define JSONCPP_VERSION_MAJOR 0 # define JSONCPP_VERSION_MINOR 10 -# define JSONCPP_VERSION_PATCH 3 +# define JSONCPP_VERSION_PATCH 4 # define JSONCPP_VERSION_QUALIFIER # define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8)) diff --git a/version b/version index a3f5a8ed4..9b40aa6c2 100644 --- a/version +++ b/version @@ -1 +1 @@ -0.10.3 +0.10.4 From d48bff5fcbdffe872f7f68919a34af3d3e0d44e8 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sun, 12 Jul 2015 14:56:36 -0500 Subject: [PATCH 28/54] gcc-4.6 in Travis and clang-3.0, the default --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index bc2f45ea3..dc05f35f0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ install: #- if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi - if [ "$CXX" = "g++" ]; then export CXX="g++-4.6" CC="gcc-4.6"; fi # /usr/bin/clang is our version already, and clang-X.Y does not exist. -#- if [ "$CXX" = "clang++" ]; then export CXX="clang++-3.3" CC="clang-3.3"; fi +#- if [ "$CXX" = "clang++" ]; then export CXX="clang++-3.0" CC="clang-3.0"; fi - echo ${PATH} - ls /usr/local - export PATH=/usr/bin:${PATH} @@ -24,7 +24,7 @@ addons: packages: - gcc-4.6 - g++-4.6 - - clang-3.3 + - clang - valgrind os: - linux From 1b32e3e869059e437c43ba0f8765c3e5857801f7 Mon Sep 17 00:00:00 2001 From: Michael Shields Date: Mon, 27 Jul 2015 16:35:19 -0700 Subject: [PATCH 29/54] Fix cases where the most negative signed integer was negated, causing undefined behavior. --- src/lib_json/json_reader.cpp | 6 ++++-- src/lib_json/json_writer.cpp | 13 ++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index 15e030450..d76b8ebc8 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -517,7 +517,7 @@ bool Reader::decodeNumber(Token& token, Value& decoded) { ++current; // TODO: Help the compiler do the div and mod at compile time or get rid of them. Value::LargestUInt maxIntegerValue = - isNegative ? Value::LargestUInt(-Value::minLargestInt) + isNegative ? Value::LargestUInt(Value::maxLargestInt) + 1 : Value::maxLargestUInt; Value::LargestUInt threshold = maxIntegerValue / 10; Value::LargestUInt value = 0; @@ -538,7 +538,9 @@ bool Reader::decodeNumber(Token& token, Value& decoded) { } value = value * 10 + digit; } - if (isNegative) + if (isNegative && value == maxIntegerValue) + decoded = Value::minLargestInt; + else if (isNegative) decoded = -Value::LargestInt(value); else if (value <= Value::LargestUInt(Value::maxInt)) decoded = Value::LargestInt(value); diff --git a/src/lib_json/json_writer.cpp b/src/lib_json/json_writer.cpp index b2f5583eb..33f5b0478 100644 --- a/src/lib_json/json_writer.cpp +++ b/src/lib_json/json_writer.cpp @@ -71,12 +71,15 @@ static bool containsControlCharacter0(const char* str, unsigned len) { std::string valueToString(LargestInt value) { UIntToStringBuffer buffer; char* current = buffer + sizeof(buffer); - bool isNegative = value < 0; - if (isNegative) - value = -value; - uintToString(LargestUInt(value), current); - if (isNegative) + if (value == Value::minLargestInt) { + uintToString(LargestUInt(Value::maxLargestInt) + 1, current); *--current = '-'; + } else if (value < 0) { + uintToString(LargestUInt(-value), current); + *--current = '-'; + } else { + uintToString(LargestUInt(value), current); + } assert(current >= buffer); return current; } From ffea45bbe10683a33b83ac8e95ae6f090fc78f60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Krause?= Date: Thu, 30 Jul 2015 23:47:05 +0200 Subject: [PATCH 30/54] Remove Werror -Werror shouldn't be used in released code since it can cause random build failures on moderate warnings. It also depends on the used toolchain since different toolchains may or may not print the same warnings. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ca9789835..e8a8a8787 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,7 +101,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") # using GCC set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wshadow -Wextra -pedantic -Wno-long-long") - # not yet ready for -Wconversion + # not yet ready for -Wsign-conversion endif() IF(JSONCPP_WITH_WARNING_AS_ERROR) From 22ec823cc707f38ee465805cfb158879e56758a3 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Mon, 3 Aug 2015 10:58:29 +1000 Subject: [PATCH 31/54] Remove undefined behavior from a left shift of a negative value. Fixed by shifting a positive value, then negating the result. (Credit: Richard Trieu) --- src/test_lib_json/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test_lib_json/main.cpp b/src/test_lib_json/main.cpp index 080ba6e44..3d3188862 100644 --- a/src/test_lib_json/main.cpp +++ b/src/test_lib_json/main.cpp @@ -1215,7 +1215,7 @@ JSONTEST_FIXTURE(ValueTest, nonIntegers) { JSONTEST_ASSERT_EQUAL(-2147483648.5, val.asDouble()); JSONTEST_ASSERT_EQUAL(float(-2147483648.5), val.asFloat()); #ifdef JSON_HAS_INT64 - JSONTEST_ASSERT_EQUAL(-Json::Int64(1) << 31, val.asLargestInt()); + JSONTEST_ASSERT_EQUAL(-(Json::Int64(1) << 31), val.asLargestInt()); #endif JSONTEST_ASSERT_EQUAL(true, val.asBool()); JSONTEST_ASSERT_EQUAL("-2147483648.5", From aaf3417654d7d6b702981dff45c4cbb3d83c3b31 Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Sun, 9 Aug 2015 17:56:16 -0500 Subject: [PATCH 32/54] Add .gitattributes file --- .gitattributes | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..63e493a05 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,6 @@ +* text=auto +*.sh eol=lf +*.bat eol=crlf +*.vcproj eol=crlf +*.vcxproj eol=crlf +*.sln eol=crlf From 28dcc3589aca634c7893eeea85529e5deb927f8b Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Sun, 9 Aug 2015 17:58:59 -0500 Subject: [PATCH 33/54] Normalize line endings This commit contains nothing but line ending normalization changes. These changes were performed after the introduction of .gitattributes into the repository. --- devtools/agent_vmw7.json | 66 ++--- devtools/agent_vmxp.json | 52 ++-- makefiles/vs71/jsoncpp.sln | 92 +++---- makefiles/vs71/jsontest.vcproj | 238 ++++++++-------- makefiles/vs71/lib_json.vcproj | 410 ++++++++++++++-------------- makefiles/vs71/test_lib_json.vcproj | 260 +++++++++--------- 6 files changed, 559 insertions(+), 559 deletions(-) diff --git a/devtools/agent_vmw7.json b/devtools/agent_vmw7.json index 086ad9abb..0810a9954 100644 --- a/devtools/agent_vmw7.json +++ b/devtools/agent_vmw7.json @@ -1,33 +1,33 @@ -{ - "cmake_variants" : [ - {"name": "generator", - "generators": [ - {"generator": [ - "Visual Studio 7 .NET 2003", - "Visual Studio 9 2008", - "Visual Studio 9 2008 Win64", - "Visual Studio 10", - "Visual Studio 10 Win64", - "Visual Studio 11", - "Visual Studio 11 Win64" - ] - }, - {"generator": ["MinGW Makefiles"], - "env_prepend": [{"path": "c:/wut/prg/MinGW/bin"}] - } - ] - }, - {"name": "shared_dll", - "variables": [ - ["BUILD_SHARED_LIBS=true"], - ["BUILD_SHARED_LIBS=false"] - ] - }, - {"name": "build_type", - "build_types": [ - "debug", - "release" - ] - } - ] -} +{ + "cmake_variants" : [ + {"name": "generator", + "generators": [ + {"generator": [ + "Visual Studio 7 .NET 2003", + "Visual Studio 9 2008", + "Visual Studio 9 2008 Win64", + "Visual Studio 10", + "Visual Studio 10 Win64", + "Visual Studio 11", + "Visual Studio 11 Win64" + ] + }, + {"generator": ["MinGW Makefiles"], + "env_prepend": [{"path": "c:/wut/prg/MinGW/bin"}] + } + ] + }, + {"name": "shared_dll", + "variables": [ + ["BUILD_SHARED_LIBS=true"], + ["BUILD_SHARED_LIBS=false"] + ] + }, + {"name": "build_type", + "build_types": [ + "debug", + "release" + ] + } + ] +} diff --git a/devtools/agent_vmxp.json b/devtools/agent_vmxp.json index 997aa5efb..b627a7221 100644 --- a/devtools/agent_vmxp.json +++ b/devtools/agent_vmxp.json @@ -1,26 +1,26 @@ -{ - "cmake_variants" : [ - {"name": "generator", - "generators": [ - {"generator": [ - "Visual Studio 6", - "Visual Studio 7", - "Visual Studio 8 2005" - ] - } - ] - }, - {"name": "shared_dll", - "variables": [ - ["BUILD_SHARED_LIBS=true"], - ["BUILD_SHARED_LIBS=false"] - ] - }, - {"name": "build_type", - "build_types": [ - "debug", - "release" - ] - } - ] -} +{ + "cmake_variants" : [ + {"name": "generator", + "generators": [ + {"generator": [ + "Visual Studio 6", + "Visual Studio 7", + "Visual Studio 8 2005" + ] + } + ] + }, + {"name": "shared_dll", + "variables": [ + ["BUILD_SHARED_LIBS=true"], + ["BUILD_SHARED_LIBS=false"] + ] + }, + {"name": "build_type", + "build_types": [ + "debug", + "release" + ] + } + ] +} diff --git a/makefiles/vs71/jsoncpp.sln b/makefiles/vs71/jsoncpp.sln index 5bfa36654..dd2f91b44 100644 --- a/makefiles/vs71/jsoncpp.sln +++ b/makefiles/vs71/jsoncpp.sln @@ -1,46 +1,46 @@ -Microsoft Visual Studio Solution File, Format Version 8.00 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lib_json", "lib_json.vcproj", "{B84F7231-16CE-41D8-8C08-7B523FF4225B}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "jsontest", "jsontest.vcproj", "{25AF2DD2-D396-4668-B188-488C33B8E620}" - ProjectSection(ProjectDependencies) = postProject - {B84F7231-16CE-41D8-8C08-7B523FF4225B} = {B84F7231-16CE-41D8-8C08-7B523FF4225B} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_lib_json", "test_lib_json.vcproj", "{B7A96B78-2782-40D2-8F37-A2DEF2B9C26D}" - ProjectSection(ProjectDependencies) = postProject - {B84F7231-16CE-41D8-8C08-7B523FF4225B} = {B84F7231-16CE-41D8-8C08-7B523FF4225B} - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfiguration) = preSolution - Debug = Debug - dummy = dummy - Release = Release - EndGlobalSection - GlobalSection(ProjectConfiguration) = postSolution - {B84F7231-16CE-41D8-8C08-7B523FF4225B}.Debug.ActiveCfg = Debug|Win32 - {B84F7231-16CE-41D8-8C08-7B523FF4225B}.Debug.Build.0 = Debug|Win32 - {B84F7231-16CE-41D8-8C08-7B523FF4225B}.dummy.ActiveCfg = dummy|Win32 - {B84F7231-16CE-41D8-8C08-7B523FF4225B}.dummy.Build.0 = dummy|Win32 - {B84F7231-16CE-41D8-8C08-7B523FF4225B}.Release.ActiveCfg = Release|Win32 - {B84F7231-16CE-41D8-8C08-7B523FF4225B}.Release.Build.0 = Release|Win32 - {25AF2DD2-D396-4668-B188-488C33B8E620}.Debug.ActiveCfg = Debug|Win32 - {25AF2DD2-D396-4668-B188-488C33B8E620}.Debug.Build.0 = Debug|Win32 - {25AF2DD2-D396-4668-B188-488C33B8E620}.dummy.ActiveCfg = Debug|Win32 - {25AF2DD2-D396-4668-B188-488C33B8E620}.dummy.Build.0 = Debug|Win32 - {25AF2DD2-D396-4668-B188-488C33B8E620}.Release.ActiveCfg = Release|Win32 - {25AF2DD2-D396-4668-B188-488C33B8E620}.Release.Build.0 = Release|Win32 - {B7A96B78-2782-40D2-8F37-A2DEF2B9C26D}.Debug.ActiveCfg = Debug|Win32 - {B7A96B78-2782-40D2-8F37-A2DEF2B9C26D}.Debug.Build.0 = Debug|Win32 - {B7A96B78-2782-40D2-8F37-A2DEF2B9C26D}.dummy.ActiveCfg = Debug|Win32 - {B7A96B78-2782-40D2-8F37-A2DEF2B9C26D}.dummy.Build.0 = Debug|Win32 - {B7A96B78-2782-40D2-8F37-A2DEF2B9C26D}.Release.ActiveCfg = Release|Win32 - {B7A96B78-2782-40D2-8F37-A2DEF2B9C26D}.Release.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EndGlobalSection - GlobalSection(ExtensibilityAddIns) = postSolution - EndGlobalSection -EndGlobal +Microsoft Visual Studio Solution File, Format Version 8.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lib_json", "lib_json.vcproj", "{B84F7231-16CE-41D8-8C08-7B523FF4225B}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "jsontest", "jsontest.vcproj", "{25AF2DD2-D396-4668-B188-488C33B8E620}" + ProjectSection(ProjectDependencies) = postProject + {B84F7231-16CE-41D8-8C08-7B523FF4225B} = {B84F7231-16CE-41D8-8C08-7B523FF4225B} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_lib_json", "test_lib_json.vcproj", "{B7A96B78-2782-40D2-8F37-A2DEF2B9C26D}" + ProjectSection(ProjectDependencies) = postProject + {B84F7231-16CE-41D8-8C08-7B523FF4225B} = {B84F7231-16CE-41D8-8C08-7B523FF4225B} + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + Debug = Debug + dummy = dummy + Release = Release + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {B84F7231-16CE-41D8-8C08-7B523FF4225B}.Debug.ActiveCfg = Debug|Win32 + {B84F7231-16CE-41D8-8C08-7B523FF4225B}.Debug.Build.0 = Debug|Win32 + {B84F7231-16CE-41D8-8C08-7B523FF4225B}.dummy.ActiveCfg = dummy|Win32 + {B84F7231-16CE-41D8-8C08-7B523FF4225B}.dummy.Build.0 = dummy|Win32 + {B84F7231-16CE-41D8-8C08-7B523FF4225B}.Release.ActiveCfg = Release|Win32 + {B84F7231-16CE-41D8-8C08-7B523FF4225B}.Release.Build.0 = Release|Win32 + {25AF2DD2-D396-4668-B188-488C33B8E620}.Debug.ActiveCfg = Debug|Win32 + {25AF2DD2-D396-4668-B188-488C33B8E620}.Debug.Build.0 = Debug|Win32 + {25AF2DD2-D396-4668-B188-488C33B8E620}.dummy.ActiveCfg = Debug|Win32 + {25AF2DD2-D396-4668-B188-488C33B8E620}.dummy.Build.0 = Debug|Win32 + {25AF2DD2-D396-4668-B188-488C33B8E620}.Release.ActiveCfg = Release|Win32 + {25AF2DD2-D396-4668-B188-488C33B8E620}.Release.Build.0 = Release|Win32 + {B7A96B78-2782-40D2-8F37-A2DEF2B9C26D}.Debug.ActiveCfg = Debug|Win32 + {B7A96B78-2782-40D2-8F37-A2DEF2B9C26D}.Debug.Build.0 = Debug|Win32 + {B7A96B78-2782-40D2-8F37-A2DEF2B9C26D}.dummy.ActiveCfg = Debug|Win32 + {B7A96B78-2782-40D2-8F37-A2DEF2B9C26D}.dummy.Build.0 = Debug|Win32 + {B7A96B78-2782-40D2-8F37-A2DEF2B9C26D}.Release.ActiveCfg = Release|Win32 + {B7A96B78-2782-40D2-8F37-A2DEF2B9C26D}.Release.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal diff --git a/makefiles/vs71/jsontest.vcproj b/makefiles/vs71/jsontest.vcproj index 99a4dd697..562c71f61 100644 --- a/makefiles/vs71/jsontest.vcproj +++ b/makefiles/vs71/jsontest.vcproj @@ -1,119 +1,119 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/makefiles/vs71/lib_json.vcproj b/makefiles/vs71/lib_json.vcproj index fe66d8ac5..24c5dd411 100644 --- a/makefiles/vs71/lib_json.vcproj +++ b/makefiles/vs71/lib_json.vcproj @@ -1,205 +1,205 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/makefiles/vs71/test_lib_json.vcproj b/makefiles/vs71/test_lib_json.vcproj index df36700bd..9ebb986a6 100644 --- a/makefiles/vs71/test_lib_json.vcproj +++ b/makefiles/vs71/test_lib_json.vcproj @@ -1,130 +1,130 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 8644269675deeed309e8befa76e812d226b470b0 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sun, 9 Aug 2015 15:53:23 -0700 Subject: [PATCH 34/54] normalized some windows VS stuff --- devtools/agent_vmw7.json | 10 +++++----- devtools/agent_vmxp.json | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/devtools/agent_vmw7.json b/devtools/agent_vmw7.json index 0810a9954..cd7b777fe 100644 --- a/devtools/agent_vmw7.json +++ b/devtools/agent_vmw7.json @@ -10,12 +10,12 @@ "Visual Studio 10 Win64", "Visual Studio 11", "Visual Studio 11 Win64" - ] + ] }, - {"generator": ["MinGW Makefiles"], + {"generator": ["MinGW Makefiles"], "env_prepend": [{"path": "c:/wut/prg/MinGW/bin"}] } - ] + ] }, {"name": "shared_dll", "variables": [ @@ -25,8 +25,8 @@ }, {"name": "build_type", "build_types": [ - "debug", - "release" + "debug", + "release" ] } ] diff --git a/devtools/agent_vmxp.json b/devtools/agent_vmxp.json index b627a7221..f82a0773a 100644 --- a/devtools/agent_vmxp.json +++ b/devtools/agent_vmxp.json @@ -6,9 +6,9 @@ "Visual Studio 6", "Visual Studio 7", "Visual Studio 8 2005" - ] + ] } - ] + ] }, {"name": "shared_dll", "variables": [ @@ -18,8 +18,8 @@ }, {"name": "build_type", "build_types": [ - "debug", - "release" + "debug", + "release" ] } ] From 1380aff5952a3f4b016900bb22f012914a7d6001 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sun, 9 Aug 2015 15:42:06 -0700 Subject: [PATCH 35/54] add .gitattributes helps #325 --- .gitattributes | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitattributes b/.gitattributes index 63e493a05..22d2b7a45 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,6 +1,11 @@ * text=auto +*.h text +*.cpp text +*.json text +*.in text *.sh eol=lf *.bat eol=crlf *.vcproj eol=crlf *.vcxproj eol=crlf *.sln eol=crlf +devtools/agent_vm* eol=crlf From 22dade5c97b805fc216e6d61d18c5e9e1110583e Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Thu, 6 Aug 2015 10:17:09 -0500 Subject: [PATCH 36/54] Clean up cmake END* * Clean up closing statements for if conditions, functions, macros, and other entities. Newer versions of CMake do not require you to redundantly respecify the parameters to the opening arguments. --- CMakeLists.txt | 22 +++++++++++----------- src/CMakeLists.txt | 2 +- src/jsontestrunner/CMakeLists.txt | 4 ++-- src/lib_json/CMakeLists.txt | 6 +++--- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e8a8a8787..2cac978ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,8 +18,8 @@ IF(NOT WIN32) SET(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Coverage." FORCE) - ENDIF(NOT CMAKE_BUILD_TYPE) -ENDIF(NOT WIN32) + ENDIF() +ENDIF() SET(DEBUG_LIBNAME_SUFFIX "" CACHE STRING "Optional suffix to append to the library name for a debug build") SET(LIB_SUFFIX "" CACHE STRING "Optional arch-dependent suffix for the library installation directory") @@ -39,7 +39,7 @@ MARK_AS_ADVANCED( RUNTIME_INSTALL_DIR ARCHIVE_INSTALL_DIR INCLUDE_INSTALL_DIR PA # Set variable named ${VAR_NAME} to value ${VALUE} FUNCTION(set_using_dynamic_name VAR_NAME VALUE) SET( "${VAR_NAME}" "${VALUE}" PARENT_SCOPE) -ENDFUNCTION(set_using_dynamic_name) +ENDFUNCTION() # Extract major, minor, patch from version text # Parse a version string "X.Y.Z" and outputs @@ -55,8 +55,8 @@ MACRO(jsoncpp_parse_version VERSION_TEXT OUPUT_PREFIX) set_using_dynamic_name( "${OUPUT_PREFIX}_FOUND" TRUE ) ELSE( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} ) set_using_dynamic_name( "${OUPUT_PREFIX}_FOUND" FALSE ) - ENDIF( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} ) -ENDMACRO(jsoncpp_parse_version) + ENDIF() +ENDMACRO() # Read out version from "version" file #FILE(STRINGS "version" JSONCPP_VERSION) @@ -83,7 +83,7 @@ macro(UseCompilationWarningAsError) # Only enabled in debug because some old versions of VS STL generate # warnings when compiled in release configuration. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /WX ") - endif( MSVC ) + endif() endmacro() # Include our configuration header @@ -93,12 +93,12 @@ if ( MSVC ) # Only enabled in debug because some old versions of VS STL generate # unreachable code warning when compiled in release configuration. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W4 ") -endif( MSVC ) +endif() if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") # using regular Clang or AppleClang set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Werror -Wall -Wshadow -Wshorten-64-to-32") -elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") +elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # using GCC set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wshadow -Wextra -pedantic -Wno-long-long") # not yet ready for -Wsign-conversion @@ -106,7 +106,7 @@ endif() IF(JSONCPP_WITH_WARNING_AS_ERROR) UseCompilationWarningAsError() -ENDIF(JSONCPP_WITH_WARNING_AS_ERROR) +ENDIF() IF(JSONCPP_WITH_PKGCONFIG_SUPPORT) CONFIGURE_FILE( @@ -115,13 +115,13 @@ IF(JSONCPP_WITH_PKGCONFIG_SUPPORT) @ONLY) INSTALL(FILES "${CMAKE_BINARY_DIR}/pkg-config/jsoncpp.pc" DESTINATION "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/pkgconfig") -ENDIF(JSONCPP_WITH_PKGCONFIG_SUPPORT) +ENDIF() IF(JSONCPP_WITH_CMAKE_PACKAGE) INSTALL(EXPORT jsoncpp DESTINATION ${PACKAGE_INSTALL_DIR}/jsoncpp FILE jsoncppConfig.cmake) -ENDIF(JSONCPP_WITH_CMAKE_PACKAGE) +ENDIF() # Build the different applications ADD_SUBDIRECTORY( src ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 608d3f7b6..ca8ac15e2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,4 +2,4 @@ ADD_SUBDIRECTORY(lib_json) IF(JSONCPP_WITH_TESTS) ADD_SUBDIRECTORY(jsontestrunner) ADD_SUBDIRECTORY(test_lib_json) -ENDIF(JSONCPP_WITH_TESTS) +ENDIF() diff --git a/src/jsontestrunner/CMakeLists.txt b/src/jsontestrunner/CMakeLists.txt index 820a7cd35..20d01e626 100644 --- a/src/jsontestrunner/CMakeLists.txt +++ b/src/jsontestrunner/CMakeLists.txt @@ -9,7 +9,7 @@ IF(BUILD_SHARED_LIBS) TARGET_LINK_LIBRARIES(jsontestrunner_exe jsoncpp_lib) ELSE(BUILD_SHARED_LIBS) TARGET_LINK_LIBRARIES(jsontestrunner_exe jsoncpp_lib_static) -ENDIF(BUILD_SHARED_LIBS) +ENDIF() SET_TARGET_PROPERTIES(jsontestrunner_exe PROPERTIES OUTPUT_NAME jsontestrunner_exe) @@ -22,4 +22,4 @@ IF(PYTHONINTERP_FOUND) DEPENDS jsontestrunner_exe jsoncpp_test ) ADD_CUSTOM_TARGET(jsoncpp_check DEPENDS jsoncpp_readerwriter_tests) -ENDIF(PYTHONINTERP_FOUND) +ENDIF() diff --git a/src/lib_json/CMakeLists.txt b/src/lib_json/CMakeLists.txt index 79ffa2ec5..99ddc7f8b 100644 --- a/src/lib_json/CMakeLists.txt +++ b/src/lib_json/CMakeLists.txt @@ -37,7 +37,7 @@ IF(JSONCPP_WITH_CMAKE_PACKAGE) SET(INSTALL_EXPORT EXPORT jsoncpp) ELSE(JSONCPP_WITH_CMAKE_PACKAGE) SET(INSTALL_EXPORT) -ENDIF(JSONCPP_WITH_CMAKE_PACKAGE) +ENDIF() IF(BUILD_SHARED_LIBS) ADD_DEFINITIONS( -DJSON_DLL_BUILD ) @@ -55,7 +55,7 @@ IF(BUILD_SHARED_LIBS) TARGET_INCLUDE_DIRECTORIES( jsoncpp_lib PUBLIC $ $) - ENDIF(NOT CMAKE_VERSION VERSION_LESS 2.8.11) + ENDIF() ENDIF() @@ -75,6 +75,6 @@ IF(BUILD_STATIC_LIBS) $ $ ) - ENDIF(NOT CMAKE_VERSION VERSION_LESS 2.8.11) + ENDIF() ENDIF() From 8bdb07dd52166e43bbfac971ad4761ab5e1d2ba8 Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Thu, 6 Aug 2015 10:17:09 -0500 Subject: [PATCH 37/54] Clean up cmake END* (again) (I missed a couple. ~cd) --- src/test_lib_json/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test_lib_json/CMakeLists.txt b/src/test_lib_json/CMakeLists.txt index f54c85f68..7000264a7 100644 --- a/src/test_lib_json/CMakeLists.txt +++ b/src/test_lib_json/CMakeLists.txt @@ -12,7 +12,7 @@ IF(BUILD_SHARED_LIBS) TARGET_LINK_LIBRARIES(jsoncpp_test jsoncpp_lib) ELSE(BUILD_SHARED_LIBS) TARGET_LINK_LIBRARIES(jsoncpp_test jsoncpp_lib_static) -ENDIF(BUILD_SHARED_LIBS) +ENDIF() # another way to solve issue #90 #set_target_properties(jsoncpp_test PROPERTIES COMPILE_FLAGS -ffloat-store) @@ -32,7 +32,7 @@ IF(JSONCPP_WITH_POST_BUILD_UNITTEST) ADD_CUSTOM_COMMAND( TARGET jsoncpp_test POST_BUILD COMMAND $) - ENDIF(BUILD_SHARED_LIBS) -ENDIF(JSONCPP_WITH_POST_BUILD_UNITTEST) + ENDIF() +ENDIF() SET_TARGET_PROPERTIES(jsoncpp_test PROPERTIES OUTPUT_NAME jsoncpp_test) From a7b80fea658413a803fe6a30b28e87e76eda4fe1 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Fri, 21 Aug 2015 20:45:37 -0500 Subject: [PATCH 38/54] Merge pull request #337 from AMDmi3/patch-1 Specify float constant as float --- src/test_lib_json/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test_lib_json/main.cpp b/src/test_lib_json/main.cpp index 3d3188862..ce6dc85d4 100644 --- a/src/test_lib_json/main.cpp +++ b/src/test_lib_json/main.cpp @@ -1257,7 +1257,7 @@ JSONTEST_FIXTURE(ValueTest, nonIntegers) { // A 16-digit floating point number. val = Json::Value(2199023255552000.0f); - JSONTEST_ASSERT_EQUAL(float(2199023255552000), val.asFloat()); + JSONTEST_ASSERT_EQUAL(float(2199023255552000.0f), val.asFloat()); JSONTEST_ASSERT_STRING_EQUAL("2199023255552000", normalizeFloatingPointStr(val.asString())); From a4354d782bec0ab405f08d7193aeffc1a48f3be0 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sat, 5 Sep 2015 11:59:54 -0500 Subject: [PATCH 39/54] Merge pull request #339 from Dani-Hub/master MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Floating-point NaN or Infinity values should be allowed as a feature … --- include/json/reader.h | 3 ++ include/json/writer.h | 4 ++ src/lib_json/json_reader.cpp | 92 +++++++++++++++++++++++-------- src/lib_json/json_writer.cpp | 49 +++++++++-------- src/test_lib_json/main.cpp | 101 ++++++++++++++++++++++++++++++++++- 5 files changed, 205 insertions(+), 44 deletions(-) diff --git a/include/json/reader.h b/include/json/reader.h index e1bd62967..9c9923a55 100644 --- a/include/json/reader.h +++ b/include/json/reader.h @@ -277,6 +277,9 @@ class JSON_API CharReaderBuilder : public CharReader::Factory { the JSON value in the input string. - `"rejectDupKeys": false or true` - If true, `parse()` returns false when a key is duplicated within an object. + - `"allowSpecialFloats": false or true` + - If true, special float values (NaNs and infinities) are allowed + and their values are lossfree restorable. You can examine 'settings_` yourself to see the defaults. You can also write and read them just like any diff --git a/include/json/writer.h b/include/json/writer.h index 2da72b688..a7fd11d2f 100644 --- a/include/json/writer.h +++ b/include/json/writer.h @@ -99,6 +99,10 @@ class JSON_API StreamWriterBuilder : public StreamWriter::Factory { Strictly speaking, this is not valid JSON. But when the output is being fed to a browser's Javascript, it makes for smaller output and the browser can handle the output just fine. + - "useSpecialFloats": false or true + - If true, outputs non-finite floating point values in the following way: + NaN values as "NaN", positive infinity as "Infinity", and negative infinity + as "-Infinity". You can examine 'settings_` yourself to see the defaults. You can also write and read them just like any diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index d76b8ebc8..53528f210 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -17,10 +17,21 @@ #include #include #include +#include -#if defined(_MSC_VER) && _MSC_VER < 1500 // VC++ 8.0 and below +#if defined(_MSC_VER) +#if !defined(WINCE) && defined(__STDC_SECURE_LIB__) && _MSC_VER >= 1500 // VC++ 9.0 and above +#define snprintf sprintf_s +#elif _MSC_VER >= 1900 // VC++ 14.0 and above +#define snprintf std::snprintf +#else #define snprintf _snprintf #endif +#elif defined(__ANDROID__) +#define snprintf snprintf +#elif __cplusplus >= 201103L +#define snprintf std::snprintf +#endif #if defined(_MSC_VER) && _MSC_VER >= 1400 // VC++ 8.0 // Disable warning about strdup being deprecated. @@ -753,15 +764,7 @@ std::string Reader::getLocationLineAndColumn(Location location) const { int line, column; getLocationLineAndColumn(location, line, column); char buffer[18 + 16 + 16 + 1]; -#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__) -#if defined(WINCE) - _snprintf(buffer, sizeof(buffer), "Line %d, Column %d", line, column); -#else - sprintf_s(buffer, sizeof(buffer), "Line %d, Column %d", line, column); -#endif -#else snprintf(buffer, sizeof(buffer), "Line %d, Column %d", line, column); -#endif return buffer; } @@ -801,6 +804,7 @@ class OurFeatures { bool allowSingleQuotes_; bool failIfExtra_; bool rejectDupKeys_; + bool allowSpecialFloats_; int stackLimit_; }; // OurFeatures @@ -812,6 +816,7 @@ OurFeatures::OurFeatures() , allowDroppedNullPlaceholders_(false), allowNumericKeys_(false) , allowSingleQuotes_(false) , failIfExtra_(false) + , allowSpecialFloats_(false) { } @@ -853,6 +858,9 @@ class OurReader { tokenTrue, tokenFalse, tokenNull, + tokenNaN, + tokenPosInf, + tokenNegInf, tokenArraySeparator, tokenMemberSeparator, tokenComment, @@ -883,7 +891,7 @@ class OurReader { bool readCppStyleComment(); bool readString(); bool readStringSingleQuote(); - void readNumber(); + bool readNumber(bool checkInf); bool readValue(); bool readObject(Token& token); bool readArray(Token& token); @@ -1029,6 +1037,24 @@ bool OurReader::readValue() { currentValue().swapPayload(v); } break; + case tokenNaN: + { + Value v(std::numeric_limits::quiet_NaN()); + currentValue().swapPayload(v); + } + break; + case tokenPosInf: + { + Value v(std::numeric_limits::infinity()); + currentValue().swapPayload(v); + } + break; + case tokenNegInf: + { + Value v(-std::numeric_limits::infinity()); + currentValue().swapPayload(v); + } + break; case tokenArraySeparator: case tokenObjectEnd: case tokenArrayEnd: @@ -1105,9 +1131,16 @@ bool OurReader::readToken(Token& token) { case '7': case '8': case '9': - case '-': token.type_ = tokenNumber; - readNumber(); + readNumber(false); + break; + case '-': + if (readNumber(true)) { + token.type_ = tokenNumber; + } else { + token.type_ = tokenNegInf; + ok = features_.allowSpecialFloats_ && match("nfinity", 7); + } break; case 't': token.type_ = tokenTrue; @@ -1121,6 +1154,22 @@ bool OurReader::readToken(Token& token) { token.type_ = tokenNull; ok = match("ull", 3); break; + case 'N': + if (features_.allowSpecialFloats_) { + token.type_ = tokenNaN; + ok = match("aN", 2); + } else { + ok = false; + } + break; + case 'I': + if (features_.allowSpecialFloats_) { + token.type_ = tokenPosInf; + ok = match("nfinity", 7); + } else { + ok = false; + } + break; case ',': token.type_ = tokenArraySeparator; break; @@ -1221,8 +1270,12 @@ bool OurReader::readCppStyleComment() { return true; } -void OurReader::readNumber() { +bool OurReader::readNumber(bool checkInf) { const char *p = current_; + if (checkInf && p != end_ && *p == 'I') { + current_ = ++p; + return false; + } char c = '0'; // stopgap for already consumed character // integral part while (c >= '0' && c <= '9') @@ -1241,6 +1294,7 @@ void OurReader::readNumber() { while (c >= '0' && c <= '9') c = (current_ = p) < end_ ? *p++ : 0; } + return true; } bool OurReader::readString() { Char c = 0; @@ -1641,15 +1695,7 @@ std::string OurReader::getLocationLineAndColumn(Location location) const { int line, column; getLocationLineAndColumn(location, line, column); char buffer[18 + 16 + 16 + 1]; -#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__) -#if defined(WINCE) - _snprintf(buffer, sizeof(buffer), "Line %d, Column %d", line, column); -#else - sprintf_s(buffer, sizeof(buffer), "Line %d, Column %d", line, column); -#endif -#else snprintf(buffer, sizeof(buffer), "Line %d, Column %d", line, column); -#endif return buffer; } @@ -1709,6 +1755,7 @@ CharReader* CharReaderBuilder::newCharReader() const features.stackLimit_ = settings_["stackLimit"].asInt(); features.failIfExtra_ = settings_["failIfExtra"].asBool(); features.rejectDupKeys_ = settings_["rejectDupKeys"].asBool(); + features.allowSpecialFloats_ = settings_["allowSpecialFloats"].asBool(); return new OurCharReader(collectComments, features); } static void getValidReaderKeys(std::set* valid_keys) @@ -1723,6 +1770,7 @@ static void getValidReaderKeys(std::set* valid_keys) valid_keys->insert("stackLimit"); valid_keys->insert("failIfExtra"); valid_keys->insert("rejectDupKeys"); + valid_keys->insert("allowSpecialFloats"); } bool CharReaderBuilder::validate(Json::Value* invalid) const { @@ -1756,6 +1804,7 @@ void CharReaderBuilder::strictMode(Json::Value* settings) (*settings)["allowSingleQuotes"] = false; (*settings)["failIfExtra"] = true; (*settings)["rejectDupKeys"] = true; + (*settings)["allowSpecialFloats"] = false; //! [CharReaderBuilderStrictMode] } // static @@ -1771,6 +1820,7 @@ void CharReaderBuilder::setDefaults(Json::Value* settings) (*settings)["stackLimit"] = 1000; (*settings)["failIfExtra"] = false; (*settings)["rejectDupKeys"] = false; + (*settings)["allowSpecialFloats"] = false; //! [CharReaderBuilderDefaults] } diff --git a/src/lib_json/json_writer.cpp b/src/lib_json/json_writer.cpp index 33f5b0478..892fb378b 100644 --- a/src/lib_json/json_writer.cpp +++ b/src/lib_json/json_writer.cpp @@ -27,8 +27,14 @@ #define isfinite std::isfinite #endif -#if defined(_MSC_VER) && _MSC_VER < 1500 // VC++ 8.0 and below +#if defined(_MSC_VER) +#if !defined(WINCE) && defined(__STDC_SECURE_LIB__) && _MSC_VER >= 1500 // VC++ 9.0 and above +#define snprintf sprintf_s +#elif _MSC_VER >= 1900 // VC++ 14.0 and above +#define snprintf std::snprintf +#else #define snprintf _snprintf +#endif #elif defined(__ANDROID__) #define snprintf snprintf #elif __cplusplus >= 201103L @@ -104,43 +110,35 @@ std::string valueToString(UInt value) { #endif // # if defined(JSON_HAS_INT64) -std::string valueToString(double value) { +std::string valueToString(double value, bool useSpecialFloats) { // Allocate a buffer that is more than large enough to store the 16 digits of // precision requested below. char buffer[32]; int len = -1; -// Print into the buffer. We need not request the alternative representation -// that always has a decimal point because JSON doesn't distingish the -// concepts of reals and integers. -#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__) // Use secure version with - // visual studio 2005 to - // avoid warning. -#if defined(WINCE) - len = _snprintf(buffer, sizeof(buffer), "%.17g", value); -#else - len = sprintf_s(buffer, sizeof(buffer), "%.17g", value); -#endif -#else + // Print into the buffer. We need not request the alternative representation + // that always has a decimal point because JSON doesn't distingish the + // concepts of reals and integers. if (isfinite(value)) { len = snprintf(buffer, sizeof(buffer), "%.17g", value); } else { // IEEE standard states that NaN values will not compare to themselves if (value != value) { - len = snprintf(buffer, sizeof(buffer), "null"); + len = snprintf(buffer, sizeof(buffer), useSpecialFloats ? "NaN" : "null"); } else if (value < 0) { - len = snprintf(buffer, sizeof(buffer), "-1e+9999"); + len = snprintf(buffer, sizeof(buffer), useSpecialFloats ? "-Infinity" : "-1e+9999"); } else { - len = snprintf(buffer, sizeof(buffer), "1e+9999"); + len = snprintf(buffer, sizeof(buffer), useSpecialFloats ? "Infinity" : "1e+9999"); } // For those, we do not need to call fixNumLoc, but it is fast. } -#endif assert(len >= 0); fixNumericLocale(buffer, buffer + len); return buffer; } +std::string valueToString(double value) { return valueToString(value, false); } + std::string valueToString(bool value) { return value ? "true" : "false"; } std::string valueToQuotedString(const char* value) { @@ -805,7 +803,8 @@ struct BuiltStyledStreamWriter : public StreamWriter CommentStyle::Enum cs, std::string const& colonSymbol, std::string const& nullSymbol, - std::string const& endingLineFeedSymbol); + std::string const& endingLineFeedSymbol, + bool useSpecialFloats); virtual int write(Value const& root, std::ostream* sout); private: void writeValue(Value const& value); @@ -832,13 +831,15 @@ struct BuiltStyledStreamWriter : public StreamWriter std::string endingLineFeedSymbol_; bool addChildValues_ : 1; bool indented_ : 1; + bool useSpecialFloats_ : 1; }; BuiltStyledStreamWriter::BuiltStyledStreamWriter( std::string const& indentation, CommentStyle::Enum cs, std::string const& colonSymbol, std::string const& nullSymbol, - std::string const& endingLineFeedSymbol) + std::string const& endingLineFeedSymbol, + bool useSpecialFloats) : rightMargin_(74) , indentation_(indentation) , cs_(cs) @@ -847,6 +848,7 @@ BuiltStyledStreamWriter::BuiltStyledStreamWriter( , endingLineFeedSymbol_(endingLineFeedSymbol) , addChildValues_(false) , indented_(false) + , useSpecialFloats_(useSpecialFloats) { } int BuiltStyledStreamWriter::write(Value const& root, std::ostream* sout) @@ -876,7 +878,7 @@ void BuiltStyledStreamWriter::writeValue(Value const& value) { pushValue(valueToString(value.asLargestUInt())); break; case realValue: - pushValue(valueToString(value.asDouble())); + pushValue(valueToString(value.asDouble(), useSpecialFloats_)); break; case stringValue: { @@ -1091,6 +1093,7 @@ StreamWriter* StreamWriterBuilder::newStreamWriter() const std::string cs_str = settings_["commentStyle"].asString(); bool eyc = settings_["enableYAMLCompatibility"].asBool(); bool dnp = settings_["dropNullPlaceholders"].asBool(); + bool usf = settings_["useSpecialFloats"].asBool(); CommentStyle::Enum cs = CommentStyle::All; if (cs_str == "All") { cs = CommentStyle::All; @@ -1112,7 +1115,7 @@ StreamWriter* StreamWriterBuilder::newStreamWriter() const std::string endingLineFeedSymbol = ""; return new BuiltStyledStreamWriter( indentation, cs, - colonSymbol, nullSymbol, endingLineFeedSymbol); + colonSymbol, nullSymbol, endingLineFeedSymbol, usf); } static void getValidWriterKeys(std::set* valid_keys) { @@ -1121,6 +1124,7 @@ static void getValidWriterKeys(std::set* valid_keys) valid_keys->insert("commentStyle"); valid_keys->insert("enableYAMLCompatibility"); valid_keys->insert("dropNullPlaceholders"); + valid_keys->insert("useSpecialFloats"); } bool StreamWriterBuilder::validate(Json::Value* invalid) const { @@ -1151,6 +1155,7 @@ void StreamWriterBuilder::setDefaults(Json::Value* settings) (*settings)["indentation"] = "\t"; (*settings)["enableYAMLCompatibility"] = false; (*settings)["dropNullPlaceholders"] = false; + (*settings)["useSpecialFloats"] = false; //! [StreamWriterBuilderDefaults] } diff --git a/src/test_lib_json/main.cpp b/src/test_lib_json/main.cpp index ce6dc85d4..12c91179e 100644 --- a/src/test_lib_json/main.cpp +++ b/src/test_lib_json/main.cpp @@ -7,6 +7,7 @@ #include #include #include +#include // Make numeric limits more convenient to talk about. // Assumes int type in 32 bits. @@ -1635,6 +1636,26 @@ JSONTEST_FIXTURE(ValueTest, zeroesInKeys) { } } +JSONTEST_FIXTURE(ValueTest, specialFloats) { + Json::StreamWriterBuilder b; + b.settings_["useSpecialFloats"] = true; + + Json::Value v = std::numeric_limits::quiet_NaN(); + std::string expected = "NaN"; + std::string result = Json::writeString(b, v); + JSONTEST_ASSERT_STRING_EQUAL(expected, result); + + v = std::numeric_limits::infinity(); + expected = "Infinity"; + result = Json::writeString(b, v); + JSONTEST_ASSERT_STRING_EQUAL(expected, result); + + v = -std::numeric_limits::infinity(); + expected = "-Infinity"; + result = Json::writeString(b, v); + JSONTEST_ASSERT_STRING_EQUAL(expected, result); +} + struct StreamWriterTest : JsonTest::TestCase {}; JSONTEST_FIXTURE(StreamWriterTest, dropNullPlaceholders) { @@ -1857,7 +1878,7 @@ JSONTEST_FIXTURE(CharReaderStrictModeTest, dupKeys) { struct CharReaderFailIfExtraTest : JsonTest::TestCase {}; JSONTEST_FIXTURE(CharReaderFailIfExtraTest, issue164) { - // This is interpretted as a string value followed by a colon. + // This is interpreted as a string value followed by a colon. Json::CharReaderBuilder b; Json::Value root; char const doc[] = @@ -2192,6 +2213,81 @@ JSONTEST_FIXTURE(CharReaderAllowZeroesTest, issue176) { delete reader; } +struct CharReaderAllowSpecialFloatsTest : JsonTest::TestCase {}; + +JSONTEST_FIXTURE(CharReaderAllowSpecialFloatsTest, issue209) { + Json::CharReaderBuilder b; + b.settings_["allowSpecialFloats"] = true; + Json::Value root; + std::string errs; + Json::CharReader* reader(b.newCharReader()); + { + char const doc[] = "{\"a\":NaN,\"b\":Infinity,\"c\":-Infinity}"; + bool ok = reader->parse( + doc, doc + std::strlen(doc), + &root, &errs); + JSONTEST_ASSERT(ok); + JSONTEST_ASSERT_STRING_EQUAL("", errs); + JSONTEST_ASSERT_EQUAL(3u, root.size()); + double n = root["a"].asDouble(); + JSONTEST_ASSERT(n != n); + JSONTEST_ASSERT_EQUAL(std::numeric_limits::infinity(), root.get("b", 0.0)); + JSONTEST_ASSERT_EQUAL(-std::numeric_limits::infinity(), root.get("c", 0.0)); + } + + struct TestData { + int line; + bool ok; + std::string in; + }; + const TestData test_data[] = { + {__LINE__, 1, "{\"a\":9}"}, + {__LINE__, 0, "{\"a\":0Infinity}"}, + {__LINE__, 0, "{\"a\":1Infinity}"}, + {__LINE__, 0, "{\"a\":9Infinity}"}, + {__LINE__, 0, "{\"a\":0nfinity}"}, + {__LINE__, 0, "{\"a\":1nfinity}"}, + {__LINE__, 0, "{\"a\":9nfinity}"}, + {__LINE__, 0, "{\"a\":nfinity}"}, + {__LINE__, 0, "{\"a\":.nfinity}"}, + {__LINE__, 0, "{\"a\":9nfinity}"}, + {__LINE__, 0, "{\"a\":-nfinity}"}, + {__LINE__, 1, "{\"a\":Infinity}"}, + {__LINE__, 0, "{\"a\":.Infinity}"}, + {__LINE__, 0, "{\"a\":_Infinity}"}, + {__LINE__, 0, "{\"a\":_nfinity}"}, + {__LINE__, 1, "{\"a\":-Infinity}"} + }; + for (size_t tdi = 0; tdi < sizeof(test_data) / sizeof(*test_data); ++tdi) { + const TestData& td = test_data[tdi]; + bool ok = reader->parse(&*td.in.begin(), + &*td.in.begin() + td.in.size(), + &root, &errs); + JSONTEST_ASSERT(td.ok == ok) + << "line:" << td.line << "\n" + << " expected: {" + << "ok:" << td.ok + << ", in:\'" << td.in << "\'" + << "}\n" + << " actual: {" + << "ok:" << ok + << "}\n"; + } + + { + char const doc[] = "{\"posInf\": Infinity, \"NegInf\": -Infinity}"; + bool ok = reader->parse( + doc, doc + std::strlen(doc), + &root, &errs); + JSONTEST_ASSERT(ok); + JSONTEST_ASSERT_STRING_EQUAL("", errs); + JSONTEST_ASSERT_EQUAL(2u, root.size()); + JSONTEST_ASSERT_EQUAL(std::numeric_limits::infinity(), root["posInf"].asDouble()); + JSONTEST_ASSERT_EQUAL(-std::numeric_limits::infinity(), root["NegInf"].asDouble()); + } + delete reader; +} + struct BuilderTest : JsonTest::TestCase {}; JSONTEST_FIXTURE(BuilderTest, settings) { @@ -2294,6 +2390,7 @@ int main(int argc, const char* argv[]) { //JSONTEST_REGISTER_FIXTURE(runner, ValueTest, nulls); JSONTEST_REGISTER_FIXTURE(runner, ValueTest, zeroes); JSONTEST_REGISTER_FIXTURE(runner, ValueTest, zeroesInKeys); + JSONTEST_REGISTER_FIXTURE(runner, ValueTest, specialFloats); JSONTEST_REGISTER_FIXTURE(runner, StreamWriterTest, dropNullPlaceholders); JSONTEST_REGISTER_FIXTURE(runner, StreamWriterTest, writeZeroes); @@ -2327,6 +2424,8 @@ int main(int argc, const char* argv[]) { JSONTEST_REGISTER_FIXTURE(runner, CharReaderAllowZeroesTest, issue176); + JSONTEST_REGISTER_FIXTURE(runner, CharReaderAllowSpecialFloatsTest, issue209); + JSONTEST_REGISTER_FIXTURE(runner, BuilderTest, settings); JSONTEST_REGISTER_FIXTURE(runner, IteratorTest, distance); From 0ea25978d536a13022d67a92467f55e77e55cd1f Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sat, 6 Feb 2016 07:55:27 -0600 Subject: [PATCH 40/54] 0004-fix-include-path.patch --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2cac978ce..517cf62c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,7 +30,7 @@ SET(ARCHIVE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX} CACHE PATH "Install dir for static libraries") SET(LIBRARY_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX} CACHE PATH "Install dir for shared libraries") -SET(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include +SET(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include/jsoncpp CACHE PATH "Install dir for headers") SET(PACKAGE_INSTALL_DIR lib${LIB_SUFFIX}/cmake CACHE PATH "Install dir for cmake package config files") From eec67941061a54be397dc3a4b61839cb88b7184c Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sat, 6 Feb 2016 08:03:34 -0600 Subject: [PATCH 41/54] fix-double-parsing.patch --- src/lib_json/json_reader.cpp | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index 53528f210..a32d18464 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -1477,33 +1477,9 @@ bool OurReader::decodeDouble(Token& token) { bool OurReader::decodeDouble(Token& token, Value& decoded) { double value = 0; - const int bufferSize = 32; - int count; - int length = int(token.end_ - token.start_); - - // Sanity check to avoid buffer overflow exploits. - if (length < 0) { - return addError("Unable to parse token length", token); - } - - // Avoid using a string constant for the format control string given to - // sscanf, as this can cause hard to debug crashes on OS X. See here for more - // info: - // - // http://developer.apple.com/library/mac/#DOCUMENTATION/DeveloperTools/gcc-4.0.1/gcc/Incompatibilities.html - char format[] = "%lf"; - - if (length <= bufferSize) { - Char buffer[bufferSize + 1]; - memcpy(buffer, token.start_, length); - buffer[length] = 0; - count = sscanf(buffer, format, &value); - } else { - std::string buffer(token.start_, token.end_); - count = sscanf(buffer.c_str(), format, &value); - } - - if (count != 1) + std::string buffer( token.start_, token.end_ ); + std::istringstream is(buffer); + if (!(is >> value)) return addError("'" + std::string(token.start_, token.end_) + "' is not a number.", token); From ecfd658e6a9a3578748b9fe6f08c4d6f92d3f255 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sat, 6 Feb 2016 08:04:11 -0600 Subject: [PATCH 42/54] 0003-fix-arm.patch Already applied to 0.y.x branch. From dde8426ded8f35d4ab98b6c5833249fe2ef84ee6 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sat, 6 Feb 2016 08:08:49 -0600 Subject: [PATCH 43/54] 0001-multiarch-path-support.patch --- CMakeLists.txt | 4 +++- src/lib_json/CMakeLists.txt | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 517cf62c1..25af1236a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,8 @@ OPTION(JSONCPP_WITH_CMAKE_PACKAGE "Generate and install cmake package files" OFF OPTION(BUILD_SHARED_LIBS "Build jsoncpp_lib as a shared library." OFF) OPTION(BUILD_STATIC_LIBS "Build jsoncpp_lib static library." ON) +include(GNUInstallDirs) + # Ensures that CMAKE_BUILD_TYPE is visible in cmake-gui on Unix IF(NOT WIN32) IF(NOT CMAKE_BUILD_TYPE) @@ -114,7 +116,7 @@ IF(JSONCPP_WITH_PKGCONFIG_SUPPORT) "pkg-config/jsoncpp.pc" @ONLY) INSTALL(FILES "${CMAKE_BINARY_DIR}/pkg-config/jsoncpp.pc" - DESTINATION "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/pkgconfig") + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") ENDIF() IF(JSONCPP_WITH_CMAKE_PACKAGE) diff --git a/src/lib_json/CMakeLists.txt b/src/lib_json/CMakeLists.txt index 99ddc7f8b..5861f035e 100644 --- a/src/lib_json/CMakeLists.txt +++ b/src/lib_json/CMakeLists.txt @@ -48,8 +48,8 @@ IF(BUILD_SHARED_LIBS) INSTALL( TARGETS jsoncpp_lib ${INSTALL_EXPORT} RUNTIME DESTINATION ${RUNTIME_INSTALL_DIR} - LIBRARY DESTINATION ${LIBRARY_INSTALL_DIR} - ARCHIVE DESTINATION ${ARCHIVE_INSTALL_DIR}) + LIBRARY DESTINATION "${LIBRARY_INSTALL_DIR}/${CMAKE_LIBRARY_ARCHITECTURE}" + ARCHIVE DESTINATION "${ARCHIVE_INSTALL_DIR}/${CMAKE_LIBRARY_ARCHITECTURE}") IF(NOT CMAKE_VERSION VERSION_LESS 2.8.11) TARGET_INCLUDE_DIRECTORIES( jsoncpp_lib PUBLIC @@ -67,8 +67,8 @@ IF(BUILD_STATIC_LIBS) INSTALL( TARGETS jsoncpp_lib_static ${INSTALL_EXPORT} RUNTIME DESTINATION ${RUNTIME_INSTALL_DIR} - LIBRARY DESTINATION ${LIBRARY_INSTALL_DIR} - ARCHIVE DESTINATION ${ARCHIVE_INSTALL_DIR}) + LIBRARY DESTINATION "${LIBRARY_INSTALL_DIR}/${CMAKE_LIBRARY_ARCHITECTURE}" + ARCHIVE DESTINATION "${ARCHIVE_INSTALL_DIR}/${CMAKE_LIBRARY_ARCHITECTURE}") IF(NOT CMAKE_VERSION VERSION_LESS 2.8.11) TARGET_INCLUDE_DIRECTORIES( jsoncpp_lib_static PUBLIC From e105003bb5cc6eea8b65d43386d0d6fd81657d5c Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sat, 6 Feb 2016 08:24:20 -0600 Subject: [PATCH 44/54] gcc-6 lacks auto_ptr<> --- src/lib_json/json_reader.cpp | 6 +++++- src/lib_json/json_writer.cpp | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index a32d18464..290e0b150 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -43,7 +43,11 @@ static int stackDepth_g = 0; // see readValue() namespace Json { -typedef std::auto_ptr CharReaderPtr; +#if __GNUC__ >= 6 +typedef std::scoped_ptr const CharReaderPtr; +#else +typedef std::auto_ptr CharReaderPtr; +#endif // Implementation of class Features // //////////////////////////////// diff --git a/src/lib_json/json_writer.cpp b/src/lib_json/json_writer.cpp index 892fb378b..9b51e5a1f 100644 --- a/src/lib_json/json_writer.cpp +++ b/src/lib_json/json_writer.cpp @@ -54,7 +54,11 @@ namespace Json { -typedef std::auto_ptr StreamWriterPtr; +#if __GNUC__ >= 6 +typedef std::scoped_ptr const StreamWriterPtr; +#else +typedef std::auto_ptr StreamWriterPtr; +#endif static bool containsControlCharacter(const char* str) { while (*str) { From 2f9a6a682cceab257e9dd55d2ab20f9210a353b1 Mon Sep 17 00:00:00 2001 From: Benjamin Knecht Date: Thu, 15 Oct 2015 17:28:56 +0200 Subject: [PATCH 45/54] Create format string with sprintf. For now use hardcoded precision '17' for now --- src/lib_json/json_writer.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/lib_json/json_writer.cpp b/src/lib_json/json_writer.cpp index 9b51e5a1f..5060ebfff 100644 --- a/src/lib_json/json_writer.cpp +++ b/src/lib_json/json_writer.cpp @@ -114,17 +114,20 @@ std::string valueToString(UInt value) { #endif // # if defined(JSON_HAS_INT64) -std::string valueToString(double value, bool useSpecialFloats) { +std::string valueToString(double value, bool useSpecialFloats, int precision) { // Allocate a buffer that is more than large enough to store the 16 digits of // precision requested below. char buffer[32]; int len = -1; + char formatString[6]; + sprintf(formatString, "%%.%dg", precision); + // Print into the buffer. We need not request the alternative representation // that always has a decimal point because JSON doesn't distingish the // concepts of reals and integers. if (isfinite(value)) { - len = snprintf(buffer, sizeof(buffer), "%.17g", value); + len = snprintf(buffer, sizeof(buffer), formatString, value); } else { // IEEE standard states that NaN values will not compare to themselves if (value != value) { @@ -141,7 +144,7 @@ std::string valueToString(double value, bool useSpecialFloats) { return buffer; } -std::string valueToString(double value) { return valueToString(value, false); } +std::string valueToString(double value) { return valueToString(value, false, 17); } std::string valueToString(bool value) { return value ? "true" : "false"; } @@ -882,7 +885,7 @@ void BuiltStyledStreamWriter::writeValue(Value const& value) { pushValue(valueToString(value.asLargestUInt())); break; case realValue: - pushValue(valueToString(value.asDouble(), useSpecialFloats_)); + pushValue(valueToString(value.asDouble(), useSpecialFloats_, 17)); break; case stringValue: { From 4a984c24b59243eb002203a4a2292e0b7799e582 Mon Sep 17 00:00:00 2001 From: Benjamin Knecht Date: Thu, 15 Oct 2015 18:00:42 +0200 Subject: [PATCH 46/54] making precision unsigned int adding precision as settings value for StreamBuilder Conflicts: src/lib_json/json_writer.cpp --- src/lib_json/json_writer.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/lib_json/json_writer.cpp b/src/lib_json/json_writer.cpp index 5060ebfff..f2eb200a9 100644 --- a/src/lib_json/json_writer.cpp +++ b/src/lib_json/json_writer.cpp @@ -114,7 +114,7 @@ std::string valueToString(UInt value) { #endif // # if defined(JSON_HAS_INT64) -std::string valueToString(double value, bool useSpecialFloats, int precision) { +std::string valueToString(double value, bool useSpecialFloats, unsigned int precision) { // Allocate a buffer that is more than large enough to store the 16 digits of // precision requested below. char buffer[32]; @@ -811,7 +811,8 @@ struct BuiltStyledStreamWriter : public StreamWriter std::string const& colonSymbol, std::string const& nullSymbol, std::string const& endingLineFeedSymbol, - bool useSpecialFloats); + bool useSpecialFloats, + unsigned int precision); virtual int write(Value const& root, std::ostream* sout); private: void writeValue(Value const& value); @@ -839,6 +840,7 @@ struct BuiltStyledStreamWriter : public StreamWriter bool addChildValues_ : 1; bool indented_ : 1; bool useSpecialFloats_ : 1; + unsigned int precision_; }; BuiltStyledStreamWriter::BuiltStyledStreamWriter( std::string const& indentation, @@ -846,7 +848,8 @@ BuiltStyledStreamWriter::BuiltStyledStreamWriter( std::string const& colonSymbol, std::string const& nullSymbol, std::string const& endingLineFeedSymbol, - bool useSpecialFloats) + bool useSpecialFloats, + unsigned int precision) : rightMargin_(74) , indentation_(indentation) , cs_(cs) @@ -856,6 +859,7 @@ BuiltStyledStreamWriter::BuiltStyledStreamWriter( , addChildValues_(false) , indented_(false) , useSpecialFloats_(useSpecialFloats) + , precision_(precision) { } int BuiltStyledStreamWriter::write(Value const& root, std::ostream* sout) @@ -885,7 +889,7 @@ void BuiltStyledStreamWriter::writeValue(Value const& value) { pushValue(valueToString(value.asLargestUInt())); break; case realValue: - pushValue(valueToString(value.asDouble(), useSpecialFloats_, 17)); + pushValue(valueToString(value.asDouble(), useSpecialFloats_, precision_)); break; case stringValue: { @@ -1101,6 +1105,7 @@ StreamWriter* StreamWriterBuilder::newStreamWriter() const bool eyc = settings_["enableYAMLCompatibility"].asBool(); bool dnp = settings_["dropNullPlaceholders"].asBool(); bool usf = settings_["useSpecialFloats"].asBool(); + unsigned int pre = settings_["precision"].asUInt(); CommentStyle::Enum cs = CommentStyle::All; if (cs_str == "All") { cs = CommentStyle::All; @@ -1119,10 +1124,11 @@ StreamWriter* StreamWriterBuilder::newStreamWriter() const if (dnp) { nullSymbol = ""; } + if (pre > 17) pre = 17; std::string endingLineFeedSymbol = ""; return new BuiltStyledStreamWriter( indentation, cs, - colonSymbol, nullSymbol, endingLineFeedSymbol, usf); + colonSymbol, nullSymbol, endingLineFeedSymbol, usf, pre); } static void getValidWriterKeys(std::set* valid_keys) { @@ -1132,6 +1138,7 @@ static void getValidWriterKeys(std::set* valid_keys) valid_keys->insert("enableYAMLCompatibility"); valid_keys->insert("dropNullPlaceholders"); valid_keys->insert("useSpecialFloats"); + valid_keys->insert("precision"); } bool StreamWriterBuilder::validate(Json::Value* invalid) const { @@ -1163,6 +1170,7 @@ void StreamWriterBuilder::setDefaults(Json::Value* settings) (*settings)["enableYAMLCompatibility"] = false; (*settings)["dropNullPlaceholders"] = false; (*settings)["useSpecialFloats"] = false; + (*settings)["precision"] = 17; //! [StreamWriterBuilderDefaults] } From 0fc51120c07113bcf620d0022f33a90827efa462 Mon Sep 17 00:00:00 2001 From: Benjamin Knecht Date: Thu, 15 Oct 2015 18:32:24 +0200 Subject: [PATCH 47/54] Add test code for precision Conflicts: src/test_lib_json/main.cpp --- src/test_lib_json/main.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/test_lib_json/main.cpp b/src/test_lib_json/main.cpp index 12c91179e..b9ca9c290 100644 --- a/src/test_lib_json/main.cpp +++ b/src/test_lib_json/main.cpp @@ -1656,6 +1656,43 @@ JSONTEST_FIXTURE(ValueTest, specialFloats) { JSONTEST_ASSERT_STRING_EQUAL(expected, result); } +JSONTEST_FIXTURE(ValueTest, precision) { + Json::StreamWriterBuilder b; + b.settings_["precision"] = 5; + + Json::Value v = 100.0/3; + std::string expected = "33.333"; + std::string result = Json::writeString(b, v); + JSONTEST_ASSERT_STRING_EQUAL(expected, result); + + v = 0.25000000; + expected = "0.25"; + result = Json::writeString(b, v); + JSONTEST_ASSERT_STRING_EQUAL(expected, result); + + v = 0.2563456; + expected = "0.25635"; + result = Json::writeString(b, v); + JSONTEST_ASSERT_STRING_EQUAL(expected, result); + + b.settings_["precision"] = 1; + expected = "0.3"; + result = Json::writeString(b, v); + JSONTEST_ASSERT_STRING_EQUAL(expected, result); + + b.settings_["precision"] = 17; + v = 1234857476305.256345694873740545068; + expected = "1234857476305.2563"; + result = Json::writeString(b, v); + JSONTEST_ASSERT_STRING_EQUAL(expected, result); + + b.settings_["precision"] = 24; + v = 0.256345694873740545068; + expected = "0.25634569487374054"; + result = Json::writeString(b, v); + JSONTEST_ASSERT_STRING_EQUAL(expected, result); +} + struct StreamWriterTest : JsonTest::TestCase {}; JSONTEST_FIXTURE(StreamWriterTest, dropNullPlaceholders) { @@ -2391,6 +2428,7 @@ int main(int argc, const char* argv[]) { JSONTEST_REGISTER_FIXTURE(runner, ValueTest, zeroes); JSONTEST_REGISTER_FIXTURE(runner, ValueTest, zeroesInKeys); JSONTEST_REGISTER_FIXTURE(runner, ValueTest, specialFloats); + JSONTEST_REGISTER_FIXTURE(runner, ValueTest, precision); JSONTEST_REGISTER_FIXTURE(runner, StreamWriterTest, dropNullPlaceholders); JSONTEST_REGISTER_FIXTURE(runner, StreamWriterTest, writeZeroes); From 20564b3f0c745b775693f68dc7d1f1d089bcc0df Mon Sep 17 00:00:00 2001 From: Gaurav Date: Wed, 16 Mar 2016 11:22:18 +0530 Subject: [PATCH 48/54] NORETURN for throw functions in 0.x.y branch Resolve issue - https://github.com/open-source-parsers/jsoncpp/issues/389 --- include/json/value.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/include/json/value.h b/include/json/value.h index fe55bfdec..2c5667a8d 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -29,6 +29,19 @@ #pragma warning(disable : 4251) #endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING) +//Conditional NORETURN attribute on the throw functions would: +// a) suppress false positives from static code analysis +// b) possibly improve optimization opportunities. +#if !defined(JSONCPP_NORETURN) +# if defined(_MSC_VER) +# define JSONCPP_NORETURN __declspec(noreturn) +# elif defined(__GNUC__) +# define JSONCPP_NORETURN __attribute__ ((__noreturn__)) +# else +# define JSONCPP_NORETURN +# endif +#endif + /** \brief JSON (JavaScript Object Notation). */ namespace Json { @@ -69,9 +82,9 @@ class JSON_API LogicError : public Exception { }; /// used internally -void throwRuntimeError(std::string const& msg); +JSONCPP_NORETURN void throwRuntimeError(std::string const& msg); /// used internally -void throwLogicError(std::string const& msg); +JSONCPP_NORETURN void throwLogicError(std::string const& msg); /** \brief Type of the value held by a Value object. */ From aec261a899f028892efebb04bf7f1dfa01b095a4 Mon Sep 17 00:00:00 2001 From: Gaurav Date: Wed, 16 Mar 2016 11:23:36 +0530 Subject: [PATCH 49/54] NORETURN for throw functions in 0.x.y branch Added in definition also. --- src/lib_json/json_value.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 4a77d00bc..018b9cdcd 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -168,11 +168,11 @@ RuntimeError::RuntimeError(std::string const& msg) LogicError::LogicError(std::string const& msg) : Exception(msg) {} -void throwRuntimeError(std::string const& msg) +JSONCPP_NORETURN void throwRuntimeError(std::string const& msg) { throw RuntimeError(msg); } -void throwLogicError(std::string const& msg) +JSONCPP_NORETURN void throwLogicError(std::string const& msg) { throw LogicError(msg); } From 226f7a2b6b1d649bba5c631d9a86caffd9ba4b5f Mon Sep 17 00:00:00 2001 From: jmealins Date: Wed, 20 Apr 2016 14:31:46 -0700 Subject: [PATCH 50/54] Fix JSONCPP_WITH_WARNING_AS_ERROR in 0.y.z branch -Werror was always being added regardless of the what JSONCPP_WITH_WARNING_AS_ERROR was set to. Additionally, -std=c++11 was being set on Clang builds. --- CMakeLists.txt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 25af1236a..6e3c554e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,10 +82,12 @@ CONFIGURE_FILE( "${PROJECT_SOURCE_DIR}/version.in" macro(UseCompilationWarningAsError) if ( MSVC ) - # Only enabled in debug because some old versions of VS STL generate - # warnings when compiled in release configuration. - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /WX ") - endif() + # Only enabled in debug because some old versions of VS STL generate + # warnings when compiled in release configuration. + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /WX ") + elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_XX_COMPILER_ID MATCHES "Clang" ) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") + endif() endmacro() # Include our configuration header @@ -99,10 +101,10 @@ endif() if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") # using regular Clang or AppleClang - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Werror -Wall -Wshadow -Wshorten-64-to-32") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wshadow -Wshorten-64-to-32") elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # using GCC - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wshadow -Wextra -pedantic -Wno-long-long") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wshadow -Wextra -pedantic -Wno-long-long") # not yet ready for -Wsign-conversion endif() From cb3b38c3eaa5b899629cd4b13e44a6505ec6edf1 Mon Sep 17 00:00:00 2001 From: jmealins Date: Wed, 20 Apr 2016 15:04:27 -0700 Subject: [PATCH 51/54] fix if alignment --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e3c554e2..759c289d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,7 +81,7 @@ CONFIGURE_FILE( "${PROJECT_SOURCE_DIR}/version.in" NEWLINE_STYLE UNIX ) macro(UseCompilationWarningAsError) - if ( MSVC ) + if ( MSVC ) # Only enabled in debug because some old versions of VS STL generate # warnings when compiled in release configuration. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /WX ") From 5ec82e482c04917dfada25c7d7753d4040ab1c75 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Fri, 22 Apr 2016 00:28:53 -0500 Subject: [PATCH 52/54] 0.10.6 <- 0.10.5 --- CMakeLists.txt | 2 +- include/json/version.h | 4 ++-- version | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 759c289d7..0ad179113 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,7 +65,7 @@ ENDMACRO() #SET( JSONCPP_VERSION_MAJOR X ) #SET( JSONCPP_VERSION_MINOR Y ) #SET( JSONCPP_VERSION_PATCH Z ) -SET( JSONCPP_VERSION 0.10.5 ) +SET( JSONCPP_VERSION 0.10.6 ) jsoncpp_parse_version( ${JSONCPP_VERSION} JSONCPP_VERSION ) #IF(NOT JSONCPP_VERSION_FOUND) # MESSAGE(FATAL_ERROR "Failed to parse version string properly. Expect X.Y.Z") diff --git a/include/json/version.h b/include/json/version.h index 087fc638c..929782f86 100644 --- a/include/json/version.h +++ b/include/json/version.h @@ -3,10 +3,10 @@ #ifndef JSON_VERSION_H_INCLUDED # define JSON_VERSION_H_INCLUDED -# define JSONCPP_VERSION_STRING "0.10.5" +# define JSONCPP_VERSION_STRING "0.10.6" # define JSONCPP_VERSION_MAJOR 0 # define JSONCPP_VERSION_MINOR 10 -# define JSONCPP_VERSION_PATCH 5 +# define JSONCPP_VERSION_PATCH 6 # define JSONCPP_VERSION_QUALIFIER # define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8)) diff --git a/version b/version index 9028ec636..69da6ebcd 100644 --- a/version +++ b/version @@ -1 +1 @@ -0.10.5 +0.10.6 From f4afa75f64f2174971b1bfd482136fcf9db643ed Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Thu, 20 Oct 2016 10:33:17 -0400 Subject: [PATCH 53/54] Revert "0001-multiarch-path-support.patch" See http://na-mic.org/Mantis/view.php?id=4281 This reverts commit dde8426ded8f35d4ab98b6c5833249fe2ef84ee6. --- CMakeLists.txt | 4 +--- src/lib_json/CMakeLists.txt | 8 ++++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ad179113..3c58faa65 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,8 +12,6 @@ OPTION(JSONCPP_WITH_CMAKE_PACKAGE "Generate and install cmake package files" OFF OPTION(BUILD_SHARED_LIBS "Build jsoncpp_lib as a shared library." OFF) OPTION(BUILD_STATIC_LIBS "Build jsoncpp_lib static library." ON) -include(GNUInstallDirs) - # Ensures that CMAKE_BUILD_TYPE is visible in cmake-gui on Unix IF(NOT WIN32) IF(NOT CMAKE_BUILD_TYPE) @@ -118,7 +116,7 @@ IF(JSONCPP_WITH_PKGCONFIG_SUPPORT) "pkg-config/jsoncpp.pc" @ONLY) INSTALL(FILES "${CMAKE_BINARY_DIR}/pkg-config/jsoncpp.pc" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + DESTINATION "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/pkgconfig") ENDIF() IF(JSONCPP_WITH_CMAKE_PACKAGE) diff --git a/src/lib_json/CMakeLists.txt b/src/lib_json/CMakeLists.txt index 5861f035e..99ddc7f8b 100644 --- a/src/lib_json/CMakeLists.txt +++ b/src/lib_json/CMakeLists.txt @@ -48,8 +48,8 @@ IF(BUILD_SHARED_LIBS) INSTALL( TARGETS jsoncpp_lib ${INSTALL_EXPORT} RUNTIME DESTINATION ${RUNTIME_INSTALL_DIR} - LIBRARY DESTINATION "${LIBRARY_INSTALL_DIR}/${CMAKE_LIBRARY_ARCHITECTURE}" - ARCHIVE DESTINATION "${ARCHIVE_INSTALL_DIR}/${CMAKE_LIBRARY_ARCHITECTURE}") + LIBRARY DESTINATION ${LIBRARY_INSTALL_DIR} + ARCHIVE DESTINATION ${ARCHIVE_INSTALL_DIR}) IF(NOT CMAKE_VERSION VERSION_LESS 2.8.11) TARGET_INCLUDE_DIRECTORIES( jsoncpp_lib PUBLIC @@ -67,8 +67,8 @@ IF(BUILD_STATIC_LIBS) INSTALL( TARGETS jsoncpp_lib_static ${INSTALL_EXPORT} RUNTIME DESTINATION ${RUNTIME_INSTALL_DIR} - LIBRARY DESTINATION "${LIBRARY_INSTALL_DIR}/${CMAKE_LIBRARY_ARCHITECTURE}" - ARCHIVE DESTINATION "${ARCHIVE_INSTALL_DIR}/${CMAKE_LIBRARY_ARCHITECTURE}") + LIBRARY DESTINATION ${LIBRARY_INSTALL_DIR} + ARCHIVE DESTINATION ${ARCHIVE_INSTALL_DIR}) IF(NOT CMAKE_VERSION VERSION_LESS 2.8.11) TARGET_INCLUDE_DIRECTORIES( jsoncpp_lib_static PUBLIC From 73b8e172d6615251ef851d883ef02f163e7075b2 Mon Sep 17 00:00:00 2001 From: "Gregory C. Sharp" Date: Thu, 16 Mar 2017 07:06:06 -0400 Subject: [PATCH 54/54] COMP: Update json_(reader|writer).cpp to fix gcc6 build error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit backports open-source-parsers/jsoncpp@e105003 and fixes error like this one: ``` /path/to/JsonCpp/src/lib_json/json_reader.cpp:47:14: error: ‘scoped_ptr’ in namespace ‘std’ does not name a template type typedef std::scoped_ptr const CharReaderPtr; ^~~~~~~~~~ /path/to/JsonCpp/src/lib_json/json_reader.cpp: In function ‘bool Json::parseFromStream(const Json::CharReader::Factory&, std::istream&, Json::Value*, std::__cxx11::string*)’: /path/to/JsonCpp/src/lib_json/json_reader.cpp:1820:3: error: ‘CharReaderPtr’ was not declared in this scope CharReaderPtr const reader(fact.newCharReader()); ^~~~~~~~~~~~~ /path/to/JsonCpp/src/lib_json/json_reader.cpp:1821:10: error: ‘reader’ was not declared in this scope return reader->parse(begin, end, root, errs); ^~~~~~ /path/to/JsonCpp/src/lib_json/json_reader.cpp:1811:32: warning: unused parameter ‘fact’ [-Wunused-parameter] CharReader::Factory const& fact, std::istream& sin, ^~~~ ``` See http://slicer-devel.65872.n3.nabble.com/Slicer-gcc-6-tt4038282.html and http://na-mic.org/Mantis/view.php?id=4268 --- src/lib_json/json_reader.cpp | 4 ++-- src/lib_json/json_writer.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index 290e0b150..6e23a5305 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -43,8 +43,8 @@ static int stackDepth_g = 0; // see readValue() namespace Json { -#if __GNUC__ >= 6 -typedef std::scoped_ptr const CharReaderPtr; +#if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520) +typedef std::unique_ptr CharReaderPtr; #else typedef std::auto_ptr CharReaderPtr; #endif diff --git a/src/lib_json/json_writer.cpp b/src/lib_json/json_writer.cpp index f2eb200a9..4c2d4b529 100644 --- a/src/lib_json/json_writer.cpp +++ b/src/lib_json/json_writer.cpp @@ -54,8 +54,8 @@ namespace Json { -#if __GNUC__ >= 6 -typedef std::scoped_ptr const StreamWriterPtr; +#if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520) +typedef std::unique_ptr StreamWriterPtr; #else typedef std::auto_ptr StreamWriterPtr; #endif