Skip to content

Commit

Permalink
Merge branch 'nlohmann:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
hnampally committed Jan 1, 2025
2 parents 2d04d40 + 4f64d8d commit f9eb241
Show file tree
Hide file tree
Showing 6 changed files with 53 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 @@ -562,7 +562,7 @@ add_custom_target(ci_test_diagnostic_positions
-S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_diagnostics_positions
COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_diagnostics_positions
COMMAND cd ${PROJECT_BINARY_DIR}/build_diagnostics_positions && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure
COMMENT "Compile and test with improved diagnostics positions enabled"
COMMENT "Compile and test with diagnostics positions enabled"
)

###############################################################################
Expand Down
22 changes: 11 additions & 11 deletions include/nlohmann/detail/input/binary_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class binary_reader
std::int32_t document_size{};
get_number<std::int32_t, true>(input_format_t::bson, document_size);

if (JSON_HEDLEY_UNLIKELY(!sax->start_object(static_cast<std::size_t>(-1))))
if (JSON_HEDLEY_UNLIKELY(!sax->start_object(detail::unknown_size())))
{
return false;
}
Expand Down Expand Up @@ -394,7 +394,7 @@ class binary_reader
std::int32_t document_size{};
get_number<std::int32_t, true>(input_format_t::bson, document_size);

if (JSON_HEDLEY_UNLIKELY(!sax->start_array(static_cast<std::size_t>(-1))))
if (JSON_HEDLEY_UNLIKELY(!sax->start_array(detail::unknown_size())))
{
return false;
}
Expand Down Expand Up @@ -654,7 +654,7 @@ class binary_reader
}

case 0x9F: // array (indefinite length)
return get_cbor_array(static_cast<std::size_t>(-1), tag_handler);
return get_cbor_array(detail::unknown_size(), tag_handler);

// map (0x00..0x17 pairs of data items follow)
case 0xA0:
Expand Down Expand Up @@ -708,7 +708,7 @@ class binary_reader
}

case 0xBF: // map (indefinite length)
return get_cbor_object(static_cast<std::size_t>(-1), tag_handler);
return get_cbor_object(detail::unknown_size(), tag_handler);

case 0xC6: // tagged item
case 0xC7:
Expand Down Expand Up @@ -1096,7 +1096,7 @@ class binary_reader
}

