perl-Glib r1072 - trunk



Author: tsch
Date: Thu Feb  5 13:57:30 2009
New Revision: 1072
URL: http://svn.gnome.org/viewvc/perl-Glib?rev=1072&view=rev

Log:
* GBoxed.xs (gperl_register_boxed)
* GObject.xs (gperl_register_object)
* GType.xs (gperl_register_fundamental): When inserting into the package â type
hash tables, use g_hash_table_replace instead of _insert so that the new string
pointer is used as the key.  Patch by Kevin Ryde.


Modified:
   trunk/ChangeLog
   trunk/GBoxed.xs
   trunk/GObject.xs
   trunk/GType.xs

Modified: trunk/GBoxed.xs
==============================================================================
--- trunk/GBoxed.xs	(original)
+++ trunk/GBoxed.xs	Thu Feb  5 13:57:30 2009
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2003-2005 by the gtk2-perl team (see the file AUTHORS for
+ * Copyright (C) 2003-2005, 2009 by the gtk2-perl team (see the file AUTHORS for
  * the full list)
  *
  * This library is free software; you can redistribute it and/or modify it
@@ -186,12 +186,17 @@
 						         NULL);
 	}
 	boxed_info = boxed_info_new (gtype, package, wrapper_class);
+
 	/* We need to insert into info_by_package first because there might
 	 * otherwise be trouble if we overwrite an entry: inserting into
 	 * info_by_gtype frees the boxed_info of the overwritten entry, so that
 	 * boxed_info->package is no longer valid at this point.
+	 *
+	 * Note also it's g_hash_table_replace() for info_by_package,
+	 * because the old key string in the old boxed_info will be freed
+	 * when info_by_gtype updates the value there.
 	 */
-	g_hash_table_insert (info_by_package, boxed_info->package, boxed_info);
+	g_hash_table_replace (info_by_package, boxed_info->package, boxed_info);
 	g_hash_table_insert (info_by_gtype, (gpointer) gtype, boxed_info);
 
 	/* GBoxed types are plain structures, so it would be really

Modified: trunk/GObject.xs
==============================================================================
--- trunk/GObject.xs	(original)
+++ trunk/GObject.xs	Thu Feb  5 13:57:30 2009
@@ -329,12 +329,17 @@
 							  NULL);
 	}
 	class_info = class_info_new (gtype, package);
+
 	/* We need to insert into types_by_package first because there might
 	 * otherwise be trouble if we overwrite an entry: inserting into
-	 * types_by_gtype frees the class_info of the overwritten entry, so
+	 * types_by_type frees the class_info of the overwritten entry, so
 	 * that class_info->package is no longer valid at this point.
+	 *
+	 * Note also it's g_hash_table_replace() for types_by_package,
+	 * because the old key string in the old class_info will be freed
+	 * when types_by_type updates the value there.
 	 */
-	g_hash_table_insert (types_by_package, class_info->package, class_info);
+	g_hash_table_replace (types_by_package, class_info->package, class_info);
 	g_hash_table_insert (types_by_type,
 	                     (gpointer) class_info->gtype, class_info);
 	/* warn ("registered class %s to package %s\n", class_info->class, class_info->package); */

Modified: trunk/GType.xs
==============================================================================
--- trunk/GType.xs	(original)
+++ trunk/GType.xs	Thu Feb  5 13:57:30 2009
@@ -98,8 +98,12 @@
 	/* We need to insert into types_by_package first because there might
 	 * otherwise be trouble if we overwrite an entry: inserting into
 	 * packages_by_type frees the copied package name.
+	 *
+	 * Note also it's g_hash_table_replace() for types_by_package, because
+	 * the old key string will be freed when packages_by_type updates the
+	 * value there.
 	 */
-	g_hash_table_insert (types_by_package, p, (gpointer) gtype);
+	g_hash_table_replace (types_by_package, p, (gpointer) gtype);
 	g_hash_table_insert (packages_by_type, (gpointer) gtype, p);
 	G_UNLOCK (types_by_package);
 	G_UNLOCK (packages_by_type);



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