Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
grisumbras committed Oct 25, 2023
1 parent 8e77316 commit 01e086a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
24 changes: 11 additions & 13 deletions include/boost/json/detail/impl/stack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,17 @@ reserve_impl(std::size_t n)
// caller checks this
BOOST_ASSERT(n > cap_);

constexpr std::size_t max_storage
= (std::numeric_limits<std::size_t>::max)();
std::size_t cap = cap_ ? cap_ : 32 ;
do
{
if(BOOST_JSON_UNLIKELY( cap > max_storage - cap ))
throw_exception( std::bad_alloc(), BOOST_CURRENT_LOCATION );
cap *= 2;
}
while(cap < n);

if(BOOST_JSON_UNLIKELY( cap > max_storage - cap ))
throw_exception( std::bad_alloc(), BOOST_CURRENT_LOCATION );
// constexpr std::size_t max_storage
// = (std::numeric_limits<std::size_t>::max)();
std::size_t cap = n;
// std::size_t cap = cap_ ? cap_ : 32 ;
// do
// {
// if(BOOST_JSON_UNLIKELY( cap > max_storage - cap ))
// throw_exception( std::bad_alloc(), BOOST_CURRENT_LOCATION );
// cap *= 2;
// }
// while(cap < n);

auto const base = static_cast<unsigned char*>( sp_->allocate(cap) );
if(base_)
Expand Down
11 changes: 11 additions & 0 deletions test/serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,16 @@ class serializer_test
v.pop_back();
st.push(v);

v.pop_back();
st.push(v);

{
std::vector<int> v1;
st.pop( v1 );

BOOST_TEST( v == v1 );
}
v.push_back(4);
{
std::vector<int> v1;
st.pop( v1 );
Expand Down Expand Up @@ -659,6 +669,7 @@ class serializer_test
BOOST_TEST( st.empty() );

st.push( 1 );
st.push(v);
st.clear();
BOOST_TEST( st.empty() );
}
Expand Down

0 comments on commit 01e086a

Please sign in to comment.