Blame SOURCES/boost-1.55.0-python-test-PyImport_AppendInittab.patch

3c181a
diff -up boost_1_55_0/libs/python/test/exec.cpp\~ boost_1_55_0/libs/python/test/exec.cpp
3c181a
--- boost_1_55_0/libs/python/test/exec.cpp~	2010-07-05 00:38:38.000000000 +0200
3c181a
+++ boost_1_55_0/libs/python/test/exec.cpp	2015-01-09 21:31:12.903218280 +0100
3c181a
@@ -56,6 +56,20 @@ void eval_test()
3c181a
   BOOST_TEST(value == "ABCDEFG");
3c181a
 }
3c181a
 
3c181a
+struct PyCtx
3c181a
+{
3c181a
+  PyCtx() {
3c181a
+    Py_Initialize();
3c181a
+  }
3c181a
+
3c181a
+  ~PyCtx() {
3c181a
+    // N.B. certain problems may arise when Py_Finalize is called when
3c181a
+    // using Boost.Python.  However in this test suite it all seems to
3c181a
+    // work fine.
3c181a
+    Py_Finalize();
3c181a
+  }
3c181a
+};
3c181a
+
3c181a
 void exec_test()
3c181a
 {
3c181a
   // Register the module with the interpreter
3c181a
@@ -68,6 +82,8 @@ void exec_test()
3c181a
                              ) == -1) 
3c181a
     throw std::runtime_error("Failed to add embedded_hello to the interpreter's "
3c181a
                  "builtin modules");
3c181a
+
3c181a
+  PyCtx ctx;
3c181a
   // Retrieve the main module
3c181a
   python::object main = python::import("__main__");
3c181a
   
3c181a
@@ -148,41 +164,43 @@ void check_pyerr(bool pyerr_expected=fal
3c181a
   }
3c181a
 }
3c181a
 
3c181a
+template <class Cb>
3c181a
+bool
3c181a
+run_and_handle_exception(Cb cb, bool pyerr_expected = false)
3c181a
+{
3c181a
+  PyCtx ctx;
3c181a
+  if (python::handle_exception(cb)) {
3c181a
+    check_pyerr(pyerr_expected);
3c181a
+    return true;
3c181a
+  } else {
3c181a
+    return false;
3c181a
+  }
3c181a
+}
3c181a
+
3c181a
 int main(int argc, char **argv)
3c181a
 {
3c181a
   BOOST_TEST(argc == 2 || argc == 3);
3c181a
   std::string script = argv[1];
3c181a
-  // Initialize the interpreter
3c181a
-  Py_Initialize();
3c181a
 
3c181a
-  if (python::handle_exception(eval_test)) {
3c181a
-    check_pyerr();
3c181a
-  }
3c181a
-  else if(python::handle_exception(exec_test)) {
3c181a
-    check_pyerr();
3c181a
-  }
3c181a
-  else if (python::handle_exception(boost::bind(exec_file_test, script))) {
3c181a
+  // N.B. exec_test mustn't be called through run_and_handle_exception
3c181a
+  // as it needs to handles the python context by itself.
3c181a
+  if (run_and_handle_exception(eval_test)
3c181a
+      || python::handle_exception(exec_test))
3c181a
     check_pyerr();
3c181a
-  }
3c181a
-  
3c181a
-  if (python::handle_exception(exec_test_error))
3c181a
-  {
3c181a
-    check_pyerr(/*pyerr_expected*/ true);
3c181a
-  }
3c181a
   else
3c181a
-  {
3c181a
+    run_and_handle_exception(boost::bind(exec_file_test, script));
3c181a
+
3c181a
+  if (!run_and_handle_exception(exec_test_error, true))
3c181a
     BOOST_ERROR("Python exception expected, but not seen.");
3c181a
-  }
3c181a
 
3c181a
   if (argc > 2) {
3c181a
+    PyCtx ctx;
3c181a
     // The main purpose is to test compilation. Since this test generates
3c181a
     // a file and I (rwgk) am uncertain about the side-effects, run it only
3c181a
     // if explicitly requested.
3c181a
     exercise_embedding_html();
3c181a
   }
3c181a
 
3c181a
-  // Boost.Python doesn't support Py_Finalize yet.
3c181a
-  // Py_Finalize();
3c181a
   return boost::report_errors();
3c181a
 }
3c181a
 
3c181a
3c181a
Diff finished.  Fri Jan  9 21:31:13 2015