|
Boost : |
From: Larry Evans (jcampbell3_at_[hidden])
Date: 2002-01-20 10:17:25
Larry Evans wrote:
> Thomas Maeder wrote:
>
> > Am 2002.01.19 14:23 schrieb(en) David Abrahams:
> > >
> > > ...which is the reason it might be better if they didn't implicitly
> > > convert, unless Peter's precautions are taken.
> >
> > Are there equivalent precautions against
> >
> > shared_ptr<Base> b(new Derived);
> >
> > ?
> >
>
> The following test driver snippet:
>
>
[snip]
>
> I am using Peter's http://groups.yahoo.com/group/boost/files/smart_ptr_3.zip.
> I've tried using gdb to trace and see what's happening, but it's skipping some
> lines of code (I guess because of optimizing). Anyway, here's the output:
Probably only the implementors would be interested in the details below.
Update: used -fno-default-inline oncompiler and traced the problem to
a work-around to no atomic.h with my compiler. I simply created my own
atomic.h as follows:
#define ATOMIC_INIT(X) X
typedef long atomic_t;
static void atomic_inc(atomic_t*a_val){++*a_val;}
static long atomic_dec_and_test(atomic_t*a_val){return --*a_val;}
static long atomic_read(atomic_t const*a_val){return *a_val;}
however, the counted_base::release() method includes the code:
if(--use_count_ == 0)
{
dispose();
}
and:
count_type use_count_;
and:
typedef atomic_count count_type;
and, in atomic_count_linux.hpp:
long operator--()
{
return !atomic_dec_and_test(&value_);
}
so, the atomic_dec_and_test in MY atomic.h returns 0, but
it's converted to non-zero in the above atomic_count_linux.hpp
code for operator--().
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk