From bc2f77a3db0b3b428ef7bc205804ce5625e46001 Mon Sep 17 00:00:00 2001 From: WKarel Date: Thu, 29 Sep 2016 13:48:46 +0200 Subject: [PATCH] Assert refcount before decrement (#64) Assert reference count before decrementing it. --- include/boost/python/object_core.hpp | 1 + include/boost/python/refcount.hpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/include/boost/python/object_core.hpp b/include/boost/python/object_core.hpp index 61857796..209310ff 100644 --- a/include/boost/python/object_core.hpp +++ b/include/boost/python/object_core.hpp @@ -422,6 +422,7 @@ inline api::object_base& api::object_base::operator=(api::object_base const& rhs inline api::object_base::~object_base() { + assert( Py_REFCNT(m_ptr) > 0 ); Py_DECREF(m_ptr); } diff --git a/include/boost/python/refcount.hpp b/include/boost/python/refcount.hpp index 5ba5433c..aa6aa5db 100755 --- a/include/boost/python/refcount.hpp +++ b/include/boost/python/refcount.hpp @@ -27,12 +27,14 @@ inline T* xincref(T* p) template inline void decref(T* p) { + assert( Py_REFCNT(python::upcast(p)) > 0 ); Py_DECREF(python::upcast(p)); } template inline void xdecref(T* p) { + assert( !p || Py_REFCNT(python::upcast(p)) > 0 ); Py_XDECREF(python::upcast(p)); }