[goffice] allow several modules to call go_plugins_init without interfering.



commit 90f514b3f9c311d69a02763e038408a89bcbf19e
Author: Jean Brefort <jean brefort normalesup org>
Date:   Wed Dec 9 17:48:47 2009 +0100

    allow several modules to call go_plugins_init without interfering.

 ChangeLog               |    6 ++++++
 goffice/app/go-plugin.c |   28 +++++++++++++++++++---------
 2 files changed, 25 insertions(+), 9 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 5d8ad5a..1831d14 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2009-12-09  Jean Brefort  <jean brefort normalesup org>
+
+	* goffice/app/go-plugin.c (append_dir), (go_plugins_set_dirs),
+	(go_plugins_init), (go_plugins_add), (go_plugins_shutdown): allow several
+	modules to call go_plugins_init without interfering.
+
 2009-12-07  Jean Brefort  <jean brefort normalesup org>
 
 	* goffice/goffice.c (libgoffice_init), (libgoffice_shutdown): allow
diff --git a/goffice/app/go-plugin.c b/goffice/app/go-plugin.c
index 1ca26e6..bf6d28e 100644
--- a/goffice/app/go-plugin.c
+++ b/goffice/app/go-plugin.c
@@ -1698,13 +1698,21 @@ ghf_collect_new_plugins (gpointer ignored,
 }
 
 static void
+append_dir (gpointer data, G_GNUC_UNUSED gpointer user_data)
+{
+	if (g_slist_find_custom (go_plugin_dirs, data, (GCompareFunc) strcmp))
+		g_free (data);
+	else
+		go_plugin_dirs = g_slist_append (go_plugin_dirs, data);
+}
+
+static void
 go_plugins_set_dirs (GSList *plugin_dirs)
 {
-	if (go_plugin_dirs != plugin_dirs) {
-		g_slist_foreach (go_plugin_dirs, (GFunc) g_free, NULL);
-		g_slist_free (go_plugin_dirs);
-		go_plugin_dirs = plugin_dirs;
-	}
+	if (!go_plugin_dirs)
+		go_plugin_dirs = g_slist_prepend (NULL, go_plugins_get_plugin_dir ());
+	g_slist_foreach (plugin_dirs, append_dir, NULL);
+	g_slist_free (plugin_dirs);
 }
 
 /**
@@ -1731,8 +1739,6 @@ go_plugins_init (GOCmdContext *context,
 	GOErrorInfo *error;
 	GSList *plugin_list;
 
-	plugin_dirs = g_slist_append (plugin_dirs, go_plugins_get_plugin_dir ());
-
 	go_default_loader_type = default_loader_type;
 	go_plugins_set_dirs (plugin_dirs);
 
@@ -1818,8 +1824,6 @@ go_plugins_add (GOCmdContext *context,
 	GOErrorInfo *error;
 	GSList *plugin_list;
 
-	plugin_dirs = g_slist_append (plugin_dirs, go_plugins_get_plugin_dir ());
-
 	go_default_loader_type = default_loader_type;
 	go_plugins_set_dirs (plugin_dirs);
 
@@ -1928,6 +1932,12 @@ go_plugins_shutdown (void)
 	g_hash_table_destroy (available_plugins_id_hash);
 	go_slist_free_custom (available_plugins, g_object_unref);
 
+	if (go_plugin_dirs) {
+		g_slist_foreach (go_plugin_dirs, (GFunc) g_free, NULL);
+		g_slist_free (go_plugin_dirs);
+		go_plugin_dirs = NULL;
+	}
+
 	return used_plugin_state_strings;
 }
 



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