From b84e3a7983862f34db743acf2fd29e7150b2a599 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Thu, 16 Nov 2000 17:13:11 +0000 Subject: [PATCH] Added a little crude leak-checking code [SVN r8228] --- extclass.cpp | 15 +++++++++++++++ extclass_demo.cpp | 31 +++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/extclass.cpp b/extclass.cpp index 13efee83..a30cfa36 100644 --- a/extclass.cpp +++ b/extclass.cpp @@ -8,17 +8,24 @@ #include "extclass.h" #include +#include namespace py { namespace detail { struct operator_dispatcher : public PyObject +#ifndef NDEBUG + , boost::noncopyable +#endif { static PyTypeObject type_object; static PyNumberMethods number_methods; operator_dispatcher(const Ptr& o, const Ptr& s); +#ifndef NDEBUG + ~operator_dispatcher(); +#endif static void dealloc(PyObject* self); static int coerce(PyObject** l, PyObject** r); static PyObject* call_add(PyObject*, PyObject*); @@ -507,11 +514,19 @@ PyNumberMethods operator_dispatcher::number_methods = 0 }; +#ifndef NDEBUG +int total_Dispatchers = 0; +operator_dispatcher::~operator_dispatcher() { --total_Dispatchers; } +#endif + operator_dispatcher::operator_dispatcher(const Ptr& o, const Ptr& s) : m_object(o), m_self(s) { ob_refcnt = 1; ob_type = &type_object; +#ifndef NDEBUG + ++total_Dispatchers; +#endif } void operator_dispatcher::dealloc(PyObject* self) diff --git a/extclass_demo.cpp b/extclass_demo.cpp index 0386f3fc..ff56299f 100644 --- a/extclass_demo.cpp +++ b/extclass_demo.cpp @@ -641,9 +641,22 @@ struct Fubar { /* */ /************************************************************/ +#ifndef NDEBUG +int total_Ints = 0; +#endif + struct Int { - explicit Int(int i) : i_(i) { } + explicit Int(int i) : i_(i) { +#ifndef NDEBUG + ++total_Ints; +#endif + } + +#ifndef NDEBUG + ~Int() { --total_Ints; } + Int(const Int& rhs) : i_(rhs.i_) { ++total_Ints; } +#endif int i() const { return i_; } @@ -1032,6 +1045,10 @@ extern "C" void structured_exception_translator(unsigned int, EXCEPTION_POINTERS } # endif +#ifndef NDEBUG +namespace py { namespace detail { extern int total_Dispatchers; }} +#endif + BOOL WINAPI DllMain( HINSTANCE, //hDllInst DWORD fdwReason, @@ -1041,7 +1058,17 @@ BOOL WINAPI DllMain( # ifdef PY_COMPILER_IS_MSVC _set_se_translator(structured_exception_translator); #endif - return 1; (void)fdwReason; // warning suppression. + +#ifndef NDEBUG + switch(fdwReason) + { + case DLL_PROCESS_DETACH: + assert(extclass_demo::total_Ints == 0); + assert(py::detail::total_Dispatchers == 0); + } +#endif + + return 1; } #endif // _WIN32