mirror of
https://github.com/MariaDB/server.git
synced 2026-05-16 20:07:13 +02:00
Made optional Json_writer_object / Json_writer_array consistency check
This commit is contained in:
parent
cf8e78a401
commit
052dda61bb
3 changed files with 22 additions and 0 deletions
|
|
@ -185,6 +185,10 @@ IF(DISABLE_SHARED)
|
|||
SET(WITHOUT_DYNAMIC_PLUGINS 1)
|
||||
ENDIF()
|
||||
OPTION(ENABLED_PROFILING "Enable profiling" ON)
|
||||
OPTION(ENABLED_JSON_WRITER_CONSISTENCY_CHECKS "Enable Json_writer_object / Json_writer_array checking to produce consistent JSON output" OFF)
|
||||
IF(ENABLED_JSON_WRITER_CONSISTENCY_CHECKS)
|
||||
ADD_DEFINITIONS(-DENABLED_JSON_WRITER_CONSISTENCY_CHECKS)
|
||||
ENDIF()
|
||||
OPTION(WITHOUT_SERVER "Build only the client library and clients" OFF)
|
||||
IF(UNIX)
|
||||
OPTION(WITH_VALGRIND "Valgrind instrumentation" OFF)
|
||||
|
|
|
|||
|
|
@ -260,7 +260,9 @@ void Json_writer::add_str(const String &str)
|
|||
add_str(str.ptr(), str.length());
|
||||
}
|
||||
|
||||
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
|
||||
thread_local std::vector<bool> Json_writer_struct::named_items_expectation;
|
||||
#endif
|
||||
|
||||
Json_writer_temp_disable::Json_writer_temp_disable(THD *thd_arg)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -312,7 +312,9 @@ public:
|
|||
/* A common base for Json_writer_object and Json_writer_array */
|
||||
class Json_writer_struct
|
||||
{
|
||||
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
|
||||
static thread_local std::vector<bool> named_items_expectation;
|
||||
#endif
|
||||
protected:
|
||||
Json_writer* my_writer;
|
||||
Json_value_helper context;
|
||||
|
|
@ -327,12 +329,16 @@ public:
|
|||
my_writer= thd->opt_trace.get_current_json();
|
||||
context.init(my_writer);
|
||||
closed= false;
|
||||
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
|
||||
named_items_expectation.push_back(expect_named_children);
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual ~Json_writer_struct()
|
||||
{
|
||||
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
|
||||
named_items_expectation.pop_back();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool trace_started() const
|
||||
|
|
@ -340,11 +346,13 @@ public:
|
|||
return my_writer != 0;
|
||||
}
|
||||
|
||||
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
|
||||
bool named_item_expected() const
|
||||
{
|
||||
return named_items_expectation.size() > 1
|
||||
&& *(named_items_expectation.rbegin() + 1);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -367,7 +375,9 @@ public:
|
|||
explicit Json_writer_object(THD *thd)
|
||||
: Json_writer_struct(thd, true)
|
||||
{
|
||||
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
|
||||
DBUG_ASSERT(!named_item_expected());
|
||||
#endif
|
||||
if (unlikely(my_writer))
|
||||
my_writer->start_object();
|
||||
}
|
||||
|
|
@ -375,7 +385,9 @@ public:
|
|||
explicit Json_writer_object(THD* thd, const char *str)
|
||||
: Json_writer_struct(thd, true)
|
||||
{
|
||||
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
|
||||
DBUG_ASSERT(named_item_expected());
|
||||
#endif
|
||||
if (unlikely(my_writer))
|
||||
my_writer->add_member(str).start_object();
|
||||
}
|
||||
|
|
@ -542,7 +554,9 @@ public:
|
|||
Json_writer_array(THD *thd)
|
||||
: Json_writer_struct(thd, false)
|
||||
{
|
||||
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
|
||||
DBUG_ASSERT(!named_item_expected());
|
||||
#endif
|
||||
if (unlikely(my_writer))
|
||||
my_writer->start_array();
|
||||
}
|
||||
|
|
@ -550,7 +564,9 @@ public:
|
|||
Json_writer_array(THD *thd, const char *str)
|
||||
: Json_writer_struct(thd, false)
|
||||
{
|
||||
#ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
|
||||
DBUG_ASSERT(named_item_expected());
|
||||
#endif
|
||||
if (unlikely(my_writer))
|
||||
my_writer->add_member(str).start_array();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue