|
| 1 | +// Copyright Stefan Seefeld 2007. |
| 2 | +// Distributed under the Boost Software License, Version 1.0. (See |
| 3 | +// accompanying file LICENSE_1_0.txt or copy at |
| 4 | +// http://www.boost.org/LICENSE_1_0.txt) |
| 5 | + |
| 6 | +#include <boost/python.hpp> |
| 7 | + |
| 8 | +#include <boost/detail/lightweight_test.hpp> |
| 9 | +#include <iostream> |
| 10 | + |
| 11 | + |
| 12 | +namespace bpl = boost::python; |
| 13 | + |
| 14 | +void import_test() |
| 15 | +{ |
| 16 | + // Retrieve the main module |
| 17 | + bpl::object import_ = bpl::import("import_"); |
| 18 | + int value = bpl::extract<int>(import_.attr("value")) BOOST_EXTRACT_WORKAROUND; |
| 19 | + std::cout << value << std::endl; |
| 20 | + BOOST_TEST(value == 42); |
| 21 | +} |
| 22 | + |
| 23 | +int main(int argc, char **argv) |
| 24 | +{ |
| 25 | + // Initialize the interpreter |
| 26 | + Py_Initialize(); |
| 27 | + |
| 28 | + if (bpl::handle_exception(import_test)) |
| 29 | + { |
| 30 | + if (PyErr_Occurred()) |
| 31 | + { |
| 32 | + BOOST_ERROR("Python Error detected"); |
| 33 | + PyErr_Print(); |
| 34 | + } |
| 35 | + else |
| 36 | + { |
| 37 | + BOOST_ERROR("A C++ exception was thrown for which " |
| 38 | + "there was no exception handler registered."); |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + // Boost.Python doesn't support Py_Finalize yet. |
| 43 | + // Py_Finalize(); |
| 44 | + return boost::report_errors(); |
| 45 | +} |
| 46 | + |
| 47 | +// Including this file makes sure |
| 48 | +// that on Windows, any crashes (e.g. null pointer dereferences) invoke |
| 49 | +// the debugger immediately, rather than being translated into structured |
| 50 | +// exceptions that can interfere with debugging. |
| 51 | +#include "module_tail.cpp" |
0 commit comments