[C++-sig] more on why does this produce a dangling reference?
David Abrahams
dave at boost-consulting.com
Wed Mar 5 03:25:02 CET 2003
"FLETCHER, Shayne, FM" <Shayne.FLETCHER at rbos.com> writes:
> Dear All:
>
> Further to my earlier posting today
> http://mail.python.org/pipermail/c++-sig/2003-March/003504.html, I have
> found one way that seems to produce the required behaviour:
>
> period const& rate_impl_wrapper::get_floating_frequency() const
> {
> boost::python::object obj(
> boost::python::call_method(m_self
> ,"get_floating_frequency"
> , (boost::type<boost::python::object>*)0));
> return boost::python::extract<period const&>(obj)();
> }
>
> This approach no longer gives rise to a dangling reference error and it
> appears to work, but, since obj refcnt is 1, surely this code is returning a
> reference to a temporary?
Not a temporary in the sense the C++ standard uses the word, but yes,
the effect is the same. You're still returning a dangling reference.
You've just managed to subvert the protections Boost.Python gives you.
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list