Boost logo

Boost :

From: Tanguy Fautre (tanguy.fautre_at_[hidden])
Date: 2006-08-28 09:04:07


Hi,

I have an object "m_RegisterEvents" which holds a reference to a Python
function. This Python function is a callback given by a Python script.

To call this function, I simply do:

void subsystem_script::register_events()
{
        m_RegisterEvents();
}

And it works.

However, if a Python exception is thrown (and converted to the C++
exception boost::python::error_already_set), I get a segfault in the
following function (m_ptr is null, hence the segfault):

inline api::object_base::~object_base()
{
     Py_DECREF(m_ptr);
}

This destructor is directly called at the end of the
subsystem_script::register_events() function, leading me to believe that
it is a temporary object being destructed.

The funny thing is that if I do the following, then it works again.

void subsystem_script::register_events()
{
        try {
                m_RegisterEvents();
        }

        catch (const error_already_set &)
        {

        }
}

However, doing a "throw;" in the catch to re-throw the exception does
the same segfault. Converting the exception by throwing another object
(e.g. std::runtime_error()) works.

I must admit that I'm totally puzzled.

Using Boost 1.33.1 with Visual C++ 2005.

Tanguy


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk