From 02ed338afa925c95646f8ea5542ea0801d0edc25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Sun, 19 Aug 2018 07:30:34 +0300 Subject: [PATCH] Remove mxs::Closer As std::unique_ptr can now be used with a json_t, there's no need for the closer. --- include/maxscale/jansson.hh | 28 ----------------- include/maxscale/utils.hh | 5 +++- server/core/config_runtime.cc | 30 +++++++++---------- server/core/internal/httprequest.hh | 2 +- server/modules/filter/masking/maskingrules.cc | 4 +-- 5 files changed, 22 insertions(+), 47 deletions(-) diff --git a/include/maxscale/jansson.hh b/include/maxscale/jansson.hh index 377e9233c..cf8aa56a9 100644 --- a/include/maxscale/jansson.hh +++ b/include/maxscale/jansson.hh @@ -21,7 +21,6 @@ #include #include #include -#include namespace std { @@ -40,28 +39,6 @@ struct default_delete namespace maxscale { -/** - * @class CloserTraits jansson.hh - * - * Specialization of @c CloserTraits for @c json_t*. - */ -template<> -struct CloserTraits -{ - static void close_if(json_t* pJson) - { - if (pJson) - { - json_decref(pJson); - } - } - - static void reset(json_t*& pJson) - { - pJson = NULL; - } -}; - /** * @brief Convenience function for dumping JSON into a string * @@ -83,11 +60,6 @@ static inline std::string json_dump(const json_t* json, int flags = 0) return rval; } -static inline std::string json_dump(const Closer& json, int flags = 0) -{ - return json_dump(json.get(), flags); -} - /** * @brief Convert JSON to string * diff --git a/include/maxscale/utils.hh b/include/maxscale/utils.hh index b77581694..3a78ab53b 100644 --- a/include/maxscale/utils.hh +++ b/include/maxscale/utils.hh @@ -154,7 +154,10 @@ struct CloserTraits * * @param t Close the resource *if* it has not been closed already. */ - static void close_if(T t); + static void close_if(T t) + { + static_assert(sizeof(T) != sizeof(T), "The base closer should never be used"); + } /** * Resets a reference to a resource. After the call, the value of t should diff --git a/server/core/config_runtime.cc b/server/core/config_runtime.cc index 3429641c7..0d5af8a9c 100644 --- a/server/core/config_runtime.cc +++ b/server/core/config_runtime.cc @@ -1721,7 +1721,7 @@ bool server_to_object_relations(SERVER* server, json_t* old_json, json_t* new_js bool runtime_alter_server_from_json(SERVER* server, json_t* new_json) { bool rval = false; - mxs::Closer old_json(server_to_json(server, "")); + std::unique_ptr old_json(server_to_json(server, "")); ss_dassert(old_json.get()); if (is_valid_resource_body(new_json) && @@ -1781,14 +1781,14 @@ static bool is_valid_relationship_body(json_t* json) bool runtime_alter_server_relationships_from_json(SERVER* server, const char* type, json_t* json) { bool rval = false; - mxs::Closer old_json(server_to_json(server, "")); + std::unique_ptr old_json(server_to_json(server, "")); ss_dassert(old_json.get()); if (is_valid_relationship_body(json)) { - mxs::Closer j(json_pack("{s: {s: {s: {s: O}}}}", "data", - "relationships", type, "data", - json_object_get(json, "data"))); + std::unique_ptr j(json_pack("{s: {s: {s: {s: O}}}}", "data", + "relationships", type, "data", + json_object_get(json, "data"))); if (server_to_object_relations(server, old_json.get(), j.get())) { @@ -2067,7 +2067,7 @@ bool service_to_filter_relations(Service* service, json_t* old_json, json_t* new bool runtime_alter_monitor_from_json(MXS_MONITOR* monitor, json_t* new_json) { bool rval = false; - mxs::Closer old_json(monitor_to_json(monitor, "")); + std::unique_ptr old_json(monitor_to_json(monitor, "")); ss_dassert(old_json.get()); if (is_valid_resource_body(new_json) && @@ -2119,14 +2119,14 @@ bool runtime_alter_monitor_from_json(MXS_MONITOR* monitor, json_t* new_json) bool runtime_alter_monitor_relationships_from_json(MXS_MONITOR* monitor, json_t* json) { bool rval = false; - mxs::Closer old_json(monitor_to_json(monitor, "")); + std::unique_ptr old_json(monitor_to_json(monitor, "")); ss_dassert(old_json.get()); if (is_valid_relationship_body(json)) { - mxs::Closer j(json_pack("{s: {s: {s: {s: O}}}}", "data", - "relationships", "servers", "data", - json_object_get(json, "data"))); + std::unique_ptr j(json_pack("{s: {s: {s: {s: O}}}}", "data", + "relationships", "servers", "data", + json_object_get(json, "data"))); if (object_to_server_relations(monitor->name, old_json.get(), j.get())) { @@ -2140,14 +2140,14 @@ bool runtime_alter_monitor_relationships_from_json(MXS_MONITOR* monitor, json_t* bool runtime_alter_service_relationships_from_json(Service* service, const char* type, json_t* json) { bool rval = false; - mxs::Closer old_json(service_to_json(service, "")); + std::unique_ptr old_json(service_to_json(service, "")); ss_dassert(old_json.get()); if (is_valid_relationship_body(json)) { - mxs::Closer j(json_pack("{s: {s: {s: {s: O}}}}", "data", - "relationships", type, "data", - json_object_get(json, "data"))); + std::unique_ptr j(json_pack("{s: {s: {s: {s: O}}}}", "data", + "relationships", type, "data", + json_object_get(json, "data"))); if (strcmp(type, CN_SERVERS) == 0) { @@ -2179,7 +2179,7 @@ static bool is_dynamic_param(const std::string& key) bool runtime_alter_service_from_json(Service* service, json_t* new_json) { bool rval = false; - mxs::Closer old_json(service_to_json(service, "")); + std::unique_ptr old_json(service_to_json(service, "")); ss_dassert(old_json.get()); if (is_valid_resource_body(new_json) && diff --git a/server/core/internal/httprequest.hh b/server/core/internal/httprequest.hh index 8f70bc9ae..9c93fed91 100644 --- a/server/core/internal/httprequest.hh +++ b/server/core/internal/httprequest.hh @@ -286,7 +286,7 @@ private: static const std::string HTTPS_PREFIX; std::map m_options; /**< Request options */ - mxs::Closer m_json; /**< Request body */ + std::unique_ptr m_json; /**< Request body */ std::string m_json_string; /**< String version of @c m_json */ std::string m_resource; /**< Requested resource */ std::deque m_resource_parts; /**< @c m_resource split into parts */ diff --git a/server/modules/filter/masking/maskingrules.cc b/server/modules/filter/masking/maskingrules.cc index a8d52db0c..428714b23 100644 --- a/server/modules/filter/masking/maskingrules.cc +++ b/server/modules/filter/masking/maskingrules.cc @@ -1331,7 +1331,7 @@ auto_ptr MaskingRules::load(const char* zPath) if (pRoot) { - Closer root(pRoot); + std::unique_ptr root(pRoot); sRules = create_from(root.get()); } @@ -1360,7 +1360,7 @@ auto_ptr MaskingRules::parse(const char* zJson) if (pRoot) { - Closer root(pRoot); + std::unique_ptr root(pRoot); sRules = create_from(root.get()); }