From fdb529bd0613308591352ac1d4e765c4d33710c9 Mon Sep 17 00:00:00 2001 From: jedav Date: Mon, 9 Sep 2024 19:53:56 -0700 Subject: [PATCH 01/13] Move removeIndex's result instead of copying (#1516) Currently removeIndex copies the removed value into removed and then destructs the original, which can cause significant performance overhead. Co-authored-by: Jordan Bayles --- src/lib_json/json_value.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 26cd843cc..a5e2dd8e4 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -1205,7 +1205,7 @@ bool Value::removeIndex(ArrayIndex index, Value* removed) { return false; } if (removed) - *removed = it->second; + *removed = std::move(it->second); ArrayIndex oldSize = size(); // shift left all items left, into the place of the "removed" for (ArrayIndex i = index; i < (oldSize - 1); ++i) { From 2072e2b4e394f90ca9cbea32db53231900c01618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20M=C3=BCller?= <34514239+appgurueu@users.noreply.github.com> Date: Tue, 10 Sep 2024 04:56:37 +0200 Subject: [PATCH 02/13] Use current source / binary dir when assuring out of source builds (#1527) Co-authored-by: Jordan Bayles --- include/PreventInSourceBuilds.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/PreventInSourceBuilds.cmake b/include/PreventInSourceBuilds.cmake index 7ddda546a..be5d0dd41 100644 --- a/include/PreventInSourceBuilds.cmake +++ b/include/PreventInSourceBuilds.cmake @@ -2,8 +2,8 @@ # This function will prevent in-source builds function(AssureOutOfSourceBuilds) # make sure the user doesn't play dirty with symlinks - get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH) - get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH) + get_filename_component(srcdir "${CMAKE_CURRENT_SOURCE_DIR}" REALPATH) + get_filename_component(bindir "${CMAKE_CURRENT_BINARY_DIR}" REALPATH) # disallow in-source builds if("${srcdir}" STREQUAL "${bindir}") From 48d2e106a71b91a1259127ae0ca4d759e11ea890 Mon Sep 17 00:00:00 2001 From: Bartosz Brachaczek Date: Tue, 10 Sep 2024 05:00:06 +0200 Subject: [PATCH 03/13] Opportunistically take advantage of C++20 move-in/out-of stringstream (#1457) * Opportunistically take advantage of C++20 move-out-of stringstream * Opportunistically take advantage of C++20 move-in/out-of stringstream --------- Co-authored-by: Jordan Bayles --- src/lib_json/json_reader.cpp | 8 +++----- src/lib_json/json_writer.cpp | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index 4ab4dffd3..8ef29f07c 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -587,8 +587,7 @@ bool Reader::decodeDouble(Token& token) { bool Reader::decodeDouble(Token& token, Value& decoded) { double value = 0; - String buffer(token.start_, token.end_); - IStringStream is(buffer); + IStringStream is(String(token.start_, token.end_)); if (!(is >> value)) { if (value == std::numeric_limits::max()) value = std::numeric_limits::infinity(); @@ -1622,8 +1621,7 @@ bool OurReader::decodeDouble(Token& token) { bool OurReader::decodeDouble(Token& token, Value& decoded) { double value = 0; - const String buffer(token.start_, token.end_); - IStringStream is(buffer); + IStringStream is(String(token.start_, token.end_)); if (!(is >> value)) { if (value == std::numeric_limits::max()) value = std::numeric_limits::infinity(); @@ -1981,7 +1979,7 @@ bool parseFromStream(CharReader::Factory const& fact, IStream& sin, Value* root, String* errs) { OStringStream ssin; ssin << sin.rdbuf(); - String doc = ssin.str(); + String doc = std::move(ssin).str(); char const* begin = doc.data(); char const* end = begin + doc.size(); // Note that we do not actually need a null-terminator. diff --git a/src/lib_json/json_writer.cpp b/src/lib_json/json_writer.cpp index 5bb5dd117..ee45c43ba 100644 --- a/src/lib_json/json_writer.cpp +++ b/src/lib_json/json_writer.cpp @@ -1251,7 +1251,7 @@ String writeString(StreamWriter::Factory const& factory, Value const& root) { OStringStream sout; StreamWriterPtr const writer(factory.newStreamWriter()); writer->write(root, &sout); - return sout.str(); + return std::move(sout).str(); } OStream& operator<<(OStream& sout, Value const& root) { From fa0dff18fdef3dc7cd0ab0376a2aa19f878dbbc2 Mon Sep 17 00:00:00 2001 From: Roelof Oomen Date: Tue, 10 Sep 2024 05:02:24 +0200 Subject: [PATCH 04/13] Protect target JsonCpp::JsonCpp against multi-include (#1435) * Protect target JsonCpp::JsonCpp against multi-include Fixes #1356 * Simplify (@BillyDonahue) --------- Co-authored-by: Jordan Bayles --- jsoncpp-namespaced-targets.cmake | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/jsoncpp-namespaced-targets.cmake b/jsoncpp-namespaced-targets.cmake index ac1504e00..70a79ee7f 100644 --- a/jsoncpp-namespaced-targets.cmake +++ b/jsoncpp-namespaced-targets.cmake @@ -1,7 +1,9 @@ -if (TARGET jsoncpp_static) - add_library(JsonCpp::JsonCpp INTERFACE IMPORTED) - set_target_properties(JsonCpp::JsonCpp PROPERTIES INTERFACE_LINK_LIBRARIES "jsoncpp_static") -elseif (TARGET jsoncpp_lib) - add_library(JsonCpp::JsonCpp INTERFACE IMPORTED) - set_target_properties(JsonCpp::JsonCpp PROPERTIES INTERFACE_LINK_LIBRARIES "jsoncpp_lib") -endif () \ No newline at end of file +if (NOT TARGET JsonCpp::JsonCpp) + if (TARGET jsoncpp_static) + add_library(JsonCpp::JsonCpp INTERFACE IMPORTED) + set_target_properties(JsonCpp::JsonCpp PROPERTIES INTERFACE_LINK_LIBRARIES "jsoncpp_static") + elseif (TARGET jsoncpp_lib) + add_library(JsonCpp::JsonCpp INTERFACE IMPORTED) + set_target_properties(JsonCpp::JsonCpp PROPERTIES INTERFACE_LINK_LIBRARIES "jsoncpp_lib") + endif () +endif () From f4590227862e62264b98b88fd8c82558002f9df7 Mon Sep 17 00:00:00 2001 From: matthieugleg <156894466+matthieugleg@users.noreply.github.com> Date: Tue, 10 Sep 2024 05:06:22 +0200 Subject: [PATCH 05/13] Update CMakeLists.txt (#1528) Remove build directory from include Co-authored-by: Jordan Bayles --- src/lib_json/CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/lib_json/CMakeLists.txt b/src/lib_json/CMakeLists.txt index ce8100b29..152635348 100644 --- a/src/lib_json/CMakeLists.txt +++ b/src/lib_json/CMakeLists.txt @@ -132,7 +132,6 @@ if(BUILD_SHARED_LIBS) target_include_directories(${SHARED_LIB} PUBLIC $ $ - $ ) list(APPEND CMAKE_TARGETS ${SHARED_LIB}) @@ -166,7 +165,6 @@ if(BUILD_STATIC_LIBS) target_include_directories(${STATIC_LIB} PUBLIC $ $ - $ ) list(APPEND CMAKE_TARGETS ${STATIC_LIB}) @@ -193,7 +191,6 @@ if(BUILD_OBJECT_LIBS) target_include_directories(${OBJECT_LIB} PUBLIC $ $ - $ ) list(APPEND CMAKE_TARGETS ${OBJECT_LIB}) From 4b1bd4405e0d5ebfcc6252f0246e28d56290611e Mon Sep 17 00:00:00 2001 From: Woodrow Douglass Date: Mon, 9 Sep 2024 23:08:12 -0400 Subject: [PATCH 06/13] Create a jsoncppConfig.cmake file, even if building under meson (#1486) * Create a jsoncppConfig.cmake file, even if building under meson * Hardcode many fewer things in the meson-generated cmake files * use join_paths for constructing paths in the output Config.cmake --------- Co-authored-by: Jordan Bayles --- jsoncppConfig.cmake.meson.in | 8 ++++++++ meson.build | 39 +++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 jsoncppConfig.cmake.meson.in diff --git a/jsoncppConfig.cmake.meson.in b/jsoncppConfig.cmake.meson.in new file mode 100644 index 000000000..0f4866d6d --- /dev/null +++ b/jsoncppConfig.cmake.meson.in @@ -0,0 +1,8 @@ +@PACKAGE_INIT@ + +@MESON_SHARED_TARGET@ +@MESON_STATIC_TARGET@ + +include ( "${CMAKE_CURRENT_LIST_DIR}/jsoncpp-namespaced-targets.cmake" ) + +check_required_components(JsonCpp) diff --git a/meson.build b/meson.build index fb2b47cd9..80703618f 100644 --- a/meson.build +++ b/meson.build @@ -15,7 +15,7 @@ project( 'cpp_std=c++11', 'warning_level=1'], license : 'Public Domain', - meson_version : '>= 0.49.0') + meson_version : '>= 0.54.0') jsoncpp_headers = files([ @@ -62,6 +62,43 @@ import('pkgconfig').generate( filebase : 'jsoncpp', description : 'A C++ library for interacting with JSON') +cmakeconf = configuration_data() +cmakeconf.set('MESON_LIB_DIR', get_option('libdir')) +cmakeconf.set('MESON_INCLUDE_DIR', get_option('includedir')) + +fs = import('fs') +if get_option('default_library') == 'shared' + shared_name = fs.name(jsoncpp_lib.full_path()) +endif +if get_option('default_library') == 'static' + static_name = fs.name(jsoncpp_lib.full_path()) +endif +if get_option('default_library') == 'both' + shared_name = fs.name(jsoncpp_lib.get_shared_lib().full_path()) + static_name = fs.name(jsoncpp_lib.get_static_lib().full_path()) +endif + +if get_option('default_library') == 'shared' or get_option('default_library') == 'both' + cmakeconf.set('MESON_SHARED_TARGET', ''' +add_library(jsoncpp_lib IMPORTED SHARED) +set_target_properties(jsoncpp_lib PROPERTIES + IMPORTED_LOCATION "''' + join_paths('${PACKAGE_PREFIX_DIR}', get_option('libdir'), shared_name) + '''" + INTERFACE_INCLUDE_DIRECTORIES "''' + join_paths('${PACKAGE_PREFIX_DIR}', get_option('includedir')) + '")') +endif +if get_option('default_library') == 'static' or get_option('default_library') == 'both' + cmakeconf.set('MESON_STATIC_TARGET', ''' +add_library(jsoncpp_static IMPORTED STATIC) +set_target_properties(jsoncpp_static PROPERTIES + IMPORTED_LOCATION "''' + join_paths('${PACKAGE_PREFIX_DIR}', get_option('libdir'), static_name) + '''" + INTERFACE_INCLUDE_DIRECTORIES "''' + join_paths('${PACKAGE_PREFIX_DIR}', get_option('includedir')) + '")') +endif + +import('cmake').configure_package_config_file( + name: 'jsoncpp', + input: 'jsoncppConfig.cmake.meson.in', + configuration: cmakeconf) +install_data('jsoncpp-namespaced-targets.cmake', install_dir : join_paths(get_option('libdir'), 'cmake', jsoncpp_lib.name())) + # for libraries bundling jsoncpp jsoncpp_dep = declare_dependency( include_directories : jsoncpp_include_directories, From 162ead383d1fc920a01b2f333e6e69fa089c2541 Mon Sep 17 00:00:00 2001 From: Kerem TAN <56820099+KeremTAN@users.noreply.github.com> Date: Tue, 10 Sep 2024 06:08:55 +0300 Subject: [PATCH 07/13] include/json/value.h is changed (#1462) Co-authored-by: Jordan Bayles --- include/json/value.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/json/value.h b/include/json/value.h index 120dea890..f1232c47f 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -3,8 +3,8 @@ // recognized in your jurisdiction. // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE -#ifndef JSON_H_INCLUDED -#define JSON_H_INCLUDED +#ifndef JSON_VALUE_H_INCLUDED +#define JSON_VALUE_H_INCLUDED #if !defined(JSON_IS_AMALGAMATION) #include "forwards.h" From 99e8ca69b129ff0b65bded458404820c6a35d898 Mon Sep 17 00:00:00 2001 From: Rudi Heitbaum Date: Tue, 10 Sep 2024 13:09:10 +1000 Subject: [PATCH 08/13] meson.build: fix the version number (#1432) Co-authored-by: Jordan Bayles --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 80703618f..e6ba08c47 100644 --- a/meson.build +++ b/meson.build @@ -9,7 +9,7 @@ project( # 2. /include/json/version.h # 3. /CMakeLists.txt # IMPORTANT: also update the SOVERSION!! - version : '1.9.4', + version : '1.9.5', default_options : [ 'buildtype=release', 'cpp_std=c++11', From 3aa1192a0071ba640f249566c1d4ba2cf391a21c Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 10 Sep 2024 05:11:44 +0200 Subject: [PATCH 09/13] Introduce CharReaderBuilder::ecma404Mode (#1333) * Introduce CharReaderBuilder::ecma404Mode * Bump micro version --------- Co-authored-by: Jordan Bayles Co-authored-by: Billy Donahue Co-authored-by: Jordan Bayles --- CMakeLists.txt | 4 ++-- include/json/reader.h | 6 ++++++ include/json/version.h | 4 ++-- meson.build | 4 ++-- src/lib_json/json_reader.cpp | 16 ++++++++++++++++ 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a37e726f7..f11425c08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,11 +62,11 @@ project(jsoncpp # 2. ./include/json/version.h # 3. ./CMakeLists.txt # IMPORTANT: also update the PROJECT_SOVERSION!! - VERSION 1.9.5 # [.[.[.]]] + VERSION 1.9.6 # [.[.[.]]] LANGUAGES CXX) message(STATUS "JsonCpp Version: ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") -set(PROJECT_SOVERSION 25) +set(PROJECT_SOVERSION 26) include(${CMAKE_CURRENT_SOURCE_DIR}/include/PreventInSourceBuilds.cmake) include(${CMAKE_CURRENT_SOURCE_DIR}/include/PreventInBuildInstalls.cmake) diff --git a/include/json/reader.h b/include/json/reader.h index 38b9360cf..d745378fc 100644 --- a/include/json/reader.h +++ b/include/json/reader.h @@ -385,6 +385,12 @@ class JSON_API CharReaderBuilder : public CharReader::Factory { * \snippet src/lib_json/json_reader.cpp CharReaderBuilderStrictMode */ static void strictMode(Json::Value* settings); + /** ECMA-404 mode. + * \pre 'settings' != NULL (but Json::null is fine) + * \remark Defaults: + * \snippet src/lib_json/json_reader.cpp CharReaderBuilderECMA404Mode + */ + static void ecma404Mode(Json::Value* settings); }; /** Consume entire stream and use its begin/end. diff --git a/include/json/version.h b/include/json/version.h index 9e9541191..38faedf11 100644 --- a/include/json/version.h +++ b/include/json/version.h @@ -9,10 +9,10 @@ // 3. /CMakeLists.txt // IMPORTANT: also update the SOVERSION!! -#define JSONCPP_VERSION_STRING "1.9.5" +#define JSONCPP_VERSION_STRING "1.9.6" #define JSONCPP_VERSION_MAJOR 1 #define JSONCPP_VERSION_MINOR 9 -#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) | \ diff --git a/meson.build b/meson.build index e6ba08c47..561b41ce7 100644 --- a/meson.build +++ b/meson.build @@ -9,7 +9,7 @@ project( # 2. /include/json/version.h # 3. /CMakeLists.txt # IMPORTANT: also update the SOVERSION!! - version : '1.9.5', + version : '1.9.6', default_options : [ 'buildtype=release', 'cpp_std=c++11', @@ -50,7 +50,7 @@ jsoncpp_lib = library( 'src/lib_json/json_value.cpp', 'src/lib_json/json_writer.cpp', ]), - soversion : 25, + soversion : 26, install : true, include_directories : jsoncpp_include_directories, cpp_args: dll_export_flag) diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index 8ef29f07c..10c97aecb 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -1961,6 +1961,22 @@ void CharReaderBuilder::setDefaults(Json::Value* settings) { (*settings)["skipBom"] = true; //! [CharReaderBuilderDefaults] } +// static +void CharReaderBuilder::ecma404Mode(Json::Value* settings) { + //! [CharReaderBuilderECMA404Mode] + (*settings)["allowComments"] = false; + (*settings)["allowTrailingCommas"] = false; + (*settings)["strictRoot"] = false; + (*settings)["allowDroppedNullPlaceholders"] = false; + (*settings)["allowNumericKeys"] = false; + (*settings)["allowSingleQuotes"] = false; + (*settings)["stackLimit"] = 1000; + (*settings)["failIfExtra"] = true; + (*settings)["rejectDupKeys"] = false; + (*settings)["allowSpecialFloats"] = false; + (*settings)["skipBom"] = false; + //! [CharReaderBuilderECMA404Mode] +} std::vector CharReader::getStructuredErrors() const { From 2067f66d662ef0925733ba95595a3cf988a2d32d Mon Sep 17 00:00:00 2001 From: zeroxia Date: Tue, 10 Sep 2024 11:14:17 +0800 Subject: [PATCH 10/13] cmake export configuration: allow repeating find_package(jsoncpp) calls (#1491) In jsoncpp-namspaced-targets.cmake, it creates JsonCpp::JsonCpp imported library without first checking whether it was already created by former call to find_package(JsonCpp). As CMake allows repeated call to find_package(), the error of "another target with the same name already exists" should be fixed. Co-authored-by: xiazuoling.xzl Co-authored-by: Jordan Bayles From 7f36cdb3ead60cdc77ec4e6a104bd2f653730b30 Mon Sep 17 00:00:00 2001 From: Timofey <45315126+petukhovtd@users.noreply.github.com> Date: Tue, 10 Sep 2024 10:14:36 +0700 Subject: [PATCH 11/13] Added Value::find with String key (#1467) * Added Value::find with String key * Fix codestyle --------- Co-authored-by: Jordan Bayles Co-authored-by: Petukhov Timofey --- include/json/value.h | 3 +++ src/lib_json/json_value.cpp | 5 ++++- src/test_lib_json/main.cpp | 9 +++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/json/value.h b/include/json/value.h index f1232c47f..c8e1aae2e 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -513,6 +513,9 @@ class JSON_API Value { /// and operator[]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 isMember()const, get()const, + /// and operator[]const + Value const* find(const String& key) const; /// Most general and efficient version of object-mutators. /// \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. diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index a5e2dd8e4..5bd8d9a27 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -1092,6 +1092,9 @@ Value const* Value::find(char const* begin, char const* end) const { return nullptr; return &(*it).second; } +Value const* Value::find(const String& key) const { + return find(key.data(), key.data() + key.length()); +} Value* Value::demand(char const* begin, char const* end) { JSON_ASSERT_MESSAGE(type() == nullValue || type() == objectValue, "in Json::Value::demand(begin, end): requires " @@ -1105,7 +1108,7 @@ const Value& Value::operator[](const char* key) const { return *found; } Value const& Value::operator[](const String& key) const { - Value const* found = find(key.data(), key.data() + key.length()); + Value const* found = find(key); if (!found) return nullSingleton(); return *found; diff --git a/src/test_lib_json/main.cpp b/src/test_lib_json/main.cpp index fa41d19ed..55ab2241d 100644 --- a/src/test_lib_json/main.cpp +++ b/src/test_lib_json/main.cpp @@ -220,11 +220,20 @@ JSONTEST_FIXTURE_LOCAL(ValueTest, objects) { JSONTEST_ASSERT(foundId != nullptr); JSONTEST_ASSERT_EQUAL(Json::Value(1234), *foundId); + const std::string stringIdKey = "id"; + const Json::Value* stringFoundId = object1_.find(stringIdKey); + JSONTEST_ASSERT(stringFoundId != nullptr); + JSONTEST_ASSERT_EQUAL(Json::Value(1234), *stringFoundId); + const char unknownIdKey[] = "unknown id"; const Json::Value* foundUnknownId = object1_.find(unknownIdKey, unknownIdKey + strlen(unknownIdKey)); JSONTEST_ASSERT_EQUAL(nullptr, foundUnknownId); + const std::string stringUnknownIdKey = "unknown id"; + const Json::Value* stringFoundUnknownId = object1_.find(stringUnknownIdKey); + JSONTEST_ASSERT_EQUAL(nullptr, stringFoundUnknownId); + // Access through demand() const char yetAnotherIdKey[] = "yet another id"; const Json::Value* foundYetAnotherId = From 89e2973c754a9c02a49974d839779b151e95afd6 Mon Sep 17 00:00:00 2001 From: Scotty1701 <37419120+Scotty1701@users.noreply.github.com> Date: Mon, 9 Sep 2024 20:18:29 -0700 Subject: [PATCH 12/13] Don't use build dir build interfaces (#1419) Do not export a location in the build directory as a build interface. This location is not created until the build step is run and can interfere with the CMake configuration step if including in another project. Co-authored-by: Jordan Bayles From 76ff1db84d5f3b7515eb3934126b78d178057af9 Mon Sep 17 00:00:00 2001 From: Paolo Monteverde Date: Thu, 12 Sep 2024 01:47:59 +0200 Subject: [PATCH 13/13] Fixes PreventInSourceBuilds.cmake to work with add_subdirectory (#1383) Co-authored-by: Jordan Bayles