[gxml: 8/18] * try using an xmlList to track unattached nodes and free them separately from the tree; (doesn't wo



commit affe6df2b81eb88d15eaa6e25e0f7d937fbfa6ca
Author: Richard Schwarting <aquarichy gmail com>
Date:   Sun Jun 9 15:30:42 2013 -0400

    * try using an xmlList to track unattached nodes and free them separately from the tree; (doesn't work)

 gxml/Document.vala   |   19 +++++++++++++++++++
 vapi/libxml-2.0.vapi |   31 +++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 0 deletions(-)
---
diff --git a/gxml/Document.vala b/gxml/Document.vala
index 649ade6..fa41003 100644
--- a/gxml/Document.vala
+++ b/gxml/Document.vala
@@ -181,6 +181,22 @@ namespace GXml {
                        }
                }
 
+               /**
+                * Finalise method for Document.
+                */
+               ~Document () {
+                       for (Xml.Link *front = new_nodes->front (); front != null; front = new_nodes->front 
()) {
+                               front->get_data ()->unlink ();
+                               front->get_data ()->free ();
+
+                               new_nodes->pop_front ();
+                       }
+
+                       this.xmldoc->free (); // TODO: figure out how to properly invoke the free_function on 
non-GObject VAPI'd classes
+               }
+
+               Xml.List *new_nodes;
+
                /** Constructor */
                /**
                 * Creates a Document based on a libxml2 Xml.Doc* object.
@@ -203,6 +219,8 @@ namespace GXml {
                        base.for_document ();
 
                        this.owner_document = this; // this doesn't exist until after base()
+
+                       this.new_nodes = new Xml.List (); // null, null);
                        this.xmldoc = doc;
                        if (doc->int_subset == null && doc->ext_subset == null) {
                                this.doctype = null;
@@ -420,6 +438,7 @@ namespace GXml {
                        Element new_elem;
 
                        xmlelem = this.xmldoc->new_node (null, tag_name, null);
+                       new_nodes->append (xmlelem); // TODO: might want to place this in BackedNode's 
constructorr
                        new_elem = new Element (xmlelem, this);
                        return new_elem;
                }
diff --git a/vapi/libxml-2.0.vapi b/vapi/libxml-2.0.vapi
index b7269cb..6362807 100644
--- a/vapi/libxml-2.0.vapi
+++ b/vapi/libxml-2.0.vapi
@@ -384,6 +384,9 @@ namespace Xml {
                [CCode (cname = "xmlDocFormatDump", instance_pos = 1.1)]
                public int dump_format (GLib.FileStream f, bool format = true);
 
+               [CCode (cname = "xmlFreeDoc")]
+               public void free (); // TODO: Don't want this, find out how to free Vala objects without 
defining their deconstructor; we already set free_function above anyway
+
                [CCode (cname = "xmlDocGetRootElement")]
                public Node* get_root_element();
 
@@ -637,6 +640,31 @@ namespace Xml {
        }
 
        [Compact]
+       [CCode (cname = "xmlLink", cheader_filename = "libxml/list.h")]
+       public class Link {
+               [CCode (cname = "xmlLinkGetData")]
+               public Xml.Node* get_data ();
+       }
+
+       [CCode (cname = "xmlListDeallocator")]
+       public delegate void ListDeallocator (Xml.Link *ptr);
+       [CCode (cname = "xmlListDataCompare")]
+       public delegate void ListDataCompare (Xml.Link *a, Xml.Link *b);
+
+       [Compact]
+       [CCode (cname = "xmlList", free_function = "xmlListDelete", cheader_filename = "libxml/list.h")]
+       public class List {
+               [CCode (cname = "xmlListFront")]
+               public Link front ();
+               [CCode (cname = "xmlListPopFront")]
+               public void pop_front ();
+               [CCode (cname = "xmlListAppend")]
+               public void append (Xml.Node *data);
+               [CCode (cname = "xmlListCreate")]
+               public List (ListDeallocator de = null); //, ListDataCompare co = null);
+       }
+
+       [Compact]
        [CCode (cname = "xmlNode", free_function = "xmlFreeNode", cheader_filename = "libxml/tree.h")]
        public class Node {
                public ElementType type;
@@ -682,6 +710,9 @@ namespace Xml {
                [CCode (cname = "xmlDocCopyNodeList")]
                public Node* doc_copy_list (Doc* doc);
 
+               [CCode (cname = "xmlFreeNode")]
+               public void free (); // TODO: Don't want this, find out how to free Vala objects without 
defining their deconstructor; we already set free_function above anyway
+
                [CCode (cname = "xmlFreeNodeList")]
                public void free_list ();
 


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