[gxml: 12/18] Document.vala, libxml-2.0.vapi: free xmlDoc and Element xmlNode structures; maintain a list of GXml-
- From: Richard Hans Schwarting <rschwart src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml: 12/18] Document.vala, libxml-2.0.vapi: free xmlDoc and Element xmlNode structures; maintain a list of GXml-
- Date: Tue, 18 Jun 2013 18:14:58 +0000 (UTC)
commit e7b2758c304fb8a1513d2caac66e937b4393d8b3
Author: Richard Schwarting <aquarichy gmail com>
Date: Sun Jun 9 18:23:29 2013 -0400
Document.vala, libxml-2.0.vapi: free xmlDoc and Element xmlNode structures; maintain a list of
GXml-created nodes that might not be in the tree for this.
gxml/Document.vala | 23 +++++++++++++++++++++++
vapi/libxml-2.0.vapi | 6 ++++++
2 files changed, 29 insertions(+), 0 deletions(-)
---
diff --git a/gxml/Document.vala b/gxml/Document.vala
index 649ade6..e78fd6b 100644
--- a/gxml/Document.vala
+++ b/gxml/Document.vala
@@ -181,6 +181,28 @@ namespace GXml {
}
}
+ List<Xml.Node*> new_nodes = new List<Xml.Node*> ();
+
+ ~Document () {
+ List<Xml.Node*> to_free = new List<Xml.Node*> ();
+
+ /* we use two separate loops, because freeing
+ a node frees its descendants, and we might
+ have a branch with children that might be
+ visited after their root ancestor
+ */
+ foreach (Xml.Node *new_node in new_nodes) {
+ if (new_node->parent == null) {
+ to_free.append (new_node);
+ }
+ }
+ foreach (Xml.Node *freeable in to_free) {
+ freeable->free ();
+ }
+
+ this.xmldoc->free ();
+ }
+
/** Constructor */
/**
* Creates a Document based on a libxml2 Xml.Doc* object.
@@ -420,6 +442,7 @@ namespace GXml {
Element new_elem;
xmlelem = this.xmldoc->new_node (null, tag_name, null);
+ this.new_nodes.append (xmlelem);
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..6743b1c 100644
--- a/vapi/libxml-2.0.vapi
+++ b/vapi/libxml-2.0.vapi
@@ -393,6 +393,9 @@ namespace Xml {
[CCode (cname = "xmlElemDump", instance_pos = 1.1)]
public void elem_dump (GLib.FileStream f, Node* cur);
+ [CCode (cname = "xmlFreeDoc")]
+ public void free ();
+
[CCode (cname = "xmlGetDocCompressMode")]
public int get_compress_mode ();
@@ -685,6 +688,9 @@ namespace Xml {
[CCode (cname = "xmlFreeNodeList")]
public void free_list ();
+ [CCode (cname = "xmlFreeNode")]
+ public void free ();
+
[CCode (cname = "xmlGetLastChild")]
public Node* get_last_child ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]