summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjell Ahlstedt <kjell.ahlstedt@bredband.net>2015-10-11 15:12:10 +0200
committerKjell Ahlstedt <kjell.ahlstedt@bredband.net>2015-10-11 15:12:10 +0200
commit54b5c013552e753fad02c879ace7d0f7f91f33b6 (patch)
tree696e07f5898946bc1882943429a98b6c30e04681
parentb5a8674628800921b46c9db94e24c75bea213227 (diff)
downloadsigc++-54b5c013552e753fad02c879ace7d0f7f91f33b6.tar.gz
slot_rep::disconnect(): Remove a comment, add a test
* sigc++/functors/slot_base.cc: Remove a TODO comment at slot_rep::disconnect(). * tests/test_slot_disconnect.cc: Add a test that assigns an empty slot.
-rw-r--r--sigc++/functors/slot_base.cc19
-rw-r--r--tests/test_slot_disconnect.cc5
2 files changed, 13 insertions, 11 deletions
diff --git a/sigc++/functors/slot_base.cc b/sigc++/functors/slot_base.cc
index 2bc0d40..88a91f9 100644
--- a/sigc++/functors/slot_base.cc
+++ b/sigc++/functors/slot_base.cc
@@ -55,23 +55,22 @@ void slot_rep::operator delete(void* p)
}
#endif
-//TODO: When we can break API: Is it necessary to invalidate the slot here?
-// If the parent misbehaves, when the slot is not invalidated, isn't that
-// a problem that should be fixed in the parent?
-// See discussion in https://bugzilla.gnome.org/show_bug.cgi?id=738602
void slot_rep::disconnect()
{
+ // Invalidate the slot.
+ // _Must_ be done here because parent_ might defer the actual
+ // destruction of the slot_rep and try to invoke it before that point.
+ // Must be done also for a slot without a parent, according to
+ // https://bugzilla.gnome.org/show_bug.cgi?id=311057
+ // See also https://bugzilla.gnome.org/show_bug.cgi?id=738602
+ call_ = nullptr;
+
if (parent_)
{
- call_ = nullptr; // Invalidate the slot.
- // _Must_ be done here because parent_ might defer the actual
- // destruction of the slot_rep and try to invoke it before that point.
auto data_ = parent_;
- parent_ = nullptr; // Just a precaution.
+ parent_ = nullptr; // Just a precaution.
(cleanup_)(data_); // Notify the parent (might lead to destruction of this!).
}
- else
- call_ = nullptr;
}
//static
diff --git a/tests/test_slot_disconnect.cc b/tests/test_slot_disconnect.cc
index 13d42e0..a1d6834 100644
--- a/tests/test_slot_disconnect.cc
+++ b/tests/test_slot_disconnect.cc
@@ -1,4 +1,3 @@
-// -*- c++ -*-
/* Copyright 2005, The libsigc++ Development Team
* Assigned to public domain. Use as you wish without restriction.
*/
@@ -45,5 +44,9 @@ int main(int argc, char* argv[])
theSlot();
util->check_result(result_stream, "Bar");
+ theSlot = sigc::slot<void>(); // Assign an empty slot.
+ theSlot();
+ util->check_result(result_stream, "");
+
return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
}