mirror of
https://github.com/boostorg/python.git
synced 2026-01-24 18:12:43 +00:00
Added a little crude leak-checking code
[SVN r8228]
This commit is contained in:
15
extclass.cpp
15
extclass.cpp
@@ -8,17 +8,24 @@
|
||||
|
||||
#include "extclass.h"
|
||||
#include <cstring>
|
||||
#include <boost/utility.hpp>
|
||||
|
||||
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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user