mirror of
https://github.com/nlohmann/json.git
synced 2026-10-01 06:25:17 +00:00
Copying and comparing stopped their descent at basic_json::nesting_depth_limit(), while serializing, hashing and merging used detail::recursion_depth_limit(). Both were 128, but nothing kept them equal. The thread-local count now tests against detail::recursion_depth_limit() as well, and a static_assert keeps the limit small enough for the byte that holds the count. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
42 lines
1.2 KiB
C++
42 lines
1.2 KiB
C++
// __ _____ _____ _____
|
|
// __| | __| | | | JSON for Modern C++
|
|
// | | |__ | | | | | | version 3.12.0
|
|
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
|
//
|
|
// SPDX-FileCopyrightText: 2013-2026 Niels Lohmann <https://nlohmann.me>
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#pragma once
|
|
|
|
#include <cstddef> // size_t
|
|
|
|
#include <nlohmann/detail/abi_macros.hpp>
|
|
|
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
|
namespace detail
|
|
{
|
|
|
|
/*!
|
|
@brief the number of nesting levels an operation recurses into
|
|
|
|
Operations that walk a value (copying, comparing, serializing, hashing, merging,
|
|
...) recurse once
|
|
per nesting level, which is fastest, but a value nested deeply enough would
|
|
exhaust the call stack. So they recurse only this many levels deep and finish
|
|
whatever lies below with an explicit stack. All of them share this limit.
|
|
|
|
Most of them pass the depth down as an argument. The copy constructor and the
|
|
comparison operators cannot, as their signatures are fixed, so they count it
|
|
in basic_json::nesting_depth() instead, a byte per thread; the limit must
|
|
therefore stay below 255.
|
|
|
|
@sa https://github.com/nlohmann/json/issues/5387
|
|
*/
|
|
constexpr std::size_t recursion_depth_limit() noexcept
|
|
{
|
|
return 128;
|
|
}
|
|
|
|
} // namespace detail
|
|
NLOHMANN_JSON_NAMESPACE_END
|