changeset 15304:7a52dce840b4

[gaim-migrate @ 18094] Fix a crash which happens when you rebind some key-bindings. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Tue, 09 Jan 2007 00:29:45 +0000
parents 70ffa34b4143
children 492f4e7416a3
files console/libgnt/gntbindable.c console/libgnt/gntutils.c console/libgnt/gntutils.h
diffstat 3 files changed, 40 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/console/libgnt/gntbindable.c	Tue Jan 09 00:24:55 2007 +0000
+++ b/console/libgnt/gntbindable.c	Tue Jan 09 00:29:45 2007 +0000
@@ -19,15 +19,35 @@
 	GNTDEBUG;
 }
 
+static gpointer
+bindable_clone(GntBindableAction *action)
+{
+	GntBindableAction *ret = g_new0(GntBindableAction, 1);
+	ret->name = g_strdup(action->name);
+	ret->u = action->u;
+	return ret;
+}
+
+static gpointer
+binding_clone(GntBindableActionParam *param)
+{
+	GntBindableActionParam *p = g_new0(GntBindableActionParam, 1);
+	p->list = g_list_copy(param->list);
+	p->action = param->action;
+	return p;
+}
+
 static void
 duplicate_hashes(GntBindableClass *klass)
 {
 	/* Duplicate the bindings from parent class */
 	if (klass->actions) {
 		klass->actions = g_hash_table_duplicate(klass->actions, g_str_hash,
-					g_str_equal, g_free, (GDestroyNotify)gnt_bindable_action_free);
+					g_str_equal, g_free, (GDestroyNotify)gnt_bindable_action_free,
+					(GDupFunc)g_strdup, (GDupFunc)bindable_clone);
 		klass->bindings = g_hash_table_duplicate(klass->bindings, g_str_hash,
-					g_str_equal, g_free, (GDestroyNotify)gnt_bindable_action_param_free);
+					g_str_equal, g_free, (GDestroyNotify)gnt_bindable_action_param_free,
+					(GDupFunc)g_strdup, (GDupFunc)binding_clone);
 	} else {
 		klass->actions = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
 					(GDestroyNotify)gnt_bindable_action_free);
--- a/console/libgnt/gntutils.c	Tue Jan 09 00:24:55 2007 +0000
+++ b/console/libgnt/gntutils.c	Tue Jan 09 00:29:45 2007 +0000
@@ -105,17 +105,28 @@
 	return g_string_free(str, FALSE);
 }
 
+struct duplicate_fns
+{
+	GDupFunc key_dup;
+	GDupFunc value_dup;
+	GHashTable *table;
+};
+
 static void
 duplicate_values(gpointer key, gpointer value, gpointer data)
 {
-	g_hash_table_insert(data, key, value);
+	struct duplicate_fns *fns = data;
+	g_hash_table_insert(fns->table, fns->key_dup ? fns->key_dup(key) : key,
+			fns->value_dup ? fns->value_dup(value) : value);
 }
 
 GHashTable *g_hash_table_duplicate(GHashTable *src, GHashFunc hash,
-		GEqualFunc equal, GDestroyNotify key_d, GDestroyNotify value_d)
+		GEqualFunc equal, GDestroyNotify key_d, GDestroyNotify value_d,
+		GDupFunc key_dup, GDupFunc value_dup)
 {
 	GHashTable *dest = g_hash_table_new_full(hash, equal, key_d, value_d);
-	g_hash_table_foreach(src, duplicate_values, dest);
+	struct duplicate_fns fns = {key_dup, value_dup, dest};
+	g_hash_table_foreach(src, duplicate_values, &fns);
 	return dest;
 }
 
--- a/console/libgnt/gntutils.h	Tue Jan 09 00:24:55 2007 +0000
+++ b/console/libgnt/gntutils.h	Tue Jan 09 00:29:45 2007 +0000
@@ -3,6 +3,8 @@
 #include "gnt.h"
 #include "gntwidget.h"
 
+typedef gpointer (*GDupFunc)(gconstpointer data);
+
 void gnt_util_get_text_bound(const char *text, int *width, int *height);
 
 /* excluding *end */
@@ -19,7 +21,8 @@
 char *gnt_util_onscreen_fit_string(const char *string, int maxw);
 
 GHashTable *g_hash_table_duplicate(GHashTable *src, GHashFunc hash,
-		GEqualFunc equal, GDestroyNotify key_d, GDestroyNotify value_d);
+		GEqualFunc equal, GDestroyNotify key_d, GDestroyNotify value_d,
+		GDupFunc key_dup, GDupFunc value_dup);
 
 
 /**