|
18 | 18 | */
|
19 | 19 |
|
20 | 20 | #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> |
39 | 22 |
|
40 | 23 | namespace sigc
|
41 | 24 | {
|
@@ -84,14 +67,11 @@ slot_rep::notify_slot_rep_invalidated(notifiable* data)
|
84 | 67 | self_->call_ = nullptr; // Invalidate the slot.
|
85 | 68 |
|
86 | 69 | // Make sure we are notified if disconnect() deletes self_, which is trackable.
|
87 |
| - destroy_notify_struct notifier; |
88 |
| - self_->add_destroy_notify_callback(¬ifier, destroy_notify_struct::notify); |
| 70 | + sigc::internal::weak_raw_ptr<slot_rep> notifier(self_); |
89 | 71 | 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) |
92 | 74 | {
|
93 |
| - self_->remove_destroy_notify_callback(¬ifier); |
94 |
| - |
95 | 75 | // Detach the stored functor from the other referred trackables and destroy it.
|
96 | 76 | // destroy() might lead to deletion of self_. Bug #564005.
|
97 | 77 | self_->destroy();
|
@@ -174,17 +154,15 @@ slot_base::delete_rep_with_check()
|
174 | 154 |
|
175 | 155 | // Make sure we are notified if disconnect() deletes rep_, which is trackable.
|
176 | 156 | // Compare slot_rep::notify().
|
177 |
| - destroy_notify_struct notifier; |
178 |
| - rep_->add_destroy_notify_callback(¬ifier, destroy_notify_struct::notify); |
| 157 | + sigc::internal::weak_raw_ptr<rep_type> notifier(rep_); |
179 | 158 | rep_->disconnect(); // Disconnect the slot (might lead to deletion of rep_!).
|
180 | 159 |
|
181 | 160 | // If rep_ has been deleted, don't try to delete it again.
|
182 | 161 | // If it has been deleted, this slot_base has probably also been deleted, so
|
183 | 162 | // don't clear the rep_ pointer. It's the responsibility of the code that
|
184 | 163 | // deletes rep_ to either clear the rep_ pointer or delete this slot_base.
|
185 |
| - if (!notifier.deleted_) |
| 164 | + if (notifier) |
186 | 165 | {
|
187 |
| - rep_->remove_destroy_notify_callback(¬ifier); |
188 | 166 | delete rep_; // Detach the stored functor from the other referred trackables and destroy it.
|
189 | 167 | rep_ = nullptr;
|
190 | 168 | }
|
|
0 commit comments