Skip to content

Commit

Permalink
base json_parser stack capacity on max_nesting_depth
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Aug 9, 2024
1 parent 2fa50cc commit c6c631b
Showing 1 changed file with 72 additions and 122 deletions.
194 changes: 72 additions & 122 deletions include/jsoncons/basic_json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2220,63 +2220,6 @@ namespace jsoncons {
}
}

template <typename TypeL,typename TypeR>
void copy_assignment_l_r(const basic_json& other)
{
copy_assignment_l_r(identity<TypeL>(), identity<TypeR>(), other);
}

template <typename TypeL,typename TypeR>
void copy_assignment_l_r(identity<TypeL>,identity<TypeR>,const basic_json& other)
{
destroy();
uninitialized_copy(other);
}

void copy_assignment_l_r(identity<long_string_storage>,identity<long_string_storage>,const basic_json& other)
{
cast<long_string_storage>().assign(other.cast<long_string_storage>());
}

void copy_assignment_l_r(identity<byte_string_storage>,identity<byte_string_storage>,const basic_json& other)
{
cast<byte_string_storage>().assign(other.cast<byte_string_storage>());
}

void copy_assignment_l_r(identity<array_storage>,identity<array_storage>,const basic_json& other)
{
cast<array_storage>().assign(other.cast<array_storage>());
}

void copy_assignment_l_r(identity<object_storage>,identity<object_storage>,const basic_json& other)
{
cast<object_storage>().assign(other.cast<object_storage>());
}

template <typename TypeR>
void copy_assignment_r(const basic_json& other)
{
switch (storage_kind())
{
case json_storage_kind::null: copy_assignment_l_r<null_storage,TypeR>(other);break;
case json_storage_kind::empty_object: copy_assignment_l_r<empty_object_storage,TypeR>(other);break;
case json_storage_kind::boolean: copy_assignment_l_r<bool_storage,TypeR>(other);break;
case json_storage_kind::int64: copy_assignment_l_r<int64_storage,TypeR>(other);break;
case json_storage_kind::uint64: copy_assignment_l_r<uint64_storage,TypeR>(other);break;
case json_storage_kind::half_float: copy_assignment_l_r<half_storage,TypeR>(other);break;
case json_storage_kind::float64: copy_assignment_l_r<double_storage,TypeR>(other);break;
case json_storage_kind::short_str: copy_assignment_l_r<short_string_storage,TypeR>(other);break;
case json_storage_kind::const_json_pointer: copy_assignment_l_r<json_const_pointer_storage,TypeR>(other);break;
case json_storage_kind::long_str: copy_assignment_l_r<long_string_storage,TypeR>(other);break;
case json_storage_kind::byte_str: copy_assignment_l_r<byte_string_storage,TypeR>(other);break;
case json_storage_kind::array: copy_assignment_l_r<array_storage,TypeR>(other);break;
case json_storage_kind::object: copy_assignment_l_r<object_storage,TypeR>(other);break;
default:
JSONCONS_UNREACHABLE();
break;
}
}

