After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 624652 - Signals strangeness
Signals strangeness
Status: RESOLVED DUPLICATE of bug 624624
Product: vala
Classification: Core
Component: Code Generator: GSignal
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2010-07-18 08:31 UTC by Luca Bruno
Modified: 2011-01-08 22:34 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Luca Bruno 2010-07-18 08:31:44 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.
Comment 1 Jürg Billeter 2010-10-16 11:58:35 UTC
I'd actually prefer to always use the equivalent of g_signal_connect_object to avoid reference cycles. See bug 624624.
Comment 2 Jürg Billeter 2011-01-08 22:34:27 UTC
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 ***