/*!
@param[in] len the length of the array or static_cast<std::size_t>(-1) for an
@param[in] len the length of the array or detail::unknown_size() for an
array of indefinite size
@param[in] tag_handler how CBOR tags should be treated
@return whether array creation completed
Expand All @@ -1109,7 +1109,7 @@ class binary_reader
return false;
}

if (len != static_cast<std::size_t>(-1))
if (len != detail::unknown_size())
{
for (std::size_t i = 0; i < len; ++i)
{
Expand All @@ -1134,7 +1134,7 @@ class binary_reader
}

/*!
@param[in] len the length of the object or static_cast<std::size_t>(-1) for an
@param[in] len the length of the object or detail::unknown_size() for an
object of indefinite size
@param[in] tag_handler how CBOR tags should be treated
@return whether object creation completed
Expand All @@ -1150,7 +1150,7 @@ class binary_reader
if (len != 0)
{
string_t key;
if (len != static_cast<std::size_t>(-1))
if (len != detail::unknown_size())
{
for (std::size_t i = 0; i < len; ++i)
{
Expand Down Expand Up @@ -2568,7 +2568,7 @@ class binary_reader
}
else
{
if (JSON_HEDLEY_UNLIKELY(!sax->start_array(static_cast<std::size_t>(-1))))
if (JSON_HEDLEY_UNLIKELY(!sax->start_array(detail::unknown_size())))
{
return false;
}
Expand Down Expand Up @@ -2646,7 +2646,7 @@ class binary_reader
}
else
{
if (JSON_HEDLEY_UNLIKELY(!sax->start_object(static_cast<std::size_t>(-1))))
if (JSON_HEDLEY_UNLIKELY(!sax->start_object(detail::unknown_size())))
{
return false;
}
Expand Down Expand Up @@ -2982,7 +2982,7 @@ class binary_reader
}

private:
static JSON_INLINE_VARIABLE constexpr std::size_t npos = static_cast<std::size_t>(-1);
static JSON_INLINE_VARIABLE constexpr std::size_t npos = detail::unknown_size();

/// input adapter
InputAdapterType ia;
Expand Down
17 changes: 11 additions & 6 deletions include/nlohmann/detail/input/json_sax.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ struct json_sax

namespace detail
{
constexpr std::size_t unknown_size()
{
return (std::numeric_limits<std::size_t>::max)();
}

/*!
@brief SAX implementation to create a JSON value from SAX events
Expand Down Expand Up @@ -242,7 +247,7 @@ class json_sax_dom_parser
}
#endif

if (JSON_HEDLEY_UNLIKELY(len != static_cast<std::size_t>(-1) && len > ref_stack.back()->max_size()))
if (JSON_HEDLEY_UNLIKELY(len != detail::unknown_size() && len > ref_stack.back()->max_size()))
{
JSON_THROW(out_of_range::create(408, concat("excessive object size: ", std::to_string(len)), ref_stack.back()));
}
Expand Down Expand Up @@ -291,7 +296,7 @@ class json_sax_dom_parser
}
#endif

if (JSON_HEDLEY_UNLIKELY(len != static_cast<std::size_t>(-1) && len > ref_stack.back()->max_size()))
if (JSON_HEDLEY_UNLIKELY(len != detail::unknown_size() && len > ref_stack.back()->max_size()))
{
JSON_THROW(out_of_range::create(408, concat("excessive array size: ", std::to_string(len)), ref_stack.back()));
}
Expand Down Expand Up @@ -559,7 +564,7 @@ class json_sax_dom_callback_parser
#endif

// check object limit
if (JSON_HEDLEY_UNLIKELY(len != static_cast<std::size_t>(-1) && len > ref_stack.back()->max_size()))
if (JSON_HEDLEY_UNLIKELY(len != detail::unknown_size() && len > ref_stack.back()->max_size()))
{
JSON_THROW(out_of_range::create(408, concat("excessive object size: ", std::to_string(len)), ref_stack.back()));
}
Expand Down Expand Up @@ -657,7 +662,7 @@ class json_sax_dom_callback_parser
#endif

// check array limit
if (JSON_HEDLEY_UNLIKELY(len != static_cast<std::size_t>(-1) && len > ref_stack.back()->max_size()))
if (JSON_HEDLEY_UNLIKELY(len != detail::unknown_size() && len > ref_stack.back()->max_size()))
{
JSON_THROW(out_of_range::create(408, concat("excessive array size: ", std::to_string(len)), ref_stack.back()));
}
Expand Down Expand Up @@ -946,7 +951,7 @@ class json_sax_acceptor
return true;
}

bool start_object(std::size_t /*unused*/ = static_cast<std::size_t>(-1))
bool start_object(std::size_t /*unused*/ = detail::unknown_size())
{
return true;
}
Expand All @@ -961,7 +966,7 @@ class json_sax_acceptor
return true;
}

bool start_array(std::size_t /*unused*/ = static_cast<std::size_t>(-1))
bool start_array(std::size_t /*unused*/ = detail::unknown_size())
{
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions include/nlohmann/detail/input/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class parser
{
case token_type::begin_object:
{
if (JSON_HEDLEY_UNLIKELY(!sax->start_object(static_cast<std::size_t>(-1))))
if (JSON_HEDLEY_UNLIKELY(!sax->start_object(detail::unknown_size())))
{
return false;
}
Expand Down Expand Up @@ -239,7 +239,7 @@ class parser

case token_type::begin_array:
{
if (JSON_HEDLEY_UNLIKELY(!sax->start_array(static_cast<std::size_t>(-1))))
if (JSON_HEDLEY_UNLIKELY(!sax->start_array(detail::unknown_size())))
{
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,10 +751,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
return it;
}

reference set_parent(reference j, std::size_t old_capacity = static_cast<std::size_t>(-1))
reference set_parent(reference j, std::size_t old_capacity = detail::unknown_size())
{
#if JSON_DIAGNOSTICS
if (old_capacity != static_cast<std::size_t>(-1))
if (old_capacity != detail::unknown_size())
{
// see https://github.com/nlohmann/json/issues/2838
JSON_ASSERT(type() == value_t::array);
Expand Down
Loading

0 comments on commit f9eb241

Please sign in to comment.