Chris@16: // Copyright David Abrahams 2002. 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: #ifndef SCOPE_DWA2002724_HPP Chris@16: # define SCOPE_DWA2002724_HPP Chris@16: Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: Chris@16: namespace boost { namespace python { Chris@16: Chris@16: namespace detail Chris@16: { Chris@16: // Making this a namespace-scope variable to avoid Cygwin issues. Chris@16: // Use a PyObject* to avoid problems with static destruction after Py_Finalize Chris@16: extern BOOST_PYTHON_DECL PyObject* current_scope; Chris@16: } Chris@16: Chris@16: class scope Chris@16: : public object Chris@16: { Chris@16: public: Chris@16: inline scope(scope const&); Chris@16: inline scope(object const&); Chris@16: inline scope(); Chris@16: inline ~scope(); Chris@16: Chris@16: private: // data members Chris@16: PyObject* m_previous_scope; Chris@16: Chris@16: private: // unimplemented functions Chris@16: void operator=(scope const&); Chris@16: }; Chris@16: Chris@16: inline scope::scope(object const& new_scope) Chris@16: : object(new_scope) Chris@16: , m_previous_scope(detail::current_scope) Chris@16: { Chris@16: detail::current_scope = python::incref(new_scope.ptr()); Chris@16: } Chris@16: Chris@16: inline scope::scope() Chris@16: : object(detail::borrowed_reference( Chris@16: detail::current_scope ? detail::current_scope : Py_None Chris@16: )) Chris@16: , m_previous_scope(python::xincref(detail::current_scope)) Chris@16: { Chris@16: } Chris@16: Chris@16: inline scope::~scope() Chris@16: { Chris@16: python::xdecref(detail::current_scope); Chris@16: detail::current_scope = m_previous_scope; Chris@16: } Chris@16: Chris@16: namespace converter Chris@16: { Chris@16: template <> Chris@16: struct object_manager_traits Chris@16: : object_manager_traits Chris@16: { Chris@16: }; Chris@16: } Chris@16: Chris@16: // Placing this after the specialization above suppresses a CWPro8.3 bug Chris@16: inline scope::scope(scope const& new_scope) Chris@16: : object(new_scope) Chris@16: , m_previous_scope(detail::current_scope) Chris@16: { Chris@16: detail::current_scope = python::incref(new_scope.ptr()); Chris@16: } Chris@16: Chris@16: }} // namespace boost::python Chris@16: Chris@16: #endif // SCOPE_DWA2002724_HPP