1 // Copyright David Abrahams 2002.
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 #ifndef SCOPE_DWA2002724_HPP
6 # define SCOPE_DWA2002724_HPP
8 # include <boost/python/detail/prefix.hpp>
9 # include <boost/python/object.hpp>
10 # include <boost/python/refcount.hpp>
12 namespace boost { namespace python {
16 // Making this a namespace-scope variable to avoid Cygwin issues.
17 // Use a PyObject* to avoid problems with static destruction after Py_Finalize
18 extern BOOST_PYTHON_DECL PyObject* current_scope;
25 inline scope(scope const&);
26 inline scope(object const&);
30 private: // data members
31 PyObject* m_previous_scope;
33 private: // unimplemented functions
34 void operator=(scope const&);
37 inline scope::scope(object const& new_scope)
39 , m_previous_scope(detail::current_scope)
41 detail::current_scope = python::incref(new_scope.ptr());
45 : object(detail::borrowed_reference(
46 detail::current_scope ? detail::current_scope : Py_None
48 , m_previous_scope(python::xincref(detail::current_scope))
52 inline scope::~scope()
54 python::xdecref(detail::current_scope);
55 detail::current_scope = m_previous_scope;
61 struct object_manager_traits<scope>
62 : object_manager_traits<object>
67 // Placing this after the specialization above suppresses a CWPro8.3 bug
68 inline scope::scope(scope const& new_scope)
70 , m_previous_scope(detail::current_scope)
72 detail::current_scope = python::incref(new_scope.ptr());
75 }} // namespace boost::python
77 #endif // SCOPE_DWA2002724_HPP