On 02/18/2010 04:24 PM, James Amundson wrote:
Boost Python seems to be failing to catch and translate C++ exceptions for me on a BlueGene/P installation. I really don't know what to do next in debugging the problem, so I would appreciate any advice.

I have finally solved this problem myself -- I am responding to my own message on these mailing lists in case this information is useful to others.

In the end the solution was to add the flag "-dynamic" to the libboost_python link line. Without the flag, boost::python mostly works on BlueGene/P, but exceptions are not caught. With the flag, boost_python passes all tests I have done.

I spent some time trying to understand how to tell bjam to add a flag to the boost_python link line, but I gave up after about fifteen minutes. With the CMake build of boost, it was easy: I simply did
    cmake -DCMAKE_SHARED_LINKER_FLAGS="-dynamic"
Overall, I found dealing with the cmake build of boost so much more pleasant than dealing with bjam that I don't understand why the CMake build hasn't taken over the mainstream yet.

--Jim Amundson

P.S. The original problem report:
I have a simple test module, pyexcept
------------------------------------------------------------
#include <boost/python.hpp>
#include <iostream>
#include <stdexcept>


void
foo()
{
    std::cout << "in foo, about to raise exception\n";
    throw std::runtime_error("runtime_error from foo");
    std::cout << "this should never be seen\n";
}

using namespace boost::python;

BOOST_PYTHON_MODULE(pyexcept)
{
    def("foo",foo);
}
------------------------------------------------------------

I test it with the following python script:
------------------------------------------------------------
#!/usr/bin/env python

import pyexcept

print "about to run pyexcept.foo, catching exception"
try:
    pyexcept.foo()
except RuntimeError,e:
    print "caught RuntimeError,",e
------------------------------------------------------------

On my Linux machine I see:
------------------------------------------------------------
about to run pyexcept.foo, catching exception
in foo, about to raise exception
caught RuntimeError, runtime_error from foo
------------------------------------------------------------

On the BlueGene/P machine I see:
------------------------------------------------------------
about to run pyexcept.foo, catching exception
in foo, about to raise exception
terminate called after throwing an instance of 'std::runtime_error'
  what():  runtime_error from foo
------------------------------------------------------------

I have (cross-)compiled boost myself using the system's installed version of the gnu compilers, 4.1.2:
------------------------------------------------------------
|login2>mpicxx.gnu --version
powerpc-bgp-linux-g++ (GCC) 4.1.2 (BGP)
------------------------------------------------------------

(The mpicxx.gnu script is a wrapper around the cross-compiling g++.) Has anyone seen a problem like this? Any ideas as to how to debug it?

Thanks for any advice.

--Jim Amundson

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to