perl-Glib r1048 - trunk



Author: tsch
Date: Sat Nov 15 13:43:25 2008
New Revision: 1048
URL: http://svn.gnome.org/viewvc/perl-Glib?rev=1048&view=rev

Log:
* GBoxed.xs (gperl_register_boxed): Use the copy of the passed-in
package name for the key of info_by_package to avoid problems when
the package name is dynamically allocated.

* GBoxed.xs (gperl_register_boxed)
* GObject.xs (gperl_register_object)
* GType.xs (gperl_register_fundamental): Always insert into the
lookup tables in the correct order to avoid prematurely freeing
the package name.


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

Modified: trunk/GBoxed.xs
==============================================================================
--- trunk/GBoxed.xs	(original)
+++ trunk/GBoxed.xs	Sat Nov 15 13:43:25 2008
@@ -186,8 +186,13 @@
 						         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.
+	 */
+	g_hash_table_insert (info_by_package, boxed_info->package, boxed_info);
 	g_hash_table_insert (info_by_gtype, (gpointer) gtype, boxed_info);
-	g_hash_table_insert (info_by_package, (gchar*)package, boxed_info);
 
 	/* GBoxed types are plain structures, so it would be really
 	 * surprising to find a boxed type that actually inherits another

Modified: trunk/GObject.xs
==============================================================================
--- trunk/GObject.xs	(original)
+++ trunk/GObject.xs	Sat Nov 15 13:43:25 2008
@@ -329,9 +329,14 @@
 							  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
+	 * that class_info->package is no longer valid at this point.
+	 */
+	g_hash_table_insert (types_by_package, class_info->package, class_info);
 	g_hash_table_insert (types_by_type,
 	                     (gpointer) class_info->gtype, class_info);
-	g_hash_table_insert (types_by_package, class_info->package, class_info);
 	/* warn ("registered class %s to package %s\n", class_info->class, class_info->package); */
 
 	/* defer the actual ISA setup to Glib::Object::_LazyLoader */

Modified: trunk/GType.xs
==============================================================================
--- trunk/GType.xs	(original)
+++ trunk/GType.xs	Sat Nov 15 13:43:25 2008
@@ -95,8 +95,12 @@
 			                       (GDestroyNotify)g_free);
 	}
 	p = g_strdup (package);
-	g_hash_table_insert (packages_by_type, (gpointer) gtype, p);
+	/* 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.
+	 */
 	g_hash_table_insert (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]