Original Post
I'm using boost to export an interface to python, however, I've run into some problems with sending strings from python to C++. Whenever I attempt to do so, the program crashes with an access violation. I've narrowed it down to this code which causes the same error. The function run in module run imports c1 and then calls print_it. There is a breakpoint on the first line of print_it but it is never reached. Am I missing some integral step in getting strings to work in boost python? I've searched on the internet but can't find anything pertinent, and the examples on the boost python website seem to use strings with no additional setup. Thanks in advance for any help.
void print_it(string data)
{
cout << data;
}
BOOST_PYTHON_MODULE(c1)
{
def("print_it", &print_it);
}
Scripts::Scripts(string module)
{
Py_Initialize();
initc1();
try
{
object name = str("run");
_MainModule = object( handle<>( borrowed( PyImport_Import(name.ptr()) ) ) );
object d = _MainModule.attr("__dict__");
_Start = d["run"];
}
catch(error_already_set)
{
PyErr_Print();
throw;
}
_Start();
}