[sigc] Invalidating parentless slots



  I got the attached message and (reversed) patch in the Debian BTS.

  Daniel

-- 
/------------------- Daniel Burrows <dburrows debian org> ------------------\
|             "Since TeX's value for infinity is quite low..."              |
|               -- The LaTeX Companion                                      |
\---------------- The Turtle Moves! -- http://www.lspace.org ---------------/
--- Begin Message ---
Package: libsigc++-2.0
Severity: normal
Tags: patch

sigc::slot can be used as a function pointer with the advantage of being
able to add function arguments with sigc::bind, etc.  However,
disconnecting such slots does not work, because it doesn't do anything
if there is no parent to notify.

In my programs it is quite usual that there isn't a parent, because I
know what happens to the slot, so I don't need a notification.  However,
I still need to invalidate the slot sometimes, and even
slot = sigc::slot0 <void> ();
doesn't work, because that simply calls disconnect ().

The attached patch invalidates the slot on disconnect, even if there is
no parent.

-- System Information:
Debian Release: testing/unstable
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.11
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)
--- slot_base.cc	2005-09-02 15:39:48.000000000 +0200
+++ libsigc++-2.0.10/sigc++/functors/slot_base.cc	2005-02-11 11:59:07.000000000 +0100
@@ -40,11 +40,11 @@ void slot_rep::operator delete(void* p)
 
 void slot_rep::disconnect()
 {
-  call_ = 0;            // 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.
   if (parent_)
   {
+    call_ = 0;          // 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.
     void* data_ = parent_;
     parent_ = 0;        // Just a precaution.
     (cleanup_)(data_);  // Notify the parent (might lead to destruction of this!).

--- End Message ---
--- Begin Message ---
I just noticed the patch is reversed, so you need -R to apply it.  Sorry about
that.

-- 
I encourage people to send encrypted e-mail (see http://www.gnupg.org).
If you have problems reading my e-mail, use a better reader.
Please send the central message of e-mails as plain text
   in the message body, not as HTML and definitely not as MS Word.
Please do not use the MS Word format for attachments either.
For more information, see http://129.125.47.90/e-mail.html

Attachment: signature.asc
Description: Digital signature


--- End Message ---

Attachment: pgpZsVpe04jxU.pgp
Description: PGP signature



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