Advertisement
Guest User

Untitled

a guest
Nov 5th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <cmath>
  2. #include <boost/Python.h>
  3.  
  4. float func( int a )
  5. {
  6.     return a*a-0.5;
  7. }
  8.  
  9. BOOST_PYTHON_MODULE(test_module)
  10. {
  11.     using namespace boost::python;
  12.     def("func", func);
  13. }
  14.  
  15. int main()
  16. {
  17.     //Try one
  18.     boost::python::exec("b = 5");
  19.     //Crash
  20.  
  21.     //Try two
  22.     Py_Initialize();
  23.     boost::python::exec("b = 5");
  24.     //Works fine
  25.  
  26.     //Try three
  27.     Py_Initialize();
  28.     boost::python::exec("import test_module");
  29.     //Throws boost::python::error_already_set and crashes
  30.  
  31.     /*
  32.     Something along the lines of
  33.     boost::python::exec("import test_module\n"
  34.                 "var = test_module.func( 3 )\n");
  35.     */    
  36.    
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement