mirror of
https://github.com/matrix-construct/construct
synced 2024-12-27 07:54:05 +01:00
ircd::json::stack: Track and assert the running recursion level.
This commit is contained in:
parent
2aaef63e04
commit
66934f317a
2 changed files with 15 additions and 1 deletions
|
@ -56,6 +56,7 @@ struct ircd::json::stack
|
||||||
checkpoint *cp {nullptr};
|
checkpoint *cp {nullptr};
|
||||||
size_t appended {0};
|
size_t appended {0};
|
||||||
size_t flushed {0};
|
size_t flushed {0};
|
||||||
|
size_t level {0};
|
||||||
size_t hiwat; ///< autoflush watermark
|
size_t hiwat; ///< autoflush watermark
|
||||||
size_t lowat; ///< flush(false) call min watermark
|
size_t lowat; ///< flush(false) call min watermark
|
||||||
|
|
||||||
|
|
15
ircd/json.cc
15
ircd/json.cc
|
@ -671,6 +671,7 @@ noexcept
|
||||||
,cp{std::move(other.cp)}
|
,cp{std::move(other.cp)}
|
||||||
,appended{std::move(other.appended)}
|
,appended{std::move(other.appended)}
|
||||||
,flushed{std::move(other.flushed)}
|
,flushed{std::move(other.flushed)}
|
||||||
|
,level{std::move(other.level)}
|
||||||
,hiwat{std::move(other.hiwat)}
|
,hiwat{std::move(other.hiwat)}
|
||||||
,lowat{std::move(other.lowat)}
|
,lowat{std::move(other.lowat)}
|
||||||
,co{std::move(other.co)}
|
,co{std::move(other.co)}
|
||||||
|
@ -838,9 +839,10 @@ noexcept try
|
||||||
|
|
||||||
log::dwarning
|
log::dwarning
|
||||||
{
|
{
|
||||||
"Flushing json::stack(%p) %zu bytes under %zu checkpoints.",
|
"Flushing json::stack(%p) bytes:%zu level:%zu checkpoints:%zu",
|
||||||
this,
|
this,
|
||||||
size(buf.completed()),
|
size(buf.completed()),
|
||||||
|
level,
|
||||||
invalidated,
|
invalidated,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -939,6 +941,7 @@ bool
|
||||||
ircd::json::stack::done()
|
ircd::json::stack::done()
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
|
assert((opened() && level) || !level);
|
||||||
return closed() && buf.consumed();
|
return closed() && buf.consumed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1057,6 +1060,7 @@ ircd::json::stack::object::object(stack &s)
|
||||||
assert(s.clean());
|
assert(s.clean());
|
||||||
s.co = this;
|
s.co = this;
|
||||||
s.append('{');
|
s.append('{');
|
||||||
|
s.level++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ircd::json::stack::object::object(stack &s,
|
ircd::json::stack::object::object(stack &s,
|
||||||
|
@ -1079,6 +1083,7 @@ ircd::json::stack::object::object(object &po,
|
||||||
pm->co = this;
|
pm->co = this;
|
||||||
s->append('{');
|
s->append('{');
|
||||||
pm->vc |= true;
|
pm->vc |= true;
|
||||||
|
s->level++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ircd::json::stack::object::object(member &pm)
|
ircd::json::stack::object::object(member &pm)
|
||||||
|
@ -1093,6 +1098,7 @@ ircd::json::stack::object::object(member &pm)
|
||||||
pm.co = this;
|
pm.co = this;
|
||||||
s->append('{');
|
s->append('{');
|
||||||
pm.vc |= true;
|
pm.vc |= true;
|
||||||
|
s->level++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ircd::json::stack::object::object(array &pa)
|
ircd::json::stack::object::object(array &pa)
|
||||||
|
@ -1110,6 +1116,7 @@ ircd::json::stack::object::object(array &pa)
|
||||||
s->append(',');
|
s->append(',');
|
||||||
|
|
||||||
s->append('{');
|
s->append('{');
|
||||||
|
s->level++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1136,6 +1143,7 @@ noexcept
|
||||||
|
|
||||||
assert(cm == nullptr);
|
assert(cm == nullptr);
|
||||||
s->append('}');
|
s->append('}');
|
||||||
|
s->level--;
|
||||||
|
|
||||||
if(pm) // branch taken if member of object
|
if(pm) // branch taken if member of object
|
||||||
{
|
{
|
||||||
|
@ -1267,6 +1275,7 @@ ircd::json::stack::array::array(stack &s)
|
||||||
assert(s.clean());
|
assert(s.clean());
|
||||||
s.ca = this;
|
s.ca = this;
|
||||||
s.append('[');
|
s.append('[');
|
||||||
|
s.level++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ircd::json::stack::array::array(stack &s,
|
ircd::json::stack::array::array(stack &s,
|
||||||
|
@ -1289,6 +1298,7 @@ ircd::json::stack::array::array(object &po,
|
||||||
pm->ca = this;
|
pm->ca = this;
|
||||||
s->append('[');
|
s->append('[');
|
||||||
pm->vc |= true;
|
pm->vc |= true;
|
||||||
|
s->level++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ircd::json::stack::array::array(array &pa)
|
ircd::json::stack::array::array(array &pa)
|
||||||
|
@ -1306,6 +1316,7 @@ ircd::json::stack::array::array(array &pa)
|
||||||
s->append(',');
|
s->append(',');
|
||||||
|
|
||||||
s->append('[');
|
s->append('[');
|
||||||
|
s->level++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ircd::json::stack::array::array(member &pm)
|
ircd::json::stack::array::array(member &pm)
|
||||||
|
@ -1320,6 +1331,7 @@ ircd::json::stack::array::array(member &pm)
|
||||||
pm.ca = this;
|
pm.ca = this;
|
||||||
s->append('[');
|
s->append('[');
|
||||||
pm.vc |= true;
|
pm.vc |= true;
|
||||||
|
s->level++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ircd::json::stack::array::~array()
|
ircd::json::stack::array::~array()
|
||||||
|
@ -1337,6 +1349,7 @@ noexcept
|
||||||
assert(co == nullptr);
|
assert(co == nullptr);
|
||||||
assert(ca == nullptr);
|
assert(ca == nullptr);
|
||||||
s->append(']');
|
s->append(']');
|
||||||
|
s->level--;
|
||||||
|
|
||||||
if(pm) // branch taken if member of object
|
if(pm) // branch taken if member of object
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue