From 717c791d4e40c3f923e79ff8d4a72111f079eaa5 Mon Sep 17 00:00:00 2001 From: Martyn Gigg Date: Mon, 29 Jun 2015 19:20:08 +0100 Subject: [PATCH 01/22] 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 d31a6ad..ba32022 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 97b7019..79ffa2e 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 4652f818fee737005eff731c6d1d285772b8f061 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sat, 11 Jul 2015 10:46:24 -0500 Subject: [PATCH 02/22] 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 546cb7e..f4966a3 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 81cb7e5c5b95ac0677c3381d46d05ddb9b25ad5d Mon Sep 17 00:00:00 2001 From: Stuart Eichert Date: Wed, 1 Jul 2015 14:05:54 -0700 Subject: [PATCH 03/22] 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 ba32022..90eb14e 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} -std=c++11 -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} -std=c++0x -Wall -Wextra -pedantic") From 702a53976260608c4497d99f00f01ff55aff7791 Mon Sep 17 00:00:00 2001 From: Stuart Eichert Date: Wed, 1 Jul 2015 14:18:15 -0700 Subject: [PATCH 04/22] 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 8fbce54..cc7d4d3 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -125,7 +125,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 3be34d9..2f940c8 100644 --- a/src/lib_json/json_writer.cpp +++ b/src/lib_json/json_writer.cpp @@ -354,7 +354,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]); } @@ -914,7 +914,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 b5e70f950e8e01d5830f4d969b2703b5cc6cd289 Mon Sep 17 00:00:00 2001 From: Mike Naberezny Date: Fri, 3 Jul 2015 15:47:00 -0700 Subject: [PATCH 05/22] 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 054eb9b..b55e146 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 89704039a030d150651ef32e9c5a9b78953b4a5a Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sat, 11 Jul 2015 12:09:59 -0500 Subject: [PATCH 06/22] minor doc fix, for #302 --- include/json/value.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/include/json/value.h b/include/json/value.h index 2ac94fa..68fc163 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -255,7 +255,7 @@ Json::Value obj_value(Json::objectValue); // {} #endif // if defined(JSON_HAS_INT64) Value(double value); Value(const char* value); ///< Copy til first 0. (NULL causes to seg-fault.) - Value(const char* beginValue, const char* endValue); ///< Copy all, incl zeroes. + Value(const char* begin, const char* end); ///< Copy all, incl zeroes. /** \brief Constructs a value from a static string. * Like other value string constructor but do not duplicate the string for @@ -306,7 +306,7 @@ Json::Value obj_value(Json::objectValue); // {} * \return false if !string. (Seg-fault if str or end are NULL.) */ bool getString( - char const** str, char const** end) const; + char const** begin, char const** end) const; #ifdef JSON_USE_CPPTL CppTL::ConstString asConstString() const; #endif @@ -435,8 +435,8 @@ Json::Value obj_value(Json::objectValue); // {} Value get(const char* key, const Value& defaultValue) const; /// Return the member named key if it exist, defaultValue otherwise. /// \note deep copy - /// \param key may contain embedded nulls. - Value get(const char* key, const char* end, const Value& defaultValue) const; + /// \note key may contain embedded nulls. + Value get(const char* begin, const char* end, const Value& defaultValue) const; /// Return the member named key if it exist, defaultValue otherwise. /// \note deep copy /// \param key may contain embedded nulls. @@ -448,12 +448,12 @@ Json::Value obj_value(Json::objectValue); // {} #endif /// Most general and efficient version of isMember()const, get()const, /// and operator[]const - /// \note As stated elsewhere, behavior is undefined if (end-key) >= 2^30 - Value const* find(char const* key, char const* end) const; + /// \note As stated elsewhere, behavior is undefined if (end-begin) >= 2^30 + Value const* find(char const* begin, char const* end) const; /// Most general and efficient version of object-mutators. - /// \note As stated elsewhere, behavior is undefined if (end-key) >= 2^30 + /// \note As stated elsewhere, behavior is undefined if (end-begin) >= 2^30 /// \return non-zero, but JSON_ASSERT if this is neither object nor nullValue. - Value const* demand(char const* key, char const* end); + Value const* demand(char const* begin, char const* end); /// \brief Remove and return the named member. /// /// Do nothing if it did not exist. @@ -466,7 +466,7 @@ Json::Value obj_value(Json::objectValue); // {} /// \param key may contain embedded nulls. /// \deprecated Value removeMember(const std::string& key); - /// Same as removeMember(const char* key, const char* end, Value* removed), + /// Same as removeMember(const char* begin, const char* end, Value* removed), /// but 'key' is null-terminated. bool removeMember(const char* key, Value* removed); /** \brief Remove the named map member. @@ -477,7 +477,7 @@ Json::Value obj_value(Json::objectValue); // {} */ bool removeMember(std::string const& key, Value* removed); /// Same as removeMember(std::string const& key, Value* removed) - bool removeMember(const char* key, const char* end, Value* removed); + bool removeMember(const char* begin, const char* end, Value* removed); /** \brief Remove the indexed array element. O(n) expensive operations. @@ -493,7 +493,7 @@ Json::Value obj_value(Json::objectValue); // {} /// \param key may contain embedded nulls. bool isMember(const std::string& key) const; /// Same as isMember(std::string const& key)const - bool isMember(const char* key, const char* end) const; + bool isMember(const char* begin, const char* end) const; #ifdef JSON_USE_CPPTL /// Return true if the object has a member named key. bool isMember(const CppTL::ConstString& key) const; From 24288898137d874d2ddb57e28de093c3f349062c Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sat, 11 Jul 2015 13:41:13 -0500 Subject: [PATCH 07/22] 1.6.3 --- CMakeLists.txt | 2 +- include/json/version.h | 4 ++-- src/lib_json/version.h.in | 3 +-- version | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 90eb14e..e7334d3 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 1.6.2 ) +SET( JSONCPP_VERSION 1.6.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 a4db8b0..134a8c1 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 "1.6.2" +# define JSONCPP_VERSION_STRING "1.6.3" # define JSONCPP_VERSION_MAJOR 1 # define JSONCPP_VERSION_MINOR 6 -# 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/src/lib_json/version.h.in b/src/lib_json/version.h.in index 761ca3a..692ab5e 100644 --- a/src/lib_json/version.h.in +++ b/src/lib_json/version.h.in @@ -1,5 +1,4 @@ -// DO NOT EDIT. This file is generated by CMake from "version" -// and "version.h.in" files. +// DO NOT EDIT. This file (and "version") is generated by CMake. // Run CMake configure step to update it. #ifndef JSON_VERSION_H_INCLUDED # define JSON_VERSION_H_INCLUDED diff --git a/version b/version index fdd3be6..266146b 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.6.2 +1.6.3 From f4e6fccd46cd39a07ec7ef381f159bb8cb5e3938 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sat, 11 Jul 2015 14:06:18 -0500 Subject: [PATCH 08/22] 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 17e52dc..4180688 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 d8e8c14ffc54d9926da184dd666d95ed6c3a9603 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sat, 11 Jul 2015 14:09:52 -0500 Subject: [PATCH 09/22] valgrind in Travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 4180688..591b354 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 658fa37e638732325eac9f46c37da82a11fbe38e Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sun, 12 Jul 2015 09:53:40 -0500 Subject: [PATCH 10/22] gcc-4.9, clang (3.0) --- .travis.yml | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 591b354..4957987 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,14 +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.9" CC="gcc-4.9"; fi +# /usr/bin/clang is our version already, and clang-X.Y does not exist. +#- if [ "$CXX" = "clang++" ]; then export CXX="clang++-3.7" CC="clang-3.7"; fi +- echo ${PATH} +- ls /usr/local +- ls /usr/local/bin +- export PATH=/usr/local/bin:/usr/bin:${PATH} +- echo ${CXX} +- ${CXX} --version +- which valgrind addons: apt: sources: - ubuntu-toolchain-r-test packages: - - gcc-4.8 - - g++-4.8 + - gcc-4.9 + - g++-4.9 - clang - valgrind os: @@ -29,6 +39,5 @@ env: - SHARED_LIB=ON STATIC_LIB=ON CMAKE_PKG=ON BUILD_TYPE=release VERBOSE_MAKE=false - SHARED_LIB=OFF STATIC_LIB=ON CMAKE_PKG=OFF BUILD_TYPE=debug VERBOSE_MAKE=true VERBOSE notifications: - email: - - aaronjjacobs@gmail.com + email: false sudo: false From fac87108a49fb1b2640eff5d8e4cc7a12723a510 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sun, 12 Jul 2015 12:08:34 -0500 Subject: [PATCH 11/22] -std=c++11 for gcc builds too --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e7334d3..c5c75d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,7 +100,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") 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} -std=c++0x -Wall -Wextra -pedantic") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -pedantic") endif() IF(JSONCPP_WITH_WARNING_AS_ERROR) From f94a0e8989150d2224e731a037e9546580a2924b Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sun, 12 Jul 2015 12:31:43 -0500 Subject: [PATCH 12/22] auto-generated file with minor update --- include/json/version.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/json/version.h b/include/json/version.h index 134a8c1..61081e9 100644 --- a/include/json/version.h +++ b/include/json/version.h @@ -1,5 +1,4 @@ -// DO NOT EDIT. This file is generated by CMake from "version" -// and "version.h.in" files. +// DO NOT EDIT. This file (and "version") is generated by CMake. // Run CMake configure step to update it. #ifndef JSON_VERSION_H_INCLUDED # define JSON_VERSION_H_INCLUDED From 46aa9d75fa9b633124025e5b85c37e25fe039d62 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sun, 12 Jul 2015 12:32:33 -0500 Subject: [PATCH 13/22] -Wconversion * 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` --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c5c75d2..cbaff68 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 -Wconversion -Wshadow") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") # using GCC - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -pedantic") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wconversion -Wshadow -Wextra -Wsign-conversion -pedantic") endif() IF(JSONCPP_WITH_WARNING_AS_ERROR) From 7275e3ce3c1139c350df20b3c3b19881148bb757 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sun, 12 Jul 2015 12:49:57 -0500 Subject: [PATCH 14/22] drop -Wsign-conversion --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cbaff68..3cf6651 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,7 +100,8 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wconversion -Wshadow") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") # using GCC - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wconversion -Wshadow -Wextra -Wsign-conversion -pedantic") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wconversion -Wshadow -Wextra -pedantic") + # not yet ready for -Wsign-conversion endif() IF(JSONCPP_WITH_WARNING_AS_ERROR) From 784433ac72c0864600655c29607df716f2259186 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sun, 12 Jul 2015 12:55:18 -0500 Subject: [PATCH 15/22] fix some warnings --- CMakeLists.txt | 2 +- src/lib_json/json_tool.h | 6 ++-- src/lib_json/json_value.cpp | 53 +++++++++++++++-------------- src/lib_json/json_valueiterator.inl | 20 +++++------ 4 files changed, 41 insertions(+), 40 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3cf6651..cb79ca7 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} -std=c++11 -Wall -Wconversion -Wshadow") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wconversion -Wshadow -Wno-sign-conversion") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") # using GCC set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wconversion -Wshadow -Wextra -pedantic") diff --git a/src/lib_json/json_tool.h b/src/lib_json/json_tool.h index f9b61c3..e6d4e92 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 cc7d4d3..334bb04 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -108,7 +108,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( @@ -232,14 +232,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) @@ -248,9 +248,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_; } @@ -312,9 +312,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: @@ -478,7 +478,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; } @@ -960,8 +961,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; start_ = 0; @@ -990,7 +991,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, @@ -998,7 +999,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; @@ -1016,13 +1017,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; @@ -1066,9 +1067,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 @@ -1081,12 +1082,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; @@ -1148,9 +1149,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 d01d3c0..b3bbc35 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 7f240623d333bac4be4f791f5354cb95da744c16 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sun, 12 Jul 2015 12:58:54 -0500 Subject: [PATCH 16/22] 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 334bb04..231089f 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -1132,8 +1132,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 d8186f36a683a70143e7e1870d9d6727820b8a22 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sun, 12 Jul 2015 14:25:21 -0500 Subject: [PATCH 17/22] -Werror --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cb79ca7..d740c99 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 -Wconversion -Wshadow -Wno-sign-conversion") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Werror -Wall -Wconversion -Wshadow -Wno-sign-conversion") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") # using GCC - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wconversion -Wshadow -Wextra -pedantic") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Werror -Wall -Wconversion -Wshadow -Wextra -pedantic") # not yet ready for -Wsign-conversion endif() From cac79543f8c7cf8dab7ffcaff77e10284f173ed4 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sun, 12 Jul 2015 14:29:51 -0500 Subject: [PATCH 18/22] 1.6.4 minor bug-fix --- 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 d740c99..f438f18 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 1.6.3 ) +SET( JSONCPP_VERSION 1.6.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 61081e9..bce0a37 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 "1.6.3" +# define JSONCPP_VERSION_STRING "1.6.4" # define JSONCPP_VERSION_MAJOR 1 # define JSONCPP_VERSION_MINOR 6 -# 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 266146b..9edc58b 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.6.3 +1.6.4 From 770fdda28b1a4a4418ee1af3aaacdb6c7ffd7ec4 Mon Sep 17 00:00:00 2001 From: filipjs Date: Tue, 14 Jul 2015 14:34:07 +0200 Subject: [PATCH 19/22] Update json_tool.h Fix a typo in comment. --- src/lib_json/json_tool.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib_json/json_tool.h b/src/lib_json/json_tool.h index e6d4e92..2de0d83 100644 --- a/src/lib_json/json_tool.h +++ b/src/lib_json/json_tool.h @@ -43,7 +43,7 @@ static inline std::string codePointToUTF8(unsigned int cp) { return result; } -/// Returns true if ch is a control character (in range [0,32[). +/// Returns true if ch is a control character (in range [0,32]). static inline bool isControlCharacter(char ch) { return ch > 0 && ch <= 0x1F; } enum { From 6ed877c77cde496a915c584343d16397df25c6ff Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Thu, 23 Jul 2015 00:25:56 -0500 Subject: [PATCH 20/22] correction for #316 --- src/lib_json/json_tool.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib_json/json_tool.h b/src/lib_json/json_tool.h index 2de0d83..e65e51b 100644 --- a/src/lib_json/json_tool.h +++ b/src/lib_json/json_tool.h @@ -43,7 +43,7 @@ static inline std::string codePointToUTF8(unsigned int cp) { return result; } -/// Returns true if ch is a control character (in range [0,32]). +/// Returns true if ch is a control character (in range [1,31]). static inline bool isControlCharacter(char ch) { return ch > 0 && ch <= 0x1F; } enum { From 949babd7b0924910564aef46aacbedaf29e1866e Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Thu, 23 Jul 2015 00:19:12 -0500 Subject: [PATCH 21/22] Exceptions declared in header resolves #272 --- include/json/value.h | 21 ++++++++++++++++++--- src/lib_json/json_value.cpp | 17 ----------------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/include/json/value.h b/include/json/value.h index 68fc163..8e996ae 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -37,21 +37,36 @@ namespace Json { * * We use nothing but these internally. Of course, STL can throw others. */ -class JSON_API Exception; +class JSON_API Exception : public std::exception { +public: + Exception(std::string const& msg); + virtual ~Exception() throw(); + virtual char const* what() const throw(); +protected: + std::string const msg_; +}; + /** Exceptions which the user cannot easily avoid. * * E.g. out-of-memory (when we use malloc), stack-overflow, malicious input * * \remark derived from Json::Exception */ -class JSON_API RuntimeError; +class JSON_API RuntimeError : public Exception { +public: + RuntimeError(std::string const& msg); +}; + /** Exceptions thrown by JSON_ASSERT/JSON_FAIL macros. * * These are precondition-violations (user bugs) and internal errors (our bugs). * * \remark derived from Json::Exception */ -class JSON_API LogicError; +class JSON_API LogicError : public Exception { +public: + LogicError(std::string const& msg); +}; /// used internally void throwRuntimeError(std::string const& msg); diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 231089f..9a16491 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -152,23 +152,6 @@ static inline void releaseStringValue(char* value) { free(value); } namespace Json { -class JSON_API Exception : public std::exception { -public: - Exception(std::string const& msg); - virtual ~Exception() throw(); - virtual char const* what() const throw(); -protected: - std::string const msg_; -}; -class JSON_API RuntimeError : public Exception { -public: - RuntimeError(std::string const& msg); -}; -class JSON_API LogicError : public Exception { -public: - LogicError(std::string const& msg); -}; - Exception::Exception(std::string const& msg) : msg_(msg) {} From d84702c9036505d0906b2f3d222ce5498ec65bc6 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Thu, 23 Jul 2015 00:20:35 -0500 Subject: [PATCH 22/22] 1.6.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 f438f18..cab0de8 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 1.6.4 ) +SET( JSONCPP_VERSION 1.6.5 ) 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 bce0a37..9df36d7 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 "1.6.4" +# define JSONCPP_VERSION_STRING "1.6.5" # define JSONCPP_VERSION_MAJOR 1 # define JSONCPP_VERSION_MINOR 6 -# define JSONCPP_VERSION_PATCH 4 +# define JSONCPP_VERSION_PATCH 5 # 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 9edc58b..9f05f9f 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.6.4 +1.6.5