refcount.hpp 838 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 REFCOUNT_DWA2002615_HPP
  6. # define REFCOUNT_DWA2002615_HPP
  7. # include <boost/python/detail/prefix.hpp>
  8. # include <boost/python/cast.hpp>
  9. namespace boost { namespace python {
  10. template <class T>
  11. inline T* incref(T* p)
  12. {
  13. Py_INCREF(python::upcast<PyObject>(p));
  14. return p;
  15. }
  16. template <class T>
  17. inline T* xincref(T* p)
  18. {
  19. Py_XINCREF(python::upcast<PyObject>(p));
  20. return p;
  21. }
  22. template <class T>
  23. inline void decref(T* p)
  24. {
  25. Py_DECREF(python::upcast<PyObject>(p));
  26. }
  27. template <class T>
  28. inline void xdecref(T* p)
  29. {
  30. Py_XDECREF(python::upcast<PyObject>(p));
  31. }
  32. }} // namespace boost::python
  33. #endif // REFCOUNT_DWA2002615_HPP