void copy_assignment(const basic_json& other)
{
if (is_scalar(other.storage_kind()))
Expand All @@ -2289,16 +2232,48 @@ namespace jsoncons {
switch (other.storage_kind())
{
case json_storage_kind::long_str:
copy_assignment_r<long_string_storage>(other);
if (storage_kind() == json_storage_kind::long_str)
{
cast<long_string_storage>().assign(other.cast<long_string_storage>());
}
else
{
destroy();
uninitialized_copy(other);
}
break;
case json_storage_kind::byte_str:
copy_assignment_r<byte_string_storage>(other);
if (storage_kind() == json_storage_kind::byte_str)
{
cast<byte_string_storage>().assign(other.cast<byte_string_storage>());
}
else
{
destroy();
uninitialized_copy(other);
}
break;
case json_storage_kind::array:
copy_assignment_r<array_storage>(other);
if (storage_kind() == json_storage_kind::array)
{
cast<array_storage>().assign(other.cast<array_storage>());
}
else
{
destroy();
uninitialized_copy(other);
}
break;
case json_storage_kind::object:
copy_assignment_r<object_storage>(other);
if (storage_kind() == json_storage_kind::object)
{
cast<object_storage>().assign(other.cast<object_storage>());
}
else
{
destroy();
uninitialized_copy(other);
}
break;
default:
JSONCONS_UNREACHABLE();
Expand All @@ -2307,63 +2282,6 @@ namespace jsoncons {
}
}

template <typename TypeL,typename TypeR>
void move_assignment_l_r(basic_json&& other)
{
move_assignment_l_r(identity<TypeL>(), identity<TypeR>(), std::move(other));
}

template <typename TypeL,typename TypeR>
void move_assignment_l_r(identity<TypeL>,identity<TypeR>,basic_json&& other)
{
destroy();
uninitialized_move(std::move(other));
}

void move_assignment_l_r(identity<long_string_storage>,identity<long_string_storage>,basic_json&& other)
{
cast<long_string_storage>().assign(std::move(other.cast<long_string_storage>()));
}

void move_assignment_l_r(identity<byte_string_storage>,identity<byte_string_storage>,basic_json&& other)
{
cast<byte_string_storage>().assign(std::move(other.cast<byte_string_storage>()));
}

void move_assignment_l_r(identity<array_storage>,identity<array_storage>,basic_json&& other)
{
cast<array_storage>().assign(std::move(other.cast<array_storage>()));
}

void move_assignment_l_r(identity<object_storage>,identity<object_storage>,basic_json&& other)
{
cast<object_storage>().assign(std::move(other.cast<object_storage>()));
}

template <typename TypeR>
void move_assignment_r(basic_json&& other)
{
switch (storage_kind())
{
case json_storage_kind::null: move_assignment_l_r<null_storage,TypeR>(std::move(other));break;
case json_storage_kind::empty_object: move_assignment_l_r<empty_object_storage,TypeR>(std::move(other));break;
case json_storage_kind::boolean: move_assignment_l_r<bool_storage,TypeR>(std::move(other));break;
case json_storage_kind::int64: move_assignment_l_r<int64_storage,TypeR>(std::move(other));break;
case json_storage_kind::uint64: move_assignment_l_r<uint64_storage,TypeR>(std::move(other));break;
case json_storage_kind::half_float: move_assignment_l_r<half_storage,TypeR>(std::move(other));break;
case json_storage_kind::float64: move_assignment_l_r<double_storage,TypeR>(std::move(other));break;
case json_storage_kind::short_str: move_assignment_l_r<short_string_storage,TypeR>(std::move(other));break;
case json_storage_kind::const_json_pointer: move_assignment_l_r<json_const_pointer_storage,TypeR>(std::move(other));break;
case json_storage_kind::long_str: move_assignment_l_r<long_string_storage,TypeR>(std::move(other));break;
case json_storage_kind::byte_str: move_assignment_l_r<byte_string_storage,TypeR>(std::move(other));break;
case json_storage_kind::array: move_assignment_l_r<array_storage,TypeR>(std::move(other));break;
case json_storage_kind::object: move_assignment_l_r<object_storage,TypeR>(std::move(other));break;
default:
JSONCONS_UNREACHABLE();
break;
}
}

void move_assignment(basic_json&& other)
{
if (is_scalar(other.storage_kind()))
Expand All @@ -2376,16 +2294,48 @@ namespace jsoncons {
switch (other.storage_kind())
{
case json_storage_kind::long_str:
move_assignment_r<long_string_storage>(std::move(other));
if (storage_kind() == json_storage_kind::long_str)
{
cast<long_string_storage>().assign(std::move(other.cast<long_string_storage>()));
}
else
{
destroy();
uninitialized_move(std::move(other));
}
break;
case json_storage_kind::byte_str:
move_assignment_r<byte_string_storage>(std::move(other));
if (storage_kind() == json_storage_kind::byte_str)
{
cast<byte_string_storage>().assign(std::move(other.cast<byte_string_storage>()));
}
else
{
destroy();
uninitialized_move(std::move(other));
}
break;
case json_storage_kind::array:
move_assignment_r<array_storage>(std::move(other));
if (storage_kind() == json_storage_kind::array)
{
cast<array_storage>().assign(std::move(other.cast<array_storage>()));
}
else
{
destroy();
uninitialized_move(std::move(other));
}
break;
case json_storage_kind::object:
move_assignment_r<object_storage>(std::move(other));
if (storage_kind() == json_storage_kind::object)
{
cast<object_storage>().assign(std::move(other.cast<object_storage>()));
}
else
{
destroy();
uninitialized_move(std::move(other));
}
break;
default:
JSONCONS_UNREACHABLE();
Expand Down

0 comments on commit c6c631b

Please sign in to comment.