[devhelp] Create util function to free GNode book tree
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devhelp] Create util function to free GNode book tree
- Date: Fri, 12 May 2017 10:22:42 +0000 (UTC)
commit c4026a96e55d6bcc38c26ed76c0b9cdcc0324607
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri May 12 12:19:41 2017 +0200
Create util function to free GNode book tree
src/dh-book.c | 19 +------------------
src/dh-parser.c | 21 ++-------------------
src/dh-util.c | 30 +++++++++++++++++++++++++++---
src/dh-util.h | 3 +++
4 files changed, 33 insertions(+), 40 deletions(-)
---
diff --git a/src/dh-book.c b/src/dh-book.c
index 12af97d..944f912 100644
--- a/src/dh-book.c
+++ b/src/dh-book.c
@@ -107,14 +107,6 @@ dh_book_dispose (GObject *object)
G_OBJECT_CLASS (dh_book_parent_class)->dispose (object);
}
-static gboolean
-unref_node_link (GNode *node,
- gpointer data)
-{
- dh_link_unref (node->data);
- return FALSE;
-}
-
static void
dh_book_finalize (GObject *object)
{
@@ -122,16 +114,7 @@ dh_book_finalize (GObject *object)
priv = dh_book_get_instance_private (DH_BOOK (object));
- if (priv->tree != NULL) {
- g_node_traverse (priv->tree,
- G_IN_ORDER,
- G_TRAVERSE_ALL,
- -1,
- unref_node_link,
- NULL);
- g_node_destroy (priv->tree);
- }
-
+ _dh_util_free_book_tree (priv->tree);
g_list_free_full (priv->keywords, (GDestroyNotify)dh_link_unref);
g_list_free_full (priv->completions, g_free);
g_free (priv->language);
diff --git a/src/dh-parser.c b/src/dh-parser.c
index 4a8e55a..618855e 100644
--- a/src/dh-parser.c
+++ b/src/dh-parser.c
@@ -24,6 +24,7 @@
#include <string.h>
#include "dh-error.h"
#include "dh-link.h"
+#include "dh-util.h"
/* It's the xmlns attribute. It is currently (well, in 2015 at least) used on
* developer.gnome.org to look for <keyword> elements attached to that
@@ -70,14 +71,6 @@ typedef struct {
guint parsing_keywords : 1;
} DhParser;
-static gboolean
-unref_node_link (GNode *node,
- gpointer data)
-{
- dh_link_unref (node->data);
- return FALSE;
-}
-
static void
dh_parser_free (DhParser *parser)
{
@@ -91,17 +84,7 @@ dh_parser_free (DhParser *parser)
g_free (parser->book_language);
g_list_free_full (parser->keywords, (GDestroyNotify)dh_link_unref);
-
- if (parser->book_node != NULL) {
- g_node_traverse (parser->book_node,
- G_IN_ORDER,
- G_TRAVERSE_ALL,
- -1,
- unref_node_link,
- NULL);
-
- g_node_destroy (parser->book_node);
- }
+ _dh_util_free_book_tree (parser->book_node);
g_free (parser);
}
diff --git a/src/dh-util.c b/src/dh-util.c
index 67aa079..da16361 100644
--- a/src/dh-util.c
+++ b/src/dh-util.c
@@ -1,8 +1,8 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
/*
- * Copyright (C) 2001 Mikael Hallendal <micke imendio com>
- * Copyright (C) 2004,2008 Imendio AB
- * Copyright (C) 2015 Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2001 Mikael Hallendal <micke imendio com>
+ * Copyright (C) 2004, 2008 Imendio AB
+ * Copyright (C) 2015, 2017 Sébastien Wilmet <swilmet gnome org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -291,3 +291,27 @@ dh_util_queue_concat (GQueue *q1,
q2->length = 0;
g_queue_free (q2);
}
+
+static gboolean
+unref_node_link (GNode *node,
+ gpointer data)
+{
+ dh_link_unref (node->data);
+ return FALSE;
+}
+
+void
+_dh_util_free_book_tree (GNode *book_tree)
+{
+ if (book_tree == NULL)
+ return;
+
+ g_node_traverse (book_tree,
+ G_IN_ORDER,
+ G_TRAVERSE_ALL,
+ -1,
+ unref_node_link,
+ NULL);
+
+ g_node_destroy (book_tree);
+}
diff --git a/src/dh-util.h b/src/dh-util.h
index ee3c81a..7f29956 100644
--- a/src/dh-util.h
+++ b/src/dh-util.h
@@ -49,6 +49,9 @@ void dh_util_window_settings_restore (GtkWindow *window,
void dh_util_queue_concat (GQueue *q1,
GQueue *q2);
+G_GNUC_INTERNAL
+void _dh_util_free_book_tree (GNode *book_tree);
+
G_END_DECLS
#endif /* DH_UTIL_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]