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 8 # include <boost/python/detail/prefix.hpp> 9 # include <boost/python/cast.hpp> 10 11 namespace boost { namespace python { 12 13 template <class T> incref(T * p)14inline T* incref(T* p) 15 { 16 Py_INCREF(python::upcast<PyObject>(p)); 17 return p; 18 } 19 20 template <class T> xincref(T * p)21inline T* xincref(T* p) 22 { 23 Py_XINCREF(python::upcast<PyObject>(p)); 24 return p; 25 } 26 27 template <class T> decref(T * p)28inline void decref(T* p) 29 { 30 assert( Py_REFCNT(python::upcast<PyObject>(p)) > 0 ); 31 Py_DECREF(python::upcast<PyObject>(p)); 32 } 33 34 template <class T> xdecref(T * p)35inline void xdecref(T* p) 36 { 37 assert( !p || Py_REFCNT(python::upcast<PyObject>(p)) > 0 ); 38 Py_XDECREF(python::upcast<PyObject>(p)); 39 } 40 41 }} // namespace boost::python 42 43 #endif // REFCOUNT_DWA2002615_HPP 44