[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [libvirt-glib 03/13] Set GVirConfigObject::doc during object creation



Now that we have a refcounted GVirConfigXmlDoc type, make sure we use
it when creating objects deriving from GVirConfigObject.
---
 libvirt-gconfig/libvirt-gconfig-object.c |   40 +++++++++++++++++++++---------
 1 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c
index de760dd..6cca49d 100644
--- a/libvirt-gconfig/libvirt-gconfig-object.c
+++ b/libvirt-gconfig/libvirt-gconfig-object.c
@@ -440,29 +440,45 @@ GVirConfigObject *gvir_config_object_new_from_xml(GType type,
                                                   const gchar *xml,
                                                   GError **error)
 {
+    GVirConfigObject *object;
+    GVirConfigXmlDoc *doc;
     xmlNodePtr node;
 
     node = gvir_config_xml_parse(xml, root_name, error);
     if ((error != NULL) && (*error != NULL))
         return NULL;
-    return GVIR_CONFIG_OBJECT(g_object_new(type,
-                                           "node", node,
-                                           "schema", schema,
-                                           NULL));
+    doc = gvir_config_xml_doc_new(node->doc);
+    object = GVIR_CONFIG_OBJECT(g_object_new(type,
+                                             "doc", doc,
+                                             "node", node,
+                                             "schema", schema,
+                                             NULL));
+    g_object_unref(G_OBJECT(doc));
+
+    return object;
 }
 
 GVirConfigObject *gvir_config_object_new(GType type,
                                          const char *root_name,
                                          const char *schema)
 {
-    xmlDocPtr doc;
+    GVirConfigObject *object;
+    GVirConfigXmlDoc *doc;
+    xmlDocPtr xml_doc;
     xmlNodePtr node;
 
-    doc = xmlNewDoc((xmlChar *)"1.0");
-    node = xmlNewDocNode(doc, NULL, (xmlChar *)root_name, NULL);
-    xmlDocSetRootElement(doc, node);
-    return GVIR_CONFIG_OBJECT(g_object_new(type,
-                                           "node", node,
-                                           "schema", schema,
-                                           NULL));
+    doc = gvir_config_xml_doc_new(NULL);
+    g_object_get(G_OBJECT(doc), "doc", &xml_doc, NULL);
+    g_assert(xml_doc != NULL);
+    node = xmlNewDocNode(xml_doc, NULL, (xmlChar *)root_name, NULL);
+    xmlDocSetRootElement(xml_doc, node);
+    object = GVIR_CONFIG_OBJECT(g_object_new(type,
+                                             "doc", doc,
+                                             "node", node,
+                                             "schema", schema,
+                                             NULL));
+
+    g_object_unref(G_OBJECT(doc));
+
+    return object;
 }
-- 
1.7.7.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]