decref_guard.hpp 572 B

123456789101112131415161718192021
  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 DECREF_GUARD_DWA20021220_HPP
  6. # define DECREF_GUARD_DWA20021220_HPP
  7. namespace boost { namespace python { namespace detail {
  8. struct decref_guard
  9. {
  10. decref_guard(PyObject* o) : obj(o) {}
  11. ~decref_guard() { Py_XDECREF(obj); }
  12. void cancel() { obj = 0; }
  13. private:
  14. PyObject* obj;
  15. };
  16. }}} // namespace boost::python::detail
  17. #endif // DECREF_GUARD_DWA20021220_HPP