sl@0: // Copyright David Abrahams 2002. sl@0: // Distributed under the Boost Software License, Version 1.0. (See sl@0: // accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: #ifndef SCOPE_DWA2002724_HPP sl@0: # define SCOPE_DWA2002724_HPP sl@0: sl@0: # include sl@0: # include sl@0: # include sl@0: # include sl@0: sl@0: namespace boost { namespace python { sl@0: sl@0: namespace detail sl@0: { sl@0: // Making this a namespace-scope variable to avoid Cygwin issues. sl@0: // Use a PyObject* to avoid problems with static destruction after Py_Finalize sl@0: extern BOOST_PYTHON_DECL PyObject* current_scope; sl@0: } sl@0: sl@0: class scope sl@0: : public object sl@0: { sl@0: public: sl@0: inline scope(scope const&); sl@0: inline scope(object const&); sl@0: inline scope(); sl@0: inline ~scope(); sl@0: sl@0: private: // data members sl@0: PyObject* m_previous_scope; sl@0: sl@0: private: // unimplemented functions sl@0: void operator=(scope const&); sl@0: }; sl@0: sl@0: inline scope::scope(object const& new_scope) sl@0: : object(new_scope) sl@0: , m_previous_scope(detail::current_scope) sl@0: { sl@0: detail::current_scope = python::incref(new_scope.ptr()); sl@0: } sl@0: sl@0: inline scope::scope() sl@0: : object(detail::borrowed_reference( sl@0: detail::current_scope ? detail::current_scope : Py_None sl@0: )) sl@0: , m_previous_scope(python::xincref(detail::current_scope)) sl@0: { sl@0: } sl@0: sl@0: inline scope::~scope() sl@0: { sl@0: python::xdecref(detail::current_scope); sl@0: detail::current_scope = m_previous_scope; sl@0: } sl@0: sl@0: namespace converter sl@0: { sl@0: template <> sl@0: struct object_manager_traits sl@0: : object_manager_traits sl@0: { sl@0: }; sl@0: } sl@0: sl@0: // Placing this after the specialization above suppresses a CWPro8.3 bug sl@0: inline scope::scope(scope const& new_scope) sl@0: : object(new_scope) sl@0: , m_previous_scope(detail::current_scope) sl@0: { sl@0: detail::current_scope = python::incref(new_scope.ptr()); sl@0: } sl@0: sl@0: }} // namespace boost::python sl@0: sl@0: #endif // SCOPE_DWA2002724_HPP