summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Krivonos <name@localhost.localdomain>2021-10-17 12:36:12 +0300
committerSergei Krivonos <name@localhost.localdomain>2021-10-17 13:20:49 +0300
commit052dda61bb8d5fef271ecd091a5b5db25d57040b (patch)
tree4fde1a821b603d795e6451433e00c04d11dcaaa5
parentcf8e78a40170118e2595e35c9c5f43aedeca91a0 (diff)
downloadmariadb-git-052dda61bb8d5fef271ecd091a5b5db25d57040b.tar.gz
Made optional Json_writer_object / Json_writer_array consistency check
-rw-r--r--CMakeLists.txt4
-rw-r--r--sql/my_json_writer.cc2
-rw-r--r--sql/my_json_writer.h16
3 files changed, 22 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 591920450ea..2bafbda9964 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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)
diff --git a/sql/my_json_writer.cc b/sql/my_json_writer.cc
index e4033ed0c02..8e6f0942857 100644
--- a/sql/my_json_writer.cc
+++ b/sql/my_json_writer.cc
@@ -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)
{
diff --git a/sql/my_json_writer.h b/sql/my_json_writer.h
index f91a7c9ba8c..9686984ba9b 100644
--- a/sql/my_json_writer.h
+++ b/sql/my_json_writer.h
@@ -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();
}