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 311057 - slot<>::disconnect() does not work.
slot<>::disconnect() does not work.
Status: RESOLVED FIXED
Product: libsigc++
Classification: Bindings
Component: general
2.0.x
Other Windows
: Normal normal
: ---
Assigned To: Martin Schulze
Martin Schulze
Depends on:
Blocks:
 
 
Reported: 2005-07-20 19:54 UTC by James Lin
Modified: 2005-12-01 11:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Sample code that tries to copy a null slot (509 bytes, text/plain)
2005-07-20 19:55 UTC, James Lin
Details

Description James Lin 2005-07-20 19:54:06 UTC
Version details: 2.0.14
Distribution/Version: Windows 2000 SP4

Attempting to overwrite a sigc::slot with a null (default-constructed) slot
seems to have no effect.  sigc::slot::disconnect() also seems to do nothing,
although possibly I'm misunderstanding the docs.
Comment 1 James Lin 2005-07-20 19:55:35 UTC
Created attachment 49483 [details]
Sample code that tries to copy a null slot

Sample code attached.

The output I expect is simply:
Bar

but the output I get is:
Foo
Foo
Bar
Comment 2 Murray Cumming 2005-08-01 07:00:05 UTC
Did this work with a previous version?
Comment 3 James Lin 2005-08-01 09:07:15 UTC
I know it doesn't work in 2.0.6 either.  I haven't tried versions earlier than
that.
Comment 4 Murray Cumming 2005-12-01 10:32:20 UTC
The problem here seems to be that slot::disconnect() does not work, regardless
of the null slot.
Comment 5 Murray Cumming 2005-12-01 11:07:38 UTC
I've added the simplified test case to cvs:
http://cvs.gnome.org/viewcvs/libsigc%2B%2B2/tests/test_slot_disconnect.cc?view=markup

So now I am wondering what constructor or operator= is used to convert the
sigc::pointer_functor<void> to a sigc::slot0<void>. I think that the
rep_::parent is not set properly when that happens, and that stops disconnect()
from working.
Comment 6 Murray Cumming 2005-12-01 11:47:08 UTC
I think it's this simple. I've commited it:

2005-12-01  Murray Cumming <murrayc@murrayc.com>
 
+	* sigc++/functors/slot_base.cc: 
+	slot_base::disconnect(): Set call_ to 0, 
+	to invalidate the slot, even if parent_ is 0. 
+	I think parent_ is, for instance, a signal, but 
+	disconnect should still work on a slot that is not 
+	connected to a signal, because a slot can be invoked 
+	directly.
+	Fixes bug #311057 from James Lin.
+
+2005-12-01  Murray Cumming <murrayc@murrayc.com>
+
 	* tests/Makefile.am:
 	* tests/test_slot_disconnect.cc: Added test 
 	case from bug #311057.
Index: sigc++/functors/slot_base.cc
===================================================================
RCS file: /cvs/gnome/libsigc++2/sigc++/functors/slot_base.cc,v
retrieving revision 1.9
diff -u -p -r1.9 slot_base.cc
--- sigc++/functors/slot_base.cc	1 May 2005 02:00:46 -0000	1.9
+++ sigc++/functors/slot_base.cc	1 Dec 2005 11:38:08 -0000
@@ -49,6 +49,8 @@ void slot_rep::disconnect()
     parent_ = 0;        // Just a precaution.
     (cleanup_)(data_);  // Notify the parent (might lead to destruction of this!).
   }
+  else
+    call_ = 0;
 }
 
 //static