more on why does this produce a dangling reference?
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? - Shayne. ******************************************************************** Visit our Internet site at http://www.rbsmarkets.com This e-mail is intended only for the addressee named above. As this e-mail may contain confidential or privileged information, if you are not the named addressee, you are not authorised to retain, read, copy or disseminate this message or any part of it. The Royal Bank of Scotland plc is registered in Scotland No 90312 Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB Regulated by the Financial Services Authority ********************************************************************
"FLETCHER, Shayne, FM" <Shayne.FLETCHER@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
participants (2)
-
David Abrahams -
FLETCHER, Shayne, FM