Signed-off-by: Rafael Fonseca <r4f4rfs@xxxxxxxxx> --- src/conf/network_conf.c | 31 ++++++++++++++----------------- src/conf/network_conf.h | 12 +++++++++--- src/network/bridge_driver.c | 2 +- tests/networkxml2xmltest.c | 3 +-- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 819b645df7..c56dc95688 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -70,35 +70,32 @@ VIR_ENUM_IMPL(virNetworkTaint, "hook-script", ); -static virClassPtr virNetworkXMLOptionClass; +G_DEFINE_TYPE(virNetworkXMLOption, vir_network_xml_option, G_TYPE_OBJECT); static void -virNetworkXMLOptionDispose(void *obj G_GNUC_UNUSED) +virNetworkXMLOptionFinalize(GObject *obj) { - return; + G_OBJECT_CLASS(vir_network_xml_option_parent_class)->finalize(obj); } -static int -virNetworkXMLOnceInit(void) +static void +vir_network_xml_option_init(virNetworkXMLOption *xmlopt G_GNUC_UNUSED) { - if (!VIR_CLASS_NEW(virNetworkXMLOption, virClassForObject())) - return -1; - - return 0; } -VIR_ONCE_GLOBAL_INIT(virNetworkXML); +static void +vir_network_xml_option_class_init(virNetworkXMLOptionClass *klass) +{ + GObjectClass *obj = G_OBJECT_CLASS(klass); + + obj->finalize = virNetworkXMLOptionFinalize; +} virNetworkXMLOptionPtr virNetworkXMLOptionNew(virXMLNamespacePtr xmlns) { - virNetworkXMLOptionPtr xmlopt; - - if (virNetworkXMLInitialize() < 0) - return NULL; - - if (!(xmlopt = virObjectNew(virNetworkXMLOptionClass))) - return NULL; + virNetworkXMLOptionPtr xmlopt = + VIR_NETWORK_XML_OPTION(g_object_new(VIR_TYPE_NETWORK_XML_OPTION, NULL)); if (xmlns) xmlopt->ns = *xmlns; diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index db7243eef5..e492ca9c6f 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -33,17 +33,23 @@ #include "device_conf.h" #include "virbitmap.h" #include "networkcommon_conf.h" -#include "virobject.h" #include "virmacmap.h" #include "virenum.h" #include "virxml.h" +#include <glib-object.h> struct _virNetworkXMLOption { - virObject parent; + GObject parent; virXMLNamespace ns; }; -typedef struct _virNetworkXMLOption virNetworkXMLOption; + +#define VIR_TYPE_NETWORK_XML_OPTION vir_network_xml_option_get_type() +G_DECLARE_FINAL_TYPE(virNetworkXMLOption, + vir_network_xml_option, + VIR, + NETWORK_XML_OPTION, + GObject); typedef virNetworkXMLOption *virNetworkXMLOptionPtr; diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 6148bf6a7e..77b5aafb60 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -889,7 +889,7 @@ networkStateCleanup(void) return -1; virObjectUnref(network_driver->networkEventState); - virObjectUnref(network_driver->xmlopt); + g_object_unref(network_driver->xmlopt); /* free inactive networks */ virObjectUnref(network_driver->networks); diff --git a/tests/networkxml2xmltest.c b/tests/networkxml2xmltest.c index ec679e72ee..b881e03c3b 100644 --- a/tests/networkxml2xmltest.c +++ b/tests/networkxml2xmltest.c @@ -30,7 +30,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml, int ret; testCompareNetXML2XMLResult result = TEST_COMPARE_NET_XML2XML_RESULT_SUCCESS; virNetworkDefPtr dev = NULL; - virNetworkXMLOptionPtr xmlopt = NULL; + g_autoptr(virNetworkXMLOption) xmlopt = NULL; if (!(xmlopt = networkDnsmasqCreateXMLConf())) goto cleanup; @@ -72,7 +72,6 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml, VIR_FREE(actual); virNetworkDefFree(dev); - virObjectUnref(xmlopt); return ret; } -- 2.25.1