Chris@16: // (C) Copyright David Abrahams 2000. Chris@16: // Distributed under the Boost Software License, Version 1.0. (See Chris@16: // accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: // The author gratefully acknowleges the support of Dragon Systems, Inc., in Chris@16: // producing this work. Chris@16: Chris@16: #ifndef ERRORS_DWA052500_H_ Chris@16: # define ERRORS_DWA052500_H_ Chris@16: Chris@16: # include Chris@16: # include Chris@16: Chris@16: namespace boost { namespace python { Chris@16: Chris@16: struct BOOST_PYTHON_DECL_EXCEPTION error_already_set Chris@16: { Chris@16: virtual ~error_already_set(); Chris@16: }; Chris@16: Chris@16: // Handles exceptions caught just before returning to Python code. Chris@16: // Returns true iff an exception was caught. Chris@16: BOOST_PYTHON_DECL bool handle_exception_impl(function0); Chris@16: Chris@16: template Chris@16: bool handle_exception(T f) Chris@16: { Chris@16: return handle_exception_impl(function0(boost::ref(f))); Chris@16: } Chris@16: Chris@16: namespace detail { inline void rethrow() { throw; } } Chris@16: Chris@16: inline void handle_exception() Chris@16: { Chris@16: handle_exception(detail::rethrow); Chris@16: } Chris@16: Chris@16: BOOST_PYTHON_DECL void throw_error_already_set(); Chris@16: Chris@16: template Chris@16: inline T* expect_non_null(T* x) Chris@16: { Chris@16: if (x == 0) Chris@16: throw_error_already_set(); Chris@16: return x; Chris@16: } Chris@16: Chris@16: // Return source if it is an instance of pytype; throw an appropriate Chris@16: // exception otherwise. Chris@16: BOOST_PYTHON_DECL PyObject* pytype_check(PyTypeObject* pytype, PyObject* source); Chris@16: Chris@16: }} // namespace boost::python Chris@16: Chris@16: #endif // ERRORS_DWA052500_H_