Skip to content

Commit 6193a2c

Browse files
committed
slot_base: Use weak_raw_ptr instead of destroy_notify_struct.
This seems cleaner.
1 parent 846d1fe commit 6193a2c

File tree

1 file changed

+6
-28
lines changed

1 file changed

+6
-28
lines changed

sigc++/functors/slot_base.cc

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,7 @@
1818
*/
1919

2020
#include <sigc++/functors/slot_base.h>
21-
22-
namespace
23-
{
24-
// Used by slot_rep::notify() and slot_base::operator=(). They must be
25-
// notified, if the slot_rep is deleted when they call disconnect().
26-
struct destroy_notify_struct : public sigc::notifiable
27-
{
28-
destroy_notify_struct() noexcept : deleted_(false) {}
29-
30-
static void notify(notifiable* data) noexcept
31-
{
32-
auto self_ = static_cast<destroy_notify_struct*>(data);
33-
self_->deleted_ = true;
34-
}
35-
36-
bool deleted_;
37-
};
38-
} // anonymous namespace
21+
#include <sigc++/weak_raw_ptr.h>
3922

4023
namespace sigc
4124
{
@@ -84,14 +67,11 @@ slot_rep::notify_slot_rep_invalidated(notifiable* data)
8467
self_->call_ = nullptr; // Invalidate the slot.
8568

8669
// Make sure we are notified if disconnect() deletes self_, which is trackable.
87-
destroy_notify_struct notifier;
88-
self_->add_destroy_notify_callback(&notifier, destroy_notify_struct::notify);
70+
sigc::internal::weak_raw_ptr<slot_rep> notifier(self_);
8971
self_->disconnect(); // Disconnect the slot (might lead to deletion of self_!).
90-
// If self_ has been deleted, the destructor has called destroy().
91-
if (!notifier.deleted_)
72+
// If self_ has been deleted, then the weak_raw_ptr will have been invalidated.
73+
if (notifier)
9274
{
93-
self_->remove_destroy_notify_callback(&notifier);
94-
9575
// Detach the stored functor from the other referred trackables and destroy it.
9676
// destroy() might lead to deletion of self_. Bug #564005.
9777
self_->destroy();
@@ -174,17 +154,15 @@ slot_base::delete_rep_with_check()
174154

175155
// Make sure we are notified if disconnect() deletes rep_, which is trackable.
176156
// Compare slot_rep::notify().
177-
destroy_notify_struct notifier;
178-
rep_->add_destroy_notify_callback(&notifier, destroy_notify_struct::notify);
157+
sigc::internal::weak_raw_ptr<rep_type> notifier(rep_);
179158
rep_->disconnect(); // Disconnect the slot (might lead to deletion of rep_!).
180159

181160
// If rep_ has been deleted, don't try to delete it again.
182161
// If it has been deleted, this slot_base has probably also been deleted, so
183162
// don't clear the rep_ pointer. It's the responsibility of the code that
184163
// deletes rep_ to either clear the rep_ pointer or delete this slot_base.
185-
if (!notifier.deleted_)
164+
if (notifier)
186165
{
187-
rep_->remove_destroy_notify_callback(&notifier);
188166
delete rep_; // Detach the stored functor from the other referred trackables and destroy it.
189167
rep_ = nullptr;
190168
}

0 commit comments

Comments
 (0)