mirror of
https://github.com/matrix-construct/construct
synced 2024-11-17 15:30:52 +01:00
ircd::json: Improve conformity of various limitation constants.
This commit is contained in:
parent
e2431a3f18
commit
efc4831497
4 changed files with 33 additions and 13 deletions
|
@ -51,7 +51,7 @@ struct ircd::json::iov
|
||||||
IRCD_EXCEPTION(error, exists);
|
IRCD_EXCEPTION(error, exists);
|
||||||
IRCD_EXCEPTION(error, oversize);
|
IRCD_EXCEPTION(error, oversize);
|
||||||
|
|
||||||
static const size_t MAX_SIZE;
|
static const size_t max_size;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool has(const string_view &key) const;
|
bool has(const string_view &key) const;
|
||||||
|
|
|
@ -71,6 +71,7 @@ struct ircd::json::object
|
||||||
using key_compare = std::less<member>;
|
using key_compare = std::less<member>;
|
||||||
|
|
||||||
static const uint max_recursion_depth;
|
static const uint max_recursion_depth;
|
||||||
|
static const size_t max_sorted_members;
|
||||||
|
|
||||||
// fundamental
|
// fundamental
|
||||||
const_iterator end() const;
|
const_iterator end() const;
|
||||||
|
|
|
@ -56,6 +56,8 @@ namespace ircd::json
|
||||||
///
|
///
|
||||||
struct ircd::json::value
|
struct ircd::json::value
|
||||||
{
|
{
|
||||||
|
static const size_t max_string_size;
|
||||||
|
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
int64_t integer;
|
int64_t integer;
|
||||||
|
|
41
ircd/json.cc
41
ircd/json.cc
|
@ -1253,8 +1253,8 @@ ircd::json::_prev(chase &c)
|
||||||
// iov.h
|
// iov.h
|
||||||
//
|
//
|
||||||
|
|
||||||
decltype(ircd::json::iov::MAX_SIZE)
|
decltype(ircd::json::iov::max_size)
|
||||||
ircd::json::iov::MAX_SIZE
|
ircd::json::iov::max_size
|
||||||
{
|
{
|
||||||
1024
|
1024
|
||||||
};
|
};
|
||||||
|
@ -1271,11 +1271,13 @@ ircd::json::stringify(mutable_buffer &buf,
|
||||||
const iov &iov)
|
const iov &iov)
|
||||||
{
|
{
|
||||||
const ctx::critical_assertion ca;
|
const ctx::critical_assertion ca;
|
||||||
thread_local const member *m[iov.MAX_SIZE];
|
thread_local const member *m[iov.max_size];
|
||||||
if(unlikely(size_t(iov.size()) > iov.MAX_SIZE))
|
if(unlikely(size_t(iov.size()) > iov.max_size))
|
||||||
throw iov::oversize
|
throw iov::oversize
|
||||||
{
|
{
|
||||||
"IOV has %zd members but maximum is %zu", iov.size(), iov.MAX_SIZE
|
"IOV has %zd members but maximum is %zu",
|
||||||
|
iov.size(),
|
||||||
|
iov.max_size
|
||||||
};
|
};
|
||||||
|
|
||||||
std::transform(std::begin(iov), std::end(iov), m, []
|
std::transform(std::begin(iov), std::end(iov), m, []
|
||||||
|
@ -1561,7 +1563,7 @@ ircd::json::insert(const strung &s,
|
||||||
};
|
};
|
||||||
|
|
||||||
size_t mctr {0};
|
size_t mctr {0};
|
||||||
thread_local std::array<member, iov::MAX_SIZE> mb;
|
thread_local std::array<member, iov::max_size> mb;
|
||||||
for(const object::member &m : object{s})
|
for(const object::member &m : object{s})
|
||||||
mb.at(mctr++) = member{m};
|
mb.at(mctr++) = member{m};
|
||||||
|
|
||||||
|
@ -1588,7 +1590,7 @@ ircd::json::remove(const strung &s,
|
||||||
};
|
};
|
||||||
|
|
||||||
size_t mctr {0};
|
size_t mctr {0};
|
||||||
thread_local std::array<object::member, iov::MAX_SIZE> mb;
|
thread_local std::array<object::member, iov::max_size> mb;
|
||||||
for(const object::member &m : object{s})
|
for(const object::member &m : object{s})
|
||||||
if(m.first != key)
|
if(m.first != key)
|
||||||
mb.at(mctr++) = m;
|
mb.at(mctr++) = m;
|
||||||
|
@ -1615,7 +1617,7 @@ ircd::json::remove(const strung &s,
|
||||||
};
|
};
|
||||||
|
|
||||||
size_t mctr{0}, i{0};
|
size_t mctr{0}, i{0};
|
||||||
thread_local std::array<string_view, iov::MAX_SIZE> mb;
|
thread_local std::array<string_view, iov::max_size> mb;
|
||||||
for(const string_view &m : array{s})
|
for(const string_view &m : array{s})
|
||||||
if(i++ != idx)
|
if(i++ != idx)
|
||||||
mb.at(mctr++) = m;
|
mb.at(mctr++) = m;
|
||||||
|
@ -1707,11 +1709,17 @@ const
|
||||||
//
|
//
|
||||||
|
|
||||||
decltype(ircd::json::object::max_recursion_depth)
|
decltype(ircd::json::object::max_recursion_depth)
|
||||||
const ircd::json::object::max_recursion_depth
|
ircd::json::object::max_recursion_depth
|
||||||
{
|
{
|
||||||
32
|
32
|
||||||
};
|
};
|
||||||
|
|
||||||
|
decltype(ircd::json::object::max_sorted_members)
|
||||||
|
ircd::json::object::max_sorted_members
|
||||||
|
{
|
||||||
|
iov::max_size
|
||||||
|
};
|
||||||
|
|
||||||
std::ostream &
|
std::ostream &
|
||||||
ircd::json::operator<<(std::ostream &s, const object::member &member)
|
ircd::json::operator<<(std::ostream &s, const object::member &member)
|
||||||
{
|
{
|
||||||
|
@ -1754,7 +1762,7 @@ ircd::json::stringify(mutable_buffer &buf,
|
||||||
const object &object)
|
const object &object)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using member_array = std::array<object::member, iov::MAX_SIZE>;
|
using member_array = std::array<object::member, object::max_sorted_members>;
|
||||||
using member_arrays = std::array<member_array, object::max_recursion_depth>;
|
using member_arrays = std::array<member_array, object::max_recursion_depth>;
|
||||||
static_assert(sizeof(member_arrays) == 1_MiB); // yay reentrance .. joy :/
|
static_assert(sizeof(member_arrays) == 1_MiB); // yay reentrance .. joy :/
|
||||||
|
|
||||||
|
@ -2165,7 +2173,7 @@ ircd::json::stringify(mutable_buffer &buf,
|
||||||
const member *const &e)
|
const member *const &e)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using member_array = std::array<const member *, iov::MAX_SIZE>;
|
using member_array = std::array<const member *, object::max_sorted_members>;
|
||||||
using member_arrays = std::array<member_array, object::max_recursion_depth>;
|
using member_arrays = std::array<member_array, object::max_recursion_depth>;
|
||||||
static_assert(sizeof(member_arrays) == 256_KiB);
|
static_assert(sizeof(member_arrays) == 256_KiB);
|
||||||
|
|
||||||
|
@ -2277,6 +2285,12 @@ static_assert
|
||||||
ircd::json::undefined_number != 0
|
ircd::json::undefined_number != 0
|
||||||
);
|
);
|
||||||
|
|
||||||
|
decltype(ircd::json::value::max_string_size)
|
||||||
|
ircd::json::value::max_string_size
|
||||||
|
{
|
||||||
|
64_KiB
|
||||||
|
};
|
||||||
|
|
||||||
std::ostream &
|
std::ostream &
|
||||||
ircd::json::operator<<(std::ostream &s, const value &v)
|
ircd::json::operator<<(std::ostream &s, const value &v)
|
||||||
{
|
{
|
||||||
|
@ -2492,7 +2506,10 @@ ircd::json::serialized(const value &v)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
throw type_error("deciding the size of a type[%u] is undefined", int(v.type));
|
throw type_error
|
||||||
|
{
|
||||||
|
"deciding the size of a type[%u] is undefined", int(v.type)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
|
|
Loading…
Reference in a new issue