🐛 fix leak for all types

parent 0011cd1b
...@@ -30,6 +30,7 @@ struct external_constructor<value_t::boolean> ...@@ -30,6 +30,7 @@ struct external_constructor<value_t::boolean>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, typename BasicJsonType::boolean_t b) noexcept static void construct(BasicJsonType& j, typename BasicJsonType::boolean_t b) noexcept
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::boolean; j.m_type = value_t::boolean;
j.m_value = b; j.m_value = b;
j.assert_invariant(); j.assert_invariant();
...@@ -42,6 +43,7 @@ struct external_constructor<value_t::string> ...@@ -42,6 +43,7 @@ struct external_constructor<value_t::string>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, const typename BasicJsonType::string_t& s) static void construct(BasicJsonType& j, const typename BasicJsonType::string_t& s)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::string; j.m_type = value_t::string;
j.m_value = s; j.m_value = s;
j.assert_invariant(); j.assert_invariant();
...@@ -50,6 +52,7 @@ struct external_constructor<value_t::string> ...@@ -50,6 +52,7 @@ struct external_constructor<value_t::string>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, typename BasicJsonType::string_t&& s) static void construct(BasicJsonType& j, typename BasicJsonType::string_t&& s)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::string; j.m_type = value_t::string;
j.m_value = std::move(s); j.m_value = std::move(s);
j.assert_invariant(); j.assert_invariant();
...@@ -60,6 +63,7 @@ struct external_constructor<value_t::string> ...@@ -60,6 +63,7 @@ struct external_constructor<value_t::string>
int > = 0 > int > = 0 >
static void construct(BasicJsonType& j, const CompatibleStringType& str) static void construct(BasicJsonType& j, const CompatibleStringType& str)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::string; j.m_type = value_t::string;
j.m_value.string = j.template create<typename BasicJsonType::string_t>(str); j.m_value.string = j.template create<typename BasicJsonType::string_t>(str);
j.assert_invariant(); j.assert_invariant();
...@@ -72,6 +76,7 @@ struct external_constructor<value_t::binary> ...@@ -72,6 +76,7 @@ struct external_constructor<value_t::binary>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, const typename BasicJsonType::binary_t& b) static void construct(BasicJsonType& j, const typename BasicJsonType::binary_t& b)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::binary; j.m_type = value_t::binary;
j.m_value = typename BasicJsonType::binary_t(b); j.m_value = typename BasicJsonType::binary_t(b);
j.assert_invariant(); j.assert_invariant();
...@@ -80,6 +85,7 @@ struct external_constructor<value_t::binary> ...@@ -80,6 +85,7 @@ struct external_constructor<value_t::binary>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, typename BasicJsonType::binary_t&& b) static void construct(BasicJsonType& j, typename BasicJsonType::binary_t&& b)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::binary; j.m_type = value_t::binary;
j.m_value = typename BasicJsonType::binary_t(std::move(b));; j.m_value = typename BasicJsonType::binary_t(std::move(b));;
j.assert_invariant(); j.assert_invariant();
...@@ -92,6 +98,7 @@ struct external_constructor<value_t::number_float> ...@@ -92,6 +98,7 @@ struct external_constructor<value_t::number_float>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, typename BasicJsonType::number_float_t val) noexcept static void construct(BasicJsonType& j, typename BasicJsonType::number_float_t val) noexcept
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::number_float; j.m_type = value_t::number_float;
j.m_value = val; j.m_value = val;
j.assert_invariant(); j.assert_invariant();
...@@ -104,6 +111,7 @@ struct external_constructor<value_t::number_unsigned> ...@@ -104,6 +111,7 @@ struct external_constructor<value_t::number_unsigned>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, typename BasicJsonType::number_unsigned_t val) noexcept static void construct(BasicJsonType& j, typename BasicJsonType::number_unsigned_t val) noexcept
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::number_unsigned; j.m_type = value_t::number_unsigned;
j.m_value = val; j.m_value = val;
j.assert_invariant(); j.assert_invariant();
...@@ -116,6 +124,7 @@ struct external_constructor<value_t::number_integer> ...@@ -116,6 +124,7 @@ struct external_constructor<value_t::number_integer>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, typename BasicJsonType::number_integer_t val) noexcept static void construct(BasicJsonType& j, typename BasicJsonType::number_integer_t val) noexcept
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::number_integer; j.m_type = value_t::number_integer;
j.m_value = val; j.m_value = val;
j.assert_invariant(); j.assert_invariant();
...@@ -128,6 +137,7 @@ struct external_constructor<value_t::array> ...@@ -128,6 +137,7 @@ struct external_constructor<value_t::array>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, const typename BasicJsonType::array_t& arr) static void construct(BasicJsonType& j, const typename BasicJsonType::array_t& arr)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::array; j.m_type = value_t::array;
j.m_value = arr; j.m_value = arr;
j.set_parents(); j.set_parents();
...@@ -137,6 +147,7 @@ struct external_constructor<value_t::array> ...@@ -137,6 +147,7 @@ struct external_constructor<value_t::array>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, typename BasicJsonType::array_t&& arr) static void construct(BasicJsonType& j, typename BasicJsonType::array_t&& arr)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::array; j.m_type = value_t::array;
j.m_value = std::move(arr); j.m_value = std::move(arr);
j.set_parents(); j.set_parents();
...@@ -150,6 +161,8 @@ struct external_constructor<value_t::array> ...@@ -150,6 +161,8 @@ struct external_constructor<value_t::array>
{ {
using std::begin; using std::begin;
using std::end; using std::end;
j.m_value.destroy(j.m_type);
j.m_type = value_t::array; j.m_type = value_t::array;
j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr)); j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
j.set_parents(); j.set_parents();
...@@ -159,6 +172,7 @@ struct external_constructor<value_t::array> ...@@ -159,6 +172,7 @@ struct external_constructor<value_t::array>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, const std::vector<bool>& arr) static void construct(BasicJsonType& j, const std::vector<bool>& arr)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::array; j.m_type = value_t::array;
j.m_value = value_t::array; j.m_value = value_t::array;
j.m_value.array->reserve(arr.size()); j.m_value.array->reserve(arr.size());
...@@ -174,6 +188,7 @@ struct external_constructor<value_t::array> ...@@ -174,6 +188,7 @@ struct external_constructor<value_t::array>
enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0> enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0>
static void construct(BasicJsonType& j, const std::valarray<T>& arr) static void construct(BasicJsonType& j, const std::valarray<T>& arr)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::array; j.m_type = value_t::array;
j.m_value = value_t::array; j.m_value = value_t::array;
j.m_value.array->resize(arr.size()); j.m_value.array->resize(arr.size());
...@@ -192,6 +207,7 @@ struct external_constructor<value_t::object> ...@@ -192,6 +207,7 @@ struct external_constructor<value_t::object>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, const typename BasicJsonType::object_t& obj) static void construct(BasicJsonType& j, const typename BasicJsonType::object_t& obj)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::object; j.m_type = value_t::object;
j.m_value = obj; j.m_value = obj;
j.set_parents(); j.set_parents();
...@@ -201,6 +217,7 @@ struct external_constructor<value_t::object> ...@@ -201,6 +217,7 @@ struct external_constructor<value_t::object>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, typename BasicJsonType::object_t&& obj) static void construct(BasicJsonType& j, typename BasicJsonType::object_t&& obj)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::object; j.m_type = value_t::object;
j.m_value = std::move(obj); j.m_value = std::move(obj);
j.set_parents(); j.set_parents();
...@@ -214,6 +231,7 @@ struct external_constructor<value_t::object> ...@@ -214,6 +231,7 @@ struct external_constructor<value_t::object>
using std::begin; using std::begin;
using std::end; using std::end;
j.m_value.destroy(j.m_type);
j.m_type = value_t::object; j.m_type = value_t::object;
j.m_value.object = j.template create<typename BasicJsonType::object_t>(begin(obj), end(obj)); j.m_value.object = j.template create<typename BasicJsonType::object_t>(begin(obj), end(obj));
j.set_parents(); j.set_parents();
...@@ -236,10 +254,6 @@ template<typename BasicJsonType, typename CompatibleString, ...@@ -236,10 +254,6 @@ template<typename BasicJsonType, typename CompatibleString,
enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value, int> = 0> enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value, int> = 0>
void to_json(BasicJsonType& j, const CompatibleString& s) void to_json(BasicJsonType& j, const CompatibleString& s)
{ {
if (!j.is_null())
{
j = BasicJsonType();
}
external_constructor<value_t::string>::construct(j, s); external_constructor<value_t::string>::construct(j, s);
} }
......
...@@ -4488,6 +4488,7 @@ struct external_constructor<value_t::boolean> ...@@ -4488,6 +4488,7 @@ struct external_constructor<value_t::boolean>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, typename BasicJsonType::boolean_t b) noexcept static void construct(BasicJsonType& j, typename BasicJsonType::boolean_t b) noexcept
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::boolean; j.m_type = value_t::boolean;
j.m_value = b; j.m_value = b;
j.assert_invariant(); j.assert_invariant();
...@@ -4500,6 +4501,7 @@ struct external_constructor<value_t::string> ...@@ -4500,6 +4501,7 @@ struct external_constructor<value_t::string>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, const typename BasicJsonType::string_t& s) static void construct(BasicJsonType& j, const typename BasicJsonType::string_t& s)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::string; j.m_type = value_t::string;
j.m_value = s; j.m_value = s;
j.assert_invariant(); j.assert_invariant();
...@@ -4508,6 +4510,7 @@ struct external_constructor<value_t::string> ...@@ -4508,6 +4510,7 @@ struct external_constructor<value_t::string>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, typename BasicJsonType::string_t&& s) static void construct(BasicJsonType& j, typename BasicJsonType::string_t&& s)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::string; j.m_type = value_t::string;
j.m_value = std::move(s); j.m_value = std::move(s);
j.assert_invariant(); j.assert_invariant();
...@@ -4518,6 +4521,7 @@ struct external_constructor<value_t::string> ...@@ -4518,6 +4521,7 @@ struct external_constructor<value_t::string>
int > = 0 > int > = 0 >
static void construct(BasicJsonType& j, const CompatibleStringType& str) static void construct(BasicJsonType& j, const CompatibleStringType& str)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::string; j.m_type = value_t::string;
j.m_value.string = j.template create<typename BasicJsonType::string_t>(str); j.m_value.string = j.template create<typename BasicJsonType::string_t>(str);
j.assert_invariant(); j.assert_invariant();
...@@ -4530,6 +4534,7 @@ struct external_constructor<value_t::binary> ...@@ -4530,6 +4534,7 @@ struct external_constructor<value_t::binary>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, const typename BasicJsonType::binary_t& b) static void construct(BasicJsonType& j, const typename BasicJsonType::binary_t& b)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::binary; j.m_type = value_t::binary;
j.m_value = typename BasicJsonType::binary_t(b); j.m_value = typename BasicJsonType::binary_t(b);
j.assert_invariant(); j.assert_invariant();
...@@ -4538,6 +4543,7 @@ struct external_constructor<value_t::binary> ...@@ -4538,6 +4543,7 @@ struct external_constructor<value_t::binary>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, typename BasicJsonType::binary_t&& b) static void construct(BasicJsonType& j, typename BasicJsonType::binary_t&& b)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::binary; j.m_type = value_t::binary;
j.m_value = typename BasicJsonType::binary_t(std::move(b));; j.m_value = typename BasicJsonType::binary_t(std::move(b));;
j.assert_invariant(); j.assert_invariant();
...@@ -4550,6 +4556,7 @@ struct external_constructor<value_t::number_float> ...@@ -4550,6 +4556,7 @@ struct external_constructor<value_t::number_float>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, typename BasicJsonType::number_float_t val) noexcept static void construct(BasicJsonType& j, typename BasicJsonType::number_float_t val) noexcept
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::number_float; j.m_type = value_t::number_float;
j.m_value = val; j.m_value = val;
j.assert_invariant(); j.assert_invariant();
...@@ -4562,6 +4569,7 @@ struct external_constructor<value_t::number_unsigned> ...@@ -4562,6 +4569,7 @@ struct external_constructor<value_t::number_unsigned>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, typename BasicJsonType::number_unsigned_t val) noexcept static void construct(BasicJsonType& j, typename BasicJsonType::number_unsigned_t val) noexcept
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::number_unsigned; j.m_type = value_t::number_unsigned;
j.m_value = val; j.m_value = val;
j.assert_invariant(); j.assert_invariant();
...@@ -4574,6 +4582,7 @@ struct external_constructor<value_t::number_integer> ...@@ -4574,6 +4582,7 @@ struct external_constructor<value_t::number_integer>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, typename BasicJsonType::number_integer_t val) noexcept static void construct(BasicJsonType& j, typename BasicJsonType::number_integer_t val) noexcept
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::number_integer; j.m_type = value_t::number_integer;
j.m_value = val; j.m_value = val;
j.assert_invariant(); j.assert_invariant();
...@@ -4586,6 +4595,7 @@ struct external_constructor<value_t::array> ...@@ -4586,6 +4595,7 @@ struct external_constructor<value_t::array>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, const typename BasicJsonType::array_t& arr) static void construct(BasicJsonType& j, const typename BasicJsonType::array_t& arr)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::array; j.m_type = value_t::array;
j.m_value = arr; j.m_value = arr;
j.set_parents(); j.set_parents();
...@@ -4595,6 +4605,7 @@ struct external_constructor<value_t::array> ...@@ -4595,6 +4605,7 @@ struct external_constructor<value_t::array>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, typename BasicJsonType::array_t&& arr) static void construct(BasicJsonType& j, typename BasicJsonType::array_t&& arr)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::array; j.m_type = value_t::array;
j.m_value = std::move(arr); j.m_value = std::move(arr);
j.set_parents(); j.set_parents();
...@@ -4608,6 +4619,8 @@ struct external_constructor<value_t::array> ...@@ -4608,6 +4619,8 @@ struct external_constructor<value_t::array>
{ {
using std::begin; using std::begin;
using std::end; using std::end;
j.m_value.destroy(j.m_type);
j.m_type = value_t::array; j.m_type = value_t::array;
j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr)); j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
j.set_parents(); j.set_parents();
...@@ -4617,6 +4630,7 @@ struct external_constructor<value_t::array> ...@@ -4617,6 +4630,7 @@ struct external_constructor<value_t::array>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, const std::vector<bool>& arr) static void construct(BasicJsonType& j, const std::vector<bool>& arr)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::array; j.m_type = value_t::array;
j.m_value = value_t::array; j.m_value = value_t::array;
j.m_value.array->reserve(arr.size()); j.m_value.array->reserve(arr.size());
...@@ -4632,6 +4646,7 @@ struct external_constructor<value_t::array> ...@@ -4632,6 +4646,7 @@ struct external_constructor<value_t::array>
enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0> enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0>
static void construct(BasicJsonType& j, const std::valarray<T>& arr) static void construct(BasicJsonType& j, const std::valarray<T>& arr)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::array; j.m_type = value_t::array;
j.m_value = value_t::array; j.m_value = value_t::array;
j.m_value.array->resize(arr.size()); j.m_value.array->resize(arr.size());
...@@ -4650,6 +4665,7 @@ struct external_constructor<value_t::object> ...@@ -4650,6 +4665,7 @@ struct external_constructor<value_t::object>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, const typename BasicJsonType::object_t& obj) static void construct(BasicJsonType& j, const typename BasicJsonType::object_t& obj)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::object; j.m_type = value_t::object;
j.m_value = obj; j.m_value = obj;
j.set_parents(); j.set_parents();
...@@ -4659,6 +4675,7 @@ struct external_constructor<value_t::object> ...@@ -4659,6 +4675,7 @@ struct external_constructor<value_t::object>
template<typename BasicJsonType> template<typename BasicJsonType>
static void construct(BasicJsonType& j, typename BasicJsonType::object_t&& obj) static void construct(BasicJsonType& j, typename BasicJsonType::object_t&& obj)
{ {
j.m_value.destroy(j.m_type);
j.m_type = value_t::object; j.m_type = value_t::object;
j.m_value = std::move(obj); j.m_value = std::move(obj);
j.set_parents(); j.set_parents();
...@@ -4672,6 +4689,7 @@ struct external_constructor<value_t::object> ...@@ -4672,6 +4689,7 @@ struct external_constructor<value_t::object>
using std::begin; using std::begin;
using std::end; using std::end;
j.m_value.destroy(j.m_type);
j.m_type = value_t::object; j.m_type = value_t::object;
j.m_value.object = j.template create<typename BasicJsonType::object_t>(begin(obj), end(obj)); j.m_value.object = j.template create<typename BasicJsonType::object_t>(begin(obj), end(obj));
j.set_parents(); j.set_parents();
...@@ -4694,10 +4712,6 @@ template<typename BasicJsonType, typename CompatibleString, ...@@ -4694,10 +4712,6 @@ template<typename BasicJsonType, typename CompatibleString,
enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value, int> = 0> enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value, int> = 0>
void to_json(BasicJsonType& j, const CompatibleString& s) void to_json(BasicJsonType& j, const CompatibleString& s)
{ {
if (!j.is_null())
{
j = BasicJsonType();
}
external_constructor<value_t::string>::construct(j, s); external_constructor<value_t::string>::construct(j, s);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment