GNOME Bugzilla – Bug 624652
Signals strangeness
Last modified: 2011-01-08 22:34:27 UTC
Hello, class Foo { public int bar; public signal void sig (); public void test () { int bar2 = 1; sig.connect (() => { bar = 2; bar2 = 2; }); } } "this" in the lambda is owned: _data1_->self = foo_ref (self); g_signal_connect_data (self, "sig", (GCallback) __lambda0__foo_sig, block1_data_ref (_data1_), (GClosureNotify) block1_data_unref, 0); -------------- class Foo { public int bar; public signal void sig (); public void test () { sig.connect (() => { bar = 2; }); } } "this" in the lambda is unowned: g_signal_connect (self, "sig", (GCallback) __lambda0__foo_sig, self); -------------- class Foo: Object { ... } "this in the lambda is unowned: g_signal_connect_object (self, "sig", (GCallback) __lambda0__foo_sig, self, 0); The issue: It must be either alwas unowned or owned. I think the language assumes "this" is always owned. If unowned it can lead to crashes when "self" gets unreferenced but the signal is still connected. Proposal: Always use g_signal_connect_data like the first case. For what concerns g_signal_connect_object, if using g_signal_connect_data there's no more the need to surround the callback with ref/unref.
I'd actually prefer to always use the equivalent of g_signal_connect_object to avoid reference cycles. See bug 624624.
Thanks for the bug report. This particular bug has already been reported into our bug tracking system, but please feel free to report any further bugs you find. *** This bug has been marked as a duplicate of bug 624624 ***