Skip to content

Commit

Permalink
Fix ci issues
Browse files Browse the repository at this point in the history
  • Loading branch information
barcode committed Dec 25, 2022
1 parent db06dab commit 7d91147
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 43 deletions.
2 changes: 1 addition & 1 deletion cmake/ci.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,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"
)

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/sax_parse_with_src_location_in_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class sax_with_token_start_stop_metadata
return false;
}

constexpr bool is_errored() const
bool is_errored() const
{
return errored;
}
Expand Down
3 changes: 2 additions & 1 deletion include/nlohmann/detail/meta/is_sax.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <nlohmann/detail/abi_macros.hpp>
#include <nlohmann/detail/meta/detected.hpp>
#include <nlohmann/detail/meta/type_traits.hpp>
#include <nlohmann/detail/input/position_t.hpp>

NLOHMANN_JSON_NAMESPACE_BEGIN
namespace detail
Expand Down Expand Up @@ -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<void, call_t, SAX, const position_t >::value;
is_detected_exact<void, call_t, SAX, position_t >::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;
Expand Down
4 changes: 3 additions & 1 deletion single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8962,6 +8962,8 @@ NLOHMANN_JSON_NAMESPACE_END

// #include <nlohmann/detail/meta/type_traits.hpp>

// #include <nlohmann/detail/input/position_t.hpp>


NLOHMANN_JSON_NAMESPACE_BEGIN
namespace detail
Expand Down Expand Up @@ -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<void, call_t, SAX, const position_t >::value;
is_detected_exact<void, call_t, SAX, position_t >::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;
Expand Down
57 changes: 24 additions & 33 deletions tests/src/unit-sax-parser-extended.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ,
Expand All @@ -553,7 +553,7 @@ void fill_expected_sax_pos_json(SAX& sax,
case nlohmann::json::value_t::string:
{
const auto val = part.get<std::string>();
std::size_t nbytes = val.size() + 2; //'"' + value + '"'
const std::size_t nbytes = val.size() + 2; //'"' + value + '"'
sax.pos_string.emplace(element(nbytes));
}
break;
Expand All @@ -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::int64_t>();
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::uint64_t>();
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<double>();
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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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:
Expand All @@ -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::int64_t>(std::numeric_limits<std::uint8_t>::max()))
else if (-(val + 1) <= static_cast<std::int64_t>(std::numeric_limits<std::uint8_t>::max()))
{
nbytes += 1;
}
else if (-val - 1 <= static_cast<std::int64_t>(std::numeric_limits<std::uint16_t>::max()))
else if (-(val + 1) <= static_cast<std::int64_t>(std::numeric_limits<std::uint16_t>::max()))
{
nbytes += 2;
}
else if (-val - 1 <= static_cast<std::int64_t>(std::numeric_limits<std::uint32_t>::max()))
else if (-(val + 1) <= static_cast<std::int64_t>(std::numeric_limits<std::uint32_t>::max()))
{
nbytes += 4;
}
Expand Down Expand Up @@ -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:
Expand All @@ -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();
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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:
Expand Down
17 changes: 11 additions & 6 deletions tests/src/unit-sax-parser-store-source-location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -210,7 +215,7 @@ class sax_with_token_start_stop_metadata
return false;
}

constexpr bool is_errored() const
bool is_errored() const
{
return errored;
}
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 7d91147

Please sign in to comment.