diff -up boost_1_55_0/libs/python/test/exec.cpp\~ boost_1_55_0/libs/python/test/exec.cpp
|
old
|
new
|
void eval_test()
|
| 56 | 56 | BOOST_TEST(value == "ABCDEFG"); |
| 57 | 57 | } |
| 58 | 58 | |
| | 59 | struct PyCtx |
| | 60 | { |
| | 61 | PyCtx() { |
| | 62 | Py_Initialize(); |
| | 63 | } |
| | 64 | |
| | 65 | ~PyCtx() { |
| | 66 | // N.B. certain problems may arise when Py_Finalize is called when |
| | 67 | // using Boost.Python. However in this test suite it all seems to |
| | 68 | // work fine. |
| | 69 | Py_Finalize(); |
| | 70 | } |
| | 71 | }; |
| | 72 | |
| 59 | 73 | void exec_test() |
| 60 | 74 | { |
| 61 | 75 | // Register the module with the interpreter |
| … |
… |
void exec_test()
|
| 68 | 82 | ) == -1) |
| 69 | 83 | throw std::runtime_error("Failed to add embedded_hello to the interpreter's " |
| 70 | 84 | "builtin modules"); |
| | 85 | |
| | 86 | PyCtx ctx; |
| 71 | 87 | // Retrieve the main module |
| 72 | 88 | python::object main = python::import("__main__"); |
| 73 | 89 | |
| … |
… |
void check_pyerr(bool pyerr_expected=fal
|
| 148 | 164 | } |
| 149 | 165 | } |
| 150 | 166 | |
| | 167 | template <class Cb> |
| | 168 | bool |
| | 169 | run_and_handle_exception(Cb cb, bool pyerr_expected = false) |
| | 170 | { |
| | 171 | PyCtx ctx; |
| | 172 | if (python::handle_exception(cb)) { |
| | 173 | check_pyerr(pyerr_expected); |
| | 174 | return true; |
| | 175 | } else { |
| | 176 | return false; |
| | 177 | } |
| | 178 | } |
| | 179 | |
| 151 | 180 | int main(int argc, char **argv) |
| 152 | 181 | { |
| 153 | 182 | BOOST_TEST(argc == 2 || argc == 3); |
| 154 | 183 | std::string script = argv[1]; |
| 155 | | // Initialize the interpreter |
| 156 | | Py_Initialize(); |
| 157 | 184 | |
| 158 | | if (python::handle_exception(eval_test)) { |
| 159 | | check_pyerr(); |
| 160 | | } |
| 161 | | else if(python::handle_exception(exec_test)) { |
| 162 | | check_pyerr(); |
| 163 | | } |
| 164 | | else if (python::handle_exception(boost::bind(exec_file_test, script))) { |
| | 185 | // N.B. exec_test mustn't be called through run_and_handle_exception |
| | 186 | // as it needs to handles the python context by itself. |
| | 187 | if (run_and_handle_exception(eval_test) |
| | 188 | || python::handle_exception(exec_test)) |
| 165 | 189 | check_pyerr(); |
| 166 | | } |
| 167 | | |
| 168 | | if (python::handle_exception(exec_test_error)) |
| 169 | | { |
| 170 | | check_pyerr(/*pyerr_expected*/ true); |
| 171 | | } |
| 172 | 190 | else |
| 173 | | { |
| | 191 | run_and_handle_exception(boost::bind(exec_file_test, script)); |
| | 192 | |
| | 193 | if (!run_and_handle_exception(exec_test_error, true)) |
| 174 | 194 | BOOST_ERROR("Python exception expected, but not seen."); |
| 175 | | } |
| 176 | 195 | |
| 177 | 196 | if (argc > 2) { |
| | 197 | PyCtx ctx; |
| 178 | 198 | // The main purpose is to test compilation. Since this test generates |
| 179 | 199 | // a file and I (rwgk) am uncertain about the side-effects, run it only |
| 180 | 200 | // if explicitly requested. |
| 181 | 201 | exercise_embedding_html(); |
| 182 | 202 | } |
| 183 | 203 | |
| 184 | | // Boost.Python doesn't support Py_Finalize yet. |
| 185 | | // Py_Finalize(); |
| 186 | 204 | return boost::report_errors(); |
| 187 | 205 | } |
| 188 | 206 | |