[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
boxed re-registration key freeing
- From: Kevin Ryde <user42 zip com au>
- To: gtk-perl-list gnome org
- Subject: boxed re-registration key freeing
- Date: Wed, 28 Jan 2009 09:58:11 +1100
With the current cvs the foo.pl below gets an error,
type Gtk2::Border is not registered with Glib-Perl at foo.pl line 8.
Chasing it down in gdb it looks like Gtk2.xs register.xsh registers
Gtk2::Border with gperl_register_boxed, and then the Gtk2::Entry boot
code re-registers it. On that second registration the info_by_gtype
update frees the boxed_info of the first registration, but the package
name string "Gtk2::Border" in that boxed_info is still in use as the key
in info_by_package. Changing g_hash_table_insert to
g_hash_table_replace to update the key in info_by_package seems to do
the trick.
The GType of GtkBorder is unchanging, so the info_by_gtype doesn't care
between _insert or _replace, if I'm not mistaken.
Is GtkEntry.xs meant to register Gtk2::Border, or can it be left to
register.xsh?
use strict;
use warnings;
use Gtk2 '-init';
Gtk2::Entry->new;
print "Gtk2::Border->copy is ",Gtk2::Border->can('copy'),"\n";
my $pspec = Glib::ParamSpec->boxed ('foo','foo','blurb',
'Gtk2::Border',
['readable']);
print "pspec ",$pspec,"\n";
print "value_type ",$pspec->get_value_type,"\n";
Index: GBoxed.xs
===================================================================
--- GBoxed.xs (revision 1062)
+++ GBoxed.xs (working copy)
@@ -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
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]