]> git.ipfire.org Git - people/pmueller/ipfire-3.x.git/blame - boost/patches/boost-1.55.0-python-test-PyImport_AppendInittab.patch
] boost: Update to 1.60.0.
[people/pmueller/ipfire-3.x.git] / boost / patches / boost-1.55.0-python-test-PyImport_AppendInittab.patch
CommitLineData
cbe7d7b5
SS
1diff -up boost_1_55_0/libs/python/test/exec.cpp\~ boost_1_55_0/libs/python/test/exec.cpp
2--- boost_1_55_0/libs/python/test/exec.cpp~ 2010-07-05 00:38:38.000000000 +0200
3+++ boost_1_55_0/libs/python/test/exec.cpp 2015-01-09 21:31:12.903218280 +0100
4@@ -56,6 +56,20 @@ void eval_test()
5 BOOST_TEST(value == "ABCDEFG");
6 }
7
8+struct PyCtx
9+{
10+ PyCtx() {
11+ Py_Initialize();
12+ }
13+
14+ ~PyCtx() {
15+ // N.B. certain problems may arise when Py_Finalize is called when
16+ // using Boost.Python. However in this test suite it all seems to
17+ // work fine.
18+ Py_Finalize();
19+ }
20+};
21+
22 void exec_test()
23 {
24 // Register the module with the interpreter
25@@ -68,6 +82,8 @@ void exec_test()
26 ) == -1)
27 throw std::runtime_error("Failed to add embedded_hello to the interpreter's "
28 "builtin modules");
29+
30+ PyCtx ctx;
31 // Retrieve the main module
32 python::object main = python::import("__main__");
33
34@@ -148,41 +164,43 @@ void check_pyerr(bool pyerr_expected=fal
35 }
36 }
37
38+template <class Cb>
39+bool
40+run_and_handle_exception(Cb cb, bool pyerr_expected = false)
41+{
42+ PyCtx ctx;
43+ if (python::handle_exception(cb)) {
44+ check_pyerr(pyerr_expected);
45+ return true;
46+ } else {
47+ return false;
48+ }
49+}
50+
51 int main(int argc, char **argv)
52 {
53 BOOST_TEST(argc == 2 || argc == 3);
54 std::string script = argv[1];
55- // Initialize the interpreter
56- Py_Initialize();
57
58- if (python::handle_exception(eval_test)) {
59- check_pyerr();
60- }
61- else if(python::handle_exception(exec_test)) {
62- check_pyerr();
63- }
64- else if (python::handle_exception(boost::bind(exec_file_test, script))) {
65+ // N.B. exec_test mustn't be called through run_and_handle_exception
66+ // as it needs to handles the python context by itself.
67+ if (run_and_handle_exception(eval_test)
68+ || python::handle_exception(exec_test))
69 check_pyerr();
70- }
71-
72- if (python::handle_exception(exec_test_error))
73- {
74- check_pyerr(/*pyerr_expected*/ true);
75- }
76 else
77- {
78+ run_and_handle_exception(boost::bind(exec_file_test, script));
79+
80+ if (!run_and_handle_exception(exec_test_error, true))
81 BOOST_ERROR("Python exception expected, but not seen.");
82- }
83
84 if (argc > 2) {
85+ PyCtx ctx;
86 // The main purpose is to test compilation. Since this test generates
87 // a file and I (rwgk) am uncertain about the side-effects, run it only
88 // if explicitly requested.
89 exercise_embedding_html();
90 }
91
92- // Boost.Python doesn't support Py_Finalize yet.
93- // Py_Finalize();
94 return boost::report_errors();
95 }
96
97
98Diff finished. Fri Jan 9 21:31:13 2015