tnintemann / rpms / boost

Forked from rpms/boost 3 years ago
Clone

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

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