Skip to content

Commit bc2f77a

Browse files
WKarelstefanseefeld
authored andcommitted
Assert refcount before decrement (boostorg#64)
Assert reference count before decrementing it.
1 parent aaf0d22 commit bc2f77a

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

include/boost/python/object_core.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ inline api::object_base& api::object_base::operator=(api::object_base const& rhs
422422

423423
inline api::object_base::~object_base()
424424
{
425+
assert( Py_REFCNT(m_ptr) > 0 );
425426
Py_DECREF(m_ptr);
426427
}
427428

include/boost/python/refcount.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ inline T* xincref(T* p)
2727
template <class T>
2828
inline void decref(T* p)
2929
{
30+
assert( Py_REFCNT(python::upcast<PyObject>(p)) > 0 );
3031
Py_DECREF(python::upcast<PyObject>(p));
3132
}
3233

3334
template <class T>
3435
inline void xdecref(T* p)
3536
{
37+
assert( !p || Py_REFCNT(python::upcast<PyObject>(p)) > 0 );
3638
Py_XDECREF(python::upcast<PyObject>(p));
3739
}
3840

0 commit comments

Comments
 (0)