Re: [gdome]reference counting
- From: Chaoron <chaoron ludens elte hu>
- To: gdome gnome org
- Subject: Re: [gdome]reference counting
- Date: Tue, 11 Jun 2002 02:00:21 +0200
Here is the code for the above example:
#include <gdome.h>
#define ENABLE_SEGFAULT 0
static void traverse_tree(GdomeNode *root);
static gchar *treetext = "<?xml version=\"1.0\"?>\n" \
"<root><child/></root>\n";
int
main(int argc, char *argv[])
{
GdomeDOMImplementation *imp;
GdomeDocument *doc;
GdomeNode *root, *node;
GdomeDOMString *domstr;
GdomeException exc;
/* Parse tree */
imp = gdome_di_mkref();
doc = gdome_di_createDocFromMemory(imp, treetext,
GDOME_LOAD_PARSING, &exc);
gdome_di_unref(imp, &exc);
root = (GdomeNode *) gdome_doc_documentElement(doc, &exc);
traverse_tree(root);
gdome_n_unref(root, &exc);
gdome_doc_unref(doc, &exc);
/* Create tree "by hand" */
domstr = gdome_str_mkref("root");
imp = gdome_di_mkref();
doc = gdome_di_createDocument(imp, NULL, domstr, NULL, &exc);
gdome_di_unref(imp, &exc);
gdome_str_unref(domstr);
root = (GdomeNode *) gdome_doc_documentElement(doc, &exc);
domstr = gdome_str_mkref("child");
node = (GdomeNode *) gdome_doc_createElement(doc, domstr, &exc);
gdome_str_unref(domstr);
gdome_n_appendChild(root, node, &exc);
gdome_n_unref(node, &exc);
traverse_tree(root);
gdome_n_unref(node, &exc);
gdome_n_unref(root, &exc);
gdome_doc_unref(doc, &exc);
return 0;
}
static void
traverse_tree(GdomeNode *root)
{
GdomeNode *node;
GdomeException exc;
/* (Do something with the current root) */
node = gdome_n_firstChild(root, &exc);
while (node != NULL)
{
traverse_tree(node);
#if ENABLE_SEGFAULT == 1
gdome_n_unref(node, &exc); /* !!! Leak or segfault !!! */
#endif
node = gdome_n_nextSibling(node, &exc);
}
}
I hope it helps you understand the problem.
Daniel
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]