|
Boost : |
Subject: Re: [boost] possible bug introduced in boost function
From: Niels Dekker - mail address until 2008-12-31 (nd_mail_address_valid_until_2008-12-31_at_[hidden])
Date: 2008-09-06 03:41:05
Emil Dotchevski wrote:
> I have strong suspicions that the changes in boost::function made
> today introduce a serious bug in the lifetime management of the
> contained object.
...
> Reverting to revision 48607 makes the shared_ptr refcount correct.
Thank you, Emil! Douglas has fixed the issue just a few hours ago:
http://svn.boost.org/trac/boost/changeset/48627
See also:
http://svn.boost.org/trac/boost/ticket/1910#comment:6
> Here's a simple test case, I tried it with msvc 9:
>
> #include "boost/function.hpp"
>
> int instances=0;
> struct X
> {
> X() { ++instances; }
> X(X const &) { ++instances; }
> ~X() { --instances; }
> void operator()() { }
> };
> boost::function<void()> f() { return X(); }
>
> int main( int argc, char const * argv[] )
> {
> boost::function<void()> f2;
> f2=f();
> assert(instances==1);
> }
I just tried your little test case. Before Doug's fix [48627],
"instances" was -1 during the assert, now it's 1 again, as it should.
:-)
So now we have a boost::function::swap function that significantly
outperforms std::swap<boost::function>, when swapping large functors.
:-)
Kind regards, Niels
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk