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

[libvirt] [libvirt-glib 13/23] Remove GVirConfigObject::docHandle



GVirConfigObject also contains an xmlNodePtr which is more useful
since it indicates the position of the current config object in
the source XML file. Since xmlNode has a 'doc' member, having
both an xmlNodePtr and an xmlDocPtr in GVirConfigObject is
redundant.
---
 libvirt-gconfig/libvirt-gconfig-object.c |   50 +++++++++++++----------------
 libvirt-gconfig/libvirt-gconfig-object.h |    1 -
 libvirt-gconfig/libvirt-gconfig.sym      |    1 -
 3 files changed, 22 insertions(+), 30 deletions(-)

diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c
index 66102ec..b7829c9 100644
--- a/libvirt-gconfig/libvirt-gconfig-object.c
+++ b/libvirt-gconfig/libvirt-gconfig-object.c
@@ -43,10 +43,6 @@ struct _GVirConfigObjectPrivate
     gchar *doc;
     gchar *schema;
 
-    /* FIXME: docHandle is node->doc, can probably be removed to avoid the
-     * 2 getting out of sync
-     */
-    xmlDocPtr docHandle;
     xmlNodePtr node;
 };
 
@@ -117,15 +113,17 @@ static void gvir_config_object_set_property(GObject *object,
         priv->schema = g_value_dup_string(value);
         break;
 
-    case PROP_NODE:
-        priv->node = g_value_get_pointer(value);
-        if ((priv->docHandle != NULL) && (priv->docHandle != priv->node->doc))
-            xmlFreeDoc(priv->docHandle);
-        if (priv->node)
-            priv->docHandle = priv->node->doc;
-        else
-            priv->docHandle = NULL;
+    case PROP_NODE: {
+        xmlNodePtr node;
+        node = g_value_get_pointer(value);
+        if ((priv->node != NULL)
+             && (priv->node->doc != NULL)
+             && (priv->node->doc != node->doc)) {
+            xmlFreeDoc(priv->node->doc);
+        }
+        priv->node = node;
         break;
+    }
 
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
@@ -143,8 +141,12 @@ static void gvir_config_object_finalize(GObject *object)
     g_free(priv->doc);
     g_free(priv->schema);
 
-    if (priv->docHandle)
-        xmlFreeDoc(priv->docHandle);
+    /* FIXME: all objects describing a given XML document will share the
+     * same document so we can't destroy it here like this, we need some
+     * refcounting to know when to destroy it.
+     */
+    if (priv->node)
+        xmlFreeDoc(priv->node->doc);
 
     G_OBJECT_CLASS(gvir_config_object_parent_class)->finalize(object);
 }
@@ -212,7 +214,8 @@ gvir_config_object_parse(GVirConfigObject *config,
                          GError **err)
 {
     GVirConfigObjectPrivate *priv = config->priv;
-    if (priv->docHandle)
+    xmlDocPtr doc;
+    if (priv->node)
         return;
 
     if (!priv->doc) {
@@ -223,14 +226,14 @@ gvir_config_object_parse(GVirConfigObject *config,
         return;
     }
 
-    priv->docHandle = xmlParseMemory(priv->doc, strlen(priv->doc));
-    if (!priv->docHandle) {
+    doc = xmlParseMemory(priv->doc, strlen(priv->doc));
+    if (!doc) {
         *err = gvir_xml_error_new(GVIR_CONFIG_OBJECT_ERROR,
                                   0,
                                   "%s",
                                   "Unable to parse configuration");
     }
-    priv->node = priv->docHandle->children;
+    priv->node = doc->children;
 }
 
 
@@ -279,7 +282,7 @@ void gvir_config_object_validate(GVirConfigObject *config,
         return;
     }
 
-    if (xmlRelaxNGValidateDoc(rngValid, priv->docHandle) != 0) {
+    if (xmlRelaxNGValidateDoc(rngValid, priv->node->doc) != 0) {
         *err = gvir_xml_error_new(GVIR_CONFIG_OBJECT_ERROR,
                                   0,
                                   "%s",
@@ -324,15 +327,6 @@ const gchar *gvir_config_object_get_schema(GVirConfigObject *config)
     return priv->schema;
 }
 
-/* NB: the xmlDocPtr must not be freed by the caller */
-/* gupnp has wrapped xmlDoc in a gobject */
-/* not really useful, can be obtained from xmlNode::doc */
-xmlDocPtr gvir_config_object_get_xml_doc(GVirConfigObject *config, GError **error)
-{
-    gvir_config_object_parse(config, error);
-    return config->priv->docHandle;
-}
-
 /* FIXME: will we always have one xmlNode per GConfig object? */
 /* FIXME: need to return the right node from subclasses */
 /* NB: the xmlNodePtr must not be freed by the caller */
diff --git a/libvirt-gconfig/libvirt-gconfig-object.h b/libvirt-gconfig/libvirt-gconfig-object.h
index f6ac28b..40480ba 100644
--- a/libvirt-gconfig/libvirt-gconfig-object.h
+++ b/libvirt-gconfig/libvirt-gconfig-object.h
@@ -66,7 +66,6 @@ gchar *gvir_config_object_to_xml(GVirConfigObject *config);
 
 const gchar *gvir_config_object_get_doc(GVirConfigObject *config);
 const gchar *gvir_config_object_get_schema(GVirConfigObject *config);
-xmlDocPtr  gvir_config_object_get_xml_doc(GVirConfigObject *config, GError **error);
 xmlNodePtr gvir_config_object_get_xml_node(GVirConfigObject *config, GError **error);
 
 G_END_DECLS
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
index 5c4492e..94e596e 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -29,7 +29,6 @@ LIBVIRT_GOBJECT_0.0.1 {
 	gvir_config_object_new;
 	gvir_config_object_get_doc;
 	gvir_config_object_get_schema;
-	gvir_config_object_get_xml_doc;
 	gvir_config_object_get_xml_node;
 	gvir_config_object_to_xml;
 	gvir_config_object_validate;
-- 
1.7.6.4


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