Skip to content

Commit c07d75d

Browse files
committed
Revert "signal_with_accumulator derives from trackable"
This reverts commit 8fb7890. It's not safe. See #80
1 parent d627131 commit c07d75d

File tree

3 files changed

+13
-38
lines changed

3 files changed

+13
-38
lines changed

sigc++/signal.h

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -371,14 +371,8 @@ struct signal_emit<void, void, T_arg...>
371371

372372
} /* namespace internal */
373373

374-
// TODO: When we can break ABI, let signal_base instead of signal_with_accumulator
375-
// derive from trackable, as in sigc++2. One of them must derive from trackable.
376-
// Otherwise the slot returned from signal_with_accumulator::make_slot() is not
377-
// automatically disconnected when the signal is deleted.
378-
// https://github.com/libsigcplusplus/libsigcplusplus/issues/80
379-
380374
/** Signal declaration.
381-
* %signal_with_accumulator can be used to connect() slots that are invoked
375+
* signal_with_accumulator can be used to connect() slots that are invoked
382376
* during subsequent calls to emit(). Any functor or slot
383377
* can be passed into connect(). It is converted into a slot
384378
* implicitly.
@@ -402,9 +396,7 @@ struct signal_emit<void, void, T_arg...>
402396
* @ingroup signal
403397
*/
404398
template<typename T_return, typename T_accumulator, typename... T_arg>
405-
class signal_with_accumulator
406-
: public signal_base
407-
, public trackable
399+
class signal_with_accumulator : public signal_base
408400
{
409401
public:
410402
using slot_type = slot<T_return(T_arg...)>;
@@ -469,6 +461,11 @@ class signal_with_accumulator
469461
}
470462

471463
/** Creates a functor that calls emit() on this signal.
464+
*
465+
* @note %sigc::signal does not derive from sigc::trackable in sigc++3.
466+
* If you connect the returned functor (calling %emit() on signal1) to
467+
* another signal (signal2) and then delete signal1, you must manually
468+
* disconnect signal1 from signal2 before you delete signal1.
472469
*
473470
* @code
474471
* sigc::mem_fun(mysignal, &sigc::signal_with_accumulator::emit)
@@ -488,28 +485,19 @@ class signal_with_accumulator
488485

489486
signal_with_accumulator() = default;
490487

491-
signal_with_accumulator(const signal_with_accumulator& src) : signal_base(src), trackable(src) {}
488+
signal_with_accumulator(const signal_with_accumulator& src) : signal_base(src) {}
492489

493-
signal_with_accumulator(signal_with_accumulator&& src)
494-
: signal_base(std::move(src)), trackable(std::move(src))
495-
{
496-
}
490+
signal_with_accumulator(signal_with_accumulator&& src) : signal_base(std::move(src)) {}
497491

498492
signal_with_accumulator& operator=(const signal_with_accumulator& src)
499493
{
500494
signal_base::operator=(src);
501-
// Don't call trackable::operator=(src).
502-
// It calls notify_callbacks(). This signal is not destroyed.
503495
return *this;
504496
}
505497

506498
signal_with_accumulator& operator=(signal_with_accumulator&& src)
507499
{
508500
signal_base::operator=(std::move(src));
509-
if (src.impl_ != impl_)
510-
src.notify_callbacks();
511-
// Don't call trackable::operator=(std::move(src)).
512-
// It calls notify_callbacks(). This signal is not destroyed.
513501
return *this;
514502
}
515503
};
@@ -543,7 +531,7 @@ class signal_with_accumulator
543531
* @par Example:
544532
* @code
545533
* void foo(int) {}
546-
* sigc::signal<void(long)> sig;
534+
* sigc::signal<void, long> sig;
547535
* sig.connect(sigc::ptr_fun(&foo));
548536
* sig.emit(19);
549537
* @endcode

sigc++/signal_base.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,9 @@ struct SIGC_API signal_impl_holder
266266
* @ref sigc::signal_with_accumulator::connect() "sigc::signal::connect()".
267267
*/
268268

269-
// TODO: When we can break ABI, let signal_base instead of signal_with_accumulator
270-
// derive from trackable, as in sigc++2. One of them must derive from trackable.
271-
// Otherwise the slot returned from signal_with_accumulator::make_slot() is not
272-
// automatically disconnected when the signal is deleted.
269+
// TODO: When we can break ABI, let signal_base derive from trackable again.
270+
// It does in sigc++2. Otherwise the slot returned from signal::make_slot()
271+
// is not automatically disconnected when the signal is deleted.
273272
// https://github.com/libsigcplusplus/libsigcplusplus/issues/80
274273

275274
/** Base class for the @ref sigc::signal<T_return(T_arg...)> "sigc::signal" template.

tests/test_signal.cc

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include "testutilities.h"
66
#include <sigc++/trackable.h>
77
#include <sigc++/signal.h>
8-
#include <memory>
98

109
namespace
1110
{
@@ -111,17 +110,6 @@ test_make_slot()
111110
sig2.connect(sig.make_slot());
112111
sig2(3);
113112
util->check_result(result_stream, "foo(int 3) bar(float 3) foo(int 3) ");
114-
115-
// Delete a signal that has been connected to sig2.
116-
sig2.clear();
117-
sig2.connect(sigc::ptr_fun(&bar));
118-
auto sig3 = std::make_unique<sigc::signal<int(int)>>();
119-
sig3->connect(sigc::ptr_fun(&foo));
120-
sig2.connect(sig3->make_slot());
121-
sig2(2);
122-
sig3.reset();
123-
sig2(42);
124-
util->check_result(result_stream, "bar(float 2) foo(int 2) bar(float 42) ");
125113
}
126114

127115
void

0 commit comments

Comments
 (0)