From a41686881881e8c8cb2924eac60d72235efe2bc4 Mon Sep 17 00:00:00 2001 From: barcode Date: Fri, 23 Dec 2022 21:12:27 +0100 Subject: [PATCH] Fix ci issues --- cmake/ci.cmake | 2 +- .../sax_parse_with_src_location_in_json.cpp | 2 +- include/nlohmann/detail/meta/is_sax.hpp | 3 +- single_include/nlohmann/json.hpp | 4 +- tests/src/unit-sax-parser-extended.cpp | 57 ++++++++----------- .../unit-sax-parser-store-source-location.cpp | 17 ++++-- 6 files changed, 42 insertions(+), 43 deletions(-) diff --git a/cmake/ci.cmake b/cmake/ci.cmake index bbb2d4cb9..29d58d83b 100644 --- a/cmake/ci.cmake +++ b/cmake/ci.cmake @@ -636,7 +636,7 @@ add_custom_target(ci_test_valgrind -DJSON_BuildTests=ON -DJSON_Valgrind=ON -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_valgrind COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_valgrind - COMMAND cd ${PROJECT_BINARY_DIR}/build_valgrind && ${CMAKE_CTEST_COMMAND} -L valgrind --parallel ${N} --output-on-failure + COMMAND cd ${PROJECT_BINARY_DIR}/build_valgrind && ${CMAKE_CTEST_COMMAND} -L valgrind --parallel ${N} --output-on-failure --timeout 10000 COMMENT "Compile and test with Valgrind" ) diff --git a/docs/examples/sax_parse_with_src_location_in_json.cpp b/docs/examples/sax_parse_with_src_location_in_json.cpp index cf7adc1fb..8e7818352 100644 --- a/docs/examples/sax_parse_with_src_location_in_json.cpp +++ b/docs/examples/sax_parse_with_src_location_in_json.cpp @@ -187,7 +187,7 @@ class sax_with_token_start_stop_metadata return false; } - constexpr bool is_errored() const + bool is_errored() const { return errored; } diff --git a/include/nlohmann/detail/meta/is_sax.hpp b/include/nlohmann/detail/meta/is_sax.hpp index 6e8266f3f..38831e56c 100644 --- a/include/nlohmann/detail/meta/is_sax.hpp +++ b/include/nlohmann/detail/meta/is_sax.hpp @@ -15,6 +15,7 @@ #include #include #include +#include NLOHMANN_JSON_NAMESPACE_BEGIN namespace detail @@ -63,7 +64,7 @@ struct sax_call_function //the sax parser supports calls with a lexer static constexpr bool detected_call_with_lex_pos = !called_with_byte_pos && - is_detected_exact::value; + is_detected_exact::value; //there either has to be a version accepting a lexer or a position static constexpr bool valid = detected_call_with_byte_pos || detected_call_with_lex_pos; diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index aabe9fbbe..8cc45335c 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -8962,6 +8962,8 @@ NLOHMANN_JSON_NAMESPACE_END // #include +// #include + NLOHMANN_JSON_NAMESPACE_BEGIN namespace detail @@ -9010,7 +9012,7 @@ struct sax_call_function //the sax parser supports calls with a lexer static constexpr bool detected_call_with_lex_pos = !called_with_byte_pos && - is_detected_exact::value; + is_detected_exact::value; //there either has to be a version accepting a lexer or a position static constexpr bool valid = detected_call_with_byte_pos || detected_call_with_lex_pos; diff --git a/tests/src/unit-sax-parser-extended.cpp b/tests/src/unit-sax-parser-extended.cpp index 88342965d..e81107fba 100644 --- a/tests/src/unit-sax-parser-extended.cpp +++ b/tests/src/unit-sax-parser-extended.cpp @@ -521,7 +521,7 @@ void fill_expected_sax_pos_json(SAX& sax, case nlohmann::json::value_t::object: { sax.pos_start_object.emplace(element(1)); // { - for (auto& el : part.items()) + for (const auto& el : part.items()) { sax.pos_key.emplace(element(el.key().size() + 2)); //'"' + str + '"' offset += 1; // separator ':' between key and value @@ -538,7 +538,7 @@ void fill_expected_sax_pos_json(SAX& sax, case nlohmann::json::value_t::array: { sax.pos_start_array.emplace(element(1)); // [ - for (auto& el : part.items()) + for (const auto& el : part.items()) { fill_expected_sax_pos_json(sax, element, el.value(), offset); offset += 1; // add , @@ -553,7 +553,7 @@ void fill_expected_sax_pos_json(SAX& sax, case nlohmann::json::value_t::string: { const auto val = part.get(); - std::size_t nbytes = val.size() + 2; //'"' + value + '"' + const std::size_t nbytes = val.size() + 2; //'"' + value + '"' sax.pos_string.emplace(element(nbytes)); } break; @@ -573,21 +573,21 @@ void fill_expected_sax_pos_json(SAX& sax, case nlohmann::json::value_t::number_integer: { const auto val = part.get(); - std::size_t nbytes = std::to_string(val).size(); + const std::size_t nbytes = std::to_string(val).size(); sax.pos_number_integer.emplace(element(nbytes)); } break; case nlohmann::json::value_t::number_unsigned: { const auto val = part.get(); - std::size_t nbytes = std::to_string(val).size(); + const std::size_t nbytes = std::to_string(val).size(); sax.pos_number_unsigned.emplace(element(nbytes)); } break; case nlohmann::json::value_t::number_float: { const auto val = part.get(); - std::size_t nbytes = std::to_string(val).size(); + const std::size_t nbytes = std::to_string(val).size(); sax.pos_number_float.emplace(element(nbytes)); } break; @@ -632,7 +632,7 @@ void fill_expected_sax_pos_bson(SAX& sax, case nlohmann::json::value_t::object: { sax.pos_start_object.emplace(element(4)); //32 bit size - for (auto& el : part.items()) + for (const auto& el : part.items()) { offset += 1; // type of item sax.pos_key.emplace(element(el.key().size() + 1)); // str + terminator @@ -645,7 +645,7 @@ void fill_expected_sax_pos_bson(SAX& sax, { sax.pos_start_array.emplace(element(4)); //32 bit size std::size_t i = 0; - for (auto& el : part.items()) + for (const auto& el : part.items()) { offset += 1; // type of item offset += 1 + std::to_string(i).size(); // dummy key + terminator @@ -667,8 +667,7 @@ void fill_expected_sax_pos_bson(SAX& sax, case nlohmann::json::value_t::boolean: { //type is before the key -> not included - std::size_t nbytes = 1; //value - sax.pos_boolean.emplace(element(nbytes)); + sax.pos_boolean.emplace(element(1)); //value } break; case nlohmann::json::value_t::number_integer: @@ -741,8 +740,7 @@ void fill_expected_sax_pos_cbor(SAX& sax, const FN& element, const nlohmann::jso { case nlohmann::json::value_t::null: { - std::size_t nbytes = 1; //type - sax.pos_null.emplace(element(nbytes)); + sax.pos_null.emplace(element(1)); //type } break; case nlohmann::json::value_t::object: @@ -770,7 +768,7 @@ void fill_expected_sax_pos_cbor(SAX& sax, const FN& element, const nlohmann::jso } sax.pos_start_object.emplace(element(nbytes)); //key follows same rules as string - for (auto& el : part.items()) + for (const auto& el : part.items()) { std::size_t nbyteskey = 1; //type nbyteskey += el.key().size(); @@ -862,8 +860,7 @@ void fill_expected_sax_pos_cbor(SAX& sax, const FN& element, const nlohmann::jso break; case nlohmann::json::value_t::boolean: { - std::size_t nbytes = 1; //type - sax.pos_boolean.emplace(element(nbytes)); + sax.pos_boolean.emplace(element(1)); //type } break; case nlohmann::json::value_t::number_integer: @@ -880,15 +877,15 @@ void fill_expected_sax_pos_cbor(SAX& sax, const FN& element, const nlohmann::jso { //value implicit in type } - else if (-val - 1 <= static_cast(std::numeric_limits::max())) + else if (-(val + 1) <= static_cast(std::numeric_limits::max())) { nbytes += 1; } - else if (-val - 1 <= static_cast(std::numeric_limits::max())) + else if (-(val + 1) <= static_cast(std::numeric_limits::max())) { nbytes += 2; } - else if (-val - 1 <= static_cast(std::numeric_limits::max())) + else if (-(val + 1) <= static_cast(std::numeric_limits::max())) { nbytes += 4; } @@ -993,8 +990,7 @@ void fill_expected_sax_pos_msgpack(SAX& sax, const FN& element, const nlohmann:: { case nlohmann::json::value_t::null: { - std::size_t nbytes = 1; //type - sax.pos_null.emplace(element(nbytes)); + sax.pos_null.emplace(element(1)); //type } break; case nlohmann::json::value_t::object: @@ -1018,7 +1014,7 @@ void fill_expected_sax_pos_msgpack(SAX& sax, const FN& element, const nlohmann:: } sax.pos_start_object.emplace(element(nbytes)); //key follows same rules as string - for (auto& el : part.items()) + for (const auto& el : part.items()) { std::size_t nbyteskey = 1; //type nbyteskey += el.key().size(); @@ -1106,8 +1102,7 @@ void fill_expected_sax_pos_msgpack(SAX& sax, const FN& element, const nlohmann:: break; case nlohmann::json::value_t::boolean: { - std::size_t nbytes = 1; //type - sax.pos_boolean.emplace(element(nbytes)); + sax.pos_boolean.emplace(element(1)); //type } break; case nlohmann::json::value_t::number_integer: @@ -1233,15 +1228,14 @@ void fill_expected_sax_pos_ubjson(SAX& sax, const FN& element, const nlohmann::j { case nlohmann::json::value_t::null: { - std::size_t nbytes = 1; //type - sax.pos_null.emplace(element(nbytes)); + sax.pos_null.emplace(element(1)); //type } break; case nlohmann::json::value_t::object: { sax.pos_start_object.emplace(element(1)); //key follows same rules as string - for (auto& el : part.items()) + for (const auto& el : part.items()) { std::size_t nbyteskey = 1; //type of len nbyteskey += el.key().size(); @@ -1305,8 +1299,7 @@ void fill_expected_sax_pos_ubjson(SAX& sax, const FN& element, const nlohmann::j break; case nlohmann::json::value_t::boolean: { - std::size_t nbytes = 1; //type - sax.pos_boolean.emplace(element(nbytes)); + sax.pos_boolean.emplace(element(1)); //type } break; case nlohmann::json::value_t::number_integer: @@ -1442,15 +1435,14 @@ void fill_expected_sax_pos_bjdata(SAX& sax, const FN& element, const nlohmann::j { case nlohmann::json::value_t::null: { - std::size_t nbytes = 1; //type - sax.pos_null.emplace(element(nbytes)); + sax.pos_null.emplace(element(1)); //type } break; case nlohmann::json::value_t::object: { sax.pos_start_object.emplace(element(1)); //key follows same rules as string - for (auto& el : part.items()) + for (const auto& el : part.items()) { std::size_t nbyteskey = 1; //type of len nbyteskey += el.key().size(); @@ -1514,8 +1506,7 @@ void fill_expected_sax_pos_bjdata(SAX& sax, const FN& element, const nlohmann::j break; case nlohmann::json::value_t::boolean: { - std::size_t nbytes = 1; //type - sax.pos_boolean.emplace(element(nbytes)); + sax.pos_boolean.emplace(element(1)); //type } break; case nlohmann::json::value_t::number_integer: diff --git a/tests/src/unit-sax-parser-store-source-location.cpp b/tests/src/unit-sax-parser-store-source-location.cpp index 4a069c38b..68805f40c 100644 --- a/tests/src/unit-sax-parser-store-source-location.cpp +++ b/tests/src/unit-sax-parser-store-source-location.cpp @@ -83,13 +83,18 @@ class sax_with_token_start_stop_metadata */ explicit sax_with_token_start_stop_metadata(json& r, const bool allow_exceptions_ = true) : root(r) - , ref_stack{} - , object_element{nullptr} - , errored{false} + , object_element{nullptr} // NOLINT(modernize-use-default-member-init) + , errored{false} // NOLINT(modernize-use-default-member-init) , allow_exceptions(allow_exceptions_) - , start_stop{} {} + sax_with_token_start_stop_metadata(sax_with_token_start_stop_metadata&&) = delete; + sax_with_token_start_stop_metadata(const sax_with_token_start_stop_metadata&) = delete; + sax_with_token_start_stop_metadata& operator=(sax_with_token_start_stop_metadata&&) = delete; + sax_with_token_start_stop_metadata& operator=(const sax_with_token_start_stop_metadata&) = delete; + + ~sax_with_token_start_stop_metadata() = default; + void next_token_start(const nlohmann::position_t& p) { start_stop.start = p; @@ -210,7 +215,7 @@ class sax_with_token_start_stop_metadata return false; } - constexpr bool is_errored() const + bool is_errored() const { return errored; } @@ -263,7 +268,7 @@ class sax_with_token_start_stop_metadata /// whether to throw exceptions in case of errors const bool allow_exceptions = true; /// start / stop information for the current token - token_start_stop start_stop{}; + token_start_stop start_stop {}; }; TEST_CASE("parse-json-with-position-info")