GNOME Bugzilla – Bug 567688
signal_chain_from_overridden in size_request class closure
Last modified: 2009-06-04 23:18:04 UTC
As noted in the Gtk2::Widget signals pod, chaining up to a superclass size_request doesn't fill in any data. The program below prints (among other things) after chain: 0x0 where I hoped the signal_chain_from_overridden would go to the Gtk2::Label size_request handler and get a desired size from it. (You can see the desired size by changing $foo to a plain Gtk2::Label per the commented out line in main). Chasing it down, I believe somewhere deep in signal_chain_from_overridden the Gtk2::Requisition supplied in the perl call is copied, so the pointer going to the g_signal_chain_from_overridden (in a GValue) is not the original and so the width/height stored in it by GtkLabel are never seen. It made me wonder if most of the time a boxed object should be copied or not copied when passed to a C func. But certainly in this case it shouldn't, since it's a kind of output location. package Foo; use strict; use warnings; use Gtk2; use Glib::Object::Subclass 'Gtk2::Label', signals => { size_request => \&_do_size_request }; sub _do_size_request { my ($self, $req) = @_; print "this is Foo::_do_size_request\n"; print "text is '",$self->get_text,"'\n"; print "before chain: ",$req->width,"x",$req->height,"\n"; Glib::Object::signal_chain_from_overridden ($self, $req); print "after chain: ",$req->width,"x",$req->height,"\n"; } package main; use strict; use warnings; use Gtk2 '-init'; my $window = Gtk2::Window->new('toplevel'); my $foo = Foo->new(); # # my $foo = Gtk2::Label->new(); # $foo->set_text ('hello world'); $window->add ($foo); $window->show_all; my $req = $foo->size_request(); print "main: foo size ",$req->width,"x",$req->height,"\n"; Gtk2->main();
As noted on the mailing list, the latest change to Glib to have boxed objects not copied fixes this problem. The change below removes the note in the docs and adds a test case exercising the now-successful chaining, when ready to have a dependency on that new enough Glib.
Created attachment 135853 [details] [review] doc update and test case
Ah, sweet. I love it when bugs fix themselves. I created a stable branch for Gtk2 so that this can go into master: <http://git.gnome.org/cgit/perl-Gtk2/commit/?id=07d6735c82898346d412c72f0ce22a56a78ab8f7> <http://git.gnome.org/cgit/perl-Gtk2/commit/?id=9c0a15933209c4a2a33028c08f884063c68ea6ea> Thanks for the test case!
Created attachment 135993 [details] [review] depend on Glib 1.221 Don't forget to bump the Glib dependency when ready, since of course the tests fail with 1.220.