[libsigcplusplus/libsigc++-2-10] signal_impl::clear(): Don't clear the slot list during signal emission



commit abadda40f1732cb88f4a91335d2be1bb95b89a92
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Mon Jul 17 10:18:02 2017 +0200

    signal_impl::clear(): Don't clear the slot list during signal emission
    
    If signal_impl::clear() is called during signal emission, don't call
    slots_.clear(). Let signal_impl::sweep() erase all slots after the signal
    emission. Bug 784550

 sigc++/signal_base.cc |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)
---
diff --git a/sigc++/signal_base.cc b/sigc++/signal_base.cc
index cc8342b..bf9aa37 100644
--- a/sigc++/signal_base.cc
+++ b/sigc++/signal_base.cc
@@ -54,6 +54,7 @@ void signal_impl::clear()
 {
   // Don't let signal_impl::notify() erase the slots. It would invalidate the
   // iterator in the following loop.
+  const bool during_signal_emission = exec_count_ > 0;
   const bool saved_deferred = deferred_;
   signal_exec exec(this);
 
@@ -62,9 +63,15 @@ void signal_impl::clear()
   for (auto& slot : slots_)
     slot.disconnect();
 
-  deferred_ = saved_deferred;
-
-  slots_.clear();
+  // Don't clear slots_ during signal emission. Provided deferred_ is true,
+  // sweep() will be called from ~signal_exec() after signal emission,
+  // and it will erase all disconnected slots.
+  // https://bugzilla.gnome.org/show_bug.cgi?id=784550
+  if (!during_signal_emission)
+  {
+    deferred_ = saved_deferred;
+    slots_.clear();
+  }
 }
 
 signal_impl::size_type signal_impl::size() const noexcept


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]