From 9289748ceda0195c346437632be8558587441287 Mon Sep 17 00:00:00 2001 From: Andreas Monzner Date: Tue, 10 Jan 2006 14:23:28 +0000 Subject: [PATCH] add a dummy class to debug python refcounting (add entrys of TestObj to your tuple or list) include and use New_TestObj to create a testobject.. --- lib/python/enigma_python.i | 7 +++++++ lib/python/python.cpp | 12 ++++++++++++ lib/python/python.h | 20 ++++++++++++++++++-- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/lib/python/enigma_python.i b/lib/python/enigma_python.i index 16ca40c..5a6f126 100644 --- a/lib/python/enigma_python.i +++ b/lib/python/enigma_python.i @@ -79,6 +79,7 @@ is usually caused by not marking PSignals as immutable. #include #include #include +#include extern void runMainloop(); extern void quitMainloop(int exit_code); @@ -182,6 +183,7 @@ typedef long time_t; %include %include %include +%include /************** eptr **************/ %template(eActionMapPtr) ePtr; @@ -243,4 +245,9 @@ RESULT SwigFromPython(ePtr &result, PyObject *obj) result = *res; return 0; } +PyObject *New_TestObj() +{ + TestObj *result = (TestObj *)new TestObj(); + return SWIG_NewPointerObj((void*)(result), SWIGTYPE_p_TestObj, 1); +} %} diff --git a/lib/python/python.cpp b/lib/python/python.cpp index 642d70b..f467bc8 100644 --- a/lib/python/python.cpp +++ b/lib/python/python.cpp @@ -4,6 +4,18 @@ extern "C" void init_enigma(); +DEFINE_REF(TestObj); + +TestObj::TestObj() +{ + eDebug("create %p", this); +} + +TestObj::~TestObj() +{ + eDebug("destroy %p", this); +} + #if 0 ePyObject::ePyObject(void *ptr): m_object(ptr) { diff --git a/lib/python/python.h b/lib/python/python.h index e9a2b8d..46e1a03 100644 --- a/lib/python/python.h +++ b/lib/python/python.h @@ -2,7 +2,24 @@ #define __lib_python_python_h #include +#include +typedef struct _object PyObject; + +// useable for debugging python refcounting + +extern PyObject *New_TestObj(); + +class TestObj +{ +DECLARE_REF(TestObj); +public: + TestObj(); + ~TestObj(); +}; +TEMPLATE_TYPEDEF(ePtr, TestObjPtr); + +#ifndef SWIG /* class ePyObject { void *m_object; @@ -16,8 +33,6 @@ public: void *get() { return m_object; } }; */ -typedef struct _object PyObject; - class ePython { public: @@ -28,5 +43,6 @@ public: static PyObject *resolve(const std::string &pythonfile, const std::string &funcname); private: }; +#endif // SWIG #endif -- 2.7